5
5
#include " guiButton.h"
6
6
7
7
8
+ #include " client/guiscalingfilter.h"
9
+ #include " client/tile.h"
8
10
#include " IGUISkin.h"
9
11
#include " IGUIEnvironment.h"
10
12
#include " IVideoDriver.h"
11
13
#include " IGUIFont.h"
14
+ #include " irrlicht_changes/static_text.h"
12
15
#include " porting.h"
16
+ #include " StyleSpec.h"
13
17
14
18
using namespace irr ;
15
19
using namespace gui ;
@@ -49,6 +53,9 @@ GUIButton::GUIButton(IGUIEnvironment* environment, IGUIElement* parent,
49
53
core::clamp<u32>(Colors[i].getGreen () * COLOR_PRESSED_MOD, 0 , 255 ),
50
54
core::clamp<u32>(Colors[i].getBlue () * COLOR_PRESSED_MOD, 0 , 255 ));
51
55
}
56
+
57
+ StaticText = gui::StaticText::add (Environment, Text.c_str (), core::rect<s32>(0 ,0 ,rectangle.getWidth (),rectangle.getHeight ()), false , false , this , id);
58
+ StaticText->setTextAlignment (EGUIA_CENTER, EGUIA_CENTER);
52
59
// END PATCH
53
60
}
54
61
@@ -262,7 +269,7 @@ void GUIButton::draw()
262
269
{
263
270
// PATCH
264
271
skin->drawColored3DButtonPaneStandard (this , AbsoluteRect, &AbsoluteClippingRect,
265
- Environment-> getHovered () == this ? HoveredColors : Colors);
272
+ isHovered () ? HoveredColors : Colors);
266
273
// END PATCH
267
274
}
268
275
else
@@ -318,7 +325,7 @@ void GUIButton::draw()
318
325
drawSprite (state, FocusTime, pos);
319
326
320
327
// mouse over / off animation
321
- state = Environment-> getHovered () == this ? EGBS_BUTTON_MOUSE_OVER : EGBS_BUTTON_MOUSE_OFF;
328
+ state = isHovered () ? EGBS_BUTTON_MOUSE_OVER : EGBS_BUTTON_MOUSE_OFF;
322
329
drawSprite (state, HoverTime, pos);
323
330
}
324
331
else
@@ -328,23 +335,6 @@ void GUIButton::draw()
328
335
}
329
336
}
330
337
331
- if (Text.size ())
332
- {
333
- IGUIFont* font = getActiveFont ();
334
-
335
- core::rect<s32> rect = AbsoluteRect;
336
- if (Pressed)
337
- {
338
- rect.UpperLeftCorner .X += skin->getSize (EGDS_BUTTON_PRESSED_TEXT_OFFSET_X);
339
- rect.UpperLeftCorner .Y += skin->getSize (EGDS_BUTTON_PRESSED_TEXT_OFFSET_Y);
340
- }
341
-
342
- if (font)
343
- font->draw (Text.c_str (), rect,
344
- OverrideColorEnabled ? OverrideColor : skin->getColor (isEnabled () ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT),
345
- true , true , &AbsoluteClippingRect);
346
- }
347
-
348
338
IGUIElement::draw ();
349
339
}
350
340
@@ -371,11 +361,18 @@ void GUIButton::drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::p
371
361
}
372
362
373
363
EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState (bool pressed) const
364
+ {
365
+ // PATCH
366
+ return getImageState (pressed, ButtonImages);
367
+ // END PATCH
368
+ }
369
+
370
+ EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState (bool pressed, const ButtonImage* images) const
374
371
{
375
372
// figure state we should have
376
373
EGUI_BUTTON_IMAGE_STATE state = EGBIS_IMAGE_DISABLED;
377
374
bool focused = Environment->hasFocus ((IGUIElement*)this );
378
- bool mouseOver = static_cast < const IGUIElement*>(Environment-> getHovered ()) == this ; // (static cast for Borland)
375
+ bool mouseOver = isHovered ();
379
376
if (isEnabled ())
380
377
{
381
378
if ( pressed )
@@ -403,7 +400,7 @@ EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed) const
403
400
}
404
401
405
402
// find a compatible state that has images
406
- while ( state != EGBIS_IMAGE_UP && !ButtonImages [(u32)state].Texture )
403
+ while ( state != EGBIS_IMAGE_UP && !images [(u32)state].Texture )
407
404
{
408
405
// PATCH
409
406
switch ( state )
@@ -451,6 +448,8 @@ void GUIButton::setOverrideFont(IGUIFont* font)
451
448
452
449
if (OverrideFont)
453
450
OverrideFont->grab ();
451
+
452
+ StaticText->setOverrideFont (font);
454
453
}
455
454
456
455
// ! Gets the override font (if any)
@@ -475,6 +474,8 @@ void GUIButton::setOverrideColor(video::SColor color)
475
474
{
476
475
OverrideColor = color;
477
476
OverrideColorEnabled = true ;
477
+
478
+ StaticText->setOverrideColor (color);
478
479
}
479
480
480
481
video::SColor GUIButton::getOverrideColor () const
@@ -540,6 +541,14 @@ void GUIButton::setHoveredImage(video::ITexture* image, const core::rect<s32>& p
540
541
setImage (gui::EGBIS_IMAGE_UP_MOUSEOVER, image, pos);
541
542
setImage (gui::EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER, image, pos);
542
543
}
544
+
545
+ // ! Sets the text displayed by the button
546
+ void GUIButton::setText (const wchar_t * text)
547
+ {
548
+ StaticText->setText (text);
549
+
550
+ IGUIButton::setText (text);
551
+ }
543
552
// END PATCH
544
553
545
554
// ! Sets if the button should behave like a push button. Which means it
@@ -557,6 +566,14 @@ bool GUIButton::isPressed() const
557
566
return Pressed;
558
567
}
559
568
569
+ // PATCH
570
+ // ! Returns if this element (or one of its direct children) is hovered
571
+ bool GUIButton::isHovered () const
572
+ {
573
+ IGUIElement *hovered = Environment->getHovered ();
574
+ return hovered == this || (hovered != nullptr && hovered->getParent () == this );
575
+ }
576
+ // END PATCH
560
577
561
578
// ! Sets the pressed state of the button if this is a pushbutton
562
579
void GUIButton::setPressed (bool pressed)
@@ -565,6 +582,24 @@ void GUIButton::setPressed(bool pressed)
565
582
{
566
583
ClickTime = porting::getTimeMs ();
567
584
Pressed = pressed;
585
+
586
+ GUISkin* skin = dynamic_cast <GUISkin*>(Environment->getSkin ());
587
+
588
+ for (IGUIElement *child : getChildren ())
589
+ {
590
+ core::rect<s32> originalRect = child->getRelativePosition ();
591
+ if (Pressed) {
592
+ child->setRelativePosition (originalRect +
593
+ core::dimension2d<s32>(
594
+ skin->getSize (irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
595
+ skin->getSize (irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y)));
596
+ } else {
597
+ child->setRelativePosition (originalRect -
598
+ core::dimension2d<s32>(
599
+ skin->getSize (irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
600
+ skin->getSize (irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y)));
601
+ }
602
+ }
568
603
}
569
604
}
570
605
@@ -722,4 +757,42 @@ void GUIButton::setPressedColor(video::SColor color)
722
757
PressedColors[i] = base.getInterpolated (color, d);
723
758
}
724
759
}
760
+
761
+ // ! Set element properties from a StyleSpec
762
+ void GUIButton::setFromStyle (const StyleSpec& style, ISimpleTextureSource *tsrc)
763
+ {
764
+ if (style.isNotDefault (StyleSpec::BGCOLOR)) {
765
+ setColor (style.getColor (StyleSpec::BGCOLOR));
766
+ }
767
+ if (style.isNotDefault (StyleSpec::BGCOLOR_HOVERED)) {
768
+ setHoveredColor (style.getColor (StyleSpec::BGCOLOR_HOVERED));
769
+ }
770
+ if (style.isNotDefault (StyleSpec::BGCOLOR_PRESSED)) {
771
+ setPressedColor (style.getColor (StyleSpec::BGCOLOR_PRESSED));
772
+ }
773
+
774
+ if (style.isNotDefault (StyleSpec::TEXTCOLOR)) {
775
+ setOverrideColor (style.getColor (StyleSpec::TEXTCOLOR));
776
+ }
777
+ setNotClipped (style.getBool (StyleSpec::NOCLIP, isNotClipped ()));
778
+ setDrawBorder (style.getBool (StyleSpec::BORDER, DrawBorder));
779
+ setUseAlphaChannel (style.getBool (StyleSpec::ALPHA, true ));
780
+
781
+ if (style.isNotDefault (StyleSpec::BGIMG)) {
782
+ video::ITexture *texture = style.getTexture (StyleSpec::BGIMG, tsrc);
783
+ video::ITexture *hovered_texture = style.getTexture (StyleSpec::BGIMG_HOVERED, tsrc, texture);
784
+ video::ITexture *pressed_texture = style.getTexture (StyleSpec::BGIMG_PRESSED, tsrc, texture);
785
+
786
+ const core::position2di buttonCenter (AbsoluteRect.getCenter ());
787
+ core::position2d<s32> geom (buttonCenter);
788
+
789
+ setImage (guiScalingImageButton (
790
+ Environment->getVideoDriver (), texture, geom.X , geom.Y ));
791
+ setHoveredImage (guiScalingImageButton (
792
+ Environment->getVideoDriver (), hovered_texture, geom.X , geom.Y ));
793
+ setPressedImage (guiScalingImageButton (
794
+ Environment->getVideoDriver (), pressed_texture, geom.X , geom.Y ));
795
+ setScaleImage (true );
796
+ }
797
+ }
725
798
// END PATCH
0 commit comments