home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Borland Programmer's Resource
/
Borland_Programmers_Resource_CD_1995.iso
/
code
/
stdg44
/
lines.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-18
|
1KB
|
55 lines
#include <stdio.h>
#include "stdg.h"
/* this program tests the drawing of some straight lines. */
point p0, p1, p2, p3, p4;
void resize(window *w) /* recalculate what the window looks like */
{
rectangle r = w->b->r;
p0 = pt(dx(r)/2,dy(r)/2);
p1 = pt(20,20);
p2 = pt(20,r.max.y-20);
p3 = pt(r.max.x-20,r.max.y-20);
p4 = pt(r.max.x-20,20);
}
void redraw(window *w) /* this function knows how to draw the window */
{
fill_rect(w->b, w->b->r, WHITE); /* clear window */
draw_line(w->b, p1, p2, RED);
draw_line(w->b, p2, p3, GREEN);
draw_line(w->b, p3, p4, BLUE);
draw_line(w->b, p4, p1, BLACK);
draw_line(w->b, p0, addp(p1,pt(+2,+2)), BLUE);
draw_line(w->b, p0, addp(p2,pt(+2,-2)), BLACK);
draw_line(w->b, p0, addp(p3,pt(-2,-2)), RED);
draw_line(w->b, p0, addp(p4,pt(-2,+2)), GREEN);
invert_rect(w->b, insetr(w->b->r,4)); /* inverting colours is fun */
gflush();
}
int main(int argc, char **argv)
{
int c;
mouse m;
window *w;
ginit("Sample", NULL, NULL);
w = new_window("Lines", rect(0,0,0,0), Titlebar+Resize+Maximize);
set_winfns(w, NULL, &resize, &redraw);
show_window(w);
while(1)
can_event();
return 0;
}