Example #1
0
void oledDrawChar(int x, int y, char c, int font) {
  if (x >= OLED_WIDTH || y >= OLED_HEIGHT || y <= -FONT_HEIGHT) {
    return;
  }

  int zoom = (font & FONT_DOUBLE ? 2 : 1);
  int char_width = fontCharWidth(font & 0x7f, c);
  const uint8_t *char_data = fontCharData(font & 0x7f, c);

  if (x <= -char_width * zoom) {
    return;
  }

  for (int xo = 0; xo < char_width; xo++) {
    for (int yo = 0; yo < FONT_HEIGHT; yo++) {
      if (char_data[xo] & (1 << (FONT_HEIGHT - 1 - yo))) {
        if (zoom <= 1) {
          oledDrawPixel(x + xo, y + yo);
        } else {
          oledBox(x + xo * zoom, y + yo * zoom, x + (xo + 1) * zoom - 1,
                  y + (yo + 1) * zoom - 1, true);
        }
      }
    }
  }
}
Example #2
0
void oledDrawString(int x, int y, const char* text)
{
	if (!text) return;
	const char *c;
	int l = 0;
	for (c = text; *c; c++) {
		oledDrawChar(x + l, y, *c);
		l += fontCharWidth(*c) + 1;
	}
}
Example #3
0
int oledStringWidth(const char *text) {
	if (!text) return 0;
	int l = 0;
	char c;
	for (; *text; text++) {
		c = oledConvertChar(*text);
		if (c) {
			l += fontCharWidth(c) + 1;
		}
	}
	return l;
}
Example #4
0
void oledDrawString(int x, int y, const char *text, int font) {
  if (!text) return;
  int l = 0;
  int size = (font & FONT_DOUBLE ? 2 : 1);
  for (; *text; text++) {
    char c = oledConvertChar(*text);
    if (c) {
      oledDrawChar(x + l, y, c, font);
      l += size * (fontCharWidth(font & 0x7f, c) + 1);
    }
  }
}
Example #5
0
int oledStringWidth(const char *text, int font) {
  if (!text) return 0;
  int size = (font & FONT_DOUBLE ? 2 : 1);
  int l = 0;
  for (; *text; text++) {
    char c = oledConvertChar(*text);
    if (c) {
      l += size * (fontCharWidth(font & 0x7f, c) + 1);
    }
  }
  return l;
}
Example #6
0
void oledDrawString(int x, int y, const char* text)
{
	if (!text) return;
	int l = 0;
	char c;
	for (; *text; text++) {
		c = oledConvertChar(*text);
		if (c) {
			oledDrawChar(x + l, y, c);
			l += fontCharWidth(c) + 1;
		}
	}
}
Example #7
0
void layoutDialog(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6)
{
	int left = 0;
	oledClear();
	if (icon) {
		oledDrawBitmap(0, 0, icon);
		left = icon->width + 4;
	}
	if (line1) oledDrawString(left, 0 * 9, line1);
	if (line2) oledDrawString(left, 1 * 9, line2);
	if (line3) oledDrawString(left, 2 * 9, line3);
	if (line4) oledDrawString(left, 3 * 9, line4);
	if (desc) {
		oledDrawStringCenter(OLED_HEIGHT - 2 * 9 - 1, desc);
		if (btnYes || btnNo) {
			oledHLine(OLED_HEIGHT - 21);
		}
	} else {
		if (line5) oledDrawString(left, 4 * 9, line5);
		if (line6) oledDrawString(left, 5 * 9, line6);
		if (btnYes || btnNo) {
			oledHLine(OLED_HEIGHT - 13);
		}
	}
	if (btnNo) {
		oledDrawString(1, OLED_HEIGHT - 8, "\x15");
		oledDrawString(fontCharWidth('\x15') + 3, OLED_HEIGHT - 8, btnNo);
		oledInvert(0, OLED_HEIGHT - 9, fontCharWidth('\x15') + oledStringWidth(btnNo) + 2, OLED_HEIGHT - 1);
	}
	if (btnYes) {
		oledDrawString(OLED_WIDTH - fontCharWidth('\x06') - 1, OLED_HEIGHT - 8, "\x06");
		oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 3, OLED_HEIGHT - 8, btnYes);
		oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
	}
	oledRefresh();
}
Example #8
0
int main(int argc, char **argv) {
	char *line;
	while ((line = readline(NULL)) != NULL) {
		size_t length = strlen(line);
		if (length) {
			add_history(line);
		}

		size_t width = 0;
		for (size_t i = 0; i < length; i++) {
			width += fontCharWidth(convert(line[i])) + 1;
		}

		printf("%zu\n", width);
		free(line);
	}
}
Example #9
0
void oledDrawString(int x, int y, const char* text)
{
	if (!text) return;
	int size = 1;
	if (*text == 0x01) { // double size
		text++;
		size = 2;
	}
	int l = 0;
	char c;
	for (; *text; text++) {
		c = oledConvertChar(*text);
		if (c) {
			oledDrawChar(x + l, y, c, size);
			l += size * (fontCharWidth(c) + 1);
		}
	}
}
Example #10
0
void oledDrawChar(int x, int y, char c)
{
	int char_width;
	const uint8_t *char_data;

	if ((x >= OLED_WIDTH) || (y >= OLED_HEIGHT)) return;

	char_width = fontCharWidth(c);
	char_data = fontCharData(c);

	int xoffset, yoffset;
	for (xoffset = 0; xoffset < char_width; xoffset++) {
		for (yoffset = 0; yoffset < FONT_HEIGHT; yoffset++) {
			if (char_data[xoffset] & (1 << (FONT_HEIGHT - 1 - yoffset))) {
				oledDrawPixel(x + xoffset, y + yoffset);
			}
		}
	}
}
Example #11
0
void oledDrawChar(int x, int y, char c, int zoom)
{
	int char_width;
	const uint8_t *char_data;

	if ((x >= OLED_WIDTH) || (y >= OLED_HEIGHT)) return;

	char_width = fontCharWidth(c);
	char_data = fontCharData(c);

	int xo, yo;
	for (xo = 0; xo < char_width; xo++) {
		for (yo = 0; yo < FONT_HEIGHT; yo++) {
			if (char_data[xo] & (1 << (FONT_HEIGHT - 1 - yo))) {
				if (zoom <= 1) {
					oledDrawPixel(x + xo, y + yo);
				} else {
					oledBox(x + xo * zoom, y + yo * zoom, x + (xo + 1) * zoom - 1, y + (yo + 1) * zoom - 1, true);
				}
			}
		}
	}
}
Example #12
0
void layoutButtonYes(const char *btnYes)
{
	oledDrawString(OLED_WIDTH - fontCharWidth(FONT_STANDARD, '\x06') - 1, OLED_HEIGHT - 8, "\x06", FONT_STANDARD);
	oledDrawStringRight(OLED_WIDTH - fontCharWidth(FONT_STANDARD, '\x06') - 3, OLED_HEIGHT - 8, btnYes, FONT_STANDARD);
	oledInvert(OLED_WIDTH - oledStringWidth(btnYes, FONT_STANDARD) - fontCharWidth(FONT_STANDARD, '\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
}
Example #13
0
void layoutButtonNo(const char *btnNo)
{
	oledDrawString(1, OLED_HEIGHT - 8, "\x15", FONT_STANDARD);
	oledDrawString(fontCharWidth(FONT_STANDARD, '\x15') + 3, OLED_HEIGHT - 8, btnNo, FONT_STANDARD);
	oledInvert(0, OLED_HEIGHT - 9, fontCharWidth(FONT_STANDARD, '\x15') + oledStringWidth(btnNo, FONT_STANDARD) + 2, OLED_HEIGHT - 1);
}