/* * BSX-draw, SRGP version * (c)1991 Bram Stolk */ #define VERSION "2.0" #include #include "srgp.h" #define WINSIZEY 2 #define WINSIZEX 3 int x,y,i,j; /* Some multi prurpouse vars */ point p; int dc; /* Drawing color */ char quit; typedef struct { int size; int color; point points[32]; } polygon; polygon pic[32]; /* Actual picture */ int picsize; /* Size of picture */ void setup() { unsigned short r[16],g[16],b[16]; int max,med; char title[20]; sprintf(title,"BSX-Draw %s",VERSION); SRGP_begin(title,(256+50)*WINSIZEX,(256+8)*WINSIZEY,4,0); sleep(4); max=60000;med=40000; r[ 0]= 0; g[ 0]= 0; b[ 0]= 0; r[ 1]= 0; g[ 1]= 0; b[ 1]= med; r[ 2]= 0; g[ 2]= med; b[ 2]= 0; r[ 3]= 0; g[ 3]= med; b[ 3]= med; r[ 4]= med; g[ 4]= 0; b[ 4]= 0; r[ 5]= med; g[ 5]= 0; b[ 5]= med; r[ 6]= med; g[ 6]= med; b[ 6]= 0; r[ 7]= med; g[ 7]= med; b[ 7]= med; r[ 8]=23000; g[ 8]=23000; b[ 8]=23000; /* Exception */ r[ 9]= 0; g[ 9]= 0; b[ 9]= max; r[10]= 0; g[10]= max; b[10]= 0; r[11]= 0; g[11]= max; b[11]= max; r[12]= max; g[12]= 0; b[12]= 0; r[13]= max; g[13]= 0; b[13]= max; r[14]= max; g[14]= max; b[14]= 0; r[15]= max; g[15]= max; b[15]= max; SRGP_loadColorTable(0,16,r,g,b); SRGP_refresh(); /* * Draw 8 buttons on top of window */ SRGP_setColor(14); SRGP_refresh(); SRGP_lineCoord(0,0,10,10); SRGP_lineCoord(0,256*WINSIZEY,256*WINSIZEX,256*WINSIZEY); SRGP_lineCoord(0,264*WINSIZEY-1,256*WINSIZEX,264*WINSIZEY-1); for (i=0; i<9; i++) SRGP_lineCoord(i*32*WINSIZEX,256*WINSIZEY,i*32*WINSIZEX,264*WINSIZEY-1); SRGP_setColor(15); p.y = 257*WINSIZEY; p.x = 2*WINSIZEX; SRGP_text(p,"POLY"); p.x = p.x + 32*WINSIZEX; SRGP_text(p,"COLOR"); p.x = p.x + 32*WINSIZEX; SRGP_text(p,"DELETE"); p.x = p.x + 32*WINSIZEX; SRGP_text(p,"LOAD"); p.x = p.x + 32*WINSIZEX; SRGP_text(p,"SAVE"); p.x = p.x + 32*WINSIZEX; SRGP_text(p,""); p.x = p.x + 32*WINSIZEX; SRGP_text(p,""); p.x = p.x + 32*WINSIZEX; SRGP_text(p,"QUIT"); p.x = p.x + 32*WINSIZEX; /* * Draw 16 color fields at righthand side of window */ for (i=0;i<16;i++) { point p[4]; p[0].x = 256*WINSIZEX; p[0].y = i*16*WINSIZEY; p[2].x = 306*WINSIZEX - 1; p[2].y = (i+1)*16*WINSIZEY-1; p[1].x = p[2].x; p[1].y = p[0].y; p[3].x = p[0].x; p[3].y = p[2].y; SRGP_setColor(i); SRGP_fillPolygon(4,p); } SRGP_refresh(); /* * Use mouse in Sample modus */ SRGP_setInputMode(LOCATOR,SAMPLE); SRGP_setLocatorButtonMask(LEFT_BUTTON_MASK||MIDDLE_BUTTON_MASK||RIGHT_BUTTON_MASK); SRGP_setLocatorEchoType(CURSOR); dc = 15; quit = 0; } /* * Wait for mouse in rest */ void wait_4_all_buttons_up() { locator_measure m; do { SRGP_sampleLocator(&m); } while ((m.button_chord[0]==DOWN) || (m.button_chord[1]==DOWN) || (m.button_chord[2]==DOWN)) ; } /* * Wait for mousepress inside colorbox */ int get_color() { locator_measure m; wait_4_all_buttons_up(); while (1) { do { SRGP_sampleLocator(&m); } while (m.button_chord[0]==UP); if ((m.position.x>=256*WINSIZEX) && (m.position.y<256*WINSIZEY)) return(m.position.y / (16*WINSIZEY)); } } /* * Wait for mousepress inside toolbox */ int get_tool() { locator_measure m; wait_4_all_buttons_up(); while (1) { do { SRGP_sampleLocator(&m); } while (m.button_chord[0]==UP); if ((m.position.y>=256*WINSIZEY) && (m.position.x<256*WINSIZEX)) return(m.position.x / (32*WINSIZEX)); } } /* * Wait for a mousepress inside drawing area */ void get_point(p,b) point *p; int *b; { locator_measure m; wait_4_all_buttons_up(); while (1) { do { SRGP_sampleLocator(&m); } while ((m.button_chord[0]==UP) && (m.button_chord[1]==UP) && (m.button_chord[2]==UP)); if ((m.position.y<256*WINSIZEY) && (m.position.x<256*WINSIZEX)) { if (m.button_chord[0]==DOWN) *b=1; if (m.button_chord[1]==DOWN) *b=2; if (m.button_chord[2]==DOWN) *b=3; p->x = m.position.x / WINSIZEX; p->y = m.position.y / WINSIZEY; return; } } } void redraw_picture() { SRGP_setColor(0); SRGP_fillRectangleCoord(0,0,WINSIZEX*256-1,WINSIZEY*256-1); SRGP_setColor(8); SRGP_lineCoord(128*WINSIZEX,0,128*WINSIZEX,256*WINSIZEY-1); SRGP_lineCoord(0,128*WINSIZEY,256*WINSIZEX-1,128*WINSIZEY); for (i=0; i0) SRGP_lineCoord(pic[picsize].points[s].x*WINSIZEX, pic[picsize].points[s].y*WINSIZEY, pic[picsize].points[s-1].x*WINSIZEX, pic[picsize].points[s-1].y*WINSIZEY); if (s<31) s++; if ((s>2)&&(but==3)) { pic[picsize].size = s; pic[picsize].color = dc; if (picsize<31) picsize++; redraw_picture(); SRGP_setLocatorEchoType(CURSOR); return; } } } void pick_color() { point p; p.x = (256+25)*WINSIZEX; p.y = (256+4) *WINSIZEY; SRGP_setLocatorMeasure(p); dc = get_color(); } void delete_last() { if (picsize) picsize--; redraw_picture(); } void fputhex(b,f) unsigned char b; FILE *f; { unsigned char lo,hi; hi = b / 16; lo = b % 16; if (hi > 9) hi = hi + 55; else hi = hi + 48; if (lo > 9) lo = lo + 55; else lo = lo + 48; fputc(hi,f); fputc(lo,f); } void save_file() { FILE *f,*g; f = fopen("picture.ppf","wb"); g = fopen("picture.bsx","w"); printf("Writing %d polygons to disk.\n",picsize); fputc(picsize,f); fputhex(picsize,g); for (i=0; i