コード例 #1
0
ファイル: terminal.c プロジェクト: lberezy/avr_boot
void term_draw(terminal_t* term) {
  uint8_t max_rows = term->rows;
  uint8_t cursor_current_col = term->cursor_y;
  for(uint8_t y = 0; y < max_rows;  y++) {
    //uint8_t scrolling_row = ((( cursor_current_col - y ) % max_rows) + max_rows) % max_rows;
    //uint8_t scrolling_row = ((( cursor_current_col + y ) % max_rows) + max_rows) % max_rows;
    uint8_t scrolling_row = ( cursor_current_col + y  + 1) % (max_rows);

    for(uint8_t x = 0; x < term->width; x++) {
      gfx_draw_char(x * FONT_GLYPH_WIDTH, y, term->buffer[(scrolling_row * (term->width)) + x ]);
      //gfx_draw_char(x*FONT_GLYPH_WIDTH, y, term->buffer[(y * term->width) + x]);
    }
  }
}
コード例 #2
0
ファイル: graphics.c プロジェクト: lberezy/avr_boot
void gfx_draw_string(uint8_t x, uint8_t line, const char* str) {
  uint8_t cursor_x = x;
  uint8_t cursor_y = line;
  while(*str != '\0') {
    // Go to next line if character won't fit or newline character encountered
    if ((cursor_x + FONT_GLYPH_WIDTH) > DISPLAY_WIDTH || *str == '\n') {
      if (cursor_y + 1 <= (DISPLAY_HEIGHT / 8)) {
        cursor_y++;   //  move y cursor down one line
        cursor_x = 0; // reset x cursor to start of new line
      } else {
        return; // ran out of space for more characters on screen
      }
    }

    gfx_draw_char(cursor_x, cursor_y, *str);
    cursor_x += 1 + FONT_GLYPH_WIDTH; // increment cursor pos by width of character + 1 pixel
    str++; // increment string pointer
  }
}
コード例 #3
0
ファイル: gfx_text.c プロジェクト: warezak/PoundNineNewsWire
/**
 * \brief Draws an aligned string located in program memory to the display
 *
 * This function will draw a string located in program memory to the display
 * with the specified alignment. This differs from gfx_draw_aligned_string() by
 * using constant string data from the program memory instead of string data in
 * RAM.
 *
 * \param str         Pointer to string located in program memory
 * \param x           X coordinate on screen.
 * \param y           Y coordinate on screen.
 * \param font        Font to draw string in
 * \param bg_color    Background color to draw behind the text string
 * \param text_color  Foreground color to draw the text string in
 * \param text_pos    Position of the coordinate relative to the text paragraph
 * \param text_align  Alignment of text lines within the paragraph bounding box
 */
void gfx_draw_progmem_string_aligned(char PROGMEM_PTR_T str,
		gfx_coord_t x, gfx_coord_t y, const struct font *font,
		const gfx_color_t bg_color, const gfx_color_t text_color,
		enum gfx_text_position text_pos,
		enum gfx_text_alignment text_align)
{
	gfx_coord_t bounding_x, bounding_y;
	char curr_str_char;

	/* Sanity check on parameters, assert if str or font is NULL. */
	Assert(str != NULL);
	Assert(font != NULL);

	/* Retrieve the bounding box of the overall text paragraph */
	gfx_get_progmem_string_bounding_box(str, font,
			&bounding_x, &bounding_y);

	/* Move the Y coordinate according to the Y positional setting given */
	if (text_pos & TEXT_POS_CENTER_Y) {
		y -= bounding_y / 2;
	} else if (text_pos & TEXT_POS_BOTTOM) {
		y -= bounding_y;
	}

	/* Move the X coordinate according to the X positional setting given */
	if (text_pos & TEXT_POS_CENTER_X) {
		x -= bounding_x / 2;
	} else if (text_pos & TEXT_POS_RIGHT) {
		x -= bounding_x;
	}

	curr_str_char = PROGMEM_READ_BYTE((uint8_t PROGMEM_PTR_T)str);

	/* Need to draw each line of the text paragraph individually */
	while (curr_str_char != '\0') {
		char PROGMEM_PTR_T curr_line_text = str;
		char curr_line_char;
		gfx_coord_t curr_line_x = x;
		gfx_coord_t curr_line_width = 0;

		/* Determine width of current line in the the paragraph */
		do {
			if (curr_str_char == '\n') {
				curr_str_char
					= PROGMEM_READ_BYTE(
						(uint8_t PROGMEM_PTR_T)(++str));
				break;
			} else if (curr_str_char != '\r') {
				curr_line_width += font->width;
			}

			curr_str_char = PROGMEM_READ_BYTE(
					(uint8_t PROGMEM_PTR_T)(++str));
		} while (curr_str_char != '\0');

		/* Move the line starting X coordinate on the display according
		 * to the line width and the specified text alignment parameter
		 */
		if (text_align == TEXT_ALIGN_CENTER) {
			curr_line_x += (bounding_x / 2) - (curr_line_width / 2);
		} else if (text_align == TEXT_ALIGN_RIGHT) {
			curr_line_x += bounding_x - curr_line_width;
		}

		curr_line_char = PROGMEM_READ_BYTE(
				(uint8_t PROGMEM_PTR_T)curr_line_text);

		/* Draw current line to the display with the calculated
		 * coordinates
		 */
		do {
			if (*curr_line_text == '\n') {
				break;
			} else if (*curr_line_text != '\r') {
				gfx_draw_char(*curr_line_text, curr_line_x, y,
						font, bg_color, text_color);

				/* Step to the next character display X
				 *coordinate
				 */
				curr_line_x += font->width;
			}

			curr_line_char = PROGMEM_READ_BYTE(
					(uint8_t PROGMEM_PTR_T)(++curr_line_text));
		} while (curr_line_char != '\0');

		/* Step to the next Y line coordinate for the next line in
		 * paragraph
		 */
		y += font->height + 1;
	}
}
コード例 #4
0
ファイル: kernal.c プロジェクト: MagerValp/CGTerm
void ffd2(unsigned char a) {

  switch (a) {

    /* colors */

  case 5:
    gfx_fgcolor(COLOR_WHITE);
    break;

  case 28:
    gfx_fgcolor(COLOR_RED);
    break;

  case 30:
    gfx_fgcolor(COLOR_GREEN);
    break;

  case 31:
    gfx_fgcolor(COLOR_BLUE);
    break;

  case 129:
    gfx_fgcolor(COLOR_ORANGE);
    break;

  case 144:
    gfx_fgcolor(COLOR_BLACK);
    break;

  case 149:
    gfx_fgcolor(COLOR_BROWN);
    break;

  case 150:
    gfx_fgcolor(COLOR_LTRED);
    break;

  case 151:
    gfx_fgcolor(COLOR_DKGRAY);
    break;

  case 152:
    gfx_fgcolor(COLOR_GRAY);
    break;

  case 153:
    gfx_fgcolor(COLOR_LTGREEN);
    break;

  case 154:
    gfx_fgcolor(COLOR_LTBLUE);
    break;

  case 155:
    gfx_fgcolor(COLOR_LTGRAY);
    break;

  case 156:
    gfx_fgcolor(COLOR_PURPLE);
    break;

  case 158:
    gfx_fgcolor(COLOR_YELLOW);
    break;

  case 159:
    gfx_fgcolor(COLOR_CYAN);
    break;


    /* movement */

  case 10:
    break;

  case 13:
  case 141:
    gfx_setcursx(0);
    rvson = 0;
    /* fall through */

  case 17:
    gfx_cursdown();
    break;

  case 147:
    gfx_setcursxy(0, 0);
    gfx_cls();
    break;

  case 19:
    gfx_setcursxy(0, 0);
    break;

  case 20:
    gfx_delete();
    break;

  case 157:
    gfx_cursleft();
    break;

  case 29:
    gfx_cursright();
    break;

  case 145:
    gfx_cursup();
    break;

  case 148:
    gfx_insert();
    break;


    /* fonts */

  case 8:
    enableshiftcbm = 0;
    /* printf("shift+cbm disabled\n"); */
    break;

  case 9:
    enableshiftcbm = 1;
    /* printf("shift+cbm enabled\n"); */
    break;

  case 14:
    gfx_setfont(1);
    /* printf("switching to lower case\n"); */
    break;

  case 142:
    gfx_setfont(0);
    /* printf("switching to upper case\n"); */
    break;

  case 18:
    rvson = 1;
    break;

  case 146:
    rvson = 0;
    break;


    /* terminal */

  case 3:
    break;

  case 7:
    sound_play_sample(sound_bell);
    break;


    /* printables */

  default:
    if ((a >= 32 && a <= 127) || (a >= 160)) {
      gfx_draw_char(screencode[a] + rvson * 128);
      gfx_cursadvance();
    }
    break;

  }

}