libdgl/TEST/TEXT.C

98 lines
2.9 KiB
C++
Raw Normal View History

2018-04-30 18:23:39 -04:00
#include "text.h"
#include "dglgfx.h"
#include "dgldraw.h"
#include "dglmath.h"
2018-04-30 18:23:39 -04:00
#include <stdio.h>
#include <string.h>
// prints out some simple text messages, including ones with newlines in them.
// also prints out the entire 1-127 ASCII character set in a 16x8 grid.
// a duplicate set of text is drawn using the "fast" variants.
void test_text(void) {
int i, x, y;
char string[255];
char *p;
surface_clear(screen, 0);
memset(string, 0, 255);
draw_text(screen, 10, 10, 15, "Hello, world!");
draw_text_f(screen, 170, 10, 15, "Hello, world!");
2018-04-30 18:23:39 -04:00
draw_filled_rect(screen, 8, 28, 114, 40, 7);
draw_text(screen, 10, 30, 15, "transparency!");
draw_filled_rect_f(screen, 168, 28, 274, 40, 7);
draw_text_f(screen, 170, 30, 15, "transparency!");
2018-04-30 18:23:39 -04:00
draw_text(screen, 10, 50, 15, "line 1\nline 2");
draw_text_f(screen, 170, 50, 15, "line 1\nline 2");
2018-04-30 18:23:39 -04:00
draw_printf(screen, 10, 70, 15, "printf pi %.5f", PI);
draw_printf_f(screen, 170, 70, 15, "printf pi %.5f", PI);
2018-04-30 18:23:39 -04:00
p = &string[0];
for (i = 1; i <= 127; ++i, ++p) {
if (i % 16 == 0) {
*p = '\n';
++p;
}
if (i == 10)
*p = ' '; // will be interpreted as a \n (and hence, not shown)
else
*p = (char)i;
}
draw_text(screen, 10, 100, 15, string);
draw_text_f(screen, 170, 100, 15, string);
2018-04-30 18:23:39 -04:00
getch();
}
// text is drawn along each edge of the screen. two messages are drawn at each
// edge, but one is completely out of bounds so the second should not be
// visible. red rects are drawn marking the extents of the text.
void test_text_clipping(void) {
int x, y;
char message[] = "Hello, world!";
int len = strlen(message);
int width = len * 8;
int height = 8;
surface_clear(screen, 0);
x = -32; y = 10;
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
draw_text(screen, x, y, 9, message);
2018-04-30 18:23:39 -04:00
x = 80; y = -4;
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
draw_text(screen, x, y, 10, message);
2018-04-30 18:23:39 -04:00
x = 288; y = 120;
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
draw_text(screen, x, y, 11, message);
2018-04-30 18:23:39 -04:00
x = 200; y = 196;
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
draw_text(screen, x, y, 12, message);
2018-04-30 18:23:39 -04:00
x = -232; y = 10;
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
draw_text(screen, x, y, 5, message);
2018-04-30 18:23:39 -04:00
x = 80; y = -24;
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
draw_text(screen, x, y, 6, message);
2018-04-30 18:23:39 -04:00
x = 360; y = 120;
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
draw_text(screen, x, y, 7, message);
2018-04-30 18:23:39 -04:00
x = 200; y = 240;
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
draw_text(screen, x, y, 8, message);
2018-04-30 18:23:39 -04:00
getch();
}