Skip to content

Commit

Permalink
Make WIDGET::hitTest() const
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Feb 27, 2024
1 parent d07dfc7 commit 85eac7f
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/widget/form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void W_FORM::screenSizeDidChange(int oldWidth, int oldHeight, int newWidth, int
WIDGET::screenSizeDidChange(oldWidth, oldHeight, newWidth, newHeight);
}

bool W_FORM::hitTest(int x, int y)
bool W_FORM::hitTest(int x, int y) const
{
if (!minimizable || formState != FormState::MINIMIZED)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/form.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class W_FORM : public WIDGET
void display(int xOffset, int yOffset) override;

void screenSizeDidChange(int oldWidth, int oldHeight, int newWidth, int newHeight) override;
bool hitTest(int x, int y) override;
bool hitTest(int x, int y) const override;
bool processClickRecursive(W_CONTEXT *psContext, WIDGET_KEY key, bool wasPressed) override;
void displayRecursive(WidgetGraphicsContext const &context) override;
using WIDGET::displayRecursive;
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void TableRow::displayRecursive(WidgetGraphicsContext const& context)
pie_UniTransBoxFill(x0, y0, x0 + width(), y0 + height(), disabledColor);
}

bool TableRow::hitTest(int x, int y)
bool TableRow::hitTest(int x, int y) const
{
if (disabledRow) { return false; }
return W_BUTTON::hitTest(x, y);
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TableRow: public W_BUTTON
protected:
virtual void display(int, int) override;
virtual void displayRecursive(WidgetGraphicsContext const& context) override;
virtual bool hitTest(int x, int y) override;
virtual bool hitTest(int x, int y) const override;
public:
virtual bool processClickRecursive(W_CONTEXT *psContext, WIDGET_KEY key, bool wasPressed) override;
protected:
Expand Down
4 changes: 2 additions & 2 deletions lib/widget/widgbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ typedef std::function<void (WIDGET *psWidget)> WIDGET_CALCLAYOUT_FUNC;
typedef std::function<void (WIDGET *psWidget)> WIDGET_ONDELETE_FUNC;

/* The optional hit-testing function, used for custom hit-testing within the outer bounding rectangle */
typedef std::function<bool (WIDGET *psWidget, int x, int y)> WIDGET_HITTEST_FUNC;
typedef std::function<bool (const WIDGET *psWidget, int x, int y)> WIDGET_HITTEST_FUNC;


/* The different base types of widget */
Expand Down Expand Up @@ -218,7 +218,7 @@ class WIDGET: public std::enable_shared_from_this<WIDGET>
virtual void display(int, int) {}
virtual void geometryChanged() {}

virtual bool hitTest(int x, int y);
virtual bool hitTest(int x, int y) const;

public:
virtual unsigned getState();
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ void WIDGET::runRecursive(W_CONTEXT *psContext)
}
}

bool WIDGET::hitTest(int x, int y)
bool WIDGET::hitTest(int x, int y) const
{
// default hit-testing bounding rect (based on the widget's x, y, width, height)
bool hitTestResult = dim.contains(x, y);
Expand Down
2 changes: 1 addition & 1 deletion src/hci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void setReticuleButtonDimensions(W_BUTTON &button, const WzString &filename)
button.setGeometry(button.x(), button.y(), image->Width / 2, image->Height / 2);

// add a custom hit-testing function that uses a tighter bounding ellipse
button.setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool {
button.setCustomHitTest([](const WIDGET *psWidget, int x, int y) -> bool {

// determine center of ellipse contained within the bounding rect
float centerX = ((psWidget->x()) + (psWidget->x() + psWidget->width())) / 2.f;
Expand Down
2 changes: 1 addition & 1 deletion src/multiint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4565,7 +4565,7 @@ void WzMultiplayerOptionsTitleUI::openPlayerSlotSwapChooser(uint32_t playerIndex

// Now create a dummy row for the row being swapped, and display beneath
auto playerRow = WzPlayerRow::make(playerIndex, titleUI);
playerRow->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; }); // ensure clicks on this display-only row have no effect
playerRow->setTransparentToMouse(true); // ensure clicks on this display-only row have no effect
swapContextForm->attach(playerRow);
playerRow->setCalcLayout([swapContextFormPadding, textHeight](WIDGET *psWidget) {
psWidget->setGeometry(PLAYERBOX_X0, swapContextFormPadding + textHeight + 4, MULTIOP_PLAYERWIDTH, MULTIOP_PLAYERHEIGHT);
Expand Down
24 changes: 8 additions & 16 deletions src/musicmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,7 @@ static void UpdateTrackDetailsBox(TrackDetailsForm *pTrackDetailsBox)
psNowPlaying->setFont(font_regular, WZCOL_TEXT_MEDIUM);
psNowPlaying->setString((selectedTrack) ? (WzString::fromUtf8(_("NOW PLAYING")) + ":") : "");
psNowPlaying->setTextAlignment(WLAB_ALIGNTOPLEFT);
// set a custom hit-testing function that ignores all mouse input / clicks
psNowPlaying->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; });
psNowPlaying->setTransparentToMouse(true);

// Add Selected Track name
if (!psSelectedTrackName)
Expand All @@ -501,8 +500,7 @@ static void UpdateTrackDetailsBox(TrackDetailsForm *pTrackDetailsBox)
psSelectedTrackName->setFont(font_regular_bold, WZCOL_TEXT_BRIGHT);
psSelectedTrackName->setString((selectedTrack) ? WzString::fromUtf8(selectedTrack->title) : "");
psSelectedTrackName->setTextAlignment(WLAB_ALIGNTOPLEFT);
// set a custom hit-testing function that ignores all mouse input / clicks
psSelectedTrackName->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; });
psSelectedTrackName->setTransparentToMouse(true);

// Add Selected Track author details
if (!psSelectedTrackAuthorName)
Expand All @@ -513,8 +511,7 @@ static void UpdateTrackDetailsBox(TrackDetailsForm *pTrackDetailsBox)
psSelectedTrackAuthorName->setFont(font_regular, WZCOL_TEXT_BRIGHT);
psSelectedTrackAuthorName->setString((selectedTrack) ? WzString::fromUtf8(selectedTrack->author) : "");
psSelectedTrackAuthorName->setTextAlignment(WLAB_ALIGNTOPLEFT);
// set a custom hit-testing function that ignores all mouse input / clicks
psSelectedTrackAuthorName->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; });
psSelectedTrackAuthorName->setTransparentToMouse(true);

// album info xPosStart
int albumInfoXPosStart = psNowPlaying->x() + psNowPlaying->width() + 10 + WZ_TRACKDETAILS_IMAGE_SIZE + 10;
Expand All @@ -529,8 +526,7 @@ static void UpdateTrackDetailsBox(TrackDetailsForm *pTrackDetailsBox)
psSelectedTrackAlbumName->setFont(font_small, WZCOL_TEXT_BRIGHT);
psSelectedTrackAlbumName->setString((pAlbum) ? (WzString::fromUtf8(_("Album")) + ": " + WzString::fromUtf8(pAlbum->title)) : "");
psSelectedTrackAlbumName->setTextAlignment(WLAB_ALIGNTOPLEFT);
// set a custom hit-testing function that ignores all mouse input / clicks
psSelectedTrackAlbumName->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; });
psSelectedTrackAlbumName->setTransparentToMouse(true);

if (!psSelectedTrackAlbumDate)
{
Expand All @@ -540,8 +536,7 @@ static void UpdateTrackDetailsBox(TrackDetailsForm *pTrackDetailsBox)
psSelectedTrackAlbumDate->setFont(font_small, WZCOL_TEXT_BRIGHT);
psSelectedTrackAlbumDate->setString((pAlbum) ? (WzString::fromUtf8(_("Date")) + ": " + WzString::fromUtf8(pAlbum->date)) : "");
psSelectedTrackAlbumDate->setTextAlignment(WLAB_ALIGNTOPLEFT);
// set a custom hit-testing function that ignores all mouse input / clicks
psSelectedTrackAlbumDate->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; });
psSelectedTrackAlbumDate->setTransparentToMouse(true);

if (!psSelectedTrackAlbumDescription)
{
Expand All @@ -552,8 +547,7 @@ static void UpdateTrackDetailsBox(TrackDetailsForm *pTrackDetailsBox)
int heightOfTitleLabel = psSelectedTrackAlbumDescription->setFormattedString((pAlbum) ? WzString::fromUtf8(pAlbum->description) : "", maxWidthOfAlbumLabel, font_small);
psSelectedTrackAlbumDescription->setGeometry(albumInfoXPosStart, 12 + 13 + 15, maxWidthOfAlbumLabel, heightOfTitleLabel);
psSelectedTrackAlbumDescription->setTextAlignment(WLAB_ALIGNTOPLEFT);
// set a custom hit-testing function that ignores all mouse input / clicks
psSelectedTrackAlbumDescription->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; });
psSelectedTrackAlbumDescription->setTransparentToMouse(true);

pTrackDetailsBox->loadImage((pAlbum) ? pAlbum->album_cover_filename : "");
}
Expand Down Expand Up @@ -674,17 +668,15 @@ static void addTrackList(WIDGET *parent, bool ingame)
title_header->setFontColour(WZCOL_TEXT_MEDIUM);
title_header->setString(_("Title"));
title_header->setTextAlignment(WLAB_ALIGNTOPLEFT);
// set a custom hit-testing function that ignores all mouse input / clicks
title_header->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; });
title_header->setTransparentToMouse(true);

auto album_header = std::make_shared<W_LABEL>();
pHeader->attach(album_header);
album_header->setGeometry(W_TRACK_COL_ALBUM_X, headerColY, W_TRACK_COL_ALBUM_W, W_TRACK_HEADER_HEIGHT);
album_header->setFontColour(WZCOL_TEXT_MEDIUM);
album_header->setString(_("Album"));
album_header->setTextAlignment(WLAB_ALIGNTOPLEFT);
// set a custom hit-testing function that ignores all mouse input / clicks
album_header->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; });
album_header->setTransparentToMouse(true);

for (int musicModeIdx = 0; musicModeIdx < NUM_MUSICGAMEMODES; musicModeIdx++)
{
Expand Down
6 changes: 2 additions & 4 deletions src/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,7 @@ std::shared_ptr<W_NOTIFICATION> W_NOTIFICATION::make(WZ_Queued_Notification* req
}
label_title->setGeometry(titleStartXPos, titleStartYPos, maxTitleWidth, heightOfTitleLabel);
label_title->setTextAlignment(WLAB_ALIGNTOPLEFT);
// set a custom hit-testing function that ignores all mouse input / clicks
label_title->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; });
label_title->setTransparentToMouse(true);
int titleBottom = label_title->y() + label_title->height();
if (isModal)
{
Expand All @@ -693,8 +692,7 @@ std::shared_ptr<W_NOTIFICATION> W_NOTIFICATION::make(WZ_Queued_Notification* req
int heightOfContentsLabel = label_contents->setFormattedString(WzString::fromUtf8(request->notification.contentText), maxContentsWidth, font_regular, WZ_NOTIFICATION_CONTENTS_LINE_SPACING);
label_contents->setGeometry(label_contents->x(), label_contents->y(), maxContentsWidth, heightOfContentsLabel);
label_contents->setTextAlignment(WLAB_ALIGNTOPLEFT);
// set a custom hit-testing function that ignores all mouse input / clicks
label_contents->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool { return false; });
label_contents->setTransparentToMouse(true);

// Add action buttons
std::string dismissLabel = _("Dismiss");
Expand Down
4 changes: 2 additions & 2 deletions src/radar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class RadarWidget : public WIDGET {
protected:
void run(W_CONTEXT *) override;
void display(int xOffset, int yOffset) override;
bool hitTest(int x, int y) override;
bool hitTest(int x, int y) const override;
void clicked(W_CONTEXT *, WIDGET_KEY = WKEY_PRIMARY) override;
void released(W_CONTEXT *, WIDGET_KEY = WKEY_PRIMARY) override;
void highlight(W_CONTEXT *) override;
Expand Down Expand Up @@ -878,7 +878,7 @@ void RadarWidget::display(int xOffset, int yOffset)
drawRadar();
}

bool RadarWidget::hitTest(int x, int y)
bool RadarWidget::hitTest(int x, int y) const
{
// NOTE: CoordInRadar expects x, y in *screen* coordinates - this is _currently_ the case as a byproduct of how the radar widget is added to the UI screen
return WIDGET::hitTest(x, y) && CoordInRadar(x, y);
Expand Down
2 changes: 1 addition & 1 deletion src/spectatorwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool specLayerInit(bool showButton /*= true*/)
specStatsViewCreate();
});
});
specStatsButton->setCustomHitTest([](WIDGET *psWidget, int x, int y) -> bool {
specStatsButton->setCustomHitTest([](const WIDGET *psWidget, int x, int y) -> bool {
if (bDisplayMultiJoiningStatus)
{
// effectively: make this unclickable until the game actually starts
Expand Down

0 comments on commit 85eac7f

Please sign in to comment.