Use our GUIButton in our GUIScrollBar

Note that GUIScrollBar needs an ISimpleTextureSource now due to button styling.
This commit is contained in:
Desour 2023-08-09 01:08:16 +02:00 committed by sfan5
parent 9d62abbe46
commit 91c0439922
8 changed files with 43 additions and 25 deletions

@ -25,9 +25,10 @@ numerical
//! constructor //! constructor
GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool border, GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool border,
IGUIEnvironment* environment, IGUIElement* parent, s32 id, IGUIEnvironment* environment, IGUIElement* parent, s32 id,
const core::rect<s32>& rectangle, bool writable, bool has_vscrollbar) const core::rect<s32>& rectangle, ISimpleTextureSource *tsrc,
bool writable, bool has_vscrollbar)
: GUIEditBox(environment, parent, id, rectangle, border, writable), : GUIEditBox(environment, parent, id, rectangle, border, writable),
m_background(true), m_bg_color_used(false) m_background(true), m_bg_color_used(false), m_tsrc(tsrc)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("GUIEditBoxWithScrollBar"); setDebugName("GUIEditBoxWithScrollBar");
@ -635,7 +636,7 @@ void GUIEditBoxWithScrollBar::createVScrollBar()
irr::core::rect<s32> scrollbarrect = m_frame_rect; irr::core::rect<s32> scrollbarrect = m_frame_rect;
scrollbarrect.UpperLeftCorner.X += m_frame_rect.getWidth() - m_scrollbar_width; scrollbarrect.UpperLeftCorner.X += m_frame_rect.getWidth() - m_scrollbar_width;
m_vscrollbar = new GUIScrollBar(Environment, getParent(), -1, m_vscrollbar = new GUIScrollBar(Environment, getParent(), -1,
scrollbarrect, false, true); scrollbarrect, false, true, m_tsrc);
m_vscrollbar->setVisible(false); m_vscrollbar->setVisible(false);
m_vscrollbar->setSmallStep(3 * fontHeight); m_vscrollbar->setSmallStep(3 * fontHeight);

@ -7,6 +7,8 @@
#include "guiEditBox.h" #include "guiEditBox.h"
class ISimpleTextureSource;
class GUIEditBoxWithScrollBar : public GUIEditBox class GUIEditBoxWithScrollBar : public GUIEditBox
{ {
public: public:
@ -14,7 +16,7 @@ public:
//! constructor //! constructor
GUIEditBoxWithScrollBar(const wchar_t* text, bool border, IGUIEnvironment* environment, GUIEditBoxWithScrollBar(const wchar_t* text, bool border, IGUIEnvironment* environment,
IGUIElement* parent, s32 id, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
bool writable = true, bool has_vscrollbar = true); ISimpleTextureSource *tsrc, bool writable = true, bool has_vscrollbar = true);
//! destructor //! destructor
virtual ~GUIEditBoxWithScrollBar() {} virtual ~GUIEditBoxWithScrollBar() {}
@ -56,6 +58,8 @@ protected:
bool m_bg_color_used; bool m_bg_color_used;
video::SColor m_bg_color; video::SColor m_bg_color;
ISimpleTextureSource *m_tsrc;
}; };

@ -666,7 +666,7 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &elemen
spec.ftype = f_ScrollBar; spec.ftype = f_ScrollBar;
spec.send = true; spec.send = true;
GUIScrollBar *e = new GUIScrollBar(Environment, data->current_parent, GUIScrollBar *e = new GUIScrollBar(Environment, data->current_parent,
spec.fid, rect, is_horizontal, true); spec.fid, rect, is_horizontal, true, m_tsrc);
auto style = getDefaultStyleForElement("scrollbar", name); auto style = getDefaultStyleForElement("scrollbar", name);
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
@ -1493,7 +1493,7 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec,
gui::IGUIEditBox *e = nullptr; gui::IGUIEditBox *e = nullptr;
if (is_multiline) { if (is_multiline) {
e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, Environment, e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, Environment,
data->current_parent, spec.fid, rect, is_editable, true); data->current_parent, spec.fid, rect, m_tsrc, is_editable, true);
} else if (is_editable) { } else if (is_editable) {
e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, e = Environment->addEditBox(spec.fdefault.c_str(), rect, true,
data->current_parent, spec.fid); data->current_parent, spec.fid);

@ -1010,7 +1010,7 @@ GUIHyperText::GUIHyperText(const wchar_t *text, IGUIEnvironment *environment,
RelativeRect.getWidth() - m_scrollbar_width, 0, RelativeRect.getWidth() - m_scrollbar_width, 0,
RelativeRect.getWidth(), RelativeRect.getHeight()); RelativeRect.getWidth(), RelativeRect.getHeight());
m_vscrollbar = new GUIScrollBar(Environment, this, -1, rect, false, true); m_vscrollbar = new GUIScrollBar(Environment, this, -1, rect, false, true, tsrc);
m_vscrollbar->setVisible(false); m_vscrollbar->setVisible(false);
} }

@ -11,17 +11,19 @@ the arrow buttons where there is insufficient space.
*/ */
#include "guiScrollBar.h" #include "guiScrollBar.h"
#include <IGUIButton.h> #include "guiButton.h"
#include <IGUISkin.h> #include <IGUISkin.h>
GUIScrollBar::GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id, GUIScrollBar::GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id,
core::rect<s32> rectangle, bool horizontal, bool auto_scale) : core::rect<s32> rectangle, bool horizontal, bool auto_scale,
ISimpleTextureSource *tsrc) :
IGUIElement(EGUIET_ELEMENT, environment, parent, id, rectangle), IGUIElement(EGUIET_ELEMENT, environment, parent, id, rectangle),
up_button(nullptr), down_button(nullptr), is_dragging(false), up_button(nullptr), down_button(nullptr), is_dragging(false),
is_horizontal(horizontal), is_auto_scaling(auto_scale), is_horizontal(horizontal), is_auto_scaling(auto_scale),
dragged_by_slider(false), tray_clicked(false), scroll_pos(0), dragged_by_slider(false), tray_clicked(false), scroll_pos(0),
draw_center(0), thumb_size(0), min_pos(0), max_pos(100), small_step(10), draw_center(0), thumb_size(0), min_pos(0), max_pos(100), small_step(10),
large_step(50), drag_offset(0), page_size(100), border_size(0) large_step(50), drag_offset(0), page_size(100), border_size(0),
m_tsrc(tsrc)
{ {
refreshControls(); refreshControls();
setNotClipped(false); setNotClipped(false);
@ -343,8 +345,9 @@ void GUIScrollBar::refreshControls()
s32 h = RelativeRect.getHeight(); s32 h = RelativeRect.getHeight();
border_size = RelativeRect.getWidth() < h * 4 ? 0 : h; border_size = RelativeRect.getWidth() < h * 4 ? 0 : h;
if (!up_button) { if (!up_button) {
up_button = Environment->addButton( core::rect<s32> up_button_rect(0, 0, h, h);
core::rect<s32>(0, 0, h, h), this); up_button = GUIButton::addButton(Environment, up_button_rect, m_tsrc,
this, -1, L"");
up_button->setSubElement(true); up_button->setSubElement(true);
up_button->setTabStop(false); up_button->setTabStop(false);
} }
@ -361,10 +364,12 @@ void GUIScrollBar::refreshControls()
up_button->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, up_button->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT,
EGUIA_LOWERRIGHT); EGUIA_LOWERRIGHT);
if (!down_button) { if (!down_button) {
down_button = Environment->addButton( core::rect<s32> down_button_rect(
core::rect<s32>(RelativeRect.getWidth() - h, 0, RelativeRect.getWidth() - h, 0,
RelativeRect.getWidth(), h), RelativeRect.getWidth(), h
this); );
down_button = GUIButton::addButton(Environment, down_button_rect, m_tsrc,
this, -1, L"");
down_button->setSubElement(true); down_button->setSubElement(true);
down_button->setTabStop(false); down_button->setTabStop(false);
} }
@ -386,8 +391,9 @@ void GUIScrollBar::refreshControls()
s32 w = RelativeRect.getWidth(); s32 w = RelativeRect.getWidth();
border_size = RelativeRect.getHeight() < w * 4 ? 0 : w; border_size = RelativeRect.getHeight() < w * 4 ? 0 : w;
if (!up_button) { if (!up_button) {
up_button = Environment->addButton( core::rect<s32> up_button_rect(0, 0, w, w);
core::rect<s32>(0, 0, w, w), this); up_button = GUIButton::addButton(Environment, up_button_rect, m_tsrc,
this, -1, L"");
up_button->setSubElement(true); up_button->setSubElement(true);
up_button->setTabStop(false); up_button->setTabStop(false);
} }
@ -404,10 +410,12 @@ void GUIScrollBar::refreshControls()
up_button->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, up_button->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT,
EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (!down_button) { if (!down_button) {
down_button = Environment->addButton( core::rect<s32> down_button_rect(
core::rect<s32>(0, RelativeRect.getHeight() - w, 0, RelativeRect.getHeight() - w,
w, RelativeRect.getHeight()), w, RelativeRect.getHeight()
this); );
down_button = GUIButton::addButton(Environment, down_button_rect, m_tsrc,
this, -1, L"");
down_button->setSubElement(true); down_button->setSubElement(true);
down_button->setTabStop(false); down_button->setTabStop(false);
} }

@ -14,6 +14,8 @@ the arrow buttons where there is insufficient space.
#include "irrlichttypes_extrabloated.h" #include "irrlichttypes_extrabloated.h"
class ISimpleTextureSource;
using namespace irr; using namespace irr;
using namespace gui; using namespace gui;
@ -21,7 +23,8 @@ class GUIScrollBar : public IGUIElement
{ {
public: public:
GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id, GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id,
core::rect<s32> rectangle, bool horizontal, bool auto_scale); core::rect<s32> rectangle, bool horizontal, bool auto_scale,
ISimpleTextureSource *tsrc);
enum ArrowVisibility enum ArrowVisibility
{ {
@ -74,4 +77,6 @@ private:
core::rect<s32> slider_rect; core::rect<s32> slider_rect;
video::SColor current_icon_color; video::SColor current_icon_color;
ISimpleTextureSource *m_tsrc;
}; };

@ -66,7 +66,7 @@ GUITable::GUITable(gui::IGUIEnvironment *env,
0, 0,
RelativeRect.getWidth(), RelativeRect.getWidth(),
RelativeRect.getHeight()), RelativeRect.getHeight()),
false, true); false, true, tsrc);
m_scrollbar->setSubElement(true); m_scrollbar->setSubElement(true);
m_scrollbar->setTabStop(false); m_scrollbar->setTabStop(false);
m_scrollbar->setAlignment(gui::EGUIA_LOWERRIGHT, gui::EGUIA_LOWERRIGHT, m_scrollbar->setAlignment(gui::EGUIA_LOWERRIGHT, gui::EGUIA_LOWERRIGHT,

@ -86,7 +86,7 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
core::rect<s32> rect(0, 0, 300 * s, 20 * s); core::rect<s32> rect(0, 0, 300 * s, 20 * s);
rect = rect + v2s32(size.X / 2 - 150 * s, size.Y / 2); rect = rect + v2s32(size.X / 2 - 150 * s, size.Y / 2);
auto e = make_irr<GUIScrollBar>(Environment, this, auto e = make_irr<GUIScrollBar>(Environment, this,
ID_soundSlider, rect, true, false); ID_soundSlider, rect, true, false, m_tsrc);
e->setMax(100); e->setMax(100);
e->setPos(volume); e->setPos(volume);
} }