@@ -63,10 +63,10 @@ void CWindow::setMouseData(SDL_MouseMotionEvent motion)
6363{
6464 // cursor is on the title frame (+/-2 and +/-4 are only for a good optic)
6565 const Position titleFrameLT =
66- pos_ + Position (global::getBitmapSize (ArchiveID::Resource, WINDOW_LEFT_UPPER_CORNER ).x + 2 , 4 );
67- const Position titleFrameRB = Position (
68- pos_. x + static_cast <int >(size_.x ) - global::getBitmapSize (ArchiveID::Resource, WINDOW_RIGHT_UPPER_CORNER ). x - 2 ,
69- pos_. y + global::getBitmapSize (ArchiveID::Resource, WINDOW_UPPER_FRAME ). y - 4 );
66+ pos_ + Position (global::getBitmapSize (ArchiveID::Resource, WINDOW_LEFT_UPPER_CORNER ).x , 0 ) + Position ( 2 , 4 );
67+ const Position titleFrameRB =
68+ pos_ + Position ( static_cast <int >(size_.x ), global::getBitmapSize (ArchiveID::Resource, WINDOW_UPPER_FRAME ). y )
69+ - Position ( global::getBitmapSize (ArchiveID::Resource, WINDOW_RIGHT_UPPER_CORNER ). x + 2 , 4 );
7070 if (IsPointInRect (motion.x , motion.y , Rect (titleFrameLT, Extent (titleFrameRB - titleFrameLT))))
7171 {
7272 // left button was pressed while moving
@@ -90,32 +90,29 @@ void CWindow::setMouseData(SDL_MouseMotionEvent motion)
9090 if (canClose)
9191 {
9292 // cursor is on the button (+/-2 is only for the optic)
93- canClose_marked =
94- (motion.x >= pos_.x + 2 )
95- && (motion.x < pos_.x + global::getBitmapSize (ArchiveID::Resource, WINDOW_BUTTON_CLOSE ).x - 2 )
96- && (motion.y >= pos_.y + 2 )
97- && (motion.y < pos_.y + global::getBitmapSize (ArchiveID::Resource, WINDOW_BUTTON_CLOSE ).y - 2 );
93+ const auto closeSize = global::getBitmapSize (ArchiveID::Resource, WINDOW_BUTTON_CLOSE );
94+ canClose_marked = IsPointInRect (Position (motion.x , motion.y ),
95+ Rect (pos_ + Position (2 , 2 ), Extent (closeSize - Extent (4 , 4 ))));
9896 }
9997 // check whats happen to the minimize button
10098 if (canMinimize)
10199 {
102100 // cursor is on the button (+/-2 is only for the optic)
103- canMinimize_marked =
104- (motion.x >= pos_.x + static_cast <int >(size_.x )
105- - global::getBitmapSize (ArchiveID::Resource, WINDOW_BUTTON_MINIMIZE ).x + 2 )
106- && (motion.x < pos_.x + static_cast <int >(size_.x ) - 2 ) && (motion.y >= pos_.y + 2 )
107- && (motion.y < pos_.y + global::getBitmapSize (ArchiveID::Resource, WINDOW_BUTTON_MINIMIZE ).y - 2 );
101+ const auto minSize = global::getBitmapSize (ArchiveID::Resource, WINDOW_BUTTON_MINIMIZE );
102+ canMinimize_marked = IsPointInRect (
103+ Position (motion.x , motion.y ),
104+ Rect (pos_ + Position (static_cast <int >(size_.x ) - minSize.x + 2 , 2 ), Extent (minSize - Extent (4 , 4 ))));
108105 }
109106 // check whats happen to the resize button
110107 if (canResize)
111108 {
112109 // cursor is on the button (+/-2 is only for the optic)
113- if ((motion. x >= pos_. x + static_cast < int >(size_. x )
114- - global::getBitmapSize (ArchiveID::Resource, WINDOW_BUTTON_RESIZE ). x + 2 )
115- && (motion.x < pos_. x + static_cast < int >(size_. x ) - 2 )
116- && (motion. y >= pos_. y + static_cast <int >(size_.y )
117- - global::getBitmapSize (ArchiveID::Resource, WINDOW_BUTTON_RESIZE ) .y + 2 )
118- && (motion. y < pos_. y + static_cast < int >(size_. y ) - 2 ))
110+ const auto resizeSize = global::getBitmapSize (ArchiveID::Resource, WINDOW_BUTTON_RESIZE );
111+ if ( IsPointInRect (
112+ Position (motion.x , motion. y ),
113+ Rect ( pos_ + Position ( static_cast <int >(size_.x ) - resizeSize. x + 2 ,
114+ static_cast < int >(size_. y ) - resizeSize .y + 2 ),
115+ Extent (resizeSize - Extent ( 4 , 4 ))) ))
119116 {
120117 // left button was pressed while moving
121118 if (SDL_GetMouseState (nullptr , nullptr ) & SDL_BUTTON (SDL_BUTTON_LEFT ))
@@ -321,15 +318,14 @@ void CWindow::draw(Position /*parentOrigin*/)
321318 {
322319 getTexture (ArchiveID::Resource, WINDOW_LEFT_UPPER_CORNER ).draw (pos_);
323320
324- const int ruW = getTexture (ArchiveID::Resource, WINDOW_RIGHT_UPPER_CORNER ).getSize (). x ;
321+ const Extent ru = getTexture (ArchiveID::Resource, WINDOW_RIGHT_UPPER_CORNER ).getSize ();
325322 getTexture (ArchiveID::Resource, WINDOW_RIGHT_UPPER_CORNER )
326- .draw (pos_ + Position (static_cast <int >(size_.x ) - ruW , 0 ));
323+ .draw (pos_ + Position (static_cast <int >(size_.x ) - ru. x , 0 ));
327324
328- const int crW = getTexture (ArchiveID::Resource, WINDOW_CORNER_RECTANGLE ).getSize ().x ;
329- const int crH = getTexture (ArchiveID::Resource, WINDOW_CORNER_RECTANGLE ).getSize ().y ;
325+ const Extent cr = getTexture (ArchiveID::Resource, WINDOW_CORNER_RECTANGLE ).getSize ();
330326 getTexture (ArchiveID::Resource, WINDOW_CORNER_RECTANGLE )
331- .draw (pos_ + Position (0 , static_cast <int >(size_.y ) - crH ));
332- getTexture (ArchiveID::Resource, WINDOW_CORNER_RECTANGLE ).draw (pos_ + size_ - Position (crW, crH) );
327+ .draw (pos_ + Position (0 , static_cast <int >(size_.y ) - cr. y ));
328+ getTexture (ArchiveID::Resource, WINDOW_CORNER_RECTANGLE ).draw (pos_ + size_ - cr );
333329 }
334330
335331 // 9. Close button
@@ -355,9 +351,9 @@ void CWindow::draw(Position /*parentOrigin*/)
355351 minimizebutton = WINDOW_BUTTON_MINIMIZE_MARKED ;
356352 else
357353 minimizebutton = WINDOW_BUTTON_MINIMIZE ;
354+ const Extent minBtnSize = getTexture (ArchiveID::Resource, minimizebutton).getSize ();
358355 getTexture (ArchiveID::Resource, minimizebutton)
359- .draw (pos_
360- + Position (static_cast <int >(size_.x ) - getTexture (ArchiveID::Resource, minimizebutton).getSize ().x , 0 ));
356+ .draw (pos_ + Position (static_cast <int >(size_.x ) - minBtnSize.x , 0 ));
361357 }
362358
363359 // 11. Resize button
@@ -370,8 +366,8 @@ void CWindow::draw(Position /*parentOrigin*/)
370366 resizebutton = WINDOW_BUTTON_RESIZE_MARKED ;
371367 else
372368 resizebutton = WINDOW_BUTTON_RESIZE ;
373- getTexture (ArchiveID::Resource, resizebutton)
374- . draw (pos_ + size_ - getTexture (ArchiveID::Resource, resizebutton).getSize () );
369+ const Extent resBtnSize = getTexture (ArchiveID::Resource, resizebutton). getSize ();
370+ getTexture (ArchiveID::Resource, resizebutton).draw (pos_ + size_ - resBtnSize );
375371 }
376372}
377373
0 commit comments