Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace script strings
- {
- define H_SPACE = 10;
- define V_LINE_W = 180;
- define V_LINE_CHARS = V_LINE_W/9;
- define PAGE_H = 180;
- define MAX_LINES = PAGE_H/H_SPACE;
- //10 px height,
- define X = 16;
- define Y = 16;
- define LAYER = 6;
- define FONT = FONT_APPLEII;
- define FONT_COLOUR = 0x01;
- define FONT_BG_COLOUR = -1;
- define FONT_OPACITY = OP_OPAQUE;
- define CHAR_W = 8;
- define CHAR_H = 8;
- define CHAR_KERNING = 1;
- define LINE_KERNING = 2;
- define TAB_WIDTH = CHAR_W*4;
- void DrawPage(int buffer, int dest) //font MUST be monospaced
- {
- Screen->SetRenderTarget(dest);
- int x; int y;
- //Using DrawChars()
- for ( int q = 0; buffer[bufferPos]; ++bufferPos )
- {
- if ( buffer[bufferPos] == CHAR_CR ) { y += CHAR_H+LINE_KERNING; x = X; }
- if ( buffer[bufferPos] == CHAR_LF ) { y += CHAR_H+LINE_KERNING; x = X; }
- if ( buffer[bufferPos] == CHAR_TAB ) { x += TAB_WIDTH; }
- Screen->DrawCharacter(LAYER, X+x, Y+y. FONT, FONT_COLOUR, FONT_BG_COLOUR, -1, -1, buffer[bufferPos], FONT_OPACITY);
- x+= CHAR_W+CHAR_KERNING;
- }
- }
- //call for every keypress, and check the rval
- int WriteBuffer(int buffer)
- {
- int rval;
- int linePos; //vertical:
- int charPos; //the horizontal position. we increment this for every character that we press.
- //This allows tracking with arrow keys.
- //If we hit return, we reset this to 0.
- int bufferEnd; //this tracks the full buffer size at all times.
- if ( ReadKey(KEY_UP) )
- {
- //move back a number of chars equal to the width of one line, minus charPos.
- rval = KEY_DOWN; //We use this to know that if we are at the head of a drawn area, to reverse the drawn area by one line.
- }
- if ( ReadKey(KEY_UP) )
- {
- //move forward a number of chars equal to the width of one line, minus charPos, or tot he END of the buffer.
- rval = KEY_DOWN; //We use this to know that if we are at the end of a drawn area, to advance the drawn area by one line.
- }
- if ( ReadKey(KEY_LEFT) )
- {
- //adjust bufferPos by -1;
- if ( bufferPos > 0 ) --bufferPos;
- //if we are at the top-left of a draw area, and there is more text above, we return rval to move the lines into view.
- rval = KEY_LEFT;
- }
- if ( ReadKey(KEY_RIGHT) )
- {
- //adjust bufferPos by +1;
- if ( bufferPos < sizeof(buffer)-1 ) ++bufferPos;
- //if we are at the bottom-right of a draw area, and there is more text below, we return rval to move the lines into view.
- rval = KEY_RIGHT;
- }
- if ( ReadKey(KEY_ENTER) || ReadKey(KEY_ENTER_PAD) )
- {
- buffer[bufferPos] = CHAR_LF;
- ++bufferPos;
- rval = CHAR_LF; //if we are on the lowest line, we use this to pan up one line whwn creating the new line.
- }
- if ( ReadKey(KEY_TAB) )
- {
- buffer[bufferPos] = CHAR_TAB;
- ++bufferPos;
- }
- if ( ReadKey(KEY_BACKSPACE) )
- {
- //shift all chars in the buffer to the lef tone position?
- //that could be horribly slow. Perhaps we insert a blank char, and skip over it when processing?
- //that seems as if it would be far more efficient.
- //When processinmg, if we encounter that char, we decrement the position in the dest buffers, and
- //then we continue.
- rval = CHAR_BACKSPACE;
- //Again, if we are on the left edge of a line, and at the top line drawn, and there is text above, we pan up.
- }
- if ( ReadKey(KEY_DEL) )
- {
- //The logic for this one is more complex, and I may skip it for now.
- }
- }
- void DrawPage(int buffer, int dest, int y) //font MUST be monospaced; specify the BASE y value. This allows paging up and down.
- {
- Screen->SetRenderTarget(dest);
- int x;
- //Using DrawChars()
- for ( int q = 0; buffer[bufferPos]; ++bufferPos )
- {
- if ( buffer[bufferPos] == CHAR_CR ) { y += CHAR_H+LINE_KERNING; x = X; }
- if ( buffer[bufferPos] == CHAR_LF ) { y += CHAR_H+LINE_KERNING; x = X; }
- if ( buffer[bufferPos] == CHAR_TAB ) { x += TAB_WIDTH; }
- Screen->DrawCharacter(LAYER, X+x, Y+y. FONT, FONT_COLOUR, FONT_BG_COLOUR, -1, -1, buffer[bufferPos], FONT_OPACITY);
- x+= CHAR_W+CHAR_KERNING;
- }
- }
- void DrawPage(int buffer)
- {
- int bufferPos;
- int x; int y;
- do
- {
- int tempPos;
- int temp[V_LINE_CHARS];
- for ( ; ( buffer[bufferPos] != CHAR_CR || buffer[bufferPos] != CHAR_LF || buffer[bufferPos] != NULL ); ++bufferPos ) //until the position == NULL
- {
- //copy chars to the buffer until we hit a CR
- temp[tempPos] = buffer[bufferPos];
- ++tempPos;
- }
- //draw it
- Screen->DrawString(LAYER, x, y, FONT, FONT_COLOUR, FONT_BG_COLOUR, 0, temp, FONT_OPACITY);
- //increase Y pos
- y += H_SPACE;
- //resume with new string.
- }while(buffer[bufferPos]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement