Skip to content
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
with:
submodules: true
- name: Install boost
uses: MarkusJx/install-boost@v2.4.5
uses: MarkusJx/install-boost@v2
id: install-boost
with:
boost_version: ${{env.BOOST_VERSION}}
Expand Down
15 changes: 11 additions & 4 deletions extras/videoDrivers/SDL2/VideoSDL2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -404,9 +404,16 @@ bool VideoSDL2::MessageLoop()
}
break;
case SDL_MOUSEMOTION:
mouse_xy.pos = getGuiScale().screenToView(Position(ev.motion.x, ev.motion.y));
CallBack->Msg_MouseMove(mouse_xy);
break;
{
const auto newPos = getGuiScale().screenToView(Position(ev.motion.x, ev.motion.y));
// Avoid duplicate events especially when warping the mouse
if(newPos != mouse_xy.pos)
{
mouse_xy.pos = newPos;
CallBack->Msg_MouseMove(mouse_xy);
}
}
break;
}
}

Expand Down
12 changes: 11 additions & 1 deletion libs/s25main/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2024 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -564,3 +564,13 @@ bool Window::IsInLockedRegion(const Position& pos, const Window* exception) cons
}
return false;
}

bool Window::IsMouseOver() const
{
return IsMouseOver(VIDEODRIVER.GetMousePos());
}

bool Window::IsMouseOver(const MouseCoords& mousePos) const
{
return IsPointInRect(mousePos.GetPos(), GetBoundaryRect());
}
8 changes: 6 additions & 2 deletions libs/s25main/Window.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -98,8 +98,12 @@ class Window
void LockRegion(Window* window, const Rect& rect);
/// Gibt eine gesperrte Region wieder frei.
void FreeRegion(Window* window);
/// Check if the gicen point is in a region locked by any window other than exception
/// Check if the given point is in a region locked by any window other than exception
bool IsInLockedRegion(const Position& pos, const Window* exception = nullptr) const;
/// Check if the mouse is hovering over this control, i.e. inside its boundary.
bool IsMouseOver() const;
Comment thread
Flow86 marked this conversation as resolved.
/// Check if the given mouse position inside the boundary of this control.
bool IsMouseOver(const MouseCoords& mousePos) const;

/// Set the position for the window
void SetPos(const DrawPoint& newPos);
Expand Down
5 changes: 4 additions & 1 deletion libs/s25main/WindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ class WindowManager : public Singleton<WindowManager>, public VideoDriverLoaderI
void Msg_MouseMove(const MouseCoords& mc) override;
/// Verarbeitung Keyboard-Event
void Msg_KeyDown(const KeyEvent& ke) override;
// setzt den Tooltip
// Show a tooltip
// ttw: Window that the tooltip is for, used when updating current tooltip
// tooltip: The tooltip text, empty to hide
// updateCurrent: If true, only update if the current tooltip is for ttw
void SetToolTip(const ctrlBaseTooltip* ttw, const std::string& tooltip, bool updateCurrent = false);

/// Verarbeitung Spielfenstergröße verändert (vom Betriebssystem aus)
Expand Down
1 change: 1 addition & 0 deletions libs/s25main/controls/ctrlBaseTooltip.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ctrlBaseTooltip
ctrlBaseTooltip(std::string tooltip = "") : tooltip_(std::move(tooltip)) {}
virtual ~ctrlBaseTooltip();

/// Set the text to be shown, updates the tooltip if currently shown
void SetTooltip(const std::string& tooltip);
const std::string& GetTooltip() const { return tooltip_; }
/// Swap the tooltips of those controls
Expand Down
15 changes: 5 additions & 10 deletions libs/s25main/controls/ctrlButton.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -26,13 +26,13 @@ void ctrlButton::SetActive(bool activate)
Window::SetActive(activate);
if(!activate)
state = ButtonState::Up;
else if(IsMouseOver(VIDEODRIVER.GetMousePos()))
else if(IsMouseOver())
state = ButtonState::Hover;
}

bool ctrlButton::Msg_MouseMove(const MouseCoords& mc)
{
if(isEnabled && IsMouseOver(mc.GetPos()))
if(isEnabled && IsMouseOver(mc))
{
if(state != ButtonState::Pressed)
state = ButtonState::Hover;
Expand All @@ -47,14 +47,9 @@ bool ctrlButton::Msg_MouseMove(const MouseCoords& mc)
}
}

bool ctrlButton::IsMouseOver(const Position& mousePos) const
{
return IsPointInRect(mousePos, GetDrawRect());
}

bool ctrlButton::Msg_LeftDown(const MouseCoords& mc)
{
if(isEnabled && IsMouseOver(mc.GetPos()))
if(isEnabled && IsMouseOver(mc))
{
state = ButtonState::Pressed;
return true;
Expand All @@ -67,7 +62,7 @@ bool ctrlButton::Msg_LeftUp(const MouseCoords& mc)
{
if(state == ButtonState::Pressed)
{
if(isEnabled && IsMouseOver(mc.GetPos()))
if(isEnabled && IsMouseOver(mc))
{
state = ButtonState::Hover;
GetParent()->Msg_ButtonClick(GetID());
Expand Down
3 changes: 1 addition & 2 deletions libs/s25main/controls/ctrlButton.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -41,7 +41,6 @@ class ctrlButton : public Window, public ctrlBaseTooltip
void Draw_() override;
/// Abgeleitete Klassen müssen erweiterten Button-Inhalt zeichnen
virtual void DrawContent() const = 0;
bool IsMouseOver(const Position& mousePos) const;

/// Texturfarbe des Buttons
TextureColor tc;
Expand Down
24 changes: 13 additions & 11 deletions libs/s25main/controls/ctrlCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ ctrlCheck::ctrlCheck(Window* parent, unsigned id, const DrawPoint& pos, const Ex
: Window(parent, id, pos, size), tc(tc), text(std::move(text)), font(font), check(false), readonly(readonly)
{}

/**
* der Messagehandler.
*
* @param[in] msg Die Nachricht.
* @param[in] id Die ID des Quellsteuerelements.
* @param[in] param Ein nachrichtenspezifischer Parameter.
*/

bool ctrlCheck::Msg_LeftDown(const MouseCoords& mc)
{
if(!readonly && IsPointInRect(mc.GetPos(), GetDrawRect()))
Expand All @@ -37,9 +29,19 @@ bool ctrlCheck::Msg_LeftDown(const MouseCoords& mc)
return false;
}

/**
* zeichnet das Fenster.
*/
bool ctrlCheck::Msg_MouseMove(const MouseCoords& mc)
{
if(IsMouseOver(mc.GetPos()))
{
ShowTooltip();
return true;
} else
{
HideTooltip();
return false;
}
}

void ctrlCheck::Draw_()
{
const unsigned short boxSize = 20;
Expand Down
19 changes: 15 additions & 4 deletions libs/s25main/controls/ctrlCheck.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "Window.h"
#include "ctrlBaseTooltip.h"
#include <string>
class MouseCoords;
class glFont;

class ctrlCheck : public Window
class ctrlCheck : public Window, public ctrlBaseTooltip
{
public:
ctrlCheck(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, std::string text,
const glFont* font, bool readonly);

void setChecked(bool checked) { this->check = checked; }
ctrlCheck* setChecked(bool checked)
{
this->check = checked;
return this;
}
bool isChecked() const { return check; }
void setReadOnly(bool readonly) { this->readonly = readonly; }
ctrlCheck* setReadOnly(bool readonly)
{
this->readonly = readonly;
return this;
}
bool isReadOnly() const { return readonly; }

bool Msg_LeftDown(const MouseCoords& mc) override;
bool Msg_MouseMove(const MouseCoords& mc) override;

protected:
void Draw_() override;
Expand Down
14 changes: 7 additions & 7 deletions libs/s25main/controls/ctrlImage.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand All @@ -12,25 +12,25 @@ ctrlImage::ctrlImage(Window* parent, unsigned id, const DrawPoint& pos, ITexture

ctrlImage::~ctrlImage() = default;

/**
* zeichnet das Fenster.
*/
void ctrlImage::Draw_()
{
DrawImage(Rect(GetDrawPos(), GetImageRect().getSize()));
}

bool ctrlImage::Msg_MouseMove(const MouseCoords& mc)
{
// gültiges Bild?
if(GetImage())
{
// Jeweils Tooltip ein- und ausblenden, wenn die Maus über dem Bild ist
if(IsPointInRect(mc.GetPos(), Rect::move(GetImageRect(), GetDrawPos())))
if(IsMouseOver(mc.GetPos()))
ShowTooltip();
else
HideTooltip();
}

return false;
}

Rect ctrlImage::GetBoundaryRect() const
{
return Rect::move(GetImageRect(), GetDrawPos());
}
3 changes: 2 additions & 1 deletion libs/s25main/controls/ctrlImage.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand All @@ -18,6 +18,7 @@ class ctrlImage : public Window, public ctrlBaseTooltip, public ctrlBaseImage
~ctrlImage() override;

bool Msg_MouseMove(const MouseCoords& mc) override;
Rect GetBoundaryRect() const;

protected:
void Draw_() override;
Expand Down
9 changes: 2 additions & 7 deletions libs/s25main/controls/ctrlMapSelection.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2024 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2024 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -119,7 +119,7 @@ void ctrlMapSelection::setPreview(bool previewOnly)

bool ctrlMapSelection::Msg_LeftUp(const MouseCoords& mc)
{
if(!preview && IsMouseOver(mc.GetPos()))
if(!preview && IsMouseOver(mc))
{
const auto pickPos = invertScale(mc.GetPos() - getMapPosition());

Expand All @@ -141,11 +141,6 @@ bool ctrlMapSelection::Msg_LeftUp(const MouseCoords& mc)
return false;
}

bool ctrlMapSelection::IsMouseOver(const Position& mousePos) const
{
return IsPointInRect(mousePos, GetDrawRect());
}

float ctrlMapSelection::getScaleFactor()
{
const auto ratio = PointF(GetSize()) / mapImages.background->GetSize();
Expand Down
3 changes: 1 addition & 2 deletions libs/s25main/controls/ctrlMapSelection.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2024 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2024 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -35,7 +35,6 @@ class ctrlMapSelection : public Window
bool Msg_LeftUp(const MouseCoords& mc) override;

protected:
bool IsMouseOver(const Position& mousePos) const;
void Draw_() override;

void updateEnabledMask();
Expand Down
9 changes: 1 addition & 8 deletions libs/s25main/desktops/dskMainMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -36,22 +36,15 @@ dskMainMenu::dskMainMenu()
{
RTTR_Assert(dskMenuBase::ID_FIRST_FREE <= 3);

// "Einzelspieler"
AddTextButton(ID_btSingleplayer, DrawPoint(115, 180), Extent(220, 22), TextureColor::Green2, _("Singleplayer"),
NormalFont);
// "Mehrspieler"
AddTextButton(ID_btMultiplayer, DrawPoint(115, 210), Extent(220, 22), TextureColor::Green2, _("Multiplayer"),
NormalFont);
// "Optionen"
AddTextButton(ID_btOptions, DrawPoint(115, 250), Extent(220, 22), TextureColor::Green2, _("Options"), NormalFont);
// "Intro"
AddTextButton(ID_btIntro, DrawPoint(115, 280), Extent(220, 22), TextureColor::Green2, _("Intro"), NormalFont)
->SetEnabled(false);
// "ReadMe"
AddTextButton(ID_btReadme, DrawPoint(115, 310), Extent(220, 22), TextureColor::Green2, _("Readme"), NormalFont);
// "Credits"
AddTextButton(ID_btCredits, DrawPoint(115, 340), Extent(220, 22), TextureColor::Green2, _("Credits"), NormalFont);
// "Programm verlassen"
AddTextButton(ID_btQuit, DrawPoint(115, 390), Extent(220, 22), TextureColor::Red1, _("Quit program"), NormalFont);

AddImage(ID_logo, DrawPoint(20, 20), LOADER.GetImageN("logo", 0));
Expand Down
Loading
Loading