Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CGame_Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,29 @@ void CGame::EventHandling(SDL_Event* Event)
break;
}

case SDL_MOUSEWHEEL:
{
CWindow* wndAtCursor = nullptr;
for(auto& Window : Windows)
{
if(!Window->isWaste() && isPointInRect(Cursor.pos, Window->getRect())
&& (!wndAtCursor || Window->getPriority() > wndAtCursor->getPriority()))
wndAtCursor = Window.get();
}
if(wndAtCursor)
{
// Positions of the controls are relative to the window
wndAtCursor->setMouseWheel(Event->wheel, Cursor.pos - wndAtCursor->getPos());
break;
}
for(auto& Menu : Menus)
{
if(Menu->isActive() && !Menu->isWaste())
Menu->setMouseWheel(Event->wheel, Cursor.pos);
}
break;
}

case SDL_WINDOWEVENT:
{
if(Event->window.event == SDL_WINDOWEVENT_RESIZED)
Expand Down
1 change: 1 addition & 0 deletions CIO/CButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CButton
int getY() const { return pos_.y; };
Position getPos() const { return pos_; }
Extent getSize() const { return size_; };
Rect getRect() const { return Rect(pos_, size_); }
void setX(int x) { pos_.x = x; };
void setY(int y) { pos_.y = y; };
void setButtonPicture(int picture);
Expand Down
6 changes: 6 additions & 0 deletions CIO/CControlContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ void CControlContainer::setMouseData(const SDL_MouseButtonEvent button)
}
}

void CControlContainer::setMouseWheel(const SDL_MouseWheelEvent& wheel, Position mousePos)
{
for(const auto& selectbox : selectboxes)
selectbox->setMouseWheel(wheel, mousePos);
}

void CControlContainer::setKeyboardData(const SDL_KeyboardEvent& key)
{
for(const auto& textfield : textfields)
Expand Down
1 change: 1 addition & 0 deletions CIO/CControlContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class CControlContainer
virtual void setMouseData(SDL_MouseMotionEvent motion);
virtual void setMouseData(SDL_MouseButtonEvent button);
void setKeyboardData(const SDL_KeyboardEvent& key);
virtual void setMouseWheel(const SDL_MouseWheelEvent& wheel, Position mousePos);
void setWaste() { waste = true; }
bool isWaste() const { return waste; }
// Methods
Expand Down
5 changes: 2 additions & 3 deletions CIO/CFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ void CFont::setText(std::string text)
size_ = Extent(getTextWidth(string_, fontsize_), getLineHeight(fontsize_));
}

void CFont::setMouseData(SDL_MouseButtonEvent button)
void CFont::setMouseData(SDL_MouseButtonEvent button, const Rect& clickArea)
{
if(!callback)
return;
// left button is pressed
if(button.button == SDL_BUTTON_LEFT)
{
if(isPointInRect(button.x, button.y, Rect(pos_, size_)))
if(isPointInRect(button.x, button.y, clickArea))
{
// if mouse button is pressed ON the text
if(button.state == SDL_PRESSED && getColor() == initialColor_)
{
const auto tmpInitialColor = initialColor_;
Expand Down
4 changes: 3 additions & 1 deletion CIO/CFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class CFont
callback = nullptr;
clickedParam = 0;
}
void setMouseData(SDL_MouseButtonEvent button);
void setMouseData(SDL_MouseButtonEvent button) { setMouseData(button, Rect(pos_, size_)); }
/// Handle a click in a custom clickable area (e.g. a full row), in the same coordinate system as pos_
void setMouseData(SDL_MouseButtonEvent button, const Rect& clickArea);

/// Draw this font's text at the given absolute position
void draw(Position parentOrigin) const;
Expand Down
Loading
Loading