Advertisement
alien_fx_fiend

DoodleApp BusyPointer Mystery Code (Check Remedy)

Jul 12th, 2024 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.92 KB | None | 0 0
  1. /* Can you tell me where in this code the mouse pointer is changed to Busy Pointer I need to change it back to Normal Pointer. Can you show me the modified change only? Here is the full code: */
  2. #include <vector>
  3. #include <windows.h>
  4. using namespace std;
  5. struct Brushstroke;
  6. struct Eraserstroke;
  7. void DrawBrush(HDC hdc, int x, int y);
  8. void Erase(HDC hdc, int x, int y);
  9. void ClearDrawing(HDC hdc, int width, int height);
  10. void DrawSmoothBrush(HDC hdc, int x, int y);
  11. bool isPaintbrushSelected = true;  
  12. POINT previousPoint;  
  13. HDC hdc;
  14. HWND hWnd;  
  15. struct Brushstroke {
  16.     int x;
  17.     int y;
  18.     int size;
  19.     COLORREF color;
  20. };
  21. struct Eraserstroke {
  22.     int x;
  23.     int y;
  24.     int size;
  25.     COLORREF color;
  26. };
  27. std::vector<Brushstroke> storedBrushstrokes;
  28. std::vector<Eraserstroke> storedEraserstrokes;
  29. std::vector<Brushstroke> minimizedDrawnBrushstrokes;
  30. std::vector<Eraserstroke> minimizedErasedBrushstrokes;
  31. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  32. HINSTANCE hInst;
  33. bool isDrawing = false;
  34. bool isErasing = false;
  35. bool isClearing = false;
  36. bool isEraserSelected = false;
  37. int brushSize = 10;
  38. void DrawBrush(HDC hdc, int x, int y) {
  39.     HRGN hRgn = CreateEllipticRgn(x - brushSize, y - brushSize, x + brushSize, y + brushSize);
  40.     FillRgn(hdc, hRgn, CreateSolidBrush(RGB(255, 0, 0)));
  41.     DeleteObject(hRgn);
  42. }
  43. void Erase(HDC hdc, int x, int y) {
  44.     HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255));
  45.     SelectObject(hdc, GetStockObject(NULL_PEN));
  46.     SelectObject(hdc, hBrush);
  47.     Ellipse(hdc, x - brushSize, y - brushSize, x + brushSize, y + brushSize);
  48.     DeleteObject(hBrush);
  49. }
  50. void ClearDrawing(HDC hdc, int width, int height) {
  51.     RECT rect = { 0, 0, width, height };
  52.     HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255));
  53.     FillRect(hdc, &rect, hBrush);
  54.     DeleteObject(hBrush);
  55. }
  56. void DrawSmoothBrush(HDC hdc, int x, int y) {
  57.     if (isDrawing && (isPaintbrushSelected || isEraserSelected)) {
  58.         int numPoints = 3;
  59.         POINT currentPoint = { x, y };
  60.         for (int i = 1; i <= numPoints; i++) {
  61.             float t = (float)i / (float)numPoints;
  62.             int smoothX = (int)(previousPoint.x + t * (currentPoint.x - previousPoint.x));
  63.             int smoothY = (int)(previousPoint.y + t * (currentPoint.y - previousPoint.y));
  64.             if (isPaintbrushSelected) {
  65.                 DrawBrush(hdc, smoothX, smoothY);
  66.                 Brushstroke newBrushstroke;
  67.                 newBrushstroke.x = smoothX;
  68.                 newBrushstroke.y = smoothY;
  69.                 newBrushstroke.size = brushSize;
  70.                 newBrushstroke.color = RGB(255, 0, 0);
  71.                 storedBrushstrokes.push_back(newBrushstroke);
  72.             }
  73.             else if (isEraserSelected) {
  74.                 Erase(hdc, smoothX, smoothY);
  75.                 Eraserstroke newEraserstroke;
  76.                 newEraserstroke.x = smoothX;
  77.                 newEraserstroke.y = smoothY;
  78.                 newEraserstroke.size = brushSize;
  79.                 newEraserstroke.color = RGB(255, 255, 255);
  80.                 storedEraserstrokes.push_back(newEraserstroke);
  81.             }
  82.         }
  83.         previousPoint = currentPoint;
  84.     }
  85. }
  86. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  87.     switch (uMsg) {
  88.     case WM_CREATE:
  89.         isPaintbrushSelected = true;  
  90.         break;
  91.     case WM_KEYDOWN:
  92.         if (wParam == VK_ADD) {  
  93.             brushSize += 5;
  94.         }
  95.         else if (wParam == VK_SUBTRACT) {  
  96.             if (brushSize > 5) {
  97.                 brushSize -= 5;
  98.             }
  99.         }
  100.         else if (wParam == 0x43) {  
  101.             if (!(GetKeyState(VK_CONTROL) & 0x8000)) {
  102.                 isClearing = true;
  103.             }
  104.         }
  105.         else if (wParam == 0x50) {  
  106.             isPaintbrushSelected = true;
  107.             isEraserSelected = false;
  108.         }
  109.         else if (wParam == 0x45) {  
  110.             isEraserSelected = true;
  111.             isPaintbrushSelected = false;
  112.         }
  113.         break;
  114.     case WM_LBUTTONDOWN:
  115.         if (isPaintbrushSelected || isEraserSelected) {
  116.             previousPoint.x = LOWORD(lParam);
  117.             previousPoint.y = HIWORD(lParam);
  118.         }
  119.         isDrawing = true;
  120.         break;
  121.     case WM_LBUTTONUP:
  122.         isDrawing = false;
  123.         break;
  124.     case WM_MOUSEMOVE:
  125.         if (isDrawing && isPaintbrushSelected) {
  126.             HDC hdc = GetDC(hwnd);
  127.             int x = LOWORD(lParam);
  128.             int y = HIWORD(lParam);
  129.             DrawSmoothBrush(hdc, x, y);
  130.             ReleaseDC(hwnd, hdc);
  131.             Brushstroke newBrushstroke;
  132.             newBrushstroke.x = x;
  133.             newBrushstroke.y = y;
  134.             newBrushstroke.size = brushSize;
  135.             newBrushstroke.color = RGB(255, 0, 0);  
  136.             storedBrushstrokes.push_back(newBrushstroke);
  137.         }
  138.         else if (isDrawing && isEraserSelected) {
  139.             HDC hdc = GetDC(hwnd);
  140.             int x = LOWORD(lParam);
  141.             int y = HIWORD(lParam);
  142.             Erase(hdc, x, y);
  143.             ReleaseDC(hwnd, hdc);
  144.             Eraserstroke newEraserStroke;
  145.             newEraserStroke.x = x;
  146.             newEraserStroke.y = y;
  147.             newEraserStroke.size = brushSize;  
  148.             newEraserStroke.color = RGB(255, 255, 255);  
  149.             storedEraserstrokes.push_back(newEraserStroke);
  150.         }
  151.         else if (isClearing) {
  152.             HDC hdc = GetDC(hwnd);
  153.             RECT rect;
  154.             GetClientRect(hwnd, &rect);
  155.             ClearDrawing(hdc, rect.right, rect.bottom);
  156.             ReleaseDC(hwnd, hdc);
  157.             isClearing = false;
  158.         }
  159.         break;
  160.     case WM_SIZE:
  161.     {
  162.         static bool isMinimized = false;
  163.         if (wParam == SIZE_MINIMIZED)
  164.         {
  165.             isMinimized = true;
  166.         }
  167.         else if (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED)
  168.         {
  169.             if (isMinimized)
  170.             {
  171.                 minimizedDrawnBrushstrokes = storedBrushstrokes;
  172.                 minimizedErasedBrushstrokes = storedEraserstrokes;
  173.                 isMinimized = false;
  174.             }
  175.             InvalidateRect(hwnd, NULL, TRUE);
  176.         }
  177.     }
  178.     break;
  179.     case WM_PAINT:
  180.     {
  181.         PAINTSTRUCT ps;
  182.         HDC hdc = BeginPaint(hwnd, &ps);
  183.         HBRUSH hBackgroundBrush = CreateSolidBrush(RGB(255, 255, 255));
  184.         FillRect(hdc, &ps.rcPaint, hBackgroundBrush);
  185.         DeleteObject(hBackgroundBrush);
  186.         for (const auto& brushstroke : storedBrushstrokes) {
  187.             DrawBrush(hdc, brushstroke.x, brushstroke.y);
  188.         }
  189.         for (const auto& erasepoint : storedEraserstrokes) {
  190.             Erase(hdc, erasepoint.x, erasepoint.y);
  191.         }
  192.         EndPaint(hwnd, &ps);
  193.     }
  194.     break;
  195. //Added as a quick remedy
  196.     case WM_SETCURSOR:
  197.         if (LOWORD(lParam) == HTCLIENT) {
  198.             SetCursor(LoadCursor(NULL, IDC_ARROW)); // Change to normal pointer
  199.             return TRUE;
  200.         }
  201.         break;
  202.     case WM_DESTROY:
  203.         PostQuitMessage(0);
  204.         return 0;
  205.     default:
  206.         return DefWindowProc(hwnd, uMsg, wParam, lParam);
  207.     }
  208.     return 0;
  209. }
  210. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) {
  211.     const wchar_t CLASS_NAME[] = L"DoodleAppClass";
  212.     WNDCLASS wc = { };
  213.     wc.lpfnWndProc = WindowProc;
  214.     wc.hInstance = hInstance;
  215.     wc.lpszClassName = CLASS_NAME;
  216.     RegisterClass(&wc);
  217.     hInst = hInstance;
  218.     HWND hwnd = CreateWindowEx(
  219.         0,
  220.         CLASS_NAME,
  221.         L"Doodle App",
  222.         WS_OVERLAPPEDWINDOW | WS_MAXIMIZE,
  223.         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  224.         NULL,
  225.         NULL,
  226.         hInstance,
  227.         NULL
  228.     );
  229.     hdc = GetDC(hwnd);
  230.     if (hwnd == NULL) {
  231.         return 0;
  232.     }
  233.     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
  234.     MSG msg = {};
  235.     while (GetMessage(&msg, NULL, 0, 0)) {
  236.         TranslateMessage(&msg);
  237.         DispatchMessage(&msg);
  238.     }
  239.     return 0;
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement