Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 97e00b735e
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 183 lines (160 sloc) 4.056 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
// ========================================
// TEXT PATTERN
// ========================================

struct StringSide
{
  unsigned char charIndex;
  unsigned char charVal;
  unsigned char numCols;
  unsigned char colIndex;
};

Tpattern patText;
Tmessage *activeMessage;
unsigned char patTextFGcmd;
unsigned char patTextBGcmd;
unsigned char patTextNumChars;
StringSide patTextL;
StringSide patTextR;
Tmessage *patTextMessage;
String *patTextS;
int patTextMessageIndex = 0;
unsigned char doRandomizeTextColor = true;

void toggleTextColorRandomize()
{
  doRandomizeTextColor = 1-doRandomizeTextColor;
}

void setTextColorRandomize(unsigned char state)
{
  doRandomizeTextColor = state;
}

void selectMessage(int index)
{
  //patTextMessageIndex = index % numMessages;
  patTextMessageIndex = index % 4;
  //
  Tmessage *msg = &RopeMessages[patTextMessageIndex];
  patTextS = msg->message;
  patTextNumChars = patTextS->length();
  Tpattern *pat = &patText;
  pat->length = getStringWidth(patTextS);
  patTextFGcmd = msg->fgCmd;
  patTextBGcmd = msg->bgCmd;
  //
  patTextL.charIndex = patTextNumChars-1;
  patTextL.charVal = patTextS->charAt(patTextL.charIndex);
  patTextL.numCols = getCharWidth(patTextL.charVal);
  patTextL.colIndex = patTextL.numCols-1;
  patTextR.charIndex = 0;
  patTextR.charVal = patTextS->charAt(patTextR.charIndex);
  patTextR.numCols = getCharWidth(patTextR.charVal);
  patTextR.colIndex = 0;
}

void initPatText()
{
  selectMessage(0);
  Tpattern *pat = &patText;
  pat->length = getStringWidth(patTextS);
  pat->pos = 0;
  pat->repeats = 0;
  pat->count = 0;
  pat->restart = &patTextRestart;
  pat->paint = &patTextPaint;
  pat->randomize = &patTextRandomize;
}

int pcycle = 0;

void patTextRestart()
{
  selectMessage(pcycle);
  if (doRandomizeTextColor) patTextRandomFGcolor();
  pcycle++;
  pcycle %= 4;
}

void patTextPaint(int index)
{
   // LEFT SIDE
   set2CpatternL(getCharColumn(patTextL.charVal,patTextL.colIndex),patTextBGcmd,patTextFGcmd);
   if(patTextL.colIndex > 0)
   {
     patTextL.colIndex--;
   }
   else
   {
     // reached leftmost side of character. go to next character
     if (patTextL.charIndex > 0)
     {
       patTextL.charIndex--;
     }
     else
     {
       // !!! now what? out of characters! wraparound.
       patTextL.charIndex = patTextNumChars-1;
     }
     patTextL.charVal = patTextS->charAt(patTextL.charIndex);
     patTextL.numCols = getCharWidth(patTextL.charVal);
     patTextL.colIndex = patTextL.numCols-1;
   }
   
   // RIGHT SIDE
   set2CpatternR(getCharColumn(patTextR.charVal,patTextR.colIndex),patTextBGcmd,patTextFGcmd);
   if (patTextR.colIndex < patTextR.numCols-1)
   {
     patTextR.colIndex++;
   }
   else
   {
     // reached rightmost side of character. go to next character.
     if (patTextR.charIndex < (patTextNumChars-1))
     {
       patTextR.charIndex++;
     }
     else
     {
       // !!! now what? out of characters! wraparound.
       patTextR.charIndex = 0;
     }
     patTextR.charVal = patTextS->charAt(patTextR.charIndex);
     patTextR.numCols = getCharWidth(patTextR.charVal);
     patTextR.colIndex = 0;
   }
 }

// ===================



// -------------------------------------------------------------------


void patText_setFGcolor(int red, int green, int blue)
{
   patTextFGcmd = getRopeCommand(red,green,blue);
}

void patText_setBGcolor(int red, int green, int blue)
{
  patTextBGcmd = getRopeCommand(red,green,blue);
}

void patTextRandomColor()
{
  patTextRandomFGcolor();
  patTextRandomBGcolor();
}

void patTextRandomFGcolor()
{
  unsigned char ok = false;
  while(!ok)
  {
    patTextFGcmd = getRopeCommand(random(2),random(2),random(2));
    ok = (patTextFGcmd != 0x80);
  }
}

void patTextRandomBGcolor()
{
  unsigned char ok = false;
  while(!ok)
  {
    patTextBGcmd = getRopeCommand(random(2),random(2),random(2));
    ok = (patTextBGcmd != 0x80);
  }
}

void cycleMessage()
{
    selectMessage(patTextMessageIndex++);
}

void patTextRandomize()
{
  selectMessage(random(numMessages));
  patTextRandomColor();
}
Something went wrong with that request. Please try again.