Create FUNDING.yml
[wdl/wdl-ol.git] / WDL / wingui / wndsize.h
blob27505e3a3bf7a98a6a1ee66a35eecf272da539b6
1 /*
2 WDL - wndsize.h
3 Copyright (C) 2004 and later Cockos Incorporated
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
25 This file provides the interface for a simple class that allows one to easily
26 make resizeable dialogs and have controls that move according to ratios of the
27 new size.
29 Usually, one does a
31 static WDL_WndSizer resize;
33 in their DlgProc, and in WM_INITDIALOG:
35 resize.init(hwndDlg);
37 // add a list of items
38 resize.init_item(IDC_MASTERVOL, // dialog id
39 0.0, // left position, 0=left anchor, 1=right anchor, etc
40 0.0, // top position, 0=anchored to its initial top position, 1=anchored to distance from bottom, etc
41 0.7f, // right position
42 0.0); // bottom position
43 ...
46 then, in WM_SIZE,
47 if (wParam != SIZE_MINIMIZED)
49 resize.onResize(); // don't actually resize, just compute the rects
53 is about all that's needed.
58 #ifndef _WNDSIZE_H_
59 #define _WNDSIZE_H_
62 #include "../heapbuf.h"
64 class WDL_VWnd;
66 struct WDL_WndSizer__rec
68 HWND hwnd;
69 RECT orig;
70 RECT real_orig;
71 RECT last;
72 float scales[4];
73 WDL_VWnd *vwnd;
76 class WDL_WndSizer
78 public:
79 WDL_WndSizer()
81 m_hwnd=NULL;
82 memset(&m_min_size,0,sizeof(m_min_size));
83 memset(&m_orig_size,0,sizeof(m_orig_size));
84 memset(&m_margins,0,sizeof(m_margins));
86 ~WDL_WndSizer() { }
88 void init(HWND hwndDlg, RECT *initr=NULL);
90 // 1.0 means it moves completely with the point, 0.0 = not at all
91 void init_item(int dlg_id, float left_scale=0.0, float top_scale=0.0, float right_scale=1.0, float bottom_scale=1.0, RECT *initr=NULL);
92 void init_itemvirt(WDL_VWnd *vwnd, float left_scale=0.0, float top_scale=0.0, float right_scale=1.0, float bottom_scale=1.0);
93 void init_item(int dlg_id, float *scales, RECT *initr=NULL);
94 void init_itemvirt(WDL_VWnd *vwnd, float *scales);
95 void init_itemhwnd(HWND h, float left_scale=0.0, float top_scale=0.0, float right_scale=1.0, float bottom_scale=1.0, RECT *srcr=NULL);
96 void remove_item(int dlg_id);
97 void remove_itemvirt(WDL_VWnd *vwnd);
98 void remove_itemhwnd(HWND h);
100 WDL_WndSizer__rec *get_item(int dlg_id) const;
101 WDL_WndSizer__rec *get_itembyindex(int idx) const;
102 WDL_WndSizer__rec *get_itembywnd(HWND h) const;
103 WDL_WndSizer__rec *get_itembyvirt(WDL_VWnd *vwnd) const;
105 RECT get_orig_rect() const { RECT r={0,0,m_orig_size.x,m_orig_size.y}; return r; }
106 void set_orig_rect(const RECT *r, const POINT *minSize=NULL)
108 if (r) { m_orig_size.x = r->right; m_orig_size.y = r->bottom; }
109 if (minSize) m_min_size = *minSize;
110 else m_min_size.x=m_min_size.y=0;
112 POINT get_min_size(bool applyMargins=false) const;
114 void onResize(HWND only=0, int notouch=0, int xtranslate=0, int ytranslate=0);
117 void set_margins(int left, int top, int right, int bottom) { m_margins.left=left; m_margins.top=top; m_margins.right=right; m_margins.bottom=bottom; }
118 void get_margins(int *left, int *top, int *right, int *bottom) const
120 if (left) *left=m_margins.left;
121 if (top) *top=m_margins.top;
122 if (right) *right=m_margins.right;
123 if (bottom) *bottom=m_margins.bottom;
126 void transformRect(RECT *r, const float *scales, const RECT *wndSize) const;
128 private:
129 #ifdef _WIN32
130 static BOOL CALLBACK enum_RegionRemove(HWND hwnd,LPARAM lParam);
131 HRGN m_enum_rgn;
132 #endif
133 HWND m_hwnd;
134 POINT m_orig_size,m_min_size;
135 RECT m_margins;
137 WDL_TypedBuf<WDL_WndSizer__rec> m_list;
141 #endif//_WNDSIZE_H_