comparison foosdk/sdk/libPPUI/CMiddleDragImpl.cpp @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #include "stdafx.h"
2 #include "CMiddleDragImpl.h"
3 #include "CMiddleDragLite.h"
4 #include "ImplementOnFinalMessage.h"
5
6 double CMiddleDragCommon::myPow(double p_val, double p_exp) {
7 if (p_val < 0) {
8 return -pow(-p_val, p_exp);
9 } else {
10 return pow(p_val, p_exp);
11 }
12 }
13
14 double CMiddleDragCommon::ProcessMiddleDragDeltaInternal(double p_delta) {
15 p_delta *= (double)KTimerPeriod / 25; /*originally calculated for 25ms timer interval*/
16 return myPow(p_delta * 0.05, 2.0);
17 }
18
19 double CMiddleDragCommon::radiusHelper(double p_x, double p_y) {
20 return sqrt(p_x * p_x + p_y * p_y);
21 }
22 int CMiddleDragCommon::mySGN(LONG v) {
23 if (v > 0) return 1;
24 else if (v < 0) return -1;
25 else return 0;
26 }
27
28 int32_t CMiddleDragCommon::Round(double val, double & acc) {
29 val += acc;
30 int32_t ret = (int32_t)floor(val + 0.5);
31 acc = val - ret;
32 return ret;
33 }
34
35 LONG CMiddleDragCommon::LineToPixelsHelper(LONG & p_overflow, LONG p_pixels, LONG p_dpi, LONG p_lineWidth) {
36 const int lineWidth = MulDiv(p_lineWidth, p_dpi, 96);
37 if (lineWidth == 0) return 0;
38 p_overflow += p_pixels;
39 LONG ret = p_overflow / lineWidth;
40 p_overflow -= ret * lineWidth;
41 return ret;
42 }
43
44 void CMiddleDragOverlay::ShowHere(CPoint pt) {
45
46 auto dpi = QueryScreenDPIEx(*this);
47 CSize size(MulDiv(32, dpi.cx, 96), MulDiv(32, dpi.cy, 96));
48 // Original path values are for 32x32, don't rescale for sizes close-enough
49 if (size.cx < 48) size.cx = 32;
50 if (size.cy < 48) size.cy = 32;
51 CPoint center(pt);
52 CPoint origin = center - CSize(size.cx / 2, size.cy / 2);
53 CRect rect(origin, origin + size);
54 this->SetWindowPos(HWND_TOPMOST, rect, SWP_SHOWWINDOW | SWP_NOACTIVATE);
55 }
56
57 namespace {
58 struct pt_t { uint8_t x, y; };
59 static CPoint transform(pt_t pt, CRect const& rc) {
60 return CPoint(rc.left + MulDiv(pt.x, rc.Width(), 32), rc.top + MulDiv(pt.y, rc.Height(), 32));
61 }
62 }
63
64 void CMiddleDragOverlay::Paint(CDCHandle dc) {
65 CRect client;
66 WIN32_OP_D(GetClientRect(&client));
67 static constexpr pt_t path[] = {
68 {15,0}, {9,6}, {9,7}, {14,7}, {14, 14},
69 {7, 14}, {7, 9}, {6, 9}, {0, 15},
70 {0, 16}, {6, 22}, {7, 22}, {7, 17}, {14, 17},
71 {14, 24}, {9, 24}, {9, 25}, {15, 31},
72 {16, 31}, {22, 25}, {22, 24}, {17, 24}, {17, 17},
73 {24, 17}, {24, 22}, {25, 22}, {31, 16},
74 {31, 15}, {25, 9}, {24, 9}, {24, 14}, {17, 14},
75 {17, 7}, {22, 7}, {22, 6}, {16, 0},
76 };
77
78 POINT points[std::size(path)];
79 for (size_t walk = 0; walk < std::size(path); ++walk) {
80 points[walk] = transform(path[walk], client);
81 }
82 CRgn rgn = CreatePolygonRgn(points, (int)std::size(path), WINDING);
83 PFC_ASSERT(rgn != NULL);
84 const HBRUSH brush = (HBRUSH)GetStockObject(DC_BRUSH);
85 dc.SetDCBrushColor(0);
86 dc.FillRgn(rgn, brush);
87 dc.SetDCBrushColor(0xFFFFFF);
88 dc.FrameRgn(rgn, brush, 1, 1);
89 }
90
91
92 namespace {
93 class CMiddleDragLiteBase : public CWindowImpl<CMiddleDragLiteBase, CWindow > {
94 public:
95 BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID = 0) { return FALSE; }
96 };
97 }
98 void PP::addMiddleDragToCtrl(HWND wndCtrl) {
99 auto obj = new ImplementOnFinalMessage<CMiddleDragImpl<CMiddleDragWrapper< CMiddleDragLiteBase > > > ();
100 WIN32_OP_D( obj->SubclassWindow(wndCtrl) );
101 }