[Dda-cvs] ntdda/src/win32gui drawdialog.c,1.7,1.8
Status: Beta
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2006-08-01 05:26:14
|
Update of /cvsroot/dda/ntdda/src/win32gui In directory sc8-pr-cvs12.sourceforge.net:/tmp/cvs-serv21197/src/win32gui Modified Files: drawdialog.c Log Message: Added rooz patched for dialog handling. Index: drawdialog.c =================================================================== RCS file: /cvsroot/dda/ntdda/src/win32gui/drawdialog.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** drawdialog.c 31 Jul 2006 02:13:19 -0000 1.7 --- drawdialog.c 1 Aug 2006 05:26:10 -0000 1.8 *************** *** 1,5 **** /* File contains functions to handle the creation and editing ! * of geometry files for DDA. */ #include <math.h> --- 1,21 ---- /* File contains functions to handle the creation and editing ! * of geometry files for DDA. ! * ! * Overall behavior: ! * ! * 1. At the moment, the dialog will save and write to a file ! * any created geometry. This geometry is not passed by either ! * pointer to geometry struct or by file name to the calling ! * program. */ + + /** + * TODO list: + * + * 1. Object scaling needs to be handled on object creation, and + * the current object scale needs to be stored to allow rescaling. + * + * + */ #include <math.h> *************** *** 17,22 **** #pragma warning( disable : 4115 ) #endif - BOOL CALLBACK JointDlgProc (HWND, UINT, WPARAM, LPARAM); static HINSTANCE hInstance; --- 33,48 ---- #pragma warning( disable : 4115 ) #endif + + // Unnecessary. Prototypes are used by the compiler + // for type checking. In this case, each of these + // callbacks is defined before being invoked, rendering + // the prototype unnecessary. + //Added by Roozbeh + //BOOL CALLBACK JointDlgProc (HWND, UINT, WPARAM, LPARAM); + //BOOL CALLBACK TunnelDlgProc (HWND, UINT, WPARAM, LPARAM); + //BOOL CALLBACK ArcDlgProc (HWND, UINT, WPARAM, LPARAM); + //BOOL CALLBACK BlockDlgProc (HWND, UINT, WPARAM, LPARAM); + //Added by Roozbeh static HINSTANCE hInstance; *************** *** 187,192 **** ! ! static ddaboolean //entirely trg error here inBoundingBox (Joint * jp, POINT p, double eps) { --- 213,218 ---- ! // Changed some variable names to make this less verbose. ! static ddaboolean inBoundingBox (Joint * jp, POINT p, double eps) { *************** *** 206,210 **** if ((currentx > endpx2 + eps) || (currentx < endpx1 - eps)) return FALSE; ! } if (endpy1 > endpy2) { if ((currenty < endpy2 - eps) || (currenty > endpy1 + eps)) --- 232,237 ---- if ((currentx > endpx2 + eps) || (currentx < endpx1 - eps)) return FALSE; ! } ! if (endpy1 > endpy2) { if ((currenty < endpy2 - eps) || (currenty > endpy1 + eps)) *************** *** 241,246 **** return 0; } /* close inBoundingBoxEP */ ! static int //trg edit-->added BBox closetoJoint (Joint * jp, POINT p) { --- 268,274 ---- return 0; } /* close inBoundingBoxEP */ + ! static int closetoJoint (Joint * jp, POINT p) { *************** *** 278,282 **** ! static double //trg distBtwPoints (POINT p1, POINT p2) { --- 306,310 ---- ! static double distBtwPoints (POINT p1, POINT p2) { *************** *** 286,290 **** } ! static void //travis //drawBlackSquare(DPoint * ptmp, int radius) --- 314,322 ---- } ! ! ! // This routine needs to have an associated ROP ! // to redraw the background color when the object ! // is deselected. static void //travis //drawBlackSquare(DPoint * ptmp, int radius) *************** *** 321,325 **** } /* drawBlockBox() */ ! static void drawJointHandles (Joint * jp) --- 353,358 ---- } /* drawBlockBox() */ ! ! // Need an associated "deselection" function. static void drawJointHandles (Joint * jp) *************** *** 332,335 **** --- 365,369 ---- } + /** @todo Fix the api to not take the point struct. */ *************** *** 346,350 **** ! } /* close drawJointHandles() */ --- 380,384 ---- ! } *************** *** 362,368 **** LineTo (hdc, endp2x, endp2y); ! if (jp->is_selected) ! drawJointHandles (jp); ! } /* close drawJoint() */ //Added By Roozbeh --- 396,407 ---- LineTo (hdc, endp2x, endp2y); ! ! // Always use bracing, even around single statement blocks. ! // They tend to grow, reduces blunders. ! if (jp->is_selected) { ! drawJointHandles (jp); ! } ! } ! //Added By Roozbeh *************** *** 380,383 **** --- 419,423 ---- } /* close redrawPoints *///Added By Roozbeh + /* This produces an infinite loop and does not allow the *************** *** 434,437 **** --- 474,478 ---- } /* close handlePaint() *///Added By Roozbeh + static void *************** *** 496,499 **** --- 537,541 ---- } /* close handleMouseDown() */ + static void *************** *** 584,587 **** --- 626,630 ---- /* Now draw to screen */ + SelectObject (hdc, drawPen[type]); //Added By Roozbeh to draw type of line with various color MoveToEx (hdc, ptBegin.x, ptBegin.y, NULL); LineTo (hdc, ptNew.x, ptNew.y); *************** *** 625,638 **** RECT drawSize; int orig_x, orig_y, ext_x, ext_y; - - HANDLE h; - HBITMAP hbm; - - context = selection; ! ! ! /* Start test code for dialog param passing */ --- 668,676 ---- RECT drawSize; int orig_x, orig_y, ext_x, ext_y; + //HANDLE h; + //HBITMAP hbm; ! context = selection; /* Start test code for dialog param passing */ *************** *** 659,663 **** jointlist = dlist_new (); pointlist = dlist_new (); - //boltlist = make_dl(); boltlist = boltlist_new (); --- 697,700 ---- *************** *** 665,671 **** GetWindowRect (GetDlgItem (hDlg, IDC_DRAWSPACE), &drawSize); hdc = GetDC (GetDlgItem (hDlg, IDC_DRAWSPACE)); // i think this is DEADLY wrong TRG getDC does not "validate" ! ! ! SetClassLong (GetDlgItem (hDlg, IDC_DRAWSPACE), GCL_HCURSOR, --- 702,706 ---- GetWindowRect (GetDlgItem (hDlg, IDC_DRAWSPACE), &drawSize); hdc = GetDC (GetDlgItem (hDlg, IDC_DRAWSPACE)); // i think this is DEADLY wrong TRG getDC does not "validate" ! SetClassLong (GetDlgItem (hDlg, IDC_DRAWSPACE), GCL_HCURSOR, *************** *** 915,924 **** return 0; } ! geomstruct = gdata_new (); - transferJointlistToGeomStruct (geomstruct, jointlist); transferPointlistToGeomStruct (geomstruct, pointlist); transferBoltlistToGeomStruct (geomstruct, boltlist); --- 950,962 ---- return 0; } ! ! //////////////////////////////////////////////// ! /// Because we grabbing a new struct here, then deleting ! /// it afterwards, we can do cooler stuff here. geomstruct = gdata_new (); transferJointlistToGeomStruct (geomstruct, jointlist); transferPointlistToGeomStruct (geomstruct, pointlist); + transferBoltlistToGeomStruct (geomstruct, boltlist); *************** *** 995,999 **** ! // TODO: Combine this code with the code in graphics.c static void --- 1033,1037 ---- ! // TODO: Combine this code with the code in graphics.c static void *************** *** 1040,1049 **** dl_delete_node (pointlist->blink); ! if (grid) SendMessage (hDlg, WM_COMMAND, DD_GRON, 0L); ! else SendMessage (hDlg, WM_COMMAND, DD_GROFF, 0L); ! } /* close handleRemovePoint() */ --- 1078,1088 ---- dl_delete_node (pointlist->blink); ! if (grid) { SendMessage (hDlg, WM_COMMAND, DD_GRON, 0L); ! } else { SendMessage (hDlg, WM_COMMAND, DD_GROFF, 0L); + } ! } *************** *** 1072,1076 **** } ! } /* close drawPoints */ --- 1111,1115 ---- } ! } *************** *** 1105,1109 **** ! void transferJointlistToGeomStruct (Geometrydata * gd, JOINTLIST * jointlist) --- 1144,1150 ---- ! ! ! /// Function is scheduled for deletion. void transferJointlistToGeomStruct (Geometrydata * gd, JOINTLIST * jointlist) *************** *** 1112,1116 **** int numjoints; JOINTLIST *ptr; ! Joint *jtmp; /* just in case... */ numjoints = dlist_length (jointlist); --- 1153,1159 ---- int numjoints; JOINTLIST *ptr; ! Joint *jtmp; ! double jscale = ScaleX/maxSize; ! /* just in case... */ numjoints = dlist_length (jointlist); *************** *** 1124,1132 **** dlist_traverse (ptr, jointlist) { jtmp = ptr->val; ! ! gd->joints[i + 1][1] = jtmp->epx1 * (ScaleX / maxSize); //Added (ScaleX/maxSize) term by Roozbeh ! gd->joints[i + 1][2] = jtmp->epy1 * (ScaleX / maxSize); //Added (ScaleX/maxSize) term by Roozbeh ! gd->joints[i + 1][3] = jtmp->epx2 * (ScaleX / maxSize); //Added (ScaleX/maxSize) term by Roozbeh ! gd->joints[i + 1][4] = jtmp->epy2 * (ScaleX / maxSize); //Added (ScaleX/maxSize) term by Roozbeh gd->joints[i + 1][5] = jtmp->type; i++; --- 1167,1179 ---- dlist_traverse (ptr, jointlist) { jtmp = ptr->val; ! ! // Scaling needs to be performed at initialization of each joint. ! // If the geometry is rescaled, that should be handled by traversing ! // the joint list and rescaling as a ratio between old and new scales ! // for existing joints. New joints go in with the new scale of course. ! gd->joints[i + 1][1] = jtmp->epx1 * jscale; ! gd->joints[i + 1][2] = jtmp->epy1 * jscale; ! gd->joints[i + 1][3] = jtmp->epx2 * jscale; ! gd->joints[i + 1][4] = jtmp->epy2 * jscale; gd->joints[i + 1][5] = jtmp->type; i++; *************** *** 1134,1138 **** ! } /* close transferJointlistToGeomStruct() */ --- 1181,1185 ---- ! } *************** *** 1426,1431 **** ReleaseCapture (); } /* close handleMouseUp() */ - BOOL CALLBACK JointDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) --- 1473,1479 ---- ReleaseCapture (); } /* close handleMouseUp() */ + + // Added by Roozbeh to Draw a Joint using dialog box BOOL CALLBACK JointDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) *************** *** 1443,1449 **** case WM_COMMAND: ! switch (LOWORD (wParam)) { ! case IDOK: ptBegin.x = GetDlgItemInt (hDlg, IDC_X1, NULL, TRUE); ptBegin.y = GetDlgItemInt (hDlg, IDC_Y1, NULL, TRUE); --- 1491,1499 ---- case WM_COMMAND: ! switch (LOWORD (wParam)) { + case IDOK: + + // Make this a function call with a descriptive name. ptBegin.x = GetDlgItemInt (hDlg, IDC_X1, NULL, TRUE); ptBegin.y = GetDlgItemInt (hDlg, IDC_Y1, NULL, TRUE); *************** *** 1468,1471 **** --- 1518,1735 ---- } + // Added by Roozbeh to Draw a Tuunel using dialog box + BOOL CALLBACK + TunnelDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) + { + double r0, u, v, x1, x2, x3, y1, y2, y3, x0, y0, deg; + double xc, yc, rad; + int i, se = 20; + + switch (message) { + case WM_INITDIALOG: + + SetDlgItemInt (hDlg, IDC_XC, 0, FALSE); + SetDlgItemInt (hDlg, IDC_YC, 0, FALSE); + SetDlgItemInt (hDlg, IDC_SEG, 20, FALSE); + SetDlgItemInt (hDlg, IDC_RAD, 10, FALSE); + SetDlgItemInt (hDlg, IDC_TYPE, 1, FALSE); + + return TRUE; + + case WM_COMMAND: + switch (LOWORD (wParam)) { + case IDOK: + + deg = 360; + r0 = ((3.1415926535) * deg) / (se * 180); + xc = GetDlgItemInt (hDlg, IDC_XC, NULL, TRUE); + yc = GetDlgItemInt (hDlg, IDC_YC, NULL, TRUE); + se = GetDlgItemInt (hDlg, IDC_SEG, NULL, TRUE); + rad = GetDlgItemInt (hDlg, IDC_RAD, NULL, TRUE); + type = GetDlgItemInt (hDlg, IDC_TYPE, NULL, TRUE); + x1 = xc + rad; + y1 = yc; + x2 = xc; + y2 = yc; + x0 = x2; + y0 = y2; + x3 = x1; + y3 = y1; + for (i = 1; i < se; i++) { + u = ((x1 - x0) * (cos (r0) - 1)) - ((y1 - y0) * sin (r0)); + v = ((x1 - x0) * sin (r0)) + ((y1 - y0) * (cos (r0) - 1)); + + x2 = x1 + u; + y2 = y1 + v; + ptBegin.x = (long) floor (x1 / (ScaleX / maxSize)); + ptBegin.y = (long) floor (y1 / (ScaleY / maxSize)); + ptNew.x = (long) floor (x2 / (ScaleX / maxSize)); + ptNew.y = (long) floor (y2 / (ScaleY / maxSize)); + addJoint (hDlg); + x1 = x2; + y1 = y2; + } + x2 = x3; + y2 = y3; + ptBegin.x = (long) floor (x1 / (ScaleX / maxSize)); + ptBegin.y = (long) floor (y1 / (ScaleY / maxSize)); + ptNew.x = (long) floor (x2 / (ScaleX / maxSize)); + ptNew.y = (long) floor (y2 / (ScaleY / maxSize)); + addJoint (hDlg); + + return FALSE; + case IDCANCEL: + EndDialog (hDlg, 0); + return TRUE; + } + break; + } + return FALSE; + } + + + + // Added by Roozbeh to Draw a Arc using dialog box + + // Refactor all these messages to call functions. + // Feel free to put them into new files. It will + // make it easier to maintain in the future. + BOOL CALLBACK + ArcDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) + { + double r0, u, v, x1, x2, x3, y1, y2, y3, x0, y0, deg; + double xc, yc, xs, ys, xe, ye; + int i, se = 20; + + switch (message) { + case WM_INITDIALOG: + + SetDlgItemInt (hDlg, IDC_XC, 0, FALSE); + SetDlgItemInt (hDlg, IDC_YC, 0, FALSE); + SetDlgItemInt (hDlg, IDC_XS, 0, FALSE); + SetDlgItemInt (hDlg, IDC_YS, 0, FALSE); + SetDlgItemInt (hDlg, IDC_XE, 0, FALSE); + SetDlgItemInt (hDlg, IDC_YE, 0, FALSE); + SetDlgItemInt (hDlg, IDC_SEG, 20, FALSE); + SetDlgItemInt (hDlg, IDC_DEG, 180, FALSE); + SetDlgItemInt (hDlg, IDC_TYPE, 1, FALSE); + + return TRUE; + + case WM_COMMAND: + switch (LOWORD (wParam)) { + case IDOK: + + xc = GetDlgItemInt (hDlg, IDC_XC, NULL, TRUE); + yc = GetDlgItemInt (hDlg, IDC_YC, NULL, TRUE); + xs = GetDlgItemInt (hDlg, IDC_XS, NULL, TRUE); + ys = GetDlgItemInt (hDlg, IDC_YS, NULL, TRUE); + xe = GetDlgItemInt (hDlg, IDC_XE, NULL, TRUE); + ye = GetDlgItemInt (hDlg, IDC_YE, NULL, TRUE); + se = GetDlgItemInt (hDlg, IDC_SEG, NULL, TRUE); + deg = GetDlgItemInt (hDlg, IDC_DEG, NULL, TRUE); + type = GetDlgItemInt (hDlg, IDC_TYPE, NULL, TRUE); + r0 = ((3.1415926535) * deg) / (se * 180); + x1 = xs; + y1 = ys; + x2 = xc; + y2 = yc; + x0 = x2; + y0 = y2; + x3 = xe; + y3 = ye; + for (i = 1; i < se; i++) { + u = ((x1 - x0) * (cos (r0) - 1)) - ((y1 - y0) * sin (r0)); + v = ((x1 - x0) * sin (r0)) + ((y1 - y0) * (cos (r0) - 1)); + + x2 = x1 + u; + y2 = y1 + v; + ptBegin.x = (long) floor (x1 / (ScaleX / maxSize)); + ptBegin.y = (long) floor (y1 / (ScaleY / maxSize)); + ptNew.x = (long) floor (x2 / (ScaleX / maxSize)); + ptNew.y = (long) floor (y2 / (ScaleY / maxSize)); + addJoint (hDlg); + x1 = x2; + y1 = y2; + } + x2 = x3; + y2 = y3; + ptBegin.x = (long) floor (x1 / (ScaleX / maxSize)); + ptBegin.y = (long) floor (y1 / (ScaleY / maxSize)); + ptNew.x = (long) floor (x2 / (ScaleX / maxSize)); + ptNew.y = (long) floor (y2 / (ScaleY / maxSize)); + addJoint (hDlg); + + return FALSE; + case IDCANCEL: + EndDialog (hDlg, 0); + return TRUE; + } + break; + } + return FALSE; + } + + // Added by Roozbeh to Draw a Block using dialog box + BOOL CALLBACK + BlockDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) + { + double xl, yl, xu, yu; + + switch (message) { + case WM_INITDIALOG: + + SetDlgItemInt (hDlg, IDC_XL, 0, FALSE); + SetDlgItemInt (hDlg, IDC_YL, 0, FALSE); + SetDlgItemInt (hDlg, IDC_XU, 0, FALSE); + SetDlgItemInt (hDlg, IDC_YU, 0, FALSE); + SetDlgItemInt (hDlg, IDC_TYPE, 1, FALSE); + + return TRUE; + + case WM_COMMAND: + switch (LOWORD (wParam)) { + case IDOK: + + xl = GetDlgItemInt (hDlg, IDC_XL, NULL, TRUE); + yl = GetDlgItemInt (hDlg, IDC_YL, NULL, TRUE); + xu = GetDlgItemInt (hDlg, IDC_XU, NULL, TRUE); + yu = GetDlgItemInt (hDlg, IDC_YU, NULL, TRUE); + type = GetDlgItemInt (hDlg, IDC_TYPE, NULL, TRUE); + + ptBegin.x = (long) floor (xl / (ScaleX / maxSize)); + ptBegin.y = (long) floor (yl / (ScaleY / maxSize)); + ptNew.x = (long) floor (xu / (ScaleX / maxSize)); + ptNew.y = (long) floor (yl / (ScaleY / maxSize)); + addJoint (hDlg); + + ptBegin.x = (long) floor (xu / (ScaleX / maxSize)); + ptBegin.y = (long) floor (yl / (ScaleY / maxSize)); + ptNew.x = (long) floor (xu / (ScaleX / maxSize)); + ptNew.y = (long) floor (yu / (ScaleY / maxSize)); + addJoint (hDlg); + + ptBegin.x = (long) floor (xu / (ScaleX / maxSize)); + ptBegin.y = (long) floor (yu / (ScaleY / maxSize)); + ptNew.x = (long) floor (xl / (ScaleX / maxSize)); + ptNew.y = (long) floor (yu / (ScaleY / maxSize)); + addJoint (hDlg); + + ptBegin.x = (long) floor (xl / (ScaleX / maxSize)); + ptBegin.y = (long) floor (yu / (ScaleY / maxSize)); + ptNew.x = (long) floor (xl / (ScaleX / maxSize)); + ptNew.y = (long) floor (yl / (ScaleY / maxSize)); + addJoint (hDlg); + + return FALSE; + case IDCANCEL: + EndDialog (hDlg, 0); + return TRUE; + } + break; + } + return FALSE; + } + static int handleWMCommand (HWND hDlg, UINT iMessage, LPARAM lParam, WPARAM wParam) *************** *** 1534,1544 **** --- 1798,1818 ---- break; + //Added by Roozbeh case IDC_JOINT: DialogBox (hInstance, MAKEINTRESOURCE (IDD_JOINT), NULL, JointDlgProc); break; + case IDC_TUNNEL: + DialogBox (hInstance, MAKEINTRESOURCE (IDD_TUNNEL), NULL, TunnelDlgProc); + break; + case IDC_ARC: + DialogBox (hInstance, MAKEINTRESOURCE (IDD_ARC), NULL, ArcDlgProc); + break; + case IDC_BLOCK: + DialogBox (hInstance, MAKEINTRESOURCE (IDD_BLOCK), NULL, BlockDlgProc); break; + //Added by Roozbeh case DD_BOLT1: |