Skip to content

Add "mask" to button#151

Merged
mcarpenter622 merged 13 commits intoebitenui:masterfrom
scratch85:feature/add-mask-to-button
Jun 9, 2024
Merged

Add "mask" to button#151
mcarpenter622 merged 13 commits intoebitenui:masterfrom
scratch85:feature/add-mask-to-button

Conversation

@scratch85
Copy link
Copy Markdown
Contributor

@scratch85 scratch85 commented Jun 2, 2024

Closes #133

  • Please see "button_with_mask" example ("button" still works as expected)
  • "Mask" is created from the the given NineSlice image only (no Text, no Graphic), which is added to (Image *ButtonImage).Idle => not optimal yet
  • The expected condition to fullfill onMask(x, y) is every 4th byte of the pixels array is > 0. This is not configurable
  1. It would be better in general if button would create an offscreen image with all elements (like text, graphic, etc..) instead of directly drawing to screen. This would simply allow to use the offscreen image as mask and ignore e.g. all transparent pixels (A = 0). If you favor this approach, we can work together to get this done.

  2. If you do not feel comfortable with including this into button-widget directly, we could add another widget and make it optional to use.

@scratch85 scratch85 requested a review from mcarpenter622 June 6, 2024 11:55
@scratch85 scratch85 requested a review from mcarpenter622 June 7, 2024 14:41
@scratch85 scratch85 marked this pull request as draft June 7, 2024 14:52
}
}

func (o ButtonOptions) IgnoreTransparentPixels(ignoreTransparentPixels bool) ButtonOpt {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not in love with this name but cannot think of anything better.
Please add a comment to this method explaining it.

Copy link
Copy Markdown
Contributor Author

@scratch85 scratch85 Jun 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having trouble naming it as well. If you have any better idea let me know. Maybe @quasilyte has some idea. Added some explanation, are you happy with it?

WidgetOpts.CursorEnterHandler(func(args *WidgetCursorEnterEventArgs) {
if !b.widget.Disabled {
b.hovering = true
if b.mask == nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will CursorEnter never run if we don't ignoreTransparentPixels?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not, the cursor enter (and exit) event is handled within cursor move. As the cursor enter is fired based on the rectangular shape of the widget, which does not know anything about the mask.

b.pressing = true

b.PressedEvent.Fire(&ButtonPressedEventArgs{
if b.hovering || b.mask == nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this will ever run if ignoreTranparentPixels is false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thought the same, but actually it does.
Here is how:

  1. Press & hold anywhere within the mask
  2. While pressed move the mouse cursor outside of the widget or even the game window, where mouse move event of the widget itself is not triggered

@scratch85 scratch85 marked this pull request as ready for review June 9, 2024 11:37
@scratch85 scratch85 requested a review from mcarpenter622 June 9, 2024 11:39
@mcarpenter622 mcarpenter622 merged commit 7e4aaa7 into ebitenui:master Jun 9, 2024
@scratch85 scratch85 deleted the feature/add-mask-to-button branch June 11, 2024 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Extend button widget to support optional "mask", instead of triggering hover, press, etc on entering/clicking the widget boundaries.

2 participants