libdgl/TEST/RECT.C
Gered 62af8575c6 various updates i've left uncommitted for many months
- 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
2020-07-19 19:24:48 -04:00

210 lines
6.4 KiB
C
Executable file

#include "rect.h"
#include "dgldraw.h"
#include "dglrect.h"
#include <stdio.h>
// draws two rectangles. red pixels mark the extents of the rects. a
// duplicate of the first rectangle is drawn using the "fast" variant.
void test_rect(void) {
int x1, y1, x2, y2;
surface_clear(screen, 0);
x1 = 10; y1 = 10; x2 = 90; y2 = 90;
pset(screen, x1 - 1, y1, 4);
pset(screen, x1, y1 - 1, 4);
pset(screen, x2 + 1, y1, 4);
pset(screen, x2, y1 - 1, 4);
pset(screen, x1 - 1, y2, 4);
pset(screen, x1, y2 + 1, 4);
pset(screen, x2 + 1, y2, 4);
pset(screen, x2, y2 + 1, 4);
draw_rect(screen, x1, y1, x2, y2, 1);
x1 = 10; y1 = 110; x2 = 90; y2 = 190;
pset(screen, x1 - 1, y1, 4);
pset(screen, x1, y1 - 1, 4);
pset(screen, x2 + 1, y1, 4);
pset(screen, x2, y1 - 1, 4);
pset(screen, x1 - 1, y2, 4);
pset(screen, x1, y2 + 1, 4);
pset(screen, x2 + 1, y2, 4);
pset(screen, x2, y2 + 1, 4);
draw_rect_f(screen, x1, y1, x2, y2, 1);
x1 = 190; y1 = 90; x2 = 110; y2 = 10;
pset(screen, x2 - 1, y2, 4);
pset(screen, x2, y2 - 1, 4);
pset(screen, x1 + 1, y2, 4);
pset(screen, x1, y2 - 1, 4);
pset(screen, x2 - 1, y1, 4);
pset(screen, x2, y1 + 1, 4);
pset(screen, x1 + 1, y1, 4);
pset(screen, x1, y1 + 1, 4);
draw_rect(screen, x1, y1, x2, y2, 2);
getch();
}
// draws 4 rects in each of the top-left and bottom-right corners (two in each
// corner will be completely out of bounds, so should not be visible). also,
// two long rects are drawn along the center of the screen and they each
// extend beyond the edges of the screen. red pixels are drawn to mark rect
// extents.
void test_rect_clipping(void) {
int x1, y1, x2, y2;
surface_clear(screen, 0);
x1 = -8; y1 = 10; x2 = 7; y2 = 25;
pset(screen, x2, y1 - 1, 4);
pset(screen, x2 + 1, y1, 4);
pset(screen, x2 + 1, y2, 4);
pset(screen, x2, y2 + 1, 4);
draw_rect(screen, x1, y1, x2, y2, 1);
draw_rect(screen, -16, 30, -1, 46, 10);
x1 = 20; y1 = -8; x2 = 35; y2 = 7;
pset(screen, x1 - 1, y2, 4);
pset(screen, x1, y2 + 1, 4);
pset(screen, x2 + 1, y2, 4);
pset(screen, x2, y2 + 1, 4);
draw_rect(screen, x1, y1, x2, y2, 2);
draw_rect(screen, 40, -16, 55, -1, 11);
x1 = 313; y1 = 170; x2 = 328; y2 = 185;
pset(screen, x1, y1 - 1, 4);
pset(screen, x1 - 1, y1, 4);
pset(screen, x1 - 1, y2, 4);
pset(screen, x1, y2 + 1, 4);
draw_rect(screen, x1, y1, x2, y2, 3);
draw_rect(screen, 320, 150, 335, 165, 12);
x1 = 285; y1 = 193; x2 = 300; y2 = 208;
pset(screen, x1 - 1, y1, 4);
pset(screen, x1, y1 - 1, 4);
pset(screen, x2 + 1, y1, 4);
pset(screen, x2, y1 - 1, 4);
draw_rect(screen, x1, y1, x2, y2, 5);
draw_rect(screen, 265, 200, 280, 215, 13);
x1 = 150; y1 = -10; x2 = 170; y2 = 210;
pset(screen, x1 - 1, 10, 4);
pset(screen, x2 + 1, 10, 4);
draw_rect(screen, x1, y1, x2, y2, 7);
x1 = -10; y1 = 90; x2 = 330; y2 = 110;
pset(screen, 10, y1 - 1, 4);
pset(screen, 10, y2 + 1, 4);
draw_rect(screen, x1, y1, x2, y2, 8);
getch();
}
// draws two filled rectangles. red pixels mark the extents of the rects. a
// duplicate of the first rectangle is drawn using the "fast" variant.
void test_filled_rect(void) {
int x1, y1, x2, y2;
surface_clear(screen, 0);
x1 = 10; y1 = 10; x2 = 90; y2 = 90;
pset(screen, x1 - 1, y1, 4);
pset(screen, x1, y1 - 1, 4);
pset(screen, x2 + 1, y1, 4);
pset(screen, x2, y1 - 1, 4);
pset(screen, x1 - 1, y2, 4);
pset(screen, x1, y2 + 1, 4);
pset(screen, x2 + 1, y2, 4);
pset(screen, x2, y2 + 1, 4);
draw_filled_rect(screen, x1, y1, x2, y2, 1);
x1 = 10; y1 = 110; x2 = 90; y2 = 190;
pset(screen, x1 - 1, y1, 4);
pset(screen, x1, y1 - 1, 4);
pset(screen, x2 + 1, y1, 4);
pset(screen, x2, y1 - 1, 4);
pset(screen, x1 - 1, y2, 4);
pset(screen, x1, y2 + 1, 4);
pset(screen, x2 + 1, y2, 4);
pset(screen, x2, y2 + 1, 4);
draw_filled_rect_f(screen, x1, y1, x2, y2, 1);
x1 = 190; y1 = 90; x2 = 110; y2 = 10;
pset(screen, x2 - 1, y2, 4);
pset(screen, x2, y2 - 1, 4);
pset(screen, x1 + 1, y2, 4);
pset(screen, x1, y2 - 1, 4);
pset(screen, x2 - 1, y1, 4);
pset(screen, x2, y1 + 1, 4);
pset(screen, x1 + 1, y1, 4);
pset(screen, x1, y1 + 1, 4);
draw_filled_rect(screen, x1, y1, x2, y2, 2);
getch();
}
// draws 4 rects in each of the top-left and bottom-right corners (two in each
// corner will be completely out of bounds, so should not be visible). also,
// two long rects are drawn along the center of the screen and they each
// extend beyond the edges of the screen. red pixels are drawn to mark rect
// extents.
void test_filled_rect_clipping(void) {
int x1, y1, x2, y2;
surface_clear(screen, 0);
x1 = -8; y1 = 10; x2 = 7; y2 = 25;
pset(screen, x2, y1 - 1, 4);
pset(screen, x2 + 1, y1, 4);
pset(screen, x2 + 1, y2, 4);
pset(screen, x2, y2 + 1, 4);
draw_filled_rect(screen, x1, y1, x2, y2, 1);
draw_filled_rect(screen, -16, 30, -1, 46, 10);
x1 = 20; y1 = -8; x2 = 35; y2 = 7;
pset(screen, x1 - 1, y2, 4);
pset(screen, x1, y2 + 1, 4);
pset(screen, x2 + 1, y2, 4);
pset(screen, x2, y2 + 1, 4);
draw_filled_rect(screen, x1, y1, x2, y2, 2);
draw_filled_rect(screen, 40, -16, 55, -1, 11);
x1 = 313; y1 = 170; x2 = 328; y2 = 185;
pset(screen, x1, y1 - 1, 4);
pset(screen, x1 - 1, y1, 4);
pset(screen, x1 - 1, y2, 4);
pset(screen, x1, y2 + 1, 4);
draw_filled_rect(screen, x1, y1, x2, y2, 3);
draw_filled_rect(screen, 320, 150, 335, 165, 12);
x1 = 285; y1 = 193; x2 = 300; y2 = 208;
pset(screen, x1 - 1, y1, 4);
pset(screen, x1, y1 - 1, 4);
pset(screen, x2 + 1, y1, 4);
pset(screen, x2, y1 - 1, 4);
draw_filled_rect(screen, x1, y1, x2, y2, 5);
draw_filled_rect(screen, 265, 200, 280, 215, 13);
x1 = 150; y1 = -10; x2 = 170; y2 = 210;
pset(screen, x1 - 1, 10, 4);
pset(screen, x2 + 1, 10, 4);
draw_filled_rect(screen, x1, y1, x2, y2, 7);
x1 = -10; y1 = 90; x2 = 330; y2 = 110;
pset(screen, 10, y1 - 1, 4);
pset(screen, 10, y2 + 1, 4);
draw_filled_rect(screen, x1, y1, x2, y2, 8);
getch();
}