77
88namespace QuickNoteWidget
99{
10- /// <summary>
11- /// Interaction logic for MainWindow.xaml
12- /// </summary>
1310 public partial class MainWindow : Window
1411 {
1512 private MainWindowViewModel _mainWindowViewModel ;
13+ private const double FONT_MIN_SIZE = 5d ;
14+ private const double FONT_MAX_SIZE = 60d ;
15+ private const int WINDOW_RESIZE_FACTOR = 15 ;
1616
1717 public MainWindow ( )
1818 {
@@ -81,11 +81,35 @@ private void Info_Click(object sender, RoutedEventArgs e)
8181 _infoWindow . Show ( ) ;
8282 }
8383
84+ private void Window_KeyDown ( object sender , KeyEventArgs e )
85+ {
86+ bool ctrlKeyDown = GetCtrlKeyDown ( ) ;
87+ bool addKeyDown = GetAddKeyDown ( ) ;
88+ bool subtractKeyDown = GetSubtractKeyDown ( ) ;
89+
90+ if ( ctrlKeyDown && addKeyDown )
91+ UpdateFontSize ( true ) ;
92+ else if ( ctrlKeyDown && subtractKeyDown )
93+ UpdateFontSize ( false ) ;
94+ }
8495
8596 private void tbxMultiLine_PreviewMouseWheel ( object sender , MouseWheelEventArgs e )
8697 {
87- // React to ctrl + mouse wheel
88- bool ctrlButtonPressed = ( Keyboard . Modifiers == ModifierKeys . Control ) ;
98+ bool ctrlKeyDown = GetCtrlKeyDown ( ) ;
99+ bool altKeyDown = GetAltKeyDown ( ) ;
100+ bool hKeyDown = GetHKeyDown ( ) ; // h - height
101+ bool wKeyDown = GetWKeyDown ( ) ; // w - Width
102+
103+
104+ HandleFontSizeChange ( e , ctrlKeyDown ) ;
105+ if ( e . Handled )
106+ return ;
107+
108+ HandleWindowResize ( e , altKeyDown , hKeyDown , wKeyDown ) ;
109+
110+ }
111+ private void HandleFontSizeChange ( MouseWheelEventArgs e , bool ctrlButtonPressed )
112+ {
89113 if ( ctrlButtonPressed )
90114 {
91115 bool increase = e . Delta > 0 ;
@@ -94,8 +118,49 @@ private void tbxMultiLine_PreviewMouseWheel(object sender, MouseWheelEventArgs e
94118 }
95119 }
96120
97- private const double FONT_MIN_SIZE = 5d ;
98- private const double FONT_MAX_SIZE = 60d ;
121+ private void HandleWindowResize ( MouseWheelEventArgs e , bool altKeyDown , bool hKeyDown , bool wKeyDown )
122+ {
123+ if ( altKeyDown && hKeyDown )
124+ {
125+ bool increase = e . Delta > 0 ;
126+ double currentSize = this . Height ;
127+ if ( increase )
128+ {
129+ double newHeight = currentSize + WINDOW_RESIZE_FACTOR ;
130+ this . Height = newHeight ;
131+ }
132+ else if ( this . Height > 100 )
133+ {
134+ double newHeight = currentSize - WINDOW_RESIZE_FACTOR ;
135+ this . Height = newHeight ;
136+ }
137+ else
138+ {
139+ return ;
140+ }
141+
142+ }
143+ else if ( altKeyDown && wKeyDown )
144+ {
145+ bool increase = e . Delta > 0 ;
146+ double currentSize = this . Width ;
147+ if ( increase )
148+ {
149+ double newWidth = currentSize + WINDOW_RESIZE_FACTOR ;
150+ this . Width = newWidth ;
151+ }
152+ else if ( this . Width > 100 )
153+ {
154+ double newWidth = currentSize - WINDOW_RESIZE_FACTOR ;
155+ this . Width = newWidth ;
156+ }
157+ else
158+ {
159+ return ;
160+ }
161+ }
162+ e . Handled = true ;
163+ }
99164
100165 private void UpdateFontSize ( bool increase )
101166 {
@@ -130,16 +195,31 @@ private void TbxMultiLine_TextChanged(object sender, EventArgs e)
130195 this . _mainWindowViewModel . WordCount = this . tbxMultiLine . Document . TextLength . ToString ( ) ;
131196 }
132197
133- private void Window_KeyDown ( object sender , KeyEventArgs e )
198+ #region GetKeyDownMethods
199+ private static bool GetSubtractKeyDown ( )
134200 {
135- bool ctrlKeyDown = ( Keyboard . IsKeyDown ( Key . LeftCtrl ) || Keyboard . IsKeyDown ( Key . RightCtrl ) ) ;
136- bool addKeyDown = Keyboard . IsKeyDown ( Key . Add ) ;
137- bool subtractKeyDown = Keyboard . IsKeyDown ( Key . Subtract ) ;
138-
139- if ( ctrlKeyDown && addKeyDown )
140- UpdateFontSize ( true ) ;
141- else if ( ctrlKeyDown && subtractKeyDown )
142- UpdateFontSize ( false ) ;
201+ return Keyboard . IsKeyDown ( Key . Subtract ) ;
202+ }
203+ private static bool GetAddKeyDown ( )
204+ {
205+ return Keyboard . IsKeyDown ( Key . Add ) ;
206+ }
207+ private static bool GetCtrlKeyDown ( )
208+ {
209+ return ( Keyboard . IsKeyDown ( Key . LeftCtrl ) || Keyboard . IsKeyDown ( Key . RightCtrl ) ) ;
210+ }
211+ private static bool GetWKeyDown ( )
212+ {
213+ return Keyboard . IsKeyDown ( Key . W ) ;
214+ }
215+ private static bool GetHKeyDown ( )
216+ {
217+ return Keyboard . IsKeyDown ( Key . H ) ;
218+ }
219+ private static bool GetAltKeyDown ( )
220+ {
221+ return ( Keyboard . IsKeyDown ( Key . LeftAlt ) || Keyboard . IsKeyDown ( Key . RightAlt ) ) ;
143222 }
223+ #endregion GetKeyDownMethods
144224 }
145225}
0 commit comments