Skip to content

Commit

Permalink
Common: hotfix for change of method in how Button's curimage is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Oct 24, 2023
1 parent 46b51f1 commit 2bc7631
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
17 changes: 11 additions & 6 deletions Common/gui/guibutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ GUIButton::GUIButton()
_image = -1;
_mouseOverImage = -1;
_pushedImage = -1;
_currentImage = -1;
_imageFlags = 0;
_currentImage = -1;
_curImageFlags = 0;
Font = 0;
TextColor = 0;
TextAlignment = kAlignTopCenter;
Expand Down Expand Up @@ -211,7 +212,7 @@ void GUIButton::SetImages(int32_t normal, int32_t over, int32_t pushed, uint32_t
_image = normal;
_mouseOverImage = over;
_pushedImage = pushed;
_imageFlags = flags; // TODO: images per each kind of image?
_imageFlags = flags;
UpdateCurrentImage();
}

Expand All @@ -222,10 +223,10 @@ int32_t GUIButton::CurrentImage() const

void GUIButton::SetCurrentImage(int32_t new_image, uint32_t flags)
{
if (_currentImage == new_image && _imageFlags == flags)
if (_currentImage == new_image && _curImageFlags == flags)
return;
_currentImage = new_image;
_imageFlags = flags;
_curImageFlags = flags;
MarkChanged();
}

Expand Down Expand Up @@ -294,6 +295,7 @@ void GUIButton::OnMouseUp()
void GUIButton::UpdateCurrentImage()
{
int new_image = _currentImage;
uint32_t new_flags = 0;

if (IsPushed && (_pushedImage > 0))
{
Expand All @@ -306,9 +308,10 @@ void GUIButton::UpdateCurrentImage()
else
{
new_image = _image;
new_flags = _imageFlags;
}

SetCurrentImage(new_image);
SetCurrentImage(new_image, new_flags);
}

void GUIButton::WriteToFile(Stream *out) const
Expand Down Expand Up @@ -377,6 +380,8 @@ void GUIButton::ReadFromSavegame(Stream *in, GuiSvgVersion svg_ver)
// Update current state after reading
IsPushed = false;
IsMouseOver = false;
_curImageFlags = _imageFlags;
UpdateCurrentImage();
}

void GUIButton::WriteToSavegame(Stream *out) const
Expand Down Expand Up @@ -407,7 +412,7 @@ void GUIButton::DrawImageButton(Bitmap *ds, int x, int y, bool draw_disabled)
ds->SetClip(RectWH(x, y, _width, _height));

if (spriteset.DoesSpriteExist(_currentImage))
draw_gui_sprite_flipped(ds, _currentImage, x, y, kBlend_Normal, _imageFlags & VFLG_FLIPSPRITE);
draw_gui_sprite_flipped(ds, _currentImage, x, y, kBlend_Normal, _curImageFlags & VFLG_FLIPSPRITE);

// Draw active inventory item
if (_placeholder != kButtonPlace_None && gui_inv_pic >= 0)
Expand Down
10 changes: 5 additions & 5 deletions Common/gui/guibutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ class GUIButton : public GUIObject
Rect CalcGraphicRect(bool clipped) override;
void Draw(Bitmap *ds, int x = 0, int y = 0) override;
void SetClipImage(bool on);
void SetCurrentImage(int32_t image, uint32_t flags = 0);
void SetMouseOverImage(int32_t image);
void SetNormalImage(int32_t image);
void SetPushedImage(int32_t image);
// TODO: flags for each kind of image?
void SetImages(int32_t normal, int32_t over, int32_t pushed, uint32_t flags = 0);
void SetCurrentImage(int32_t image, uint32_t flags = 0);
void SetText(const String &text);

// Events
Expand Down Expand Up @@ -111,10 +110,11 @@ class GUIButton : public GUIObject
int32_t _image;
int32_t _mouseOverImage;
int32_t _pushedImage;
// Active displayed image
int32_t _currentImage;
// TODO: flags for each kind of image, not just "current"?
// TODO: flags for each kind of image?
uint32_t _imageFlags;
// Active displayed image
int32_t _currentImage;
uint32_t _curImageFlags;
// Text property set by user
String _text;
// type of content placeholder, if any
Expand Down

0 comments on commit 2bc7631

Please sign in to comment.