File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,17 +80,13 @@ void CWindow::setMouseData(SDL_MouseMotionEvent motion)
8080 {
8181 pos_.x += motion.xrel ;
8282 pos_.y += motion.yrel ;
83- // make sure to not move the window outside the display surface
84- if (pos_.x < 0 )
85- pos_.x = 0 ;
83+ // Clamp window position to screen bounds
8684 {
8785 const auto res = global::s2->getRes ();
88- const int resX = static_cast <int >(res.x );
89- const int resY = static_cast <int >(res.y );
90- if (pos_.x + static_cast <int >(size_.x ) >= resX) // -V807
91- pos_.x = resX - static_cast <int >(size_.x ) - 1 ;
92- if (pos_.y + static_cast <int >(size_.y ) >= resY)
93- pos_.y = resY - static_cast <int >(size_.y ) - 1 ;
86+ const int maxX = static_cast <int >(res.x - size_.x ) - 1 ;
87+ const int maxY = static_cast <int >(res.y - size_.y ) - 1 ;
88+ pos_.x = std::clamp (pos_.x , 0 , maxX);
89+ pos_.y = std::clamp (pos_.y , 0 , maxY);
9490 }
9591 }
9692
@@ -374,7 +370,7 @@ void CWindow::draw(Position /*parentOrigin*/)
374370 else
375371 resizebutton = WINDOW_BUTTON_RESIZE ;
376372 getBmpTexture (resizebutton)
377- .draw (Position ( origin + Position (static_cast <int >(size_.x ), static_cast <int >(size_.y ) ))
373+ .draw (origin + Position (static_cast <int >(size_.x ), static_cast <int >(size_.y ))
378374 - Position (getBmpTexture (resizebutton).getSize ()));
379375 }
380376}
You can’t perform that action at this time.
0 commit comments