Gered
62af8575c6
- rename standard integer types to a more familiar (u)int(8/16/32) - many function/struct renames. i don't _really_ know if what i've done for this is better, but it "feels" better to me. many draw/blit function names are shorter which is nice, at least. kinda important to me because i develop this on a real DOS machine in 80x50 text mode. - add 'extern "C"' blocks to headers for C++ compiler usage - draw/pixel color value arguments for functions should all have been changed to be uint8 instead of a full 32-bit int. feels right, but maybe should've left alone... - small fix to keyboard handler. noticed a problem on one thinkpad laptop. was a result of what i think was a typo in a constant value used during the part of the interrupt handler that tells the keyboard controller the key event was processed - fix uncommon potential crash function return in draw_filled_rect - renamed low-level "direct" assembly functions to "lowlevel_xxx" to be a little bit more explicit about what they are - add some convenience event helper functions for determining event types - add fixed point atan2 - fixed some tabs/spaces inconsistences (should all be spaces now?) - maybe some other minor things i've forgotten
98 lines
2.9 KiB
C
Executable file
98 lines
2.9 KiB
C
Executable file
#include "text.h"
|
|
#include "dglgfx.h"
|
|
#include "dgldraw.h"
|
|
#include "dglmath.h"
|
|
#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!");
|
|
|
|
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!");
|
|
|
|
draw_text(screen, 10, 50, 15, "line 1\nline 2");
|
|
draw_text_f(screen, 170, 50, 15, "line 1\nline 2");
|
|
|
|
draw_printf(screen, 10, 70, 15, "printf pi %.5f", PI);
|
|
draw_printf_f(screen, 170, 70, 15, "printf pi %.5f", PI);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
x = 80; y = -4;
|
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
|
draw_text(screen, x, y, 10, message);
|
|
|
|
x = 288; y = 120;
|
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
|
draw_text(screen, x, y, 11, message);
|
|
|
|
x = 200; y = 196;
|
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
|
draw_text(screen, x, y, 12, message);
|
|
|
|
x = -232; y = 10;
|
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
|
draw_text(screen, x, y, 5, message);
|
|
|
|
x = 80; y = -24;
|
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
|
draw_text(screen, x, y, 6, message);
|
|
|
|
x = 360; y = 120;
|
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
|
draw_text(screen, x, y, 7, message);
|
|
|
|
x = 200; y = 240;
|
|
draw_rect(screen, x - 1, y - 1, x + width, y + height, 4);
|
|
draw_text(screen, x, y, 8, message);
|
|
|
|
getch();
|
|
}
|
|
|