#include #include #include "/opt/local/srgp/SRGP_DISTRIB/include/srgp.h" #define PLACE_BUTTON 0 #define QUIT_BUTTON 2 #define BUFFER_SIZE 80 #define FALSE 0 #define TRUE 1 #define NONE 0 #define CIRCLE 1 #define V_RECT 2 #define H_RECT 3 #define SQUARE 4 #define COLOR 5 #define OBJECT 6 #define TEXT 7 #define LINE_SQUARE 8 #define FILL_SQUARE 9 #define LINE_CIRCLE 10 #define FILL_CIRCLE 11 #define LINE_ELLIPSE 12 #define FILL_ELLIPSE 13 #define LINE_ARC 14 #define FILL_ARC 15 #define POLYLINE 16 #define POLYMARK1 17 #define POLYMARK2 18 #define POLYMARK3 19 #define POLYMARK4 20 #define POLYGON 21 #define MARKER 22 typedef struct { int height; int width; } dimension; typedef struct { int type; dimension size; int color; } brush; void Make_Button(rectangle button_rect, char *name, int shape, int color); int Picked_Button(point pt, rectangle button_rect); void Draw(brush current, rectangle canvas_rect); void Reset_All(brush *current_brush); void Draw_New_Canvas(rectangle MainCanvas); void PullDown1(rectangle menu_rect, char *name, int shape, int color, brush *current_brush); void Initialize_ColorTable(void); void Text_Event(rectangle rect, rectangle menu_rect, brush current); void ColorPullDown(rectangle menu_rect, char *name, int type, int color, brush *current_brush); void MakeColorMenuCanvas(rectangle rect, int extent, int color); void MakeCircleMenuCanvas(rectangle rect, int a, int color); void MakeHRectMenuCanvas(rectangle rect, int a, int color); void MakeVRectMenuCanvas(rectangle rect, int a, int color); void MakeSquareMenuCanvas(rectangle rect, int a, int color); void MakeObjectMenuCanvas(rectangle rect, int a, int color); void MakeMarkerMenuCanvas(rectangle rect, int a, int color); void Handle_Point(point pt, rectangle rect, int a, int type, brush current, brush *temp, int color); double findAngle(point center, point pt1, point pt2); int ResizeEvent(int width, int height); int Draw_Screen(rectangle *new, rectangle *reset, rectangle *circle, rectangle *square, rectangle *vrect, rectangle *hrect, rectangle *object, rectangle *text, rectangle *color, rectangle *insert, rectangle *resize, rectangle *quit, rectangle *MainCanvas, rectangle *Window, brush current); brush current_brush; int main() { /****************** declartion of data structures */ rectangle Quit_rect /*= SRGP_defRectangle(10, 25, 175, 60)*/; rectangle Resize_rect /*= SRGP_defRectangle(10, 75, 175, 110)*/; rectangle New_rect /*= SRGP_defRectangle(10, 675, 175, 710 )*/; rectangle Reset_rect /*= SRGP_defRectangle(10, 625, 175, 660 )*/; rectangle Circle_brush_rect /*= SRGP_defRectangle(25, 550, 80, 600)*/; rectangle HRect_brush_rect /*= SRGP_defRectangle(25, 475, 80, 525)*/; rectangle VRect_brush_rect /*= SRGP_defRectangle(100, 475, 155, 525)*/; rectangle Sq_brush_rect /*= SRGP_defRectangle(100, 550, 155, 600)*/; rectangle Object_rect /*= SRGP_defRectangle(10, 400 ,175, 435)*/; rectangle Text_rect /*= SRGP_defRectangle(10, 350, 175, 385)*/; rectangle Color_rect /*= SRGP_defRectangle(10, 300, 175, 335)*/; rectangle Color_insertrect /*= SRGP_defRectangle(130, 305, 155, 330)*/; rectangle Window /*= SRGP_defRectangle(0, 0, 1000, 750)*/; rectangle MainCanvas /*= SRGP_defRectangle(200, 25, 975, 725)*/; rectangle temp,copyrect; int terminate = FALSE; char keyMeasure[80]; locatorMeasure locMeasure; int device; int small = FALSE; int fullCanvas; point pt = SRGP_defPoint(0,0); brush current_brush; /******************* Initialization */ SRGP_begin("CSC 4300 Term Project", 1000, 750, 7, FALSE); Initialize_ColorTable(); SRGP_loadCommonColor(4, "DarkSlateGrey"); SRGP_loadCommonColor(9, "DarkKhaki"); SRGP_loadCommonColor(10, "AntiqueWhite"); SRGP_setInputMode(LOCATOR, EVENT); SRGP_setLocatorButtonMask(LEFT_BUTTON_MASK | RIGHT_BUTTON_MASK); SRGP_setInputMode( KEYBOARD, EVENT ); SRGP_setKeyboardProcessingMode( RAW ); Reset_All(¤t_brush); Draw_Screen(&New_rect,&Reset_rect,&Circle_brush_rect,&Sq_brush_rect,&VRect_brush_rect, &HRect_brush_rect,&Object_rect,&Text_rect,&Color_rect,&Color_insertrect, &Resize_rect,&Quit_rect,&MainCanvas, &Window, current_brush); fullCanvas = SRGP_createCanvas(1000,750); SRGP_useCanvas(SCREEN_CANVAS); SRGP_copyPixel(fullCanvas,Window,pt); SRGP_enableBlockedWait(); SRGP_allowResize (TRUE); SRGP_registerResizeCallback(ResizeEvent); /******************** Main Executive Loop */ do { device = SRGP_waitEvent( INDEFINITE ); switch (device) { case KEYBOARD: SRGP_getKeyboard( keyMeasure, BUFFER_SIZE ); terminate = ((keyMeasure[0] == 'q') || (keyMeasure[0] == 'Q')); break; case LOCATOR: SRGP_getLocator(&locMeasure); switch ( locMeasure.buttonOfMostRecentTransition ) { case PLACE_BUTTON: if(locMeasure.buttonChord[PLACE_BUTTON] == DOWN) { if (Picked_Button(locMeasure.position, MainCanvas)) { if(locMeasure.buttonOfMostRecentTransition == QUIT_BUTTON) { terminate = TRUE; } else Draw(current_brush, MainCanvas); } if (Picked_Button(locMeasure.position, Quit_rect)) { terminate = TRUE; } if (Picked_Button(locMeasure.position, New_rect)) { SRGP_deleteCanvas(fullCanvas); fullCanvas = SRGP_createCanvas(1000,750); SRGP_copyPixel(fullCanvas,Window,pt); SRGP_useCanvas(SCREEN_CANVAS); Draw_New_Canvas(MainCanvas); } if (Picked_Button(locMeasure.position, Reset_rect)) { Reset_All(¤t_brush); SRGP_setClipRectangle(Window); Make_Button(Color_rect, "Colors ", NONE, 9); Make_Button(Color_insertrect, "", NONE, current_brush.color); SRGP_setClipRectangle(MainCanvas); } if (Picked_Button(locMeasure.position, Circle_brush_rect)) { ColorPullDown(Circle_brush_rect, "", CIRCLE, 9, ¤t_brush); } if (Picked_Button(locMeasure.position, HRect_brush_rect)) { ColorPullDown(HRect_brush_rect, "", H_RECT, 9, ¤t_brush); } if (Picked_Button(locMeasure.position, VRect_brush_rect)) { ColorPullDown(VRect_brush_rect, "", V_RECT, 9, ¤t_brush); } if (Picked_Button(locMeasure.position, Sq_brush_rect)) { ColorPullDown(Sq_brush_rect, "", SQUARE, 9, ¤t_brush); } if (Picked_Button(locMeasure.position, Text_rect)) { SRGP_setClipRectangle(Window); Make_Button(Text_rect, "Text", NONE, 10); SRGP_setClipRectangle(MainCanvas); Text_Event(MainCanvas, Text_rect, current_brush); SRGP_setClipRectangle(Window); Make_Button(Text_rect, "Text", NONE, 9); SRGP_setClipRectangle(MainCanvas); } if (Picked_Button(locMeasure.position, Object_rect)) { ColorPullDown(Object_rect, "Objects", OBJECT, 9, ¤t_brush); } if (Picked_Button(locMeasure.position, Color_rect)) { ColorPullDown(Color_rect, "Colors ", COLOR, 9, ¤t_brush); SRGP_setClipRectangle(Window); Make_Button(Color_rect, "Colors ", NONE, 9); Make_Button(Color_insertrect, "", NONE, current_brush.color); SRGP_setClipRectangle(MainCanvas); } if (Picked_Button(locMeasure.position, Resize_rect)) { if(small == FALSE) { small = TRUE; temp = SRGP_inquireClipRectangle(); SRGP_setClipRectangle(Window); SRGP_useCanvas(fullCanvas); SRGP_copyPixel(SCREEN_CANVAS, MainCanvas, pt); SRGP_useCanvas(SCREEN_CANVAS); SRGP_changeScreenCanvasSize(800, 700); SRGP_waitEvent(20); Draw_Screen(&New_rect, &Reset_rect, &Circle_brush_rect, &Sq_brush_rect, &VRect_brush_rect, &HRect_brush_rect, &Object_rect, &Text_rect,&Color_rect,&Color_insertrect, &Resize_rect, &Quit_rect,&MainCanvas, &Window, current_brush); temp = SRGP_inquireClipRectangle(); SRGP_setClipRectangle(Window); SRGP_useCanvas(SCREEN_CANVAS); pt.x = MainCanvas.bottomLeft.x; pt.y = MainCanvas.bottomLeft.y; copyrect = SRGP_defRectangle(0,0,MainCanvas.topRight.x-MainCanvas.bottomLeft.x, MainCanvas.topRight.y-MainCanvas.bottomLeft.y); SRGP_copyPixel(fullCanvas, copyrect, pt); SRGP_useCanvas(SCREEN_CANVAS); pt.x = 0; pt.y = 0; SRGP_setClipRectangle(temp);} else if(small == TRUE) { small = FALSE; temp = SRGP_inquireClipRectangle(); SRGP_setClipRectangle(Window); SRGP_useCanvas(fullCanvas); SRGP_copyPixel(SCREEN_CANVAS, MainCanvas, pt); SRGP_useCanvas(SCREEN_CANVAS); SRGP_changeScreenCanvasSize(1000, 750); SRGP_waitEvent(20); Draw_Screen(&New_rect, &Reset_rect, &Circle_brush_rect, &Sq_brush_rect, &VRect_brush_rect, &HRect_brush_rect, &Object_rect, &Text_rect,&Color_rect,&Color_insertrect, &Resize_rect, &Quit_rect,&MainCanvas, &Window, current_brush); temp = SRGP_inquireClipRectangle(); SRGP_setClipRectangle(Window); SRGP_useCanvas(SCREEN_CANVAS); pt.x = MainCanvas.bottomLeft.x; pt.y = MainCanvas.bottomLeft.y; copyrect = SRGP_defRectangle(0,0,MainCanvas.topRight.x-MainCanvas.bottomLeft.x, MainCanvas.topRight.y-MainCanvas.bottomLeft.y); SRGP_copyPixel(fullCanvas, copyrect, pt); SRGP_useCanvas(SCREEN_CANVAS); pt.x = 0; pt.y = 0; SRGP_setClipRectangle(temp); } } } /* end of if(button = down) */ break; case QUIT_BUTTON: /*terminate = TRUE;*/ break; } /* end of switch on */ } /* end of switch on */ } while(!terminate); /* end of do-while loop */ } /* end of main 8 */ /*****************Paint_Package.h*************************************/ int ResizeEvent(int width, int height) { rectangle Quit_rect; rectangle Resize_rect; rectangle New_rect; rectangle Reset_rect; rectangle Circle_brush_rect; rectangle HRect_brush_rect; rectangle VRect_brush_rect; rectangle Sq_brush_rect; rectangle Object_rect; rectangle Text_rect; rectangle Color_rect; rectangle Color_insertrect; rectangle Window; rectangle MainCanvas; rectangle clip_rect = SRGP_defRectangle(0,0,1000,750); SRGP_waitEvent(60); SRGP_setClipRectangle(clip_rect); SRGP_waitEvent(60); Draw_Screen(&New_rect, &Reset_rect, &Circle_brush_rect, &Sq_brush_rect, &VRect_brush_rect, &HRect_brush_rect, &Object_rect, &Text_rect,&Color_rect,&Color_insertrect, &Resize_rect, &Quit_rect,&MainCanvas, &Window, current_brush); } int Draw_Screen(rectangle *new, rectangle *reset, rectangle *circle, rectangle *square, rectangle *vrect, rectangle *hrect, rectangle *object, rectangle *text, rectangle *color, rectangle *insert, rectangle *resize, rectangle *quit, rectangle *MainCanvas, rectangle *Window, brush current) { int CanvasWidth, CanvasHeight; SRGP_inquireCanvasSize(SCREEN_CANVAS, &CanvasWidth, &CanvasHeight); *new = SRGP_defRectangle(10,CanvasHeight-75, 175, CanvasHeight-40); *reset = SRGP_defRectangle(10,CanvasHeight-125, 175, CanvasHeight-90); *circle = SRGP_defRectangle(25,CanvasHeight-200, 80, CanvasHeight-150); *square = SRGP_defRectangle(100,CanvasHeight-200, 155, CanvasHeight-150); *vrect = SRGP_defRectangle(100,CanvasHeight-275, 155, CanvasHeight-225); *hrect = SRGP_defRectangle(25,CanvasHeight-275, 80, CanvasHeight-225); *object = SRGP_defRectangle(10,CanvasHeight-350, 175, CanvasHeight-315); *text = SRGP_defRectangle(10,CanvasHeight-400, 175, CanvasHeight-365); *color = SRGP_defRectangle(10,CanvasHeight-450, 175, CanvasHeight-415); *insert = SRGP_defRectangle(130,CanvasHeight-445, 155, CanvasHeight-420); *resize = SRGP_defRectangle(10, 75, 175, 110); *quit = SRGP_defRectangle(10, 25, 175, 60); *MainCanvas = SRGP_defRectangle(200,25,CanvasWidth-25, CanvasHeight-25); *Window = SRGP_defRectangle(0,0,CanvasWidth,CanvasHeight); SRGP_setClipRectangle(*Window); SRGP_setColor(4); SRGP_fillRectangle(*Window); Draw_New_Canvas(*MainCanvas); Make_Button(*quit, "Quit", NONE, 9); Make_Button(*new, "New Canvas", NONE, 9); Make_Button(*reset, "Reset Attributes", NONE, 9); Make_Button(*circle, "Circle Brush", CIRCLE, 9); Make_Button(*hrect, "Horizontal Rectangle", H_RECT, 9); Make_Button(*vrect, "Vertical Rectangle", V_RECT, 9); Make_Button(*square, "Square Brush", SQUARE, 9); Make_Button(*object, "Objects", NONE, 9); Make_Button(*text, "Text", NONE, 9); Make_Button(*color, "Colors ", NONE, 9); Make_Button(*insert, "", NONE, current.color); Make_Button(*resize, "Resize Canvas", NONE, 9); SRGP_setClipRectangle(*MainCanvas); } void Make_Button( rectangle buttonRect, char *name, int shape, int color) { point centerOfButton, textOrigin; int width, height, descent; rectangle temp; point pt1, pt2; SRGP_setFillStyle(SOLID); SRGP_setColor(color); SRGP_fillRectangle(buttonRect); SRGP_setColor(COLOR_BLACK); SRGP_setLineWidth(2); SRGP_rectangle(buttonRect); SRGP_setColor(0); pt1.x = buttonRect.bottomLeft.x; pt1.y = buttonRect.bottomLeft.y; pt2.x = pt1.x; pt2.y = buttonRect.topRight.y; SRGP_line(pt1, pt2); pt1.x = pt2.x; pt1.y = pt2.y; pt2.x = buttonRect.topRight.x-1; pt2.y = buttonRect.topRight.y; SRGP_line(pt1, pt2); SRGP_setColor(COLOR_BLACK); SRGP_inquireTextExtent(name, &width, &height, &descent); centerOfButton.x = (buttonRect.bottomLeft.x + buttonRect.topRight.x)/2; centerOfButton.y = (buttonRect.bottomLeft.y + buttonRect.topRight.y)/2; textOrigin.x = centerOfButton.x - (width/2); textOrigin.y = centerOfButton.y - ((height+descent)/2); if(shape == NONE) { SRGP_text(textOrigin, name); } if(shape == CIRCLE) { temp = SRGP_defRectangle(centerOfButton.x - 15, centerOfButton.y - 15, centerOfButton.x + 15, centerOfButton.y + 15); SRGP_setFillStyle(SOLID); SRGP_setColor(COLOR_BLACK); SRGP_fillEllipse(temp); } if(shape == H_RECT) { temp = SRGP_defRectangle(centerOfButton.x - 15, centerOfButton.y - 6, centerOfButton.x + 15, centerOfButton.y + 6); SRGP_setFillStyle(SOLID); SRGP_setColor(COLOR_BLACK); SRGP_fillRectangle(temp); } if(shape == V_RECT) { temp = SRGP_defRectangle(centerOfButton.x - 6, centerOfButton.y - 15, centerOfButton.x + 6, centerOfButton.y + 15); SRGP_setFillStyle(SOLID); SRGP_setColor(COLOR_BLACK); SRGP_fillRectangle(temp); } if(shape == SQUARE) { temp = SRGP_defRectangle(centerOfButton.x - 12, centerOfButton.y - 12, centerOfButton.x + 12, centerOfButton.y + 12); SRGP_setFillStyle(SOLID); SRGP_setColor(COLOR_BLACK); SRGP_fillRectangle(temp); } } int Picked_Button(point now, rectangle rect) { if( (now.x >= rect.bottom_left.x) && (now.x <= rect.top_right.x) && (now.y >= rect.bottom_left.y) && (now.y <= rect.top_right.y) ) return TRUE; else return FALSE; } void Draw(brush current, rectangle canvas_rect) { int halfBrushWidth = (current.size.height/2); int halfBrushHeight= (current.size.width/2); rectangle rect; locatorMeasure locMeasure; point pt1, pt2, pt3, pt4, pt0, p1, p2, center; int device; int count = 0, terminate = FALSE; point vertices[80]; double start_angle, end_angle; SRGP_setInputMode(LOCATOR, SAMPLE); SRGP_setColor(current.color); if (current.type < LINE_SQUARE) { SRGP_sampleLocator(&locMeasure); do{ rect = SRGP_defRectangle(locMeasure.position.x - halfBrushWidth, locMeasure.position.y - halfBrushHeight, locMeasure.position.x + halfBrushWidth, locMeasure.position.y + halfBrushHeight); if( (current.type == SQUARE) || (current.type == H_RECT) || (current.type == V_RECT) ) SRGP_fillRectangle(rect); if( (current.type == CIRCLE) ) SRGP_fillEllipse(rect); SRGP_sampleLocator(&locMeasure); } while( (locMeasure.buttonChord[0] == DOWN) ); SRGP_setInputMode(LOCATOR, EVENT); SRGP_setLocatorEchoType(CURSOR); } if ((current.type == LINE_SQUARE) || (current.type == FILL_SQUARE) || (current.type == LINE_CIRCLE) || (current.type == FILL_CIRCLE) ){ SRGP_setInputMode(LOCATOR, EVENT); SRGP_setLocatorEchoType(RUBBER_RECT); device = SRGP_waitEvent( INDEFINITE ); switch (device) { case LOCATOR: SRGP_getLocator(&locMeasure); SRGP_setLocatorEchoRubberAnchor(locMeasure.position); pt1 = locMeasure.position; } device = SRGP_waitEvent( INDEFINITE ); switch (device) { case LOCATOR: SRGP_getLocator(&locMeasure); pt2 = locMeasure.position; } SRGP_setLocatorEchoType(CURSOR); if(pt1.x <= pt2.x) { p1.x = pt1.x; p2.x = pt2.x; } if(pt2.x < pt1.x) { p1.x = pt2.x; p2.x = pt1.x; } if(pt1.y <= pt2.y) { p1.y = pt1.y; p2.y = pt2.y; } if(pt2.y < pt1.y) { p1.y = pt2.y; p2.y = pt1.y; } rect = SRGP_defRectangle(p1.x, p1.y, p2.x, p2.y); switch(current.type) { case LINE_SQUARE: SRGP_rectangle(rect); break; case FILL_SQUARE: SRGP_setFillStyle(SOLID); SRGP_fillRectangle(rect); break; case LINE_CIRCLE: SRGP_ellipse(rect); break; case FILL_CIRCLE: SRGP_setFillStyle(SOLID); SRGP_fillEllipse(rect); break; case LINE_ELLIPSE: SRGP_ellipse(rect); break; case FILL_ELLIPSE: SRGP_setFillStyle(SOLID); SRGP_fillEllipse(rect); break; } } if ((current.type == LINE_ELLIPSE) || (current.type == FILL_ELLIPSE) ) { SRGP_setInputMode(LOCATOR, EVENT); SRGP_setLocatorEchoType(RUBBER_RECT); device = SRGP_waitEvent( INDEFINITE ); switch (device) { case LOCATOR: SRGP_getLocator(&locMeasure); SRGP_setLocatorEchoRubberAnchor(locMeasure.position); pt1 = locMeasure.position; } device = SRGP_waitEvent( INDEFINITE ); switch (device) { case LOCATOR: SRGP_getLocator(&locMeasure); pt2 = locMeasure.position; } SRGP_setLocatorEchoType(CURSOR); if(pt1.x <= pt2.x) { p1.x = pt1.x; p2.x = pt2.x; } if(pt2.x < pt1.x) { p1.x = pt2.x; p2.x = pt1.x; } if(pt1.y <= pt2.y) { p1.y = pt1.y; p2.y = pt2.y; } if(pt2.y < pt1.y) { p1.y = pt2.y; p2.y = pt1.y; } rect = SRGP_defRectangle(p1.x, p1.y, p2.x, p2.y); switch(current.type) { case LINE_SQUARE: SRGP_rectangle(rect); break; case FILL_SQUARE: SRGP_setFillStyle(SOLID); SRGP_fillRectangle(rect); break; case LINE_CIRCLE: SRGP_ellipse(rect); break; case FILL_CIRCLE: SRGP_setFillStyle(SOLID); SRGP_fillEllipse(rect); break; case LINE_ELLIPSE: SRGP_ellipse(rect); break; case FILL_ELLIPSE: SRGP_setFillStyle(SOLID); SRGP_fillEllipse(rect); break; } } if ((current.type == LINE_ARC) || (current.type == FILL_ARC) ) { SRGP_setInputMode(LOCATOR, EVENT); SRGP_setLocatorEchoType(RUBBER_RECT); device = SRGP_waitEvent( INDEFINITE ); switch (device) { case LOCATOR: SRGP_getLocator(&locMeasure); SRGP_setLocatorEchoRubberAnchor(locMeasure.position); pt1 = locMeasure.position; } device = SRGP_waitEvent( INDEFINITE ); switch (device) { case LOCATOR: SRGP_getLocator(&locMeasure); pt2 = locMeasure.position; } if(pt1.x <= pt2.x) { p1.x = pt1.x; p2.x = pt2.x; } if(pt2.x < pt1.x) { p1.x = pt2.x; p2.x = pt1.x; } if(pt1.y <= pt2.y) { p1.y = pt1.y; p2.y = pt2.y; } if(pt2.y < pt1.y) { p1.y = pt2.y; p2.y = pt1.y; } rect = SRGP_defRectangle(p1.x, p1.y, p2.x, p2.y); center.x = (rect.bottomLeft.x + rect.topRight.x)/2; center.y = (rect.bottomLeft.y + rect.topRight.y)/2; SRGP_setLocatorEchoType(RUBBER_LINE); SRGP_setLocatorEchoRubberAnchor(center); device = SRGP_waitEvent( INDEFINITE ); switch (device) { case LOCATOR: SRGP_getLocator(&locMeasure); pt3 = locMeasure.position; } SRGP_setLocatorEchoRubberAnchor(center); device = SRGP_waitEvent( INDEFINITE ); switch (device) { case LOCATOR: SRGP_getLocator(&locMeasure); pt3 = locMeasure.position; } SRGP_setLocatorEchoRubberAnchor(center); device = SRGP_waitEvent( INDEFINITE ); switch (device) { case LOCATOR: SRGP_getLocator(&locMeasure); pt3 = locMeasure.position; } SRGP_setLocatorEchoRubberAnchor(center); device = SRGP_waitEvent( INDEFINITE ); switch (device) { case LOCATOR: SRGP_getLocator(&locMeasure); pt4 = locMeasure.position; } pt0 = SRGP_defPoint(center.x+100, center.y); start_angle = findAngle(center, pt3, pt0); end_angle = findAngle(center, pt4, pt0); switch(current.type) { case LINE_ARC: SRGP_ellipseArc(rect, start_angle, end_angle); break; case FILL_ARC: SRGP_setFillStyle(SOLID); SRGP_fillEllipseArc(rect, start_angle, end_angle); break; } SRGP_setLocatorEchoType(CURSOR); } if ((current.type == POLYLINE) || (current.type == POLYGON) || (current.type == POLYMARK1) || (current.type == POLYMARK2) || (current.type == POLYMARK3) || (current.type == POLYMARK3)) { SRGP_setInputMode(LOCATOR, EVENT); do { device = SRGP_waitEvent( INDEFINITE ); switch (device) { case KEYBOARD: break; case LOCATOR: SRGP_getLocator(&locMeasure); switch ( locMeasure.buttonOfMostRecentTransition ) { case PLACE_BUTTON: if(locMeasure.buttonChord[PLACE_BUTTON] == DOWN) { vertices[count] = locMeasure.position; count++; if((current.type == POLYLINE) || (current.type == POLYGON)) { SRGP_setLocatorEchoType(RUBBER_LINE); SRGP_setLocatorEchoRubberAnchor(locMeasure.position); if(count>1) { SRGP_line(vertices[count-1], vertices[count-2]); } } if(current.type == POLYMARK1) { SRGP_setMarkerStyle(MARKER_CIRCLE); SRGP_marker(locMeasure.position); } if(current.type == POLYMARK2) { SRGP_setMarkerStyle(MARKER_SQUARE); SRGP_marker(locMeasure.position); } if(current.type == POLYMARK3) { SRGP_setMarkerStyle(MARKER_X); SRGP_marker(locMeasure.position); } if(!Picked_Button(locMeasure.position, canvas_rect)) terminate = TRUE; } break; case QUIT_BUTTON: terminate = TRUE; break; } /* end of switch on */ } /* end of switch on */ } while(!terminate); /* end of do-while loop */ SRGP_setLocatorEchoType(CURSOR); if(count > 2) { switch(current.type) { case POLYLINE: SRGP_polyLine(count, vertices); break; case POLYGON: SRGP_fillPolygon(count, vertices); break; case POLYMARK1: SRGP_setMarkerStyle(MARKER_CIRCLE); SRGP_polyMarker(count, vertices); break; case POLYMARK2: SRGP_setMarkerStyle(MARKER_SQUARE); SRGP_polyMarker(count, vertices); break; case POLYMARK3: SRGP_setMarkerStyle(MARKER_X); SRGP_polyMarker(count, vertices); break; } } } /*end of if */ } double findAngle(point center, point pt1, point pt2) { double result, length1, length2, vector_product; point vector1 = SRGP_defPoint(pt1.x-center.x, pt1.y - center.y); point vector2 = SRGP_defPoint(pt2.x-center.x, pt2.y - center.y); vector_product = (vector1.x*vector2.x)+(vector1.y*vector2.y); length1 = ((vector1.x*vector1.x)+(vector1.y*vector1.y)); length2 = ((vector2.x*vector2.x)+(vector2.y*vector2.y)); length1 = sqrt(length1); length2 = sqrt(length2); result = acos(vector_product / ((length1) * (length2)) ); result = result*180/M_PI; if(vector1.y < 0) result = 360 - result; return result; } void Draw_New_Canvas(rectangle MainCanvas) { SRGP_setLineWidth(6); SRGP_setFillStyle(SOLID); SRGP_setColor(COLOR_WHITE); SRGP_fillRectangle(MainCanvas); SRGP_setColor(COLOR_BLACK); SRGP_setLineWidth(5); SRGP_rectangle(MainCanvas); } void Reset_All(brush *current_brush) { current_brush->type = CIRCLE; current_brush->color = 83; current_brush->size.height = 16; current_brush->size.width = 16; } void Text_Event(rectangle rect, rectangle menu_rect, brush current) { char buffer[80]; int canvas1, canvas2; int terminate = FALSE; int device; point pt = SRGP_defPoint(0,0); int test = FALSE; point text_start; locatorMeasure locMeasure; rectangle save_rect, saveClipRectangle; save_rect = SRGP_defRectangle(0,0,1000,750); canvas1 = SRGP_createCanvas(1000, 750); canvas2 = SRGP_createCanvas(1000, 750); SRGP_useCanvas(canvas1); SRGP_copyPixel(SCREEN_CANVAS, save_rect, pt); SRGP_useCanvas(canvas2); SRGP_copyPixel(SCREEN_CANVAS, save_rect, pt); SRGP_useCanvas(SCREEN_CANVAS); SRGP_setInputMode(KEYBOARD,EVENT); SRGP_setKeyboardProcessingMode(EDIT); text_start = SRGP_defPoint(500, 375); do{ SRGP_setKeyboardEchoColor(current.color); device = SRGP_waitEvent( INDEFINITE ); switch (device) { case KEYBOARD: SRGP_getKeyboard(buffer, BUFFER_SIZE); SRGP_setColor(current.color); SRGP_text(text_start, buffer); test = TRUE; break; case LOCATOR: { SRGP_getLocator(&locMeasure); switch ( locMeasure.buttonOfMostRecentTransition ) { case PLACE_BUTTON: if( Picked_Button(locMeasure.position, rect) ) { SRGP_useCanvas(canvas1); SRGP_copyPixel(canvas2, save_rect, pt); SRGP_setColor(current.color); text_start = locMeasure.position; SRGP_text(text_start, buffer); SRGP_useCanvas(SCREEN_CANVAS); SRGP_copyPixel(canvas1, save_rect, pt); } if( Picked_Button(locMeasure.position, menu_rect) && (test == TRUE) ) { SRGP_useCanvas(SCREEN_CANVAS); SRGP_copyPixel(canvas2, save_rect, pt); terminate = TRUE; } break; case QUIT_BUTTON: terminate = TRUE; SRGP_setInputMode(KEYBOARD,EVENT); SRGP_setKeyboardProcessingMode(RAW); SRGP_setColor(current.color); SRGP_useCanvas(canvas1); SRGP_copyPixel(canvas2, save_rect, pt); SRGP_text(text_start, buffer); SRGP_useCanvas(SCREEN_CANVAS); SRGP_copyPixel(canvas1, save_rect, pt); break; } } } } while(!terminate); } void ColorPullDown(rectangle menu_rect, char* name, int type, int color, brush *current_brush) { locatorMeasure measure; brush tempbrush; int saveCanvas = 2, menuCanvas = 3; point pt; int extent; int button_width = 20; int button_height = 20; rectangle save_rect, copy_rect, saveClipRectangle; point centerOfButton, textOrigin; int width, height, descent; saveClipRectangle = SRGP_inquireClipRectangle(); save_rect = SRGP_defRectangle(0,0,1000,750); SRGP_setClipRectangle(save_rect); menuCanvas = SRGP_createCanvas(1000, 750); saveCanvas = SRGP_createCanvas(1000, 750); pt.x = 0; pt.y = 0; SRGP_useCanvas(saveCanvas); SRGP_copyPixel(SCREEN_CANVAS, save_rect, pt); /*This creates the menu on the non-visible menuCanvas*/ SRGP_useCanvas(menuCanvas); SRGP_copyPixel(saveCanvas, save_rect, pt); switch(type) { case COLOR: extent = 385; MakeColorMenuCanvas(menu_rect, extent, color); break; case SQUARE: extent = 275; MakeSquareMenuCanvas(menu_rect, extent, color); break; case H_RECT: extent = 275; MakeHRectMenuCanvas(menu_rect, extent, color); break; case V_RECT: extent = 275; MakeVRectMenuCanvas(menu_rect, extent, color); break; case CIRCLE: extent = 275; MakeCircleMenuCanvas(menu_rect, extent, color); break; case OBJECT: extent = 385; MakeObjectMenuCanvas(menu_rect, extent, color); break; case MARKER: extent = 585; MakeMarkerMenuCanvas(menu_rect, extent, color); break; } SRGP_useCanvas(SCREEN_CANVAS); copy_rect = SRGP_defRectangle(0,0, 1000, 750); SRGP_copyPixel(menuCanvas, copy_rect ,pt); while (LOCATOR!=SRGP_waitEvent (INDEFINITE)); SRGP_waitEvent (INDEFINITE); SRGP_getLocator (&measure); Handle_Point(measure.position, menu_rect, extent, type, *current_brush, &tempbrush, color); current_brush->size.height = tempbrush.size.height; current_brush->size.width = tempbrush.size.width; current_brush->color = tempbrush.color; current_brush->type = tempbrush.type; SRGP_copyPixel (saveCanvas, copy_rect, pt); SRGP_deleteCanvas(saveCanvas); SRGP_deleteCanvas(menuCanvas); SRGP_setClipRectangle(saveClipRectangle); } void Handle_Point(point pt, rectangle rect, int a, int type, brush current, brush *temp, int color) { int i, j, w, h; int colorindex = 20; int ycoord = 280; int y = rect.bottomLeft.y-20; int botY = rect.bottomLeft.y-25; int topY = rect.bottomLeft.y; brush t; rectangle test; temp->size.height = current.size.height; temp->size.width = current.size.width; temp->color = current.color; temp->type = current.type; switch(type) { case COLOR: for(j=0; j<= 8-1; j++) { for(i=0; i<= 8-1; i++) { test = SRGP_defRectangle(a-(8*20)+(20*i),y, a-(7*20)+(20*i),y+20); if(Picked_Button(pt,test)) { temp->color = colorindex+i; } } colorindex += 8; y -= 20; } break; case OBJECT: for(i=1; i<= 11; i++) { test = SRGP_defRectangle(a-200, botY, a, topY); if(Picked_Button(pt, test)) { switch(i-1) { case 0: temp->type = LINE_SQUARE; break; case 1: temp->type = FILL_SQUARE; break; case 2: temp->type = LINE_CIRCLE; break; case 3: temp->type = FILL_CIRCLE; break; case 4: temp->type = LINE_ELLIPSE; break; case 5: temp->type = FILL_ELLIPSE; break; case 6: temp->type = LINE_ARC; break; case 7: temp->type = FILL_ARC; break; case 8: temp->type = POLYLINE; break; case 9: temp->type = POLYGON; break; case 10: ColorPullDown(test, "Mark Types", MARKER, color, &t); temp->type = t.type; break; } } botY -= 25; topY -= 25; } break; case MARKER: for(i=1; i<= 3; i++) { test = SRGP_defRectangle(a-200, botY, a, topY); if(Picked_Button(pt, test)) { switch(i-1) { case 0: temp->type = POLYMARK1; break; case 1: temp->type = POLYMARK2; break; case 2: temp->type = POLYMARK3; break; } } botY -= 25; topY -= 25; } break; case CIRCLE: for(i=1; i<= 6; i++) { test = SRGP_defRectangle(a-50, botY, a, topY); if(Picked_Button(pt, test)) { switch(i-1) { case 0: h = 64; w = 64; break; case 1: h = 32; w = 32; break; case 2: h = 16; w = 16; break; case 3: h = 8; w = 8; break; case 4: h = 4; w = 4; break; case 5: h = 2; w = 2; break; } temp->size.height = w; temp->size.width = h; temp->color = current.color; temp->type = type; } botY -= 25; topY -= 25; } break; case SQUARE: for(i=1; i<= 1; i++) { test = SRGP_defRectangle(a-50, botY, a, topY); if(Picked_Button(pt, test)) { switch(i-1) { case 0: h = 10; w = 10; break; } temp->size.height = w; temp->size.width = h; temp->color = current.color; temp->type = type; } botY -= 25; topY -= 25; } break; case V_RECT: for(i=1; i<= 6; i++) { test = SRGP_defRectangle(a-50, botY, a, topY); if(Picked_Button(pt, test)) { switch(i-1) { case 0: h = 12; w = 8; break; case 1: h = 8; w = 4; break; case 2: h = 6; w = 4; break; case 3: h = 4; w = 2; break; case 4: h = 4; w = 2; break; } temp->size.height = w; temp->size.width = h; temp->color = current.color; temp->type = type; } botY -= 25; topY -= 25; } break; case H_RECT: for(i=1; i<= 6; i++) { test = SRGP_defRectangle(a-50, botY, a, topY); if(Picked_Button(pt, test)) { switch(i-1) { case 0: h = 8; w = 12; break; case 1: h = 4; w = 8; break; case 2: h = 4; w = 6; break; case 3: h = 2; w = 4; break; case 4: h = 3; w = 4; break; } temp->size.height = w; temp->size.width = h; temp->color = current.color; temp->type = type; } botY -= 25; topY -= 25; } break; } /* end of swith */ } void MakeObjectMenuCanvas(rectangle rect, int a, int color) { int i; int topY = rect.bottomLeft.y; int botY = rect.bottomLeft.y-25; rectangle temp; rectangle header = SRGP_defRectangle(rect.topRight.x,rect.bottomLeft.y,a,rect.topRight.y); char *label[11]; label[0] = "Outlined Square"; label[1] = "Filled Square"; label[2] = "Outlined Circle"; label[3] = "Filled Circle"; label[4] = "Outlined Ellipse"; label[5] = "Filled Ellipse"; label[6] = "Outlined Arc"; label[7] = "Filled Arc"; label[8] = "Polyline"; label[9] = "Polygon"; label[10] = "PolyMarker"; Make_Button(rect, "Objects", NONE, 10); Make_Button(header, "Object Types", NONE, color); for(i=1; i<= 11; i++) { temp = SRGP_defRectangle(a-200, botY, a, topY); Make_Button(temp, label[i-1], NONE, color); botY -= 25; topY -= 25; } } void MakeMarkerMenuCanvas(rectangle rect, int a, int color) { int i; int topY = rect.bottomLeft.y; int botY = rect.bottomLeft.y-25; rectangle temp; rectangle header = SRGP_defRectangle(rect.topRight.x,rect.bottomLeft.y,a,rect.topRight.y); char *label[4]; label[0] = "Circle Point"; label[1] = "Square Point"; label[2] = "X Point"; Make_Button(rect, "PolyMarker", NONE, 10); Make_Button(header, "Marker Types", NONE, color); for(i=1; i<= 3; i++) { temp = SRGP_defRectangle(a-200, botY, a, topY); Make_Button(temp, label[i-1], NONE, color); botY -= 25; topY -= 25; } } void MakeColorMenuCanvas(rectangle rect, int extent, int color) { int i, j; int colorindex = 20; int ycoord = rect.bottomLeft.y-20; /*280*/ rectangle temp; rectangle header = SRGP_defRectangle(rect.topRight.x, rect.bottomLeft.y, extent, rect.topRight.y); rectangle block = SRGP_defRectangle(extent-20*8, rect.bottomLeft.y-20*8, extent, rect.bottomLeft.y); Make_Button(rect, "Colors ", NONE, 10); Make_Button(header, "Color Palette", NONE, color); Make_Button(block, "",NONE, color); for(j=0; j<= 8-1; j++) { for(i=0; i<= 8-1; i++) { temp = SRGP_defRectangle(extent-8*20+20*i,ycoord, extent-7*20+20*i,ycoord+20); Make_Button(temp, "", NONE, colorindex+i); } colorindex += 8; ycoord -= 20; } } void MakeCircleMenuCanvas(rectangle rect, int a, int color) { int i; int topY = rect.bottomLeft.y; int botY = rect.bottomLeft.y-25; rectangle temp; rectangle header = SRGP_defRectangle(rect.topRight.x,rect.bottomLeft.y,a,rect.topRight.y); char *label[6]; label[0] = "64"; label[1] = "32"; label[2] = "16"; label[3] = "8"; label[4] = "4"; label[5] = "2"; Make_Button(rect, "", CIRCLE, 10); Make_Button(header, "Circle Diameter", NONE, color); for(i=1; i<= 6; i++) { temp = SRGP_defRectangle(a-50, botY, a, topY); Make_Button(temp, label[i-1], NONE, color); botY -= 25; topY -= 25; } } void MakeSquareMenuCanvas(rectangle rect, int a, int color) { int i; int topY = rect.bottomLeft.y; int botY = rect.bottomLeft.y-25; rectangle temp; rectangle header = SRGP_defRectangle(rect.topRight.x,rect.bottomLeft.y,a,rect.topRight.y); char *label[6]; label[0] = "10x10"; Make_Button(rect, "", SQUARE, 10); Make_Button(header, "Dimension", NONE, color); for(i=1; i<= 1; i++) { temp = SRGP_defRectangle(a-50, botY, a, topY); Make_Button(temp, label[i-1], NONE, color); botY -= 25; topY -= 25; } } void MakeVRectMenuCanvas(rectangle rect, int a, int color) { int i; int topY = rect.bottomLeft.y; int botY = rect.bottomLeft.y-25; rectangle temp; rectangle header = SRGP_defRectangle(rect.topRight.x,rect.bottomLeft.y,a,rect.topRight.y); char *label[6]; label[0] = "12 x 8"; label[1] = "8 x 4"; label[2] = "6 x 4"; label[3] = "4 x 2"; label[4] = "3 x 2"; Make_Button(rect, "", V_RECT, 10); Make_Button(header, "Dimensions", NONE, color); for(i=1; i<= 5; i++) { temp = SRGP_defRectangle(a-50, botY, a, topY); Make_Button(temp, label[i-1], NONE, color); botY -= 25; topY -= 25; } } void MakeHRectMenuCanvas(rectangle rect, int a, int color) { int i; int topY = rect.bottomLeft.y; int botY = rect.bottomLeft.y-25; rectangle temp; rectangle header = SRGP_defRectangle(rect.topRight.x,rect.bottomLeft.y,a,rect.topRight.y); char *label[6]; label[0] = "8 x 12"; label[1] = "4 x 8"; label[2] = "4 x 6"; label[3] = "2 x 4"; label[4] = "2 x 3"; Make_Button(rect, "", H_RECT, 10); Make_Button(header, "Dimensions", NONE, color); for(i=1; i<= 5; i++) { temp = SRGP_defRectangle(a-50, botY, a, topY); Make_Button(temp, label[i-1], NONE, color); botY -= 25; topY -= 25; } } void Initialize_ColorTable(void) { SRGP_loadCommonColor (20, "white"); SRGP_loadCommonColor (21, "seashell2"); SRGP_loadCommonColor (22, "AntiqueWhite2"); SRGP_loadCommonColor (23, "PeachPuff2"); SRGP_loadCommonColor (24, "LemonChiffon2"); SRGP_loadCommonColor (25, "cornsilk2"); SRGP_loadCommonColor (26, "honeydew2"); SRGP_loadCommonColor (27, "LavenderBlush2"); SRGP_loadCommonColor (28, "MistyRose2"); SRGP_loadCommonColor (29, "azure2"); SRGP_loadCommonColor (30, "SlateBlue2"); SRGP_loadCommonColor (31, "RoyalBlue2"); SRGP_loadCommonColor (32, "DodgerBlue2"); SRGP_loadCommonColor (33, "SteelBlue"); SRGP_loadCommonColor (34, "DeepSkyBlue2"); SRGP_loadCommonColor (35, "SkyBlue2"); SRGP_loadCommonColor (36, "LightSkyBlue2"); SRGP_loadCommonColor (37, "SlateGray2"); SRGP_loadCommonColor (38, "LightBlue2"); SRGP_loadCommonColor (39, "LightCyan2"); SRGP_loadCommonColor (40, "PaleTurquoise2"); SRGP_loadCommonColor (41, "CadetBlue2"); SRGP_loadCommonColor (42, "turquoise2"); SRGP_loadCommonColor (43, "cyan2"); SRGP_loadCommonColor (44, "aquamarine2"); SRGP_loadCommonColor (45, "DarkSeaGreen2"); SRGP_loadCommonColor (46, "SeaGreen2"); SRGP_loadCommonColor (47, "PaleGreen2"); SRGP_loadCommonColor (48, "SpringGreen2"); SRGP_loadCommonColor (49, "green2"); SRGP_loadCommonColor (50, "chartreuse2"); SRGP_loadCommonColor (51, "OliveDrab2"); SRGP_loadCommonColor (52, "DarkOliveGreen2"); SRGP_loadCommonColor (53, "khaki2"); SRGP_loadCommonColor (54, "LightGoldenrod2"); SRGP_loadCommonColor (55, "LightYellow"); SRGP_loadCommonColor (56, "yellow2"); SRGP_loadCommonColor (57, "goldenrod2"); SRGP_loadCommonColor (58, "RosyBrown2"); SRGP_loadCommonColor (59, "IndianRed2"); SRGP_loadCommonColor (60, "sienna2"); SRGP_loadCommonColor (61, "burlywood2"); SRGP_loadCommonColor (62, "wheat2"); SRGP_loadCommonColor (63, "tan2"); SRGP_loadCommonColor (64, "chocolate2"); SRGP_loadCommonColor (65, "firebrick2"); SRGP_loadCommonColor (66, "brown2"); SRGP_loadCommonColor (67, "salmon2"); SRGP_loadCommonColor (68, "LightSalmon2"); SRGP_loadCommonColor (69, "orange2"); SRGP_loadCommonColor (70, "coral2"); SRGP_loadCommonColor (71, "tomato2"); SRGP_loadCommonColor (72, "OrangeRed2"); SRGP_loadCommonColor (73, "red2"); SRGP_loadCommonColor (74, "DeepPink2"); SRGP_loadCommonColor (75, "pink2"); SRGP_loadCommonColor (76, "PaleVioletRed2"); SRGP_loadCommonColor (77, "maroon2"); SRGP_loadCommonColor (78, "magenta2"); SRGP_loadCommonColor (79, "plum2"); SRGP_loadCommonColor (80, "orchid2"); SRGP_loadCommonColor (81, "purple2"); SRGP_loadCommonColor (82, "thistle2"); SRGP_loadCommonColor (83, "gray0"); }