📄 painter.c
字号:
r2 = sqrt (dx * dx * 1.0 + dy * dy * 1.0); cos_d = dx * 1.0 / r2; ang2 = acos (cos_d); if (dy > 0) { ang2 = M_PI*2 - ang2; } a1 = (int)(ang1*180.0*64/M_PI); a2 = (int)(ang2*180.0*64/M_PI); printf ("ang1: %f, a1: %d, ang2: %f, a2: %d\n", ang1*180/M_PI, a1, ang2*180/M_PI, a2); CircleArc (hdc, sx, sy, r, a1, a2 - a1); cur_pt = 0; oldx = -1; } else { int x = pts [cur_pt - 1].x; int y = pts [cur_pt - 1].y; MoveTo (hdc, x - 2, y - 2); LineTo (hdc, x + 2, y + 2); MoveTo (hdc, x - 2, y + 2); LineTo (hdc, x + 2, y - 2); } break; case IDM_SPLINE: if (cur_pt == 4) { SplineTo (hdc, pts); cur_pt = 0; oldx = -1; } else { int x = pts [cur_pt - 1].x; int y = pts [cur_pt - 1].y; MoveTo (hdc, x - 2, y - 2); LineTo (hdc, x + 2, y + 2); MoveTo (hdc, x - 2, y + 2); LineTo (hdc, x + 2, y - 2); } break; case IDM_FILLED_RECT: if (cur_pt == 2) { int w = ABS (pts[1].x - pts[0].x) + 1; int h = ABS (pts[1].y - pts[0].y) + 1; FillBox (hdc, MIN (pts[0].x, pts[1].x), MIN (pts[0].y, pts[1].y), w, h); cur_pt = 0; oldx = -1; } break; case IDM_FILLED_ELLIPSE: if (cur_pt == 2) { int rx = ABS (pts[1].x - pts[0].x); int ry = ABS (pts[1].y - pts[0].y); if (rx == ry) FillCircle (hdc, pts[0].x, pts[0].y, rx); else FillEllipse (hdc, pts[0].x, pts[0].y, rx, ry); cur_pt = 0; oldx = -1; } break; case IDM_FILLED_POLYGON: { /* draw vertice */ int x = pts [cur_pt - 1].x; int y = pts [cur_pt - 1].y; MoveTo (hdc, x - 2, y - 2); LineTo (hdc, x + 2, y + 2); MoveTo (hdc, x - 2, y + 2); LineTo (hdc, x + 2, y - 2); } break; case IDM_FLOOD_FILL: FloodFill (hdc, pts[0].x, pts[0].y); cur_pt = 0; break; }}static void FinishObject (HDC hdc){ if (obj_type == IDM_FILLED_POLYGON) { if (cur_pt > 2) FillPolygon (hdc, pts, cur_pt); cur_pt = 0; oldx = -1; }}static void ObjectOnMouseMove (HDC hdc, int x, int y){ switch (obj_type) { case IDM_LINE: if (cur_pt > 0) { if (oldx >= 0) { MoveTo (hdc, pts[0].x, pts[0].y); LineTo (hdc, oldx, oldy); } MoveTo (hdc, pts[0].x, pts[0].y); LineTo (hdc, x, y); oldx = x; oldy = y; } break; case IDM_ELLIPSE: case IDM_FILLED_ELLIPSE: if (cur_pt > 0) { int rx; int ry; if (oldx >= 0) { rx = ABS (oldx - pts[0].x); ry = ABS (oldy - pts[0].y); Ellipse (hdc, pts[0].x, pts[0].y, rx, ry); } rx = ABS (x - pts[0].x); ry = ABS (y - pts[0].y); Ellipse (hdc, pts[0].x, pts[0].y, rx, ry); oldx = x; oldy = y; } break; case IDM_RECT: case IDM_FILLED_RECT: if (cur_pt > 0) { if (oldx >= 0) { Rectangle (hdc, pts[0].x, pts[0].y, oldx, oldy); } Rectangle (hdc, pts[0].x, pts[0].y, x, y); oldx = x; oldy = y; } break; case IDM_ARC: break; case IDM_SPLINE: break; case IDM_FILLED_POLYGON: break; case IDM_FLOOD_FILL: break; }}static int PainterWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ HDC hdc; switch (message) { case MSG_CREATE: srand (time (NULL)); break; case MSG_PAINT: hdc = BeginPaint (hWnd); TabbedTextOut (hdc, 0, 0, "\nPlease click to start..."); EndPaint (hWnd, hdc); return 0; case MSG_ACTIVEMENU: if (wParam == 2) { CheckMenuRadioItem ((HMENU)lParam, IDM_LINE, IDM_FLOOD_FILL, obj_type, MF_BYCOMMAND); } break; case MSG_LBUTTONDOWN: if (cur_pt >= MAX_POINTS) break; pts [cur_pt].x = LOWORD (lParam); pts [cur_pt].y = HIWORD (lParam); cur_pt ++; hdc = GetClientDC (hWnd); SetPenColor (hdc, RGB2Pixel (hdc, rand()%256, rand()%256, rand()%256)); SetBrushColor (hdc, RGB2Pixel (hdc, rand()%256, rand()%256, rand()%256)); DrawObject (hdc); ReleaseDC (hdc); break; case MSG_RBUTTONDOWN: hdc = GetClientDC (hWnd); srand (time (NULL)); SetPenColor (hdc, RGB2Pixel (hdc, rand()%256, rand()%256, rand()%256)); SetBrushColor (hdc, RGB2Pixel (hdc, rand()%256, rand()%256, rand()%256)); FinishObject (hdc); ReleaseDC (hdc); break; case MSG_MOUSEMOVE: hdc = GetClientDC (hWnd); SetPenColor (hdc, PIXEL_lightwhite); SetBrushColor (hdc, PIXEL_lightwhite); SetRasterOperation (hdc, ROP_XOR); ObjectOnMouseMove (hdc, LOWORD(lParam), HIWORD(lParam)); ReleaseDC (hdc); break; case MSG_COMMAND: switch (wParam) { case IDM_NEW: case IDM_OPEN: case IDM_SAVE: case IDM_SAVEAS: case IDM_CLOSE: break; case IDM_COPY: break; case IDM_PASTE: break; case IDM_EXIT: SendMessage (hWnd, MSG_CLOSE, 0, 0L); break; case IDM_LINE ... IDM_FLOOD_FILL: cur_pt = 0; obj_type = wParam; oldx = -1; break; case IDM_ABOUT_THIS: MessageBox (hWnd, "MiniGUI Painter\n" "Copyright (C) 2001 Yongming Wei (ymwei@minigui.org).\n", "About MiniGUI Painter", MB_OK | MB_ICONINFORMATION | MB_BASEDONPARENT); break; case IDM_ABOUT:#ifdef _MISC_ABOUTDLG#ifdef _LITE_VERSION OpenAboutDialog (hWnd);#else OpenAboutDialog ();#endif#endif break; } break; case MSG_CLOSE: DestroyMainWindow (hWnd); PostQuitMessage (hWnd); return 0; } return DefaultMainWinProc (hWnd, message, wParam, lParam);}static void InitCreateInfo (PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_CAPTION | WS_VISIBLE; pCreateInfo->dwExStyle = 0; pCreateInfo->spCaption = "MiniGUI Painter"; pCreateInfo->hMenu = createmenu(); pCreateInfo->hCursor = GetSystemCursor (IDC_PENCIL); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = PainterWinProc; pCreateInfo->lx = 0; pCreateInfo->ty = 0; pCreateInfo->rx = pCreateInfo->lx + DEFAULT_WIDTH; pCreateInfo->by = pCreateInfo->ty + DEFAULT_HEIGHT; pCreateInfo->iBkColor = PIXEL_lightwhite; pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = HWND_DESKTOP;}int MiniGUIMain (int args, const char* arg[]){ MSG Msg; MAINWINCREATE CreateInfo; HWND hMainWnd;#if defined(_LITE_VERSION) && !(_STAND_ALONE) int i; const char* layer = NULL; for (i = 1; i < args; i++) { if (strcmp (arg[i], "-layer") == 0) { layer = arg[i + 1]; break; } } GetLayerInfo (layer, NULL, NULL, NULL); if (JoinLayer (layer, arg[0], 0, 0) == INV_LAYER_HANDLE) { printf ("JoinLayer: invalid layer handle.\n"); exit (1); }#endif InitCreateInfo (&CreateInfo); hMainWnd = CreateMainWindow (&CreateInfo); if (hMainWnd == HWND_INVALID) return -1; while (GetMessage (&Msg, hMainWnd)) { TranslateMessage (&Msg); DispatchMessage (&Msg); } MainWindowThreadCleanup (hMainWnd); return 0;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif#endif /* _USE_NEWGAL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -