Skip to content

Commit

Permalink
Use our GUIButton in our GUIScrollBar
Browse files Browse the repository at this point in the history
Note that GUIScrollBar needs an ISimpleTextureSource now due to button styling.
  • Loading branch information
Desour authored and sfan5 committed Aug 14, 2023
1 parent 9d62abb commit 91c0439
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 25 deletions.
7 changes: 4 additions & 3 deletions src/gui/guiEditBoxWithScrollbar.cpp
Expand Up @@ -25,9 +25,10 @@ numerical
//! constructor
GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool border,
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),
m_background(true), m_bg_color_used(false)
m_background(true), m_bg_color_used(false), m_tsrc(tsrc)
{
#ifdef _DEBUG
setDebugName("GUIEditBoxWithScrollBar");
Expand Down Expand Up @@ -635,7 +636,7 @@ void GUIEditBoxWithScrollBar::createVScrollBar()
irr::core::rect<s32> scrollbarrect = m_frame_rect;
scrollbarrect.UpperLeftCorner.X += m_frame_rect.getWidth() - m_scrollbar_width;
m_vscrollbar = new GUIScrollBar(Environment, getParent(), -1,
scrollbarrect, false, true);
scrollbarrect, false, true, m_tsrc);

m_vscrollbar->setVisible(false);
m_vscrollbar->setSmallStep(3 * fontHeight);
Expand Down
6 changes: 5 additions & 1 deletion src/gui/guiEditBoxWithScrollbar.h
Expand Up @@ -7,14 +7,16 @@

#include "guiEditBox.h"

class ISimpleTextureSource;

class GUIEditBoxWithScrollBar : public GUIEditBox
{
public:

//! constructor
GUIEditBoxWithScrollBar(const wchar_t* text, bool border, IGUIEnvironment* environment,
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
virtual ~GUIEditBoxWithScrollBar() {}
Expand Down Expand Up @@ -56,6 +58,8 @@ class GUIEditBoxWithScrollBar : public GUIEditBox

bool m_bg_color_used;
video::SColor m_bg_color;

ISimpleTextureSource *m_tsrc;
};


Expand Down
4 changes: 2 additions & 2 deletions src/gui/guiFormSpecMenu.cpp
Expand Up @@ -666,7 +666,7 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &elemen
spec.ftype = f_ScrollBar;
spec.send = true;
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);
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
Expand Down Expand Up @@ -1493,7 +1493,7 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec,
gui::IGUIEditBox *e = nullptr;
if (is_multiline) {
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) {
e = Environment->addEditBox(spec.fdefault.c_str(), rect, true,
data->current_parent, spec.fid);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/guiHyperText.cpp
Expand Up @@ -1010,7 +1010,7 @@ GUIHyperText::GUIHyperText(const wchar_t *text, IGUIEnvironment *environment,
RelativeRect.getWidth() - m_scrollbar_width, 0,
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);
}

Expand Down
38 changes: 23 additions & 15 deletions src/gui/guiScrollBar.cpp
Expand Up @@ -11,17 +11,19 @@ the arrow buttons where there is insufficient space.
*/

#include "guiScrollBar.h"
#include <IGUIButton.h>
#include "guiButton.h"
#include <IGUISkin.h>

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),
up_button(nullptr), down_button(nullptr), is_dragging(false),
is_horizontal(horizontal), is_auto_scaling(auto_scale),
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),
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();
setNotClipped(false);
Expand Down Expand Up @@ -343,8 +345,9 @@ void GUIScrollBar::refreshControls()
s32 h = RelativeRect.getHeight();
border_size = RelativeRect.getWidth() < h * 4 ? 0 : h;
if (!up_button) {
up_button = Environment->addButton(
core::rect<s32>(0, 0, h, h), this);
core::rect<s32> up_button_rect(0, 0, h, h);
up_button = GUIButton::addButton(Environment, up_button_rect, m_tsrc,
this, -1, L"");
up_button->setSubElement(true);
up_button->setTabStop(false);
}
Expand All @@ -361,10 +364,12 @@ void GUIScrollBar::refreshControls()
up_button->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT,
EGUIA_LOWERRIGHT);
if (!down_button) {
down_button = Environment->addButton(
core::rect<s32>(RelativeRect.getWidth() - h, 0,
RelativeRect.getWidth(), h),
this);
core::rect<s32> down_button_rect(
RelativeRect.getWidth() - h, 0,
RelativeRect.getWidth(), h
);
down_button = GUIButton::addButton(Environment, down_button_rect, m_tsrc,
this, -1, L"");
down_button->setSubElement(true);
down_button->setTabStop(false);
}
Expand All @@ -386,8 +391,9 @@ void GUIScrollBar::refreshControls()
s32 w = RelativeRect.getWidth();
border_size = RelativeRect.getHeight() < w * 4 ? 0 : w;
if (!up_button) {
up_button = Environment->addButton(
core::rect<s32>(0, 0, w, w), this);
core::rect<s32> up_button_rect(0, 0, w, w);
up_button = GUIButton::addButton(Environment, up_button_rect, m_tsrc,
this, -1, L"");
up_button->setSubElement(true);
up_button->setTabStop(false);
}
Expand All @@ -404,10 +410,12 @@ void GUIScrollBar::refreshControls()
up_button->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT,
EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (!down_button) {
down_button = Environment->addButton(
core::rect<s32>(0, RelativeRect.getHeight() - w,
w, RelativeRect.getHeight()),
this);
core::rect<s32> down_button_rect(
0, RelativeRect.getHeight() - w,
w, RelativeRect.getHeight()
);
down_button = GUIButton::addButton(Environment, down_button_rect, m_tsrc,
this, -1, L"");
down_button->setSubElement(true);
down_button->setTabStop(false);
}
Expand Down
7 changes: 6 additions & 1 deletion src/gui/guiScrollBar.h
Expand Up @@ -14,14 +14,17 @@ the arrow buttons where there is insufficient space.

#include "irrlichttypes_extrabloated.h"

class ISimpleTextureSource;

using namespace irr;
using namespace gui;

class GUIScrollBar : public IGUIElement
{
public:
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
{
Expand Down Expand Up @@ -74,4 +77,6 @@ class GUIScrollBar : public IGUIElement

core::rect<s32> slider_rect;
video::SColor current_icon_color;

ISimpleTextureSource *m_tsrc;
};
2 changes: 1 addition & 1 deletion src/gui/guiTable.cpp
Expand Up @@ -66,7 +66,7 @@ GUITable::GUITable(gui::IGUIEnvironment *env,
0,
RelativeRect.getWidth(),
RelativeRect.getHeight()),
false, true);
false, true, tsrc);
m_scrollbar->setSubElement(true);
m_scrollbar->setTabStop(false);
m_scrollbar->setAlignment(gui::EGUIA_LOWERRIGHT, gui::EGUIA_LOWERRIGHT,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/guiVolumeChange.cpp
Expand Up @@ -86,7 +86,7 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
core::rect<s32> rect(0, 0, 300 * s, 20 * s);
rect = rect + v2s32(size.X / 2 - 150 * s, size.Y / 2);
auto e = make_irr<GUIScrollBar>(Environment, this,
ID_soundSlider, rect, true, false);
ID_soundSlider, rect, true, false, m_tsrc);
e->setMax(100);
e->setPos(volume);
}
Expand Down

0 comments on commit 91c0439

Please sign in to comment.