dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / application / UiBuilder / GridSettings.cpp
blob6ec309d98d474d2e3190829d96ed472b8dc1b1dd
1 #include "FirstUiBuilder.h"
3 #include "resource.h"
4 #include "uitypes.h"
6 #include <commctrl.h>
8 static UIColor CurrentGridColor;
9 static HBRUSH gBrush = 0;
11 extern bool gDrawGrid;
12 extern bool gSnapToGrid;
13 extern UIColor gGridColor;
14 extern unsigned long gXGridStep;
15 extern unsigned long gYGridStep;
16 extern unsigned long gGridMajorTicks;
18 static void LoadData( HWND hwndDlg )
20 SetDlgItemInt( hwndDlg, IDC_HORIZONTAL_GRID_RESOLUTION, gXGridStep, FALSE );
21 SetDlgItemInt( hwndDlg, IDC_VERTICAL_GRID_RESOLUTION, gYGridStep, FALSE );
22 SetDlgItemInt( hwndDlg, IDC_GRID_MAJORTICKS, gGridMajorTicks, FALSE );
24 if( gDrawGrid )
25 CheckDlgButton( hwndDlg, IDC_DRAWGRID, BST_CHECKED );
26 else
27 CheckDlgButton( hwndDlg, IDC_DRAWGRID, BST_UNCHECKED );
29 if( gSnapToGrid )
30 CheckDlgButton( hwndDlg, IDC_SNAPTOGRID2, BST_CHECKED );
31 else
32 CheckDlgButton( hwndDlg, IDC_SNAPTOGRID2, BST_UNCHECKED );
34 SendDlgItemMessage( hwndDlg, IDC_OPACITY_SLIDER, TBM_SETRANGE, FALSE, MAKELONG( 0, 255 ) );
35 SendDlgItemMessage( hwndDlg, IDC_OPACITY_SLIDER, TBM_SETPOS, TRUE, gGridColor.a );
37 CurrentGridColor = gGridColor;
40 static void SaveData( HWND hwndDlg )
42 BOOL Worked;
43 long NewValue;
45 NewValue = GetDlgItemInt( hwndDlg, IDC_HORIZONTAL_GRID_RESOLUTION, &Worked, FALSE );
47 if( Worked )
48 gXGridStep = NewValue;
50 NewValue = GetDlgItemInt( hwndDlg, IDC_VERTICAL_GRID_RESOLUTION, &Worked, FALSE );
52 if( Worked )
53 gYGridStep = NewValue;
55 NewValue = GetDlgItemInt( hwndDlg, IDC_GRID_MAJORTICKS, &Worked, FALSE );
57 if( Worked )
58 gGridMajorTicks = NewValue;
60 CurrentGridColor.a = (unsigned char)SendDlgItemMessage( hwndDlg, IDC_OPACITY_SLIDER, TBM_GETPOS, 0, 0 );
62 gDrawGrid = IsDlgButtonChecked( hwndDlg, IDC_DRAWGRID ) != 0;
63 gSnapToGrid = IsDlgButtonChecked( hwndDlg, IDC_SNAPTOGRID2 ) != 0;
64 gGridColor = CurrentGridColor;
67 static void ChangeGridColor( HWND hwndDlg )
69 CHOOSECOLOR cc = {sizeof(cc)};
70 COLORREF sc[16];
72 ZeroMemory( sc, sizeof( sc ) );
74 cc.hwndOwner = hwndDlg;
75 cc.rgbResult = RGB( CurrentGridColor.r, CurrentGridColor.g, CurrentGridColor.b );
76 cc.Flags = CC_RGBINIT;
77 cc.lpCustColors = sc;
79 if( ChooseColor( &cc ) )
81 CurrentGridColor.r = GetRValue( cc.rgbResult );
82 CurrentGridColor.g = GetGValue( cc.rgbResult );
83 CurrentGridColor.b = GetBValue( cc.rgbResult );
87 static void Cleanup( void )
89 if( gBrush )
91 DeleteObject( gBrush );
92 gBrush = 0;
96 BOOL CALLBACK GridSettingsDlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
98 switch( uMsg )
100 case WM_INITDIALOG:
101 LoadData( hwndDlg );
102 return TRUE;
104 case WM_CLOSE:
105 // Equivalent to pressing cancel
106 EndDialog( hwndDlg, 0 );
107 Cleanup();
108 return 0;
110 case WM_COMMAND:
111 if( LOWORD( wParam ) == IDOK )
113 SaveData( hwndDlg );
114 EndDialog( hwndDlg, 0 );
115 Cleanup();
117 else if( LOWORD( wParam ) == IDCANCEL )
119 EndDialog( hwndDlg, 0 );
120 Cleanup();
122 else if( LOWORD( wParam ) == IDC_CHANGE_GRIDCOLOR )
124 ChangeGridColor( hwndDlg );
125 InvalidateRect( GetDlgItem( hwndDlg, IDC_GRIDCOLOR ), 0, TRUE );
127 return 0;
129 case WM_CTLCOLORSTATIC:
130 if( (HWND)lParam == GetDlgItem( hwndDlg, IDC_GRIDCOLOR ) )
132 COLORREF col = RGB( CurrentGridColor.r, CurrentGridColor.g, CurrentGridColor.b );
134 if( gBrush )
135 DeleteObject( gBrush );
137 gBrush = CreateSolidBrush( col );
138 SetTextColor( (HDC)wParam, col );
139 SetBkColor( (HDC)wParam, col );
141 return (BOOL)gBrush;
143 return 0;
145 default:
146 return 0;