diff options
Diffstat (limited to 'src/gui')
46 files changed, 4476 insertions, 4461 deletions
diff --git a/src/gui/StyleSpec.h b/src/gui/StyleSpec.h index 67caf4f7b..aae2d46f8 100644 --- a/src/gui/StyleSpec.h +++ b/src/gui/StyleSpec.h @@ -138,10 +138,7 @@ public: } //! Gets the state that this style is intended for - State getState() const - { - return state_map; - } + State getState() const { return state_map; } //! Set the given state on this style void addState(State state) @@ -153,7 +150,8 @@ public: //! Using a list of styles mapped to state values, calculate the final // combined style for a state by propagating values in its component states - static StyleSpec getStyleFromStatePropagation(const std::array<StyleSpec, NUM_STATES> &styles, State state) + static StyleSpec getStyleFromStatePropagation( + const std::array<StyleSpec, NUM_STATES> &styles, State state) { StyleSpec temp = styles[StyleSpec::STATE_DEFAULT]; temp.state_map = state; @@ -210,7 +208,8 @@ public: return rect; } - irr::core::vector2d<s32> getVector2i(Property prop, irr::core::vector2d<s32> def) const + irr::core::vector2d<s32> getVector2i( + Property prop, irr::core::vector2d<s32> def) const { const auto &val = properties[prop]; if (val.empty()) @@ -260,10 +259,13 @@ public: int calc_size = 1; if (size[0] == '*') { - std::string new_size = size.substr(1); // Remove '*' (invalid for stof) - calc_size = stof(new_size) * g_fontengine->getFontSize(spec.mode); + std::string new_size = size.substr( + 1); // Remove '*' (invalid for stof) + calc_size = stof(new_size) * + g_fontengine->getFontSize(spec.mode); } else if (size[0] == '+' || size[0] == '-') { - calc_size = stoi(size) + g_fontengine->getFontSize(spec.mode); + calc_size = stoi(size) + + g_fontengine->getFontSize(spec.mode); } else { calc_size = stoi(size); } @@ -345,7 +347,7 @@ private: rect.LowerRightCorner = irr::core::vector2di(-x, -x); } else if (v_rect.size() == 2) { s32 x = stoi(v_rect[0]); - s32 y = stoi(v_rect[1]); + s32 y = stoi(v_rect[1]); rect.UpperLeftCorner = irr::core::vector2di(x, y); rect.LowerRightCorner = irr::core::vector2di(-x, -y); // `-x` is interpreted as `w - x` @@ -356,7 +358,7 @@ private: stoi(v_rect[2]), stoi(v_rect[3])); } else { warningstream << "Invalid rectangle string format: \"" << value - << "\"" << std::endl; + << "\"" << std::endl; return false; } @@ -365,7 +367,8 @@ private: return true; } - bool parseVector2i(const std::string &value, irr::core::vector2d<s32> *parsed_vec) const + bool parseVector2i(const std::string &value, + irr::core::vector2d<s32> *parsed_vec) const { irr::core::vector2d<s32> vec; std::vector<std::string> v_vector = split(value, ','); @@ -376,12 +379,12 @@ private: vec.Y = x; } else if (v_vector.size() == 2) { s32 x = stoi(v_vector[0]); - s32 y = stoi(v_vector[1]); + s32 y = stoi(v_vector[1]); vec.X = x; vec.Y = y; } else { warningstream << "Invalid vector2d string format: \"" << value - << "\"" << std::endl; + << "\"" << std::endl; return false; } diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index e66fbc250..d441e8dfc 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -23,8 +23,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "cheatMenu.h" #include <cstddef> -FontMode CheatMenu::fontStringToEnum(std::string str) { - if (str == "FM_Standard") +FontMode CheatMenu::fontStringToEnum(std::string str) +{ + if (str == "FM_Standard") return FM_Standard; else if (str == "FM_Mono") return FM_Mono; @@ -52,18 +53,21 @@ CheatMenu::CheatMenu(Client *client) : m_client(client) font_color = g_settings->getV3F("cheat_menu_font_color"); selected_font_color = g_settings->getV3F("cheat_menu_selected_font_color"); - m_bg_color = video::SColor(g_settings->getU32("cheat_menu_bg_color_alpha"), - bg_color.X, bg_color.Y, bg_color.Z); - - m_active_bg_color = video::SColor(g_settings->getU32("cheat_menu_active_bg_color_alpha"), - active_bg_color.X, active_bg_color.Y, active_bg_color.Z); + m_bg_color = video::SColor(g_settings->getU32("cheat_menu_bg_color_alpha"), + bg_color.X, bg_color.Y, bg_color.Z); + + m_active_bg_color = video::SColor( + g_settings->getU32("cheat_menu_active_bg_color_alpha"), + active_bg_color.X, active_bg_color.Y, active_bg_color.Z); m_font_color = video::SColor(g_settings->getU32("cheat_menu_font_color_alpha"), - font_color.X, font_color.Y, font_color.Z); + font_color.X, font_color.Y, font_color.Z); + + m_selected_font_color = video::SColor( + g_settings->getU32("cheat_menu_selected_font_color_alpha"), + selected_font_color.X, selected_font_color.Y, + selected_font_color.Z); - m_selected_font_color = video::SColor(g_settings->getU32("cheat_menu_selected_font_color_alpha"), - selected_font_color.X, selected_font_color.Y, selected_font_color.Z); - m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, fontMode); if (!m_font) { @@ -137,64 +141,73 @@ void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) void CheatMenu::drawHUD(video::IVideoDriver *driver, double dtime) { CHEAT_MENU_GET_SCRIPTPTR - + m_rainbow_offset += dtime; m_rainbow_offset = fmod(m_rainbow_offset, 6.0f); - + std::vector<std::string> enabled_cheats; - + int cheat_count = 0; - - for (auto category = script->m_cheat_categories.begin(); category != script->m_cheat_categories.end(); category++) { - for (auto cheat = (*category)->m_cheats.begin(); cheat != (*category)->m_cheats.end(); cheat++) { + + for (auto category = script->m_cheat_categories.begin(); + category != script->m_cheat_categories.end(); category++) { + for (auto cheat = (*category)->m_cheats.begin(); + cheat != (*category)->m_cheats.end(); cheat++) { if ((*cheat)->is_enabled()) { enabled_cheats.push_back((*cheat)->m_name); cheat_count++; } } } - + if (enabled_cheats.empty()) return; - + std::vector<video::SColor> colors; - + for (int i = 0; i < cheat_count; i++) { video::SColor color; f32 h = (f32)i * 2.0f / (f32)cheat_count - m_rainbow_offset; if (h < 0) h = 6.0f + h; f32 x = (1 - fabs(fmod(h, 2.0f) - 1.0f)) * 255.0f; - switch((int)h) { + switch ((int)h) { case 0: - color = video::SColor(255, 255, x, 0); break; + color = video::SColor(255, 255, x, 0); + break; case 1: - color = video::SColor(255, x, 255, 0); break; + color = video::SColor(255, x, 255, 0); + break; case 2: - color = video::SColor(255, 0, 255, x); break; + color = video::SColor(255, 0, 255, x); + break; case 3: - color = video::SColor(255, 0, x, 255); break; + color = video::SColor(255, 0, x, 255); + break; case 4: - color = video::SColor(255, x, 0, 255); break; + color = video::SColor(255, x, 0, 255); + break; case 5: - color = video::SColor(255, 255, 0, x); break; + color = video::SColor(255, 255, 0, x); + break; } colors.push_back(color); } - + core::dimension2d<u32> screensize = driver->getScreenSize(); - + u32 y = 5; - + int i = 0; for (std::string cheat : enabled_cheats) { - core::dimension2d<u32> dim = m_font->getDimension(utf8_to_wide(cheat).c_str()); + core::dimension2d<u32> dim = + m_font->getDimension(utf8_to_wide(cheat).c_str()); u32 x = screensize.Width - 5 - dim.Width; - + core::rect<s32> fontbounds(x, y, x + dim.Width, y + dim.Height); m_font->draw(cheat.c_str(), fontbounds, colors[i], false, false); - + y += dim.Height; i++; } diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h index 8be73c483..b15858a48 100644 --- a/src/gui/cheatMenu.h +++ b/src/gui/cheatMenu.h @@ -42,18 +42,15 @@ class CheatMenu public: CheatMenu(Client *client); - ClientScripting *getScript() - { - return m_client->getScript(); - } + ClientScripting *getScript() { return m_client->getScript(); } void draw(video::IVideoDriver *driver, bool show_debug); - + void drawHUD(video::IVideoDriver *driver, double dtime); void drawEntry(video::IVideoDriver *driver, std::string name, int number, - bool selected, bool active, - CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY); + bool selected, bool active, + CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY); void selectUp(); void selectDown(); @@ -82,6 +79,6 @@ private: gui::IGUIFont *m_font = nullptr; v2u32 m_fontsize; - + float m_rainbow_offset = 0.0; }; diff --git a/src/gui/guiAnimatedImage.cpp b/src/gui/guiAnimatedImage.cpp index b1447c45f..d8648111f 100644 --- a/src/gui/guiAnimatedImage.cpp +++ b/src/gui/guiAnimatedImage.cpp @@ -9,13 +9,14 @@ #include <vector> GUIAnimatedImage::GUIAnimatedImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, - s32 id, const core::rect<s32> &rectangle, const std::string &texture_name, - s32 frame_count, s32 frame_duration, ISimpleTextureSource *tsrc) : - gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), m_tsrc(tsrc) + s32 id, const core::rect<s32> &rectangle, const std::string &texture_name, + s32 frame_count, s32 frame_duration, ISimpleTextureSource *tsrc) : + gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), + m_tsrc(tsrc) { m_texture = m_tsrc->getTexture(texture_name); - m_frame_count = std::max(frame_count, 1); + m_frame_count = std::max(frame_count, 1); m_frame_duration = std::max(frame_duration, 0); if (m_texture != nullptr) { @@ -41,8 +42,10 @@ void GUIAnimatedImage::draw() size.Height /= m_frame_count; draw2DImageFilterScaled(driver, m_texture, AbsoluteRect, - core::rect<s32>(core::position2d<s32>(0, size.Height * m_frame_idx), size), - NoClip ? nullptr : &AbsoluteClippingRect, colors, true); + core::rect<s32>(core::position2d<s32>(0, + size.Height * m_frame_idx), + size), + NoClip ? nullptr : &AbsoluteClippingRect, colors, true); } // Step the animation @@ -64,7 +67,6 @@ void GUIAnimatedImage::draw() } } - void GUIAnimatedImage::setFrameIndex(s32 frame) { s32 idx = std::max(frame, 0); diff --git a/src/gui/guiAnimatedImage.h b/src/gui/guiAnimatedImage.h index f8e6a506e..c814f609c 100644 --- a/src/gui/guiAnimatedImage.h +++ b/src/gui/guiAnimatedImage.h @@ -5,11 +5,12 @@ class ISimpleTextureSource; -class GUIAnimatedImage : public gui::IGUIElement { +class GUIAnimatedImage : public gui::IGUIElement +{ public: - GUIAnimatedImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, - s32 id, const core::rect<s32> &rectangle, const std::string &texture_name, - s32 frame_count, s32 frame_duration, ISimpleTextureSource *tsrc); + GUIAnimatedImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, + const core::rect<s32> &rectangle, const std::string &texture_name, + s32 frame_count, s32 frame_duration, ISimpleTextureSource *tsrc); virtual void draw() override; diff --git a/src/gui/guiBackgroundImage.cpp b/src/gui/guiBackgroundImage.cpp index 21c1e88cf..6b9559087 100644 --- a/src/gui/guiBackgroundImage.cpp +++ b/src/gui/guiBackgroundImage.cpp @@ -20,11 +20,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "log.h" GUIBackgroundImage::GUIBackgroundImage(gui::IGUIEnvironment *env, - gui::IGUIElement *parent, s32 id, const core::rect<s32> &rectangle, - const std::string &name, const core::rect<s32> &middle, - ISimpleTextureSource *tsrc, bool autoclip) : - gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), - m_name(name), m_middle(middle), m_tsrc(tsrc), m_autoclip(autoclip) + gui::IGUIElement *parent, s32 id, const core::rect<s32> &rectangle, + const std::string &name, const core::rect<s32> &middle, + ISimpleTextureSource *tsrc, bool autoclip) : + gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), + m_name(name), m_middle(middle), m_tsrc(tsrc), m_autoclip(autoclip) { } @@ -37,7 +37,7 @@ void GUIBackgroundImage::draw() if (!texture) { errorstream << "GUIBackgroundImage::draw() Unable to load texture:" - << std::endl; + << std::endl; errorstream << "\t" << m_name << std::endl; return; } @@ -53,7 +53,8 @@ void GUIBackgroundImage::draw() const video::SColor colors[] = {color, color, color, color}; draw2DImageFilterScaled(driver, texture, rect, core::rect<s32>(core::position2d<s32>(0, 0), - core::dimension2di(texture->getOriginalSize())), + core::dimension2di( + texture->getOriginalSize())), nullptr, colors, true); } else { core::rect<s32> middle = m_middle; diff --git a/src/gui/guiBackgroundImage.h b/src/gui/guiBackgroundImage.h index 31fbfd09c..5c8ca690d 100644 --- a/src/gui/guiBackgroundImage.h +++ b/src/gui/guiBackgroundImage.h @@ -25,8 +25,9 @@ class GUIBackgroundImage : public gui::IGUIElement { public: GUIBackgroundImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, - const core::rect<s32> &rectangle, const std::string &name, - const core::rect<s32> &middle, ISimpleTextureSource *tsrc, bool autoclip); + const core::rect<s32> &rectangle, const std::string &name, + const core::rect<s32> &middle, ISimpleTextureSource *tsrc, + bool autoclip); virtual void draw() override; diff --git a/src/gui/guiBox.cpp b/src/gui/guiBox.cpp index 7f329cc32..23551a7c7 100644 --- a/src/gui/guiBox.cpp +++ b/src/gui/guiBox.cpp @@ -20,9 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiBox.h" GUIBox::GUIBox(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, - const core::rect<s32> &rectangle, const video::SColor &color) : - gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), - m_color(color) + const core::rect<s32> &rectangle, const video::SColor &color) : + gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), + m_color(color) { } @@ -31,8 +31,8 @@ void GUIBox::draw() if (!IsVisible) return; - Environment->getVideoDriver()->draw2DRectangle(m_color, AbsoluteRect, - &AbsoluteClippingRect); + Environment->getVideoDriver()->draw2DRectangle( + m_color, AbsoluteRect, &AbsoluteClippingRect); IGUIElement::draw(); } diff --git a/src/gui/guiBox.h b/src/gui/guiBox.h index 5306fdf65..2367e43e3 100644 --- a/src/gui/guiBox.h +++ b/src/gui/guiBox.h @@ -25,7 +25,7 @@ class GUIBox : public gui::IGUIElement { public: GUIBox(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, - const core::rect<s32> &rectangle, const video::SColor &color); + const core::rect<s32> &rectangle, const video::SColor &color); virtual void draw() override; diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp index e0d6337cd..2fb7659d7 100644 --- a/src/gui/guiButton.cpp +++ b/src/gui/guiButton.cpp @@ -4,7 +4,6 @@ #include "guiButton.h"
-
#include "client/guiscalingfilter.h"
#include "client/tile.h"
#include "IGUISkin.h"
@@ -26,16 +25,14 @@ using namespace gui; #define COLOR_PRESSED_MOD 0.85f
//! constructor
-GUIButton::GUIButton(IGUIEnvironment* environment, IGUIElement* parent,
- s32 id, core::rect<s32> rectangle, ISimpleTextureSource *tsrc,
- bool noclip)
-: IGUIButton(environment, parent, id, rectangle),
- SpriteBank(0), OverrideFont(0),
- OverrideColorEnabled(false), OverrideColor(video::SColor(101,255,255,255)),
- ClickTime(0), HoverTime(0), FocusTime(0),
- ClickShiftState(false), ClickControlState(false),
- IsPushButton(false), Pressed(false),
- UseAlphaChannel(false), DrawBorder(true), ScaleImage(false), TSrc(tsrc)
+GUIButton::GUIButton(IGUIEnvironment *environment, IGUIElement *parent, s32 id,
+ core::rect<s32> rectangle, ISimpleTextureSource *tsrc, bool noclip) :
+ IGUIButton(environment, parent, id, rectangle),
+ SpriteBank(0), OverrideFont(0), OverrideColorEnabled(false),
+ OverrideColor(video::SColor(101, 255, 255, 255)), ClickTime(0),
+ HoverTime(0), FocusTime(0), ClickShiftState(false),
+ ClickControlState(false), IsPushButton(false), Pressed(false),
+ UseAlphaChannel(false), DrawBorder(true), ScaleImage(false), TSrc(tsrc)
{
setNotClipped(noclip);
@@ -47,7 +44,10 @@ GUIButton::GUIButton(IGUIEnvironment* environment, IGUIElement* parent, for (size_t i = 0; i < 4; i++) {
Colors[i] = Environment->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
}
- StaticText = gui::StaticText::add(Environment, Text.c_str(), core::rect<s32>(0,0,rectangle.getWidth(),rectangle.getHeight()), false, false, this, id);
+ StaticText = gui::StaticText::add(Environment, Text.c_str(),
+ core::rect<s32>(0, 0, rectangle.getWidth(),
+ rectangle.getHeight()),
+ false, false, this, id);
StaticText->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
// END PATCH
}
@@ -62,29 +62,25 @@ GUIButton::~GUIButton() SpriteBank->drop();
}
-
//! Sets if the images should be scaled to fit the button
void GUIButton::setScaleImage(bool scaleImage)
{
ScaleImage = scaleImage;
}
-
//! Returns whether the button scale the used images
bool GUIButton::isScalingImage() const
{
return ScaleImage;
}
-
//! Sets if the button should use the skin to draw its border
void GUIButton::setDrawBorder(bool border)
{
DrawBorder = border;
}
-
-void GUIButton::setSpriteBank(IGUISpriteBank* sprites)
+void GUIButton::setSpriteBank(IGUISpriteBank *sprites)
{
if (sprites)
sprites->grab();
@@ -95,11 +91,12 @@ void GUIButton::setSpriteBank(IGUISpriteBank* sprites) SpriteBank = sprites;
}
-void GUIButton::setSprite(EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop, bool scale)
+void GUIButton::setSprite(EGUI_BUTTON_STATE state, s32 index, video::SColor color,
+ bool loop, bool scale)
{
- ButtonSprites[(u32)state].Index = index;
- ButtonSprites[(u32)state].Color = color;
- ButtonSprites[(u32)state].Loop = loop;
+ ButtonSprites[(u32)state].Index = index;
+ ButtonSprites[(u32)state].Color = color;
+ ButtonSprites[(u32)state].Loop = loop;
ButtonSprites[(u32)state].Scale = scale;
}
@@ -128,17 +125,16 @@ bool GUIButton::getSpriteScale(EGUI_BUTTON_STATE state) const }
//! called if an event happened.
-bool GUIButton::OnEvent(const SEvent& event)
+bool GUIButton::OnEvent(const SEvent &event)
{
if (!isEnabled())
return IGUIElement::OnEvent(event);
- switch(event.EventType)
- {
+ switch (event.EventType) {
case EET_KEY_INPUT_EVENT:
if (event.KeyInput.PressedDown &&
- (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE))
- {
+ (event.KeyInput.Key == KEY_RETURN ||
+ event.KeyInput.Key == KEY_SPACE)) {
if (!IsPushButton)
setPressed(true);
else
@@ -146,21 +142,18 @@ bool GUIButton::OnEvent(const SEvent& event) return true;
}
- if (Pressed && !IsPushButton && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE)
- {
+ if (Pressed && !IsPushButton && event.KeyInput.PressedDown &&
+ event.KeyInput.Key == KEY_ESCAPE) {
setPressed(false);
return true;
- }
- else
- if (!event.KeyInput.PressedDown && Pressed &&
- (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE))
- {
+ } else if (!event.KeyInput.PressedDown && Pressed &&
+ (event.KeyInput.Key == KEY_RETURN ||
+ event.KeyInput.Key == KEY_SPACE)) {
if (!IsPushButton)
setPressed(false);
- if (Parent)
- {
+ if (Parent) {
ClickShiftState = event.KeyInput.Shift;
ClickControlState = event.KeyInput.Control;
@@ -175,43 +168,37 @@ bool GUIButton::OnEvent(const SEvent& event) }
break;
case EET_GUI_EVENT:
- if (event.GUIEvent.Caller == this)
- {
- if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
- {
+ if (event.GUIEvent.Caller == this) {
+ if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) {
if (!IsPushButton)
setPressed(false);
FocusTime = (u32)porting::getTimeMs();
- }
- else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED)
- {
+ } else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED) {
FocusTime = (u32)porting::getTimeMs();
- }
- else if (event.GUIEvent.EventType == EGET_ELEMENT_HOVERED || event.GUIEvent.EventType == EGET_ELEMENT_LEFT)
- {
+ } else if (event.GUIEvent.EventType == EGET_ELEMENT_HOVERED ||
+ event.GUIEvent.EventType == EGET_ELEMENT_LEFT) {
HoverTime = (u32)porting::getTimeMs();
}
}
break;
case EET_MOUSE_INPUT_EVENT:
- if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
- {
+ if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
// Sometimes formspec elements can receive mouse events when the
- // mouse is outside of the formspec. Thus, we test the position here.
- if ( !IsPushButton && AbsoluteClippingRect.isPointInside(
- core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y ))) {
+ // mouse is outside of the formspec. Thus, we test the position
+ // here.
+ if (!IsPushButton &&
+ AbsoluteClippingRect.isPointInside(core::position2d<
+ s32>(event.MouseInput.X,
+ event.MouseInput.Y))) {
setPressed(true);
}
return true;
- }
- else
- if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
- {
+ } else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
bool wasPressed = Pressed;
- if ( !AbsoluteClippingRect.isPointInside( core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y ) ) )
- {
+ if (!AbsoluteClippingRect.isPointInside(core::position2d<s32>(
+ event.MouseInput.X, event.MouseInput.Y))) {
if (!IsPushButton)
setPressed(false);
return true;
@@ -219,14 +206,12 @@ bool GUIButton::OnEvent(const SEvent& event) if (!IsPushButton)
setPressed(false);
- else
- {
+ else {
setPressed(!Pressed);
}
if ((!IsPushButton && wasPressed && Parent) ||
- (IsPushButton && wasPressed != Pressed))
- {
+ (IsPushButton && wasPressed != Pressed)) {
ClickShiftState = event.MouseInput.Shift;
ClickControlState = event.MouseInput.Control;
@@ -248,7 +233,6 @@ bool GUIButton::OnEvent(const SEvent& event) return Parent ? Parent->OnEvent(event) : false;
}
-
//! draws the element and its children
void GUIButton::draw()
{
@@ -263,21 +247,17 @@ void GUIButton::draw() setFromState();
}
- GUISkin* skin = dynamic_cast<GUISkin*>(Environment->getSkin());
- video::IVideoDriver* driver = Environment->getVideoDriver();
+ GUISkin *skin = dynamic_cast<GUISkin *>(Environment->getSkin());
+ video::IVideoDriver *driver = Environment->getVideoDriver();
// END PATCH
- if (DrawBorder)
- {
- if (!Pressed)
- {
+ if (DrawBorder) {
+ if (!Pressed) {
// PATCH
skin->drawColored3DButtonPaneStandard(this, AbsoluteRect,
&AbsoluteClippingRect, Colors);
// END PATCH
- }
- else
- {
+ } else {
// PATCH
skin->drawColored3DButtonPanePressed(this, AbsoluteRect,
&AbsoluteClippingRect, Colors);
@@ -290,94 +270,108 @@ void GUIButton::draw() // The image changes based on the state, so we use the default every time.
EGUI_BUTTON_IMAGE_STATE imageState = EGBIS_IMAGE_UP;
// END PATCH
- if ( ButtonImages[(u32)imageState].Texture )
- {
+ if (ButtonImages[(u32)imageState].Texture) {
core::position2d<s32> pos(buttonCenter);
core::rect<s32> sourceRect(ButtonImages[(u32)imageState].SourceRect);
- if ( sourceRect.getWidth() == 0 && sourceRect.getHeight() == 0 )
- sourceRect = core::rect<s32>(core::position2di(0,0), ButtonImages[(u32)imageState].Texture->getOriginalSize());
+ if (sourceRect.getWidth() == 0 && sourceRect.getHeight() == 0)
+ sourceRect = core::rect<s32>(core::position2di(0, 0),
+ ButtonImages[(u32)imageState]
+ .Texture->getOriginalSize());
pos.X -= sourceRect.getWidth() / 2;
pos.Y -= sourceRect.getHeight() / 2;
- if ( Pressed )
- {
- // Create a pressed-down effect by moving the image when it looks identical to the unpressed state image
+ if (Pressed) {
+ // Create a pressed-down effect by moving the image when it looks
+ // identical to the unpressed state image
EGUI_BUTTON_IMAGE_STATE unpressedState = getImageState(false);
- if ( unpressedState == imageState || ButtonImages[(u32)imageState] == ButtonImages[(u32)unpressedState] )
- {
- pos.X += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X);
- pos.Y += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y);
+ if (unpressedState == imageState ||
+ ButtonImages[(u32)imageState] ==
+ ButtonImages[(u32)unpressedState]) {
+ pos.X += skin->getSize(
+ EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X);
+ pos.Y += skin->getSize(
+ EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y);
}
}
// PATCH
- video::ITexture* texture = ButtonImages[(u32)imageState].Texture;
+ video::ITexture *texture = ButtonImages[(u32)imageState].Texture;
if (BgMiddle.getArea() == 0) {
driver->draw2DImage(texture,
- ScaleImage? AbsoluteRect : core::rect<s32>(pos, sourceRect.getSize()),
- sourceRect, &AbsoluteClippingRect,
- 0, UseAlphaChannel);
+ ScaleImage ? AbsoluteRect
+ : core::rect<s32>(pos,
+ sourceRect.getSize()),
+ sourceRect, &AbsoluteClippingRect, 0,
+ UseAlphaChannel);
} else {
core::rect<s32> middle = BgMiddle;
// `-x` is interpreted as `w - x`
if (middle.LowerRightCorner.X < 0)
- middle.LowerRightCorner.X += texture->getOriginalSize().Width;
+ middle.LowerRightCorner.X +=
+ texture->getOriginalSize().Width;
if (middle.LowerRightCorner.Y < 0)
- middle.LowerRightCorner.Y += texture->getOriginalSize().Height;
+ middle.LowerRightCorner.Y +=
+ texture->getOriginalSize().Height;
draw2DImage9Slice(driver, texture,
- ScaleImage ? AbsoluteRect : core::rect<s32>(pos, sourceRect.getSize()),
+ ScaleImage ? AbsoluteRect
+ : core::rect<s32>(pos,
+ sourceRect.getSize()),
middle, &AbsoluteClippingRect);
}
// END PATCH
}
- if (SpriteBank)
- {
+ if (SpriteBank) {
core::position2di pos(buttonCenter);
- if (isEnabled())
- {
+ if (isEnabled()) {
// pressed / unpressed animation
- EGUI_BUTTON_STATE state = Pressed ? EGBS_BUTTON_DOWN : EGBS_BUTTON_UP;
+ EGUI_BUTTON_STATE state =
+ Pressed ? EGBS_BUTTON_DOWN : EGBS_BUTTON_UP;
drawSprite(state, ClickTime, pos);
// focused / unfocused animation
- state = Environment->hasFocus(this) ? EGBS_BUTTON_FOCUSED : EGBS_BUTTON_NOT_FOCUSED;
+ state = Environment->hasFocus(this) ? EGBS_BUTTON_FOCUSED
+ : EGBS_BUTTON_NOT_FOCUSED;
drawSprite(state, FocusTime, pos);
// mouse over / off animation
- state = isHovered() ? EGBS_BUTTON_MOUSE_OVER : EGBS_BUTTON_MOUSE_OFF;
+ state = isHovered() ? EGBS_BUTTON_MOUSE_OVER
+ : EGBS_BUTTON_MOUSE_OFF;
drawSprite(state, HoverTime, pos);
- }
- else
- {
+ } else {
// draw disabled
-// drawSprite(EGBS_BUTTON_DISABLED, 0, pos);
+ // drawSprite(EGBS_BUTTON_DISABLED, 0, pos);
}
}
IGUIElement::draw();
}
-void GUIButton::drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center)
+void GUIButton::drawSprite(
+ EGUI_BUTTON_STATE state, u32 startTime, const core::position2di ¢er)
{
u32 stateIdx = (u32)state;
- if (ButtonSprites[stateIdx].Index != -1)
- {
- if ( ButtonSprites[stateIdx].Scale )
- {
- const video::SColor colors[] = {ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color,ButtonSprites[stateIdx].Color};
- SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, AbsoluteRect.UpperLeftCorner,
- &AbsoluteClippingRect, colors[0], // FIXME: remove [0]
- porting::getTimeMs()-startTime, ButtonSprites[stateIdx].Loop);
- }
- else
- {
+ if (ButtonSprites[stateIdx].Index != -1) {
+ if (ButtonSprites[stateIdx].Scale) {
+ const video::SColor colors[] = {ButtonSprites[stateIdx].Color,
+ ButtonSprites[stateIdx].Color,
+ ButtonSprites[stateIdx].Color,
+ ButtonSprites[stateIdx].Color};
+ SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index,
+ AbsoluteRect.UpperLeftCorner,
+ &AbsoluteClippingRect,
+ colors[0], // FIXME: remove [0]
+ porting::getTimeMs() - startTime,
+ ButtonSprites[stateIdx].Loop);
+ } else {
SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, center,
- &AbsoluteClippingRect, ButtonSprites[stateIdx].Color, startTime, porting::getTimeMs(),
- ButtonSprites[stateIdx].Loop, true);
+ &AbsoluteClippingRect,
+ ButtonSprites[stateIdx].Color, startTime,
+ porting::getTimeMs(),
+ ButtonSprites[stateIdx].Loop, true);
}
}
}
@@ -389,32 +383,30 @@ EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed) const // END PATCH
}
-EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed, const ButtonImage* images) const
+EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(
+ bool pressed, const ButtonImage *images) const
{
// figure state we should have
EGUI_BUTTON_IMAGE_STATE state = EGBIS_IMAGE_DISABLED;
- bool focused = Environment->hasFocus((IGUIElement*)this);
+ bool focused = Environment->hasFocus((IGUIElement *)this);
bool mouseOver = isHovered();
- if (isEnabled())
- {
- if ( pressed )
- {
- if ( focused && mouseOver )
+ if (isEnabled()) {
+ if (pressed) {
+ if (focused && mouseOver)
state = EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER;
- else if ( focused )
+ else if (focused)
state = EGBIS_IMAGE_DOWN_FOCUSED;
- else if ( mouseOver )
+ else if (mouseOver)
state = EGBIS_IMAGE_DOWN_MOUSEOVER;
else
state = EGBIS_IMAGE_DOWN;
- }
- else // !pressed
+ } else // !pressed
{
- if ( focused && mouseOver )
+ if (focused && mouseOver)
state = EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER;
- else if ( focused )
+ else if (focused)
state = EGBIS_IMAGE_UP_FOCUSED;
- else if ( mouseOver )
+ else if (mouseOver)
state = EGBIS_IMAGE_UP_MOUSEOVER;
else
state = EGBIS_IMAGE_UP;
@@ -422,34 +414,32 @@ EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed, const ButtonImage }
// find a compatible state that has images
- while ( state != EGBIS_IMAGE_UP && !images[(u32)state].Texture )
- {
+ while (state != EGBIS_IMAGE_UP && !images[(u32)state].Texture) {
// PATCH
- switch ( state )
- {
- case EGBIS_IMAGE_UP_FOCUSED:
- state = EGBIS_IMAGE_UP;
- break;
- case EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER:
- state = EGBIS_IMAGE_UP_FOCUSED;
- break;
- case EGBIS_IMAGE_DOWN_MOUSEOVER:
- state = EGBIS_IMAGE_DOWN;
- break;
- case EGBIS_IMAGE_DOWN_FOCUSED:
+ switch (state) {
+ case EGBIS_IMAGE_UP_FOCUSED:
+ state = EGBIS_IMAGE_UP;
+ break;
+ case EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER:
+ state = EGBIS_IMAGE_UP_FOCUSED;
+ break;
+ case EGBIS_IMAGE_DOWN_MOUSEOVER:
+ state = EGBIS_IMAGE_DOWN;
+ break;
+ case EGBIS_IMAGE_DOWN_FOCUSED:
+ state = EGBIS_IMAGE_DOWN;
+ break;
+ case EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER:
+ state = EGBIS_IMAGE_DOWN_FOCUSED;
+ break;
+ case EGBIS_IMAGE_DISABLED:
+ if (pressed)
state = EGBIS_IMAGE_DOWN;
- break;
- case EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER:
- state = EGBIS_IMAGE_DOWN_FOCUSED;
- break;
- case EGBIS_IMAGE_DISABLED:
- if ( pressed )
- state = EGBIS_IMAGE_DOWN;
- else
- state = EGBIS_IMAGE_UP;
- break;
- default:
+ else
state = EGBIS_IMAGE_UP;
+ break;
+ default:
+ state = EGBIS_IMAGE_UP;
}
// END PATCH
}
@@ -457,8 +447,9 @@ EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState(bool pressed, const ButtonImage return state;
}
-//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
-void GUIButton::setOverrideFont(IGUIFont* font)
+//! sets another skin independent font. if this is set to zero, the button uses the font
+//! of the skin.
+void GUIButton::setOverrideFont(IGUIFont *font)
{
if (OverrideFont == font)
return;
@@ -475,17 +466,17 @@ void GUIButton::setOverrideFont(IGUIFont* font) }
//! Gets the override font (if any)
-IGUIFont * GUIButton::getOverrideFont() const
+IGUIFont *GUIButton::getOverrideFont() const
{
return OverrideFont;
}
//! Get the font which is used right now for drawing
-IGUIFont* GUIButton::getActiveFont() const
+IGUIFont *GUIButton::getActiveFont() const
{
- if ( OverrideFont )
+ if (OverrideFont)
return OverrideFont;
- IGUISkin* skin = Environment->getSkin();
+ IGUISkin *skin = Environment->getSkin();
if (skin)
return skin->getFont(EGDF_BUTTON);
return 0;
@@ -515,16 +506,17 @@ bool GUIButton::isOverrideColorEnabled() const return OverrideColorEnabled;
}
-void GUIButton::setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture* image, const core::rect<s32>& sourceRect)
+void GUIButton::setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture *image,
+ const core::rect<s32> &sourceRect)
{
- if ( state >= EGBIS_COUNT )
+ if (state >= EGBIS_COUNT)
return;
- if ( image )
+ if (image)
image->grab();
u32 stateIdx = (u32)state;
- if ( ButtonImages[stateIdx].Texture )
+ if (ButtonImages[stateIdx].Texture)
ButtonImages[stateIdx].Texture->drop();
ButtonImages[stateIdx].Texture = image;
@@ -532,28 +524,28 @@ void GUIButton::setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture* image, }
// PATCH
-void GUIButton::setImage(video::ITexture* image)
+void GUIButton::setImage(video::ITexture *image)
{
setImage(gui::EGBIS_IMAGE_UP, image);
}
-void GUIButton::setImage(video::ITexture* image, const core::rect<s32>& pos)
+void GUIButton::setImage(video::ITexture *image, const core::rect<s32> &pos)
{
setImage(gui::EGBIS_IMAGE_UP, image, pos);
}
-void GUIButton::setPressedImage(video::ITexture* image)
+void GUIButton::setPressedImage(video::ITexture *image)
{
setImage(gui::EGBIS_IMAGE_DOWN, image);
}
-void GUIButton::setPressedImage(video::ITexture* image, const core::rect<s32>& pos)
+void GUIButton::setPressedImage(video::ITexture *image, const core::rect<s32> &pos)
{
setImage(gui::EGBIS_IMAGE_DOWN, image, pos);
}
//! Sets the text displayed by the button
-void GUIButton::setText(const wchar_t* text)
+void GUIButton::setText(const wchar_t *text)
{
StaticText->setText(text);
@@ -569,7 +561,6 @@ void GUIButton::setIsPushButton(bool isPushButton) IsPushButton = isPushButton;
}
-
//! Returns if the button is currently pressed
bool GUIButton::isPressed() const
{
@@ -581,118 +572,110 @@ bool GUIButton::isPressed() const bool GUIButton::isHovered() const
{
IGUIElement *hovered = Environment->getHovered();
- return hovered == this || (hovered != nullptr && hovered->getParent() == this);
+ return hovered == this || (hovered != nullptr && hovered->getParent() == this);
}
// END PATCH
//! Sets the pressed state of the button if this is a pushbutton
void GUIButton::setPressed(bool pressed)
{
- if (Pressed != pressed)
- {
+ if (Pressed != pressed) {
ClickTime = porting::getTimeMs();
Pressed = pressed;
setFromState();
}
}
-
//! Returns whether the button is a push button
bool GUIButton::isPushButton() const
{
return IsPushButton;
}
-
-//! Sets if the alpha channel should be used for drawing images on the button (default is false)
+//! Sets if the alpha channel should be used for drawing images on the button (default is
+//! false)
void GUIButton::setUseAlphaChannel(bool useAlphaChannel)
{
UseAlphaChannel = useAlphaChannel;
}
-
//! Returns if the alpha channel should be used for drawing images on the button
bool GUIButton::isAlphaChannelUsed() const
{
return UseAlphaChannel;
}
-
bool GUIButton::isDrawingBorder() const
{
return DrawBorder;
}
-
//! Writes attributes of the element.
-void GUIButton::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
+void GUIButton::serializeAttributes(
+ io::IAttributes *out, io::SAttributeReadWriteOptions *options = 0) const
{
- IGUIButton::serializeAttributes(out,options);
+ IGUIButton::serializeAttributes(out, options);
- out->addBool ("PushButton", IsPushButton );
+ out->addBool("PushButton", IsPushButton);
if (IsPushButton)
- out->addBool("Pressed", Pressed);
+ out->addBool("Pressed", Pressed);
- for ( u32 i=0; i<(u32)EGBIS_COUNT; ++i )
- {
- if ( ButtonImages[i].Texture )
- {
- core::stringc name( GUIButtonImageStateNames[i] );
+ for (u32 i = 0; i < (u32)EGBIS_COUNT; ++i) {
+ if (ButtonImages[i].Texture) {
+ core::stringc name(GUIButtonImageStateNames[i]);
out->addTexture(name.c_str(), ButtonImages[i].Texture);
name += "Rect";
out->addRect(name.c_str(), ButtonImages[i].SourceRect);
}
}
- out->addBool ("UseAlphaChannel", UseAlphaChannel);
- out->addBool ("Border", DrawBorder);
- out->addBool ("ScaleImage", ScaleImage);
+ out->addBool("UseAlphaChannel", UseAlphaChannel);
+ out->addBool("Border", DrawBorder);
+ out->addBool("ScaleImage", ScaleImage);
- for ( u32 i=0; i<(u32)EGBS_COUNT; ++i )
- {
- if ( ButtonSprites[i].Index >= 0 )
- {
- core::stringc nameIndex( GUIButtonStateNames[i] );
+ for (u32 i = 0; i < (u32)EGBS_COUNT; ++i) {
+ if (ButtonSprites[i].Index >= 0) {
+ core::stringc nameIndex(GUIButtonStateNames[i]);
nameIndex += "Index";
- out->addInt(nameIndex.c_str(), ButtonSprites[i].Index );
+ out->addInt(nameIndex.c_str(), ButtonSprites[i].Index);
- core::stringc nameColor( GUIButtonStateNames[i] );
+ core::stringc nameColor(GUIButtonStateNames[i]);
nameColor += "Color";
- out->addColor(nameColor.c_str(), ButtonSprites[i].Color );
+ out->addColor(nameColor.c_str(), ButtonSprites[i].Color);
- core::stringc nameLoop( GUIButtonStateNames[i] );
+ core::stringc nameLoop(GUIButtonStateNames[i]);
nameLoop += "Loop";
- out->addBool(nameLoop.c_str(), ButtonSprites[i].Loop );
+ out->addBool(nameLoop.c_str(), ButtonSprites[i].Loop);
- core::stringc nameScale( GUIButtonStateNames[i] );
+ core::stringc nameScale(GUIButtonStateNames[i]);
nameScale += "Scale";
- out->addBool(nameScale.c_str(), ButtonSprites[i].Scale );
+ out->addBool(nameScale.c_str(), ButtonSprites[i].Scale);
}
}
// out->addString ("OverrideFont", OverrideFont);
}
-
//! Reads attributes of the element
-void GUIButton::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
+void GUIButton::deserializeAttributes(
+ io::IAttributes *in, io::SAttributeReadWriteOptions *options = 0)
{
- IGUIButton::deserializeAttributes(in,options);
+ IGUIButton::deserializeAttributes(in, options);
- IsPushButton = in->getAttributeAsBool("PushButton");
- Pressed = IsPushButton ? in->getAttributeAsBool("Pressed") : false;
+ IsPushButton = in->getAttributeAsBool("PushButton");
+ Pressed = IsPushButton ? in->getAttributeAsBool("Pressed") : false;
core::rect<s32> rec = in->getAttributeAsRect("ImageRect");
if (rec.isValid())
- setImage( in->getAttributeAsTexture("Image"), rec);
+ setImage(in->getAttributeAsTexture("Image"), rec);
else
- setImage( in->getAttributeAsTexture("Image") );
+ setImage(in->getAttributeAsTexture("Image"));
rec = in->getAttributeAsRect("PressedImageRect");
if (rec.isValid())
- setPressedImage( in->getAttributeAsTexture("PressedImage"), rec);
+ setPressedImage(in->getAttributeAsTexture("PressedImage"), rec);
else
- setPressedImage( in->getAttributeAsTexture("PressedImage") );
+ setPressedImage(in->getAttributeAsTexture("PressedImage"));
setDrawBorder(in->getAttributeAsBool("Border"));
setUseAlphaChannel(in->getAttributeAsBool("UseAlphaChannel"));
@@ -704,17 +687,19 @@ void GUIButton::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWri }
// PATCH
-GUIButton* GUIButton::addButton(IGUIEnvironment *environment,
- const core::rect<s32>& rectangle, ISimpleTextureSource *tsrc,
- IGUIElement* parent, s32 id, const wchar_t* text,
+GUIButton *GUIButton::addButton(IGUIEnvironment *environment,
+ const core::rect<s32> &rectangle, ISimpleTextureSource *tsrc,
+ IGUIElement *parent, s32 id, const wchar_t *text,
const wchar_t *tooltiptext)
{
- GUIButton* button = new GUIButton(environment, parent ? parent : environment->getRootGUIElement(), id, rectangle, tsrc);
+ GUIButton *button = new GUIButton(environment,
+ parent ? parent : environment->getRootGUIElement(), id, rectangle,
+ tsrc);
if (text)
button->setText(text);
- if ( tooltiptext )
- button->setToolTipText ( tooltiptext );
+ if (tooltiptext)
+ button->setToolTipText(tooltiptext);
button->drop();
return button;
@@ -724,7 +709,8 @@ void GUIButton::setColor(video::SColor color) {
float d = 0.65f;
for (size_t i = 0; i < 4; i++) {
- video::SColor base = Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i);
+ video::SColor base = Environment->getSkin()->getColor(
+ (gui::EGUI_DEFAULT_COLOR)i);
Colors[i] = base.getInterpolated(color, d);
}
}
@@ -744,7 +730,7 @@ void GUIButton::setFromState() }
//! Set element properties from a StyleSpec
-void GUIButton::setFromStyle(const StyleSpec& style)
+void GUIButton::setFromStyle(const StyleSpec &style)
{
bool hovered = (style.getState() & StyleSpec::STATE_HOVERED) != 0;
bool pressed = (style.getState() & StyleSpec::STATE_PRESSED) != 0;
@@ -758,17 +744,19 @@ void GUIButton::setFromStyle(const StyleSpec& style) if (!Styles[style.getState()].isNotDefault(StyleSpec::BGCOLOR)) {
for (size_t i = 0; i < 4; i++) {
if (pressed) {
- Colors[i] = multiplyColorValue(Colors[i], COLOR_PRESSED_MOD);
+ Colors[i] = multiplyColorValue(
+ Colors[i], COLOR_PRESSED_MOD);
} else if (hovered) {
- Colors[i] = multiplyColorValue(Colors[i], COLOR_HOVERED_MOD);
+ Colors[i] = multiplyColorValue(
+ Colors[i], COLOR_HOVERED_MOD);
}
}
}
} else {
for (size_t i = 0; i < 4; i++) {
- video::SColor base =
- Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i);
+ video::SColor base = Environment->getSkin()->getColor(
+ (gui::EGUI_DEFAULT_COLOR)i);
if (pressed) {
Colors[i] = multiplyColorValue(base, COLOR_PRESSED_MOD);
} else if (hovered) {
@@ -782,7 +770,7 @@ void GUIButton::setFromStyle(const StyleSpec& style) if (style.isNotDefault(StyleSpec::TEXTCOLOR)) {
setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR));
} else {
- setOverrideColor(video::SColor(255,255,255,255));
+ setOverrideColor(video::SColor(255, 255, 255, 255));
OverrideColorEnabled = false;
}
setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
@@ -791,11 +779,10 @@ void GUIButton::setFromStyle(const StyleSpec& style) setOverrideFont(style.getFont());
if (style.isNotDefault(StyleSpec::BGIMG)) {
- video::ITexture *texture = style.getTexture(StyleSpec::BGIMG,
- getTextureSource());
- setImage(guiScalingImageButton(
- Environment->getVideoDriver(), texture,
- AbsoluteRect.getWidth(), AbsoluteRect.getHeight()));
+ video::ITexture *texture =
+ style.getTexture(StyleSpec::BGIMG, getTextureSource());
+ setImage(guiScalingImageButton(Environment->getVideoDriver(), texture,
+ AbsoluteRect.getWidth(), AbsoluteRect.getHeight()));
setScaleImage(true);
} else {
setImage(nullptr);
@@ -805,23 +792,22 @@ void GUIButton::setFromStyle(const StyleSpec& style) // Child padding and offset
Padding = style.getRect(StyleSpec::PADDING, core::rect<s32>());
- Padding = core::rect<s32>(
- Padding.UpperLeftCorner + BgMiddle.UpperLeftCorner,
+ Padding = core::rect<s32>(Padding.UpperLeftCorner + BgMiddle.UpperLeftCorner,
Padding.LowerRightCorner + BgMiddle.LowerRightCorner);
- GUISkin* skin = dynamic_cast<GUISkin*>(Environment->getSkin());
+ GUISkin *skin = dynamic_cast<GUISkin *>(Environment->getSkin());
core::vector2d<s32> defaultPressOffset(
skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y));
- ContentOffset = style.getVector2i(StyleSpec::CONTENT_OFFSET, isPressed()
- ? defaultPressOffset
- : core::vector2d<s32>(0));
+ ContentOffset = style.getVector2i(StyleSpec::CONTENT_OFFSET,
+ isPressed() ? defaultPressOffset : core::vector2d<s32>(0));
- core::rect<s32> childBounds(
- Padding.UpperLeftCorner.X + ContentOffset.X,
- Padding.UpperLeftCorner.Y + ContentOffset.Y,
- AbsoluteRect.getWidth() + Padding.LowerRightCorner.X + ContentOffset.X,
- AbsoluteRect.getHeight() + Padding.LowerRightCorner.Y + ContentOffset.Y);
+ core::rect<s32> childBounds(Padding.UpperLeftCorner.X + ContentOffset.X,
+ Padding.UpperLeftCorner.Y + ContentOffset.Y,
+ AbsoluteRect.getWidth() + Padding.LowerRightCorner.X +
+ ContentOffset.X,
+ AbsoluteRect.getHeight() + Padding.LowerRightCorner.Y +
+ ContentOffset.Y);
for (IGUIElement *child : getChildren()) {
child->setRelativePosition(childBounds);
@@ -829,7 +815,7 @@ void GUIButton::setFromStyle(const StyleSpec& style) }
//! Set the styles used for each state
-void GUIButton::setStyles(const std::array<StyleSpec, StyleSpec::NUM_STATES>& styles)
+void GUIButton::setStyles(const std::array<StyleSpec, StyleSpec::NUM_STATES> &styles)
{
Styles = styles;
setFromState();
diff --git a/src/gui/guiButton.h b/src/gui/guiButton.h index 95fa1a2a1..cd0b4ec5f 100644 --- a/src/gui/guiButton.h +++ b/src/gui/guiButton.h @@ -18,52 +18,55 @@ using namespace irr;
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 8)
- namespace irr { namespace gui {
-
- //! State of buttons used for drawing texture images.
- //! Note that only a single state is active at a time
- //! Also when no image is defined for a state it will use images from another state
- //! and if that state is not set from the replacement for that,etc.
- //! So in many cases setting EGBIS_IMAGE_UP and EGBIS_IMAGE_DOWN is sufficient.
- enum EGUI_BUTTON_IMAGE_STATE {
- //! When no other states have images they will all use this one.
- EGBIS_IMAGE_UP,
- //! When not set EGBIS_IMAGE_UP is used.
- EGBIS_IMAGE_UP_MOUSEOVER,
- //! When not set EGBIS_IMAGE_UP_MOUSEOVER is used.
- EGBIS_IMAGE_UP_FOCUSED,
- //! When not set EGBIS_IMAGE_UP_FOCUSED is used.
- EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER,
- //! When not set EGBIS_IMAGE_UP is used.
- EGBIS_IMAGE_DOWN,
- //! When not set EGBIS_IMAGE_DOWN is used.
- EGBIS_IMAGE_DOWN_MOUSEOVER,
- //! When not set EGBIS_IMAGE_DOWN_MOUSEOVER is used.
- EGBIS_IMAGE_DOWN_FOCUSED,
- //! When not set EGBIS_IMAGE_DOWN_FOCUSED is used.
- EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER,
- //! When not set EGBIS_IMAGE_UP or EGBIS_IMAGE_DOWN are used (depending on button state).
- EGBIS_IMAGE_DISABLED,
- //! not used, counts the number of enumerated items
- EGBIS_COUNT
- };
-
- //! Names for gui button image states
- const c8 *const GUIButtonImageStateNames[EGBIS_COUNT + 1] =
- {
- "Image", // not "ImageUp" as it otherwise breaks serialization of old files
- "ImageUpOver",
- "ImageUpFocused",
- "ImageUpFocusedOver",
- "PressedImage", // not "ImageDown" as it otherwise breaks serialization of old files
- "ImageDownOver",
- "ImageDownFocused",
- "ImageDownFocusedOver",
- "ImageDisabled",
- 0 // count
- };
-
- }}
+namespace irr
+{
+namespace gui
+{
+
+//! State of buttons used for drawing texture images.
+//! Note that only a single state is active at a time
+//! Also when no image is defined for a state it will use images from another state
+//! and if that state is not set from the replacement for that,etc.
+//! So in many cases setting EGBIS_IMAGE_UP and EGBIS_IMAGE_DOWN is sufficient.
+enum EGUI_BUTTON_IMAGE_STATE
+{
+ //! When no other states have images they will all use this one.
+ EGBIS_IMAGE_UP,
+ //! When not set EGBIS_IMAGE_UP is used.
+ EGBIS_IMAGE_UP_MOUSEOVER,
+ //! When not set EGBIS_IMAGE_UP_MOUSEOVER is used.
+ EGBIS_IMAGE_UP_FOCUSED,
+ //! When not set EGBIS_IMAGE_UP_FOCUSED is used.
+ EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER,
+ //! When not set EGBIS_IMAGE_UP is used.
+ EGBIS_IMAGE_DOWN,
+ //! When not set EGBIS_IMAGE_DOWN is used.
+ EGBIS_IMAGE_DOWN_MOUSEOVER,
+ //! When not set EGBIS_IMAGE_DOWN_MOUSEOVER is used.
+ EGBIS_IMAGE_DOWN_FOCUSED,
+ //! When not set EGBIS_IMAGE_DOWN_FOCUSED is used.
+ EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER,
+ //! When not set EGBIS_IMAGE_UP or EGBIS_IMAGE_DOWN are used (depending on button
+ //! state).
+ EGBIS_IMAGE_DISABLED,
+ //! not used, counts the number of enumerated items
+ EGBIS_COUNT
+};
+
+//! Names for gui button image states
+const c8 *const GUIButtonImageStateNames[EGBIS_COUNT + 1] = {
+ "Image", // not "ImageUp" as it otherwise breaks serialization of old
+ // files
+ "ImageUpOver", "ImageUpFocused", "ImageUpFocusedOver",
+ "PressedImage", // not "ImageDown" as it otherwise breaks serialization of
+ // old files
+ "ImageDownOver", "ImageDownFocused", "ImageDownFocusedOver",
+ "ImageDisabled",
+ 0 // count
+};
+
+}
+}
#endif
@@ -72,29 +75,29 @@ class ISimpleTextureSource; class GUIButton : public gui::IGUIButton
{
public:
-
//! constructor
- GUIButton(gui::IGUIEnvironment* environment, gui::IGUIElement* parent,
- s32 id, core::rect<s32> rectangle, ISimpleTextureSource *tsrc,
- bool noclip=false);
+ GUIButton(gui::IGUIEnvironment *environment, gui::IGUIElement *parent, s32 id,
+ core::rect<s32> rectangle, ISimpleTextureSource *tsrc,
+ bool noclip = false);
//! destructor
virtual ~GUIButton();
//! called if an event happened.
- virtual bool OnEvent(const SEvent& event) override;
+ virtual bool OnEvent(const SEvent &event) override;
//! draws the element and its children
virtual void draw() override;
- //! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
- virtual void setOverrideFont(gui::IGUIFont* font=0) override;
+ //! sets another skin independent font. if this is set to zero, the button uses
+ //! the font of the skin.
+ virtual void setOverrideFont(gui::IGUIFont *font = 0) override;
//! Gets the override font (if any)
- virtual gui::IGUIFont* getOverrideFont() const override;
+ virtual gui::IGUIFont *getOverrideFont() const override;
//! Get the font which is used right now for drawing
- virtual gui::IGUIFont* getActiveFont() const override;
+ virtual gui::IGUIFont *getActiveFont() const override;
//! Sets another color for the button text.
virtual void setOverrideColor(video::SColor color);
@@ -102,49 +105,58 @@ public: //! Gets the override color
virtual video::SColor getOverrideColor(void) const;
- //! Sets if the button text should use the override color or the color in the gui skin.
+ //! Sets if the button text should use the override color or the color in the gui
+ //! skin.
virtual void enableOverrideColor(bool enable);
//! Checks if an override color is enabled
virtual bool isOverrideColorEnabled(void) const;
// PATCH
- //! Sets an image which should be displayed on the button when it is in the given state.
+ //! Sets an image which should be displayed on the button when it is in the given
+ //! state.
virtual void setImage(gui::EGUI_BUTTON_IMAGE_STATE state,
- video::ITexture* image=nullptr,
- const core::rect<s32>& sourceRect=core::rect<s32>(0,0,0,0));
+ video::ITexture *image = nullptr,
+ const core::rect<s32> &sourceRect = core::rect<s32>(0, 0, 0, 0));
- //! Sets an image which should be displayed on the button when it is in normal state.
- virtual void setImage(video::ITexture* image=nullptr) override;
+ //! Sets an image which should be displayed on the button when it is in normal
+ //! state.
+ virtual void setImage(video::ITexture *image = nullptr) override;
- //! Sets an image which should be displayed on the button when it is in normal state.
- virtual void setImage(video::ITexture* image, const core::rect<s32>& pos) override;
+ //! Sets an image which should be displayed on the button when it is in normal
+ //! state.
+ virtual void setImage(
+ video::ITexture *image, const core::rect<s32> &pos) override;
- //! Sets an image which should be displayed on the button when it is in pressed state.
- virtual void setPressedImage(video::ITexture* image=nullptr) override;
+ //! Sets an image which should be displayed on the button when it is in pressed
+ //! state.
+ virtual void setPressedImage(video::ITexture *image = nullptr) override;
- //! Sets an image which should be displayed on the button when it is in pressed state.
- virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos) override;
+ //! Sets an image which should be displayed on the button when it is in pressed
+ //! state.
+ virtual void setPressedImage(
+ video::ITexture *image, const core::rect<s32> &pos) override;
//! Sets the text displayed by the button
- virtual void setText(const wchar_t* text) override;
+ virtual void setText(const wchar_t *text) override;
// END PATCH
//! Sets the sprite bank used by the button
- virtual void setSpriteBank(gui::IGUISpriteBank* bank=0) override;
+ virtual void setSpriteBank(gui::IGUISpriteBank *bank = 0) override;
//! Sets the animated sprite for a specific button state
- /** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
- \param state: State of the button to set the sprite for
- \param index: The sprite number from the current sprite bank
- \param color: The color of the sprite
+ /** \param index: Number of the sprite within the sprite bank, use -1 for no
+ sprite \param state: State of the button to set the sprite for \param index: The
+ sprite number from the current sprite bank \param color: The color of the sprite
*/
virtual void setSprite(gui::EGUI_BUTTON_STATE state, s32 index,
- video::SColor color=video::SColor(255,255,255,255),
- bool loop=false, bool scale=false);
+ video::SColor color = video::SColor(255, 255, 255, 255),
+ bool loop = false, bool scale = false);
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 8)
- void setSprite(gui::EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop) override {
+ void setSprite(gui::EGUI_BUTTON_STATE state, s32 index, video::SColor color,
+ bool loop) override
+ {
setSprite(state, index, color, loop, false);
}
#endif
@@ -152,7 +164,8 @@ public: //! Get the sprite-index for the given state or -1 when no sprite is set
virtual s32 getSpriteIndex(gui::EGUI_BUTTON_STATE state) const;
- //! Get the sprite color for the given state. Color is only used when a sprite is set.
+ //! Get the sprite color for the given state. Color is only used when a sprite is
+ //! set.
virtual video::SColor getSpriteColor(gui::EGUI_BUTTON_STATE state) const;
//! Returns if the sprite in the given state does loop
@@ -164,13 +177,13 @@ public: //! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
- virtual void setIsPushButton(bool isPushButton=true) override;
+ virtual void setIsPushButton(bool isPushButton = true) override;
//! Checks whether the button is a push button
virtual bool isPushButton() const override;
//! Sets the pressed state of the button if this is a pushbutton
- virtual void setPressed(bool pressed=true) override;
+ virtual void setPressed(bool pressed = true) override;
//! Returns if the button is currently pressed
virtual bool isPressed() const override;
@@ -181,42 +194,37 @@ public: // END PATCH
//! Sets if the button should use the skin to draw its border
- virtual void setDrawBorder(bool border=true) override;
+ virtual void setDrawBorder(bool border = true) override;
//! Checks if the button face and border are being drawn
virtual bool isDrawingBorder() const override;
- //! Sets if the alpha channel should be used for drawing images on the button (default is false)
- virtual void setUseAlphaChannel(bool useAlphaChannel=true) override;
+ //! Sets if the alpha channel should be used for drawing images on the button
+ //! (default is false)
+ virtual void setUseAlphaChannel(bool useAlphaChannel = true) override;
//! Checks if the alpha channel should be used for drawing images on the button
virtual bool isAlphaChannelUsed() const override;
//! Sets if the button should scale the button images to fit
- virtual void setScaleImage(bool scaleImage=true) override;
+ virtual void setScaleImage(bool scaleImage = true) override;
//! Checks whether the button scales the used images
virtual bool isScalingImage() const override;
//! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event
- virtual bool getClickShiftState() const
- {
- return ClickShiftState;
- }
+ virtual bool getClickShiftState() const { return ClickShiftState; }
//! Get if the control key was pressed in last EGET_BUTTON_CLICKED event
- virtual bool getClickControlState() const
- {
- return ClickControlState;
- }
+ virtual bool getClickControlState() const { return ClickControlState; }
//! Writes attributes of the element.
- virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const override;
+ virtual void serializeAttributes(io::IAttributes *out,
+ io::SAttributeReadWriteOptions *options) const override;
//! Reads attributes of the element
- virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) override;
-
-
+ virtual void deserializeAttributes(io::IAttributes *in,
+ io::SAttributeReadWriteOptions *options) override;
void setColor(video::SColor color);
// PATCH
@@ -224,79 +232,76 @@ public: void setFromState();
//! Set element properties from a StyleSpec
- virtual void setFromStyle(const StyleSpec& style);
+ virtual void setFromStyle(const StyleSpec &style);
//! Set the styles used for each state
- void setStyles(const std::array<StyleSpec, StyleSpec::NUM_STATES>& styles);
+ void setStyles(const std::array<StyleSpec, StyleSpec::NUM_STATES> &styles);
// END PATCH
-
//! Do not drop returned handle
- static GUIButton* addButton(gui::IGUIEnvironment *environment,
- const core::rect<s32>& rectangle, ISimpleTextureSource *tsrc,
- IGUIElement* parent, s32 id, const wchar_t* text,
- const wchar_t *tooltiptext=L"");
+ static GUIButton *addButton(gui::IGUIEnvironment *environment,
+ const core::rect<s32> &rectangle, ISimpleTextureSource *tsrc,
+ IGUIElement *parent, s32 id, const wchar_t *text,
+ const wchar_t *tooltiptext = L"");
protected:
- void drawSprite(gui::EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center);
+ void drawSprite(gui::EGUI_BUTTON_STATE state, u32 startTime,
+ const core::position2di ¢er);
gui::EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed) const;
ISimpleTextureSource *getTextureSource() { return TSrc; }
struct ButtonImage
{
- ButtonImage() : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
- {
- }
+ ButtonImage() : Texture(0), SourceRect(core::rect<s32>(0, 0, 0, 0)) {}
- ButtonImage(const ButtonImage& other) : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
+ ButtonImage(const ButtonImage &other) :
+ Texture(0), SourceRect(core::rect<s32>(0, 0, 0, 0))
{
*this = other;
}
~ButtonImage()
{
- if ( Texture )
+ if (Texture)
Texture->drop();
}
- ButtonImage& operator=(const ButtonImage& other)
+ ButtonImage &operator=(const ButtonImage &other)
{
- if ( this == &other )
+ if (this == &other)
return *this;
if (other.Texture)
other.Texture->grab();
- if ( Texture )
+ if (Texture)
Texture->drop();
Texture = other.Texture;
SourceRect = other.SourceRect;
return *this;
}
- bool operator==(const ButtonImage& other) const
+ bool operator==(const ButtonImage &other) const
{
return Texture == other.Texture && SourceRect == other.SourceRect;
}
-
- video::ITexture* Texture;
+ video::ITexture *Texture;
core::rect<s32> SourceRect;
};
- gui::EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed, const ButtonImage* images) const;
+ gui::EGUI_BUTTON_IMAGE_STATE getImageState(
+ bool pressed, const ButtonImage *images) const;
private:
-
struct ButtonSprite
{
- ButtonSprite() : Index(-1), Loop(false), Scale(false)
- {
- }
+ ButtonSprite() : Index(-1), Loop(false), Scale(false) {}
- bool operator==(const ButtonSprite& other) const
+ bool operator==(const ButtonSprite &other) const
{
- return Index == other.Index && Color == other.Color && Loop == other.Loop && Scale == other.Scale;
+ return Index == other.Index && Color == other.Color &&
+ Loop == other.Loop && Scale == other.Scale;
}
s32 Index;
@@ -306,13 +311,13 @@ private: };
ButtonSprite ButtonSprites[gui::EGBS_COUNT];
- gui::IGUISpriteBank* SpriteBank;
+ gui::IGUISpriteBank *SpriteBank;
ButtonImage ButtonImages[gui::EGBIS_COUNT];
std::array<StyleSpec, StyleSpec::NUM_STATES> Styles;
- gui::IGUIFont* OverrideFont;
+ gui::IGUIFont *OverrideFont;
bool OverrideColorEnabled;
video::SColor OverrideColor;
diff --git a/src/gui/guiButtonImage.cpp b/src/gui/guiButtonImage.cpp index b507ffece..2f574c1a8 100644 --- a/src/gui/guiButtonImage.cpp +++ b/src/gui/guiButtonImage.cpp @@ -31,11 +31,12 @@ using namespace gui; GUIButtonImage::GUIButtonImage(gui::IGUIEnvironment *environment, gui::IGUIElement *parent, s32 id, core::rect<s32> rectangle, - ISimpleTextureSource *tsrc, bool noclip) - : GUIButton (environment, parent, id, rectangle, tsrc, noclip) + ISimpleTextureSource *tsrc, bool noclip) : + GUIButton(environment, parent, id, rectangle, tsrc, noclip) { - m_image = Environment->addImage( - core::rect<s32>(0,0,rectangle.getWidth(),rectangle.getHeight()), this); + m_image = Environment->addImage(core::rect<s32>(0, 0, rectangle.getWidth(), + rectangle.getHeight()), + this); m_image->setScaleImage(isScalingImage()); sendToBack(m_image); } @@ -56,18 +57,18 @@ void GUIButtonImage::setForegroundImage(video::ITexture *image) } //! Set element properties from a StyleSpec -void GUIButtonImage::setFromStyle(const StyleSpec& style) +void GUIButtonImage::setFromStyle(const StyleSpec &style) { GUIButton::setFromStyle(style); video::IVideoDriver *driver = Environment->getVideoDriver(); if (style.isNotDefault(StyleSpec::FGIMG)) { - video::ITexture *texture = style.getTexture(StyleSpec::FGIMG, - getTextureSource()); + video::ITexture *texture = + style.getTexture(StyleSpec::FGIMG, getTextureSource()); setForegroundImage(guiScalingImageButton(driver, texture, - AbsoluteRect.getWidth(), AbsoluteRect.getHeight())); + AbsoluteRect.getWidth(), AbsoluteRect.getHeight())); setScaleImage(true); } else { setForegroundImage(nullptr); @@ -86,7 +87,8 @@ GUIButtonImage *GUIButtonImage::addButton(IGUIEnvironment *environment, const wchar_t *tooltiptext) { GUIButtonImage *button = new GUIButtonImage(environment, - parent ? parent : environment->getRootGUIElement(), id, rectangle, tsrc); + parent ? parent : environment->getRootGUIElement(), id, rectangle, + tsrc); if (text) button->setText(text); diff --git a/src/gui/guiButtonImage.h b/src/gui/guiButtonImage.h index 59a25b4f0..c46ef36f0 100644 --- a/src/gui/guiButtonImage.h +++ b/src/gui/guiButtonImage.h @@ -35,9 +35,9 @@ public: void setForegroundImage(video::ITexture *image = nullptr); //! Set element properties from a StyleSpec - virtual void setFromStyle(const StyleSpec& style) override; + virtual void setFromStyle(const StyleSpec &style) override; - virtual void setScaleImage(bool scaleImage=true) override; + virtual void setScaleImage(bool scaleImage = true) override; //! Do not drop returned handle static GUIButtonImage *addButton(gui::IGUIEnvironment *environment, diff --git a/src/gui/guiButtonItemImage.cpp b/src/gui/guiButtonItemImage.cpp index d8b9042ac..bbd20582b 100644 --- a/src/gui/guiButtonItemImage.cpp +++ b/src/gui/guiButtonItemImage.cpp @@ -31,11 +31,12 @@ using namespace gui; GUIButtonItemImage::GUIButtonItemImage(gui::IGUIEnvironment *environment, gui::IGUIElement *parent, s32 id, core::rect<s32> rectangle, ISimpleTextureSource *tsrc, std::string item, Client *client, - bool noclip) - : GUIButton (environment, parent, id, rectangle, tsrc, noclip) + bool noclip) : + GUIButton(environment, parent, id, rectangle, tsrc, noclip) { m_image = new GUIItemImage(environment, this, id, - core::rect<s32>(0,0,rectangle.getWidth(),rectangle.getHeight()), + core::rect<s32>(0, 0, rectangle.getWidth(), + rectangle.getHeight()), item, getActiveFont(), client); sendToBack(m_image); @@ -49,8 +50,8 @@ GUIButtonItemImage *GUIButtonItemImage::addButton(IGUIEnvironment *environment, Client *client) { GUIButtonItemImage *button = new GUIButtonItemImage(environment, - parent ? parent : environment->getRootGUIElement(), - id, rectangle, tsrc, item, client); + parent ? parent : environment->getRootGUIElement(), id, rectangle, + tsrc, item, client); if (text) button->setText(text); diff --git a/src/gui/guiButtonItemImage.h b/src/gui/guiButtonItemImage.h index aad923bda..bc93c08d2 100644 --- a/src/gui/guiButtonItemImage.h +++ b/src/gui/guiButtonItemImage.h @@ -38,8 +38,8 @@ public: //! Do not drop returned handle static GUIButtonItemImage *addButton(gui::IGUIEnvironment *environment, const core::rect<s32> &rectangle, ISimpleTextureSource *tsrc, - IGUIElement *parent, s32 id, const wchar_t *text, std::string item, - Client *client); + IGUIElement *parent, s32 id, const wchar_t *text, + std::string item, Client *client); private: std::string m_item_name; diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp index 8de00c12f..7170fad15 100644 --- a/src/gui/guiChatConsole.cpp +++ b/src/gui/guiChatConsole.cpp @@ -32,29 +32,20 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <string> #if USE_FREETYPE - #include "irrlicht_changes/CGUITTFont.h" +#include "irrlicht_changes/CGUITTFont.h" #endif inline u32 clamp_u8(s32 value) { - return (u32) MYMIN(MYMAX(value, 0), 255); + return (u32)MYMIN(MYMAX(value, 0), 255); } - -GUIChatConsole::GUIChatConsole( - gui::IGUIEnvironment* env, - gui::IGUIElement* parent, - s32 id, - ChatBackend* backend, - Client* client, - IMenuManager* menumgr -): - IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, - core::rect<s32>(0,0,100,100)), - m_chat_backend(backend), - m_client(client), - m_menumgr(menumgr), - m_animate_time_old(porting::getTimeMs()) +GUIChatConsole::GUIChatConsole(gui::IGUIEnvironment *env, gui::IGUIElement *parent, + s32 id, ChatBackend *backend, Client *client, IMenuManager *menumgr) : + IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, + core::rect<s32>(0, 0, 100, 100)), + m_chat_backend(backend), m_client(client), m_menumgr(menumgr), + m_animate_time_old(porting::getTimeMs()) { // load background settings s32 console_alpha = g_settings->getS32("console_alpha"); @@ -75,8 +66,9 @@ GUIChatConsole::GUIChatConsole( } u16 chat_font_size = g_settings->getU16("chat_font_size"); - m_font = g_fontengine->getFont(chat_font_size != 0 ? - chat_font_size : FONT_SIZE_UNSPECIFIED, FM_Mono); + m_font = g_fontengine->getFont( + chat_font_size != 0 ? chat_font_size : FONT_SIZE_UNSPECIFIED, + FM_Mono); if (!m_font) { errorstream << "GUIChatConsole: Unable to load mono font" << std::endl; @@ -143,31 +135,24 @@ f32 GUIChatConsole::getDesiredHeight() const void GUIChatConsole::replaceAndAddToHistory(const std::wstring &line) { - ChatPrompt& prompt = m_chat_backend->getPrompt(); + ChatPrompt &prompt = m_chat_backend->getPrompt(); prompt.addToHistory(prompt.getLine()); prompt.replace(line); } - void GUIChatConsole::setCursor( - bool visible, bool blinking, f32 blink_speed, f32 relative_height) + bool visible, bool blinking, f32 blink_speed, f32 relative_height) { - if (visible) - { - if (blinking) - { + if (visible) { + if (blinking) { // leave m_cursor_blink unchanged m_cursor_blink_speed = blink_speed; - } - else - { - m_cursor_blink = 0x8000; // on + } else { + m_cursor_blink = 0x8000; // on m_cursor_blink_speed = 0.0; } - } - else - { - m_cursor_blink = 0; // off + } else { + m_cursor_blink = 0; // off m_cursor_blink_speed = 0.0; } m_cursor_height = relative_height; @@ -175,15 +160,14 @@ void GUIChatConsole::setCursor( void GUIChatConsole::draw() { - if(!IsVisible) + if (!IsVisible) return; - video::IVideoDriver* driver = Environment->getVideoDriver(); + video::IVideoDriver *driver = Environment->getVideoDriver(); // Check screen size v2u32 screensize = driver->getScreenSize(); - if (screensize != m_screensize) - { + if (screensize != m_screensize) { // screen size has changed // scale current console height to new window size if (m_screensize.Y != 0) @@ -199,8 +183,7 @@ void GUIChatConsole::draw() m_animate_time_old = now; // Draw console elements if visible - if (m_height > 0) - { + if (m_height > 0) { drawBackground(); drawText(); drawPrompt(); @@ -211,7 +194,8 @@ void GUIChatConsole::draw() void GUIChatConsole::reformatConsole() { - s32 cols = m_screensize.X / m_fontsize.X - 2; // make room for a margin (looks better) + s32 cols = m_screensize.X / m_fontsize.X - + 2; // make room for a margin (looks better) s32 rows = m_desired_height / m_fontsize.Y - 1; // make room for the input prompt if (cols <= 0 || rows <= 0) cols = rows = 0; @@ -232,27 +216,24 @@ void GUIChatConsole::animate(u32 msec) s32 goal = m_open ? m_desired_height : 0; // Set invisible if close animation finished (reset by openConsole) - // This function (animate()) is never called once its visibility becomes false so do not + // This function (animate()) is never called once its visibility becomes false so + // do not // actually set visible to false before the inhibited period is over if (!m_open && m_height == 0 && m_open_inhibited == 0) IGUIElement::setVisible(false); - if (m_height != goal) - { + if (m_height != goal) { s32 max_change = msec * m_screensize.Y * (m_height_speed / 1000.0); if (max_change == 0) max_change = 1; - if (m_height < goal) - { + if (m_height < goal) { // increase height if (m_height + max_change < goal) m_height += max_change; else m_height = goal; - } - else - { + } else { // decrease height if (m_height > goal + max_change) m_height -= max_change; @@ -264,8 +245,7 @@ void GUIChatConsole::animate(u32 msec) } // blink the cursor - if (m_cursor_blink_speed != 0.0) - { + if (m_cursor_blink_speed != 0.0) { u32 blink_increase = 0x10000 * msec * (m_cursor_blink_speed / 1000.0); if (blink_increase == 0) blink_increase = 1; @@ -281,24 +261,15 @@ void GUIChatConsole::animate(u32 msec) void GUIChatConsole::drawBackground() { - video::IVideoDriver* driver = Environment->getVideoDriver(); - if (m_background != NULL) - { + video::IVideoDriver *driver = Environment->getVideoDriver(); + if (m_background != NULL) { core::rect<s32> sourcerect(0, -m_height, m_screensize.X, 0); - driver->draw2DImage( - m_background, - v2s32(0, 0), - sourcerect, - &AbsoluteClippingRect, - m_background_color, - false); - } - else - { - driver->draw2DRectangle( - m_background_color, - core::rect<s32>(0, 0, m_screensize.X, m_height), - &AbsoluteClippingRect); + driver->draw2DImage(m_background, v2s32(0, 0), sourcerect, + &AbsoluteClippingRect, m_background_color, false); + } else { + driver->draw2DRectangle(m_background_color, + core::rect<s32>(0, 0, m_screensize.X, m_height), + &AbsoluteClippingRect); } } @@ -307,10 +278,9 @@ void GUIChatConsole::drawText() if (m_font == NULL) return; - ChatBuffer& buf = m_chat_backend->getConsoleBuffer(); - for (u32 row = 0; row < buf.getRows(); ++row) - { - const ChatFormattedLine& line = buf.getFormattedLine(row); + ChatBuffer &buf = m_chat_backend->getConsoleBuffer(); + for (u32 row = 0; row < buf.getRows(); ++row) { + const ChatFormattedLine &line = buf.getFormattedLine(row); if (line.fragments.empty()) continue; @@ -321,31 +291,26 @@ void GUIChatConsole::drawText() for (const ChatFormattedFragment &fragment : line.fragments) { s32 x = (fragment.column + 1) * m_fontsize.X; - core::rect<s32> destrect( - x, y, x + m_fontsize.X * fragment.text.size(), y + m_fontsize.Y); + core::rect<s32> destrect(x, y, + x + m_fontsize.X * fragment.text.size(), + y + m_fontsize.Y); #if USE_FREETYPE if (m_font->getType() == irr::gui::EGFT_CUSTOM) { // Draw colored text if FreeType is enabled - irr::gui::CGUITTFont *tmp = dynamic_cast<irr::gui::CGUITTFont *>(m_font); - tmp->draw( - fragment.text, - destrect, - video::SColor(255, 255, 255, 255), - false, - false, - &AbsoluteClippingRect); - } else + irr::gui::CGUITTFont *tmp = + dynamic_cast<irr::gui::CGUITTFont *>( + m_font); + tmp->draw(fragment.text, destrect, + video::SColor(255, 255, 255, 255), false, + false, &AbsoluteClippingRect); + } else #endif { // Otherwise use standard text - m_font->draw( - fragment.text.c_str(), - destrect, - video::SColor(255, 255, 255, 255), - false, - false, - &AbsoluteClippingRect); + m_font->draw(fragment.text.c_str(), destrect, + video::SColor(255, 255, 255, 255), false, + false, &AbsoluteClippingRect); } } } @@ -360,58 +325,44 @@ void GUIChatConsole::drawPrompt() s32 line_height = m_fontsize.Y; s32 y = row * line_height + m_height - m_desired_height; - ChatPrompt& prompt = m_chat_backend->getPrompt(); + ChatPrompt &prompt = m_chat_backend->getPrompt(); std::wstring prompt_text = prompt.getVisiblePortion(); // FIXME Draw string at once, not character by character // That will only work with the cursor once we have a monospace font - for (u32 i = 0; i < prompt_text.size(); ++i) - { + for (u32 i = 0; i < prompt_text.size(); ++i) { wchar_t ws[2] = {prompt_text[i], 0}; s32 x = (1 + i) * m_fontsize.X; - core::rect<s32> destrect( - x, y, x + m_fontsize.X, y + m_fontsize.Y); - m_font->draw( - ws, - destrect, - video::SColor(255, 255, 255, 255), - false, - false, - &AbsoluteClippingRect); + core::rect<s32> destrect(x, y, x + m_fontsize.X, y + m_fontsize.Y); + m_font->draw(ws, destrect, video::SColor(255, 255, 255, 255), false, + false, &AbsoluteClippingRect); } // Draw the cursor during on periods - if ((m_cursor_blink & 0x8000) != 0) - { + if ((m_cursor_blink & 0x8000) != 0) { s32 cursor_pos = prompt.getVisibleCursorPosition(); - if (cursor_pos >= 0) - { + if (cursor_pos >= 0) { s32 cursor_len = prompt.getCursorLength(); - video::IVideoDriver* driver = Environment->getVideoDriver(); + video::IVideoDriver *driver = Environment->getVideoDriver(); s32 x = (1 + cursor_pos) * m_fontsize.X; - core::rect<s32> destrect( - x, - y + m_fontsize.Y * (1.0 - m_cursor_height), - x + m_fontsize.X * MYMAX(cursor_len, 1), - y + m_fontsize.Y * (cursor_len ? m_cursor_height+1 : 1) - ); - video::SColor cursor_color(255,255,255,255); + core::rect<s32> destrect(x, + y + m_fontsize.Y * (1.0 - m_cursor_height), + x + m_fontsize.X * MYMAX(cursor_len, 1), + y + m_fontsize.Y * (cursor_len ? m_cursor_height + 1 + : 1)); + video::SColor cursor_color(255, 255, 255, 255); driver->draw2DRectangle( - cursor_color, - destrect, - &AbsoluteClippingRect); + cursor_color, destrect, &AbsoluteClippingRect); } } - } -bool GUIChatConsole::OnEvent(const SEvent& event) +bool GUIChatConsole::OnEvent(const SEvent &event) { ChatPrompt &prompt = m_chat_backend->getPrompt(); - if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown) - { + if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown) { // Key input if (KeyPress(event.KeyInput) == getKeySetting("keymap_console")) { closeConsole(); @@ -426,21 +377,16 @@ bool GUIChatConsole::OnEvent(const SEvent& event) closeConsoleAtOnce(); m_close_on_enter = false; // inhibit open so the_game doesn't reopen immediately - m_open_inhibited = 1; // so the ESCAPE button doesn't open the "pause menu" + m_open_inhibited = 1; // so the ESCAPE button doesn't open the + // "pause menu" return true; - } - else if(event.KeyInput.Key == KEY_PRIOR) - { + } else if (event.KeyInput.Key == KEY_PRIOR) { m_chat_backend->scrollPageUp(); return true; - } - else if(event.KeyInput.Key == KEY_NEXT) - { + } else if (event.KeyInput.Key == KEY_NEXT) { m_chat_backend->scrollPageDown(); return true; - } - else if(event.KeyInput.Key == KEY_RETURN) - { + } else if (event.KeyInput.Key == KEY_RETURN) { prompt.addToHistory(prompt.getLine()); std::wstring text = prompt.replace(L""); m_client->typeChatMessage(text); @@ -449,97 +395,76 @@ bool GUIChatConsole::OnEvent(const SEvent& event) m_close_on_enter = false; } return true; - } - else if(event.KeyInput.Key == KEY_UP) - { + } else if (event.KeyInput.Key == KEY_UP) { // Up pressed // Move back in history prompt.historyPrev(); return true; - } - else if(event.KeyInput.Key == KEY_DOWN) - { + } else if (event.KeyInput.Key == KEY_DOWN) { // Down pressed // Move forward in history prompt.historyNext(); return true; - } - else if(event.KeyInput.Key == KEY_LEFT || event.KeyInput.Key == KEY_RIGHT) - { + } else if (event.KeyInput.Key == KEY_LEFT || + event.KeyInput.Key == KEY_RIGHT) { // Left/right pressed - // Move/select character/word to the left depending on control and shift keys - ChatPrompt::CursorOp op = event.KeyInput.Shift ? - ChatPrompt::CURSOROP_SELECT : - ChatPrompt::CURSOROP_MOVE; - ChatPrompt::CursorOpDir dir = event.KeyInput.Key == KEY_LEFT ? - ChatPrompt::CURSOROP_DIR_LEFT : - ChatPrompt::CURSOROP_DIR_RIGHT; - ChatPrompt::CursorOpScope scope = event.KeyInput.Control ? - ChatPrompt::CURSOROP_SCOPE_WORD : - ChatPrompt::CURSOROP_SCOPE_CHARACTER; + // Move/select character/word to the left depending on control and + // shift keys + ChatPrompt::CursorOp op = + event.KeyInput.Shift ? ChatPrompt::CURSOROP_SELECT + : ChatPrompt::CURSOROP_MOVE; + ChatPrompt::CursorOpDir dir = + event.KeyInput.Key == KEY_LEFT + ? ChatPrompt::CURSOROP_DIR_LEFT + : ChatPrompt::CURSOROP_DIR_RIGHT; + ChatPrompt::CursorOpScope scope = + event.KeyInput.Control + ? ChatPrompt::CURSOROP_SCOPE_WORD + : ChatPrompt::CURSOROP_SCOPE_CHARACTER; prompt.cursorOperation(op, dir, scope); return true; - } - else if(event.KeyInput.Key == KEY_HOME) - { + } else if (event.KeyInput.Key == KEY_HOME) { // Home pressed // move to beginning of line - prompt.cursorOperation( - ChatPrompt::CURSOROP_MOVE, - ChatPrompt::CURSOROP_DIR_LEFT, - ChatPrompt::CURSOROP_SCOPE_LINE); + prompt.cursorOperation(ChatPrompt::CURSOROP_MOVE, + ChatPrompt::CURSOROP_DIR_LEFT, + ChatPrompt::CURSOROP_SCOPE_LINE); return true; - } - else if(event.KeyInput.Key == KEY_END) - { + } else if (event.KeyInput.Key == KEY_END) { // End pressed // move to end of line - prompt.cursorOperation( - ChatPrompt::CURSOROP_MOVE, - ChatPrompt::CURSOROP_DIR_RIGHT, - ChatPrompt::CURSOROP_SCOPE_LINE); + prompt.cursorOperation(ChatPrompt::CURSOROP_MOVE, + ChatPrompt::CURSOROP_DIR_RIGHT, + ChatPrompt::CURSOROP_SCOPE_LINE); return true; - } - else if(event.KeyInput.Key == KEY_BACK) - { + } else if (event.KeyInput.Key == KEY_BACK) { // Backspace or Ctrl-Backspace pressed // delete character / word to the left ChatPrompt::CursorOpScope scope = - event.KeyInput.Control ? - ChatPrompt::CURSOROP_SCOPE_WORD : - ChatPrompt::CURSOROP_SCOPE_CHARACTER; - prompt.cursorOperation( - ChatPrompt::CURSOROP_DELETE, - ChatPrompt::CURSOROP_DIR_LEFT, - scope); + event.KeyInput.Control + ? ChatPrompt::CURSOROP_SCOPE_WORD + : ChatPrompt::CURSOROP_SCOPE_CHARACTER; + prompt.cursorOperation(ChatPrompt::CURSOROP_DELETE, + ChatPrompt::CURSOROP_DIR_LEFT, scope); return true; - } - else if(event.KeyInput.Key == KEY_DELETE) - { + } else if (event.KeyInput.Key == KEY_DELETE) { // Delete or Ctrl-Delete pressed // delete character / word to the right ChatPrompt::CursorOpScope scope = - event.KeyInput.Control ? - ChatPrompt::CURSOROP_SCOPE_WORD : - ChatPrompt::CURSOROP_SCOPE_CHARACTER; - prompt.cursorOperation( - ChatPrompt::CURSOROP_DELETE, - ChatPrompt::CURSOROP_DIR_RIGHT, - scope); + event.KeyInput.Control + ? ChatPrompt::CURSOROP_SCOPE_WORD + : ChatPrompt::CURSOROP_SCOPE_CHARACTER; + prompt.cursorOperation(ChatPrompt::CURSOROP_DELETE, + ChatPrompt::CURSOROP_DIR_RIGHT, scope); return true; - } - else if(event.KeyInput.Key == KEY_KEY_A && event.KeyInput.Control) - { + } else if (event.KeyInput.Key == KEY_KEY_A && event.KeyInput.Control) { // Ctrl-A pressed // Select all text - prompt.cursorOperation( - ChatPrompt::CURSOROP_SELECT, - ChatPrompt::CURSOROP_DIR_LEFT, // Ignored - ChatPrompt::CURSOROP_SCOPE_LINE); + prompt.cursorOperation(ChatPrompt::CURSOROP_SELECT, + ChatPrompt::CURSOROP_DIR_LEFT, // Ignored + ChatPrompt::CURSOROP_SCOPE_LINE); return true; - } - else if(event.KeyInput.Key == KEY_KEY_C && event.KeyInput.Control) - { + } else if (event.KeyInput.Key == KEY_KEY_C && event.KeyInput.Control) { // Ctrl-C pressed // Copy text to clipboard if (prompt.getCursorLength() <= 0) @@ -548,28 +473,23 @@ bool GUIChatConsole::OnEvent(const SEvent& event) std::string selected(wselected.begin(), wselected.end()); Environment->getOSOperator()->copyToClipboard(selected.c_str()); return true; - } - else if(event.KeyInput.Key == KEY_KEY_V && event.KeyInput.Control) - { + } else if (event.KeyInput.Key == KEY_KEY_V && event.KeyInput.Control) { // Ctrl-V pressed // paste text from clipboard if (prompt.getCursorLength() > 0) { // Delete selected section of text - prompt.cursorOperation( - ChatPrompt::CURSOROP_DELETE, - ChatPrompt::CURSOROP_DIR_LEFT, // Ignored - ChatPrompt::CURSOROP_SCOPE_SELECTION); + prompt.cursorOperation(ChatPrompt::CURSOROP_DELETE, + ChatPrompt::CURSOROP_DIR_LEFT, // Ignored + ChatPrompt::CURSOROP_SCOPE_SELECTION); } IOSOperator *os_operator = Environment->getOSOperator(); const c8 *text = os_operator->getTextFromClipboard(); if (!text) return true; - std::basic_string<unsigned char> str((const unsigned char*)text); + std::basic_string<unsigned char> str((const unsigned char *)text); prompt.input(std::wstring(str.begin(), str.end())); return true; - } - else if(event.KeyInput.Key == KEY_KEY_X && event.KeyInput.Control) - { + } else if (event.KeyInput.Key == KEY_KEY_X && event.KeyInput.Control) { // Ctrl-X pressed // Cut text to clipboard if (prompt.getCursorLength() <= 0) @@ -577,55 +497,45 @@ bool GUIChatConsole::OnEvent(const SEvent& event) std::wstring wselected = prompt.getSelection(); std::string selected(wselected.begin(), wselected.end()); Environment->getOSOperator()->copyToClipboard(selected.c_str()); - prompt.cursorOperation( - ChatPrompt::CURSOROP_DELETE, - ChatPrompt::CURSOROP_DIR_LEFT, // Ignored - ChatPrompt::CURSOROP_SCOPE_SELECTION); + prompt.cursorOperation(ChatPrompt::CURSOROP_DELETE, + ChatPrompt::CURSOROP_DIR_LEFT, // Ignored + ChatPrompt::CURSOROP_SCOPE_SELECTION); return true; - } - else if(event.KeyInput.Key == KEY_KEY_U && event.KeyInput.Control) - { + } else if (event.KeyInput.Key == KEY_KEY_U && event.KeyInput.Control) { // Ctrl-U pressed // kill line to left end - prompt.cursorOperation( - ChatPrompt::CURSOROP_DELETE, - ChatPrompt::CURSOROP_DIR_LEFT, - ChatPrompt::CURSOROP_SCOPE_LINE); + prompt.cursorOperation(ChatPrompt::CURSOROP_DELETE, + ChatPrompt::CURSOROP_DIR_LEFT, + ChatPrompt::CURSOROP_SCOPE_LINE); return true; - } - else if(event.KeyInput.Key == KEY_KEY_K && event.KeyInput.Control) - { + } else if (event.KeyInput.Key == KEY_KEY_K && event.KeyInput.Control) { // Ctrl-K pressed // kill line to right end - prompt.cursorOperation( - ChatPrompt::CURSOROP_DELETE, - ChatPrompt::CURSOROP_DIR_RIGHT, - ChatPrompt::CURSOROP_SCOPE_LINE); + prompt.cursorOperation(ChatPrompt::CURSOROP_DELETE, + ChatPrompt::CURSOROP_DIR_RIGHT, + ChatPrompt::CURSOROP_SCOPE_LINE); return true; - } - else if(event.KeyInput.Key == KEY_TAB) - { + } else if (event.KeyInput.Key == KEY_TAB) { // Tab or Shift-Tab pressed // Nick completion - std::list<std::string> names = m_client->getConnectedPlayerNames(); + std::list<std::string> names = + m_client->getConnectedPlayerNames(); bool backwards = event.KeyInput.Shift; prompt.nickCompletion(names, backwards); return true; } else if (!iswcntrl(event.KeyInput.Char) && !event.KeyInput.Control) { - #if defined(__linux__) && (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9) - wchar_t wc = L'_'; - mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) ); - prompt.input(wc); - #else - prompt.input(event.KeyInput.Char); - #endif +#if defined(__linux__) && (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9) + wchar_t wc = L'_'; + mbtowc(&wc, (char *)&event.KeyInput.Char, + sizeof(event.KeyInput.Char)); + prompt.input(wc); +#else + prompt.input(event.KeyInput.Char); +#endif return true; } - } - else if(event.EventType == EET_MOUSE_INPUT_EVENT) - { - if(event.MouseInput.Event == EMIE_MOUSE_WHEEL) - { + } else if (event.EventType == EET_MOUSE_INPUT_EVENT) { + if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) { s32 rows = myround(-3.0 * event.MouseInput.Wheel); m_chat_backend->scroll(rows); } @@ -643,4 +553,3 @@ void GUIChatConsole::setVisible(bool visible) recalculateConsolePosition(); } } - diff --git a/src/gui/guiChatConsole.h b/src/gui/guiChatConsole.h index 7be40e27c..adf89e88c 100644 --- a/src/gui/guiChatConsole.h +++ b/src/gui/guiChatConsole.h @@ -29,12 +29,8 @@ class Client; class GUIChatConsole : public gui::IGUIElement { public: - GUIChatConsole(gui::IGUIEnvironment* env, - gui::IGUIElement* parent, - s32 id, - ChatBackend* backend, - Client* client, - IMenuManager* menumgr); + GUIChatConsole(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, + ChatBackend *backend, Client *client, IMenuManager *menumgr); virtual ~GUIChatConsole(); // Open the console (height = desired fraction of screen size) @@ -63,18 +59,15 @@ public: void replaceAndAddToHistory(const std::wstring &line); // Change how the cursor looks - void setCursor( - bool visible, - bool blinking = false, - f32 blink_speed = 1.0, - f32 relative_height = 1.0); + void setCursor(bool visible, bool blinking = false, f32 blink_speed = 1.0, + f32 relative_height = 1.0); // Irrlicht draw method virtual void draw(); - bool canTakeFocus(gui::IGUIElement* element) { return false; } + bool canTakeFocus(gui::IGUIElement *element) { return false; } - virtual bool OnEvent(const SEvent& event); + virtual bool OnEvent(const SEvent &event); virtual void setVisible(bool visible); @@ -89,9 +82,9 @@ private: void drawPrompt(); private: - ChatBackend* m_chat_backend; - Client* m_client; - IMenuManager* m_menumgr; + ChatBackend *m_chat_backend; + Client *m_client; + IMenuManager *m_menumgr; // current screen size v2u32 m_screensize; diff --git a/src/gui/guiConfirmRegistration.cpp b/src/gui/guiConfirmRegistration.cpp index 55c111df8..d4679b5dc 100644 --- a/src/gui/guiConfirmRegistration.cpp +++ b/src/gui/guiConfirmRegistration.cpp @@ -39,8 +39,8 @@ const int ID_message = 266; GUIConfirmRegistration::GUIConfirmRegistration(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, Client *client, - const std::string &playername, const std::string &password, - bool *aborted, ISimpleTextureSource *tsrc) : + const std::string &playername, const std::string &password, bool *aborted, + ISimpleTextureSource *tsrc) : GUIModalMenu(env, parent, id, menumgr), m_client(client), m_playername(playername), m_password(password), m_aborted(aborted), m_tsrc(tsrc) @@ -74,12 +74,9 @@ void GUIConfirmRegistration::regenerateGui(v2u32 screensize) Calculate new sizes and positions */ const float s = m_gui_scale; - DesiredRect = core::rect<s32>( - screensize.X / 2 - 600 * s / 2, - screensize.Y / 2 - 360 * s / 2, - screensize.X / 2 + 600 * s / 2, - screensize.Y / 2 + 360 * s / 2 - ); + DesiredRect = core::rect<s32>(screensize.X / 2 - 600 * s / 2, + screensize.Y / 2 - 360 * s / 2, screensize.X / 2 + 600 * s / 2, + screensize.Y / 2 + 360 * s / 2); recalculateAbsolutePosition(false); v2s32 size = DesiredRect.getSize(); @@ -95,11 +92,14 @@ void GUIConfirmRegistration::regenerateGui(v2u32 screensize) core::rect<s32> rect2(0, 0, 540 * s, 180 * s); rect2 += topleft_client + v2s32(30 * s, ypos); static const std::string info_text_template = strgettext( - "You are about to join this server with the name \"%s\" for the " + "You are about to join this server with the name \"%s\" " + "for the " "first time.\n" - "If you proceed, a new account using your credentials will be " + "If you proceed, a new account using your credentials " + "will be " "created on this server.\n" - "Please retype your password and click 'Register and Join' to " + "Please retype your password and click 'Register and " + "Join' to " "confirm account creation, or click 'Cancel' to abort."); char info_text_buf[1024]; porting::mt_snprintf(info_text_buf, sizeof(info_text_buf), @@ -223,7 +223,7 @@ bool GUIConfirmRegistration::OnEvent(const SEvent &event) if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) { if (!canTakeFocus(event.GUIEvent.Element)) { infostream << "GUIConfirmRegistration: Not allowing focus change." - << std::endl; + << std::endl; // Returning true disables focus change return true; } diff --git a/src/gui/guiEditBoxWithScrollbar.cpp b/src/gui/guiEditBoxWithScrollbar.cpp index 442406688..c803ba58c 100644 --- a/src/gui/guiEditBoxWithScrollbar.cpp +++ b/src/gui/guiEditBoxWithScrollbar.cpp @@ -17,31 +17,30 @@ todo: optional scrollbars [done] ctrl+left/right to select word -double click/ctrl click: word select + drag to select whole words, triple click to select line -optional? dragging selected text -numerical +double click/ctrl click: word select + drag to select whole words, triple click to select +line optional? dragging selected text 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) - : IGUIEditBox(environment, parent, id, rectangle), m_mouse_marking(false), - m_border(border), m_background(true), m_override_color_enabled(false), m_mark_begin(0), m_mark_end(0), - m_override_color(video::SColor(101, 255, 255, 255)), m_override_font(0), m_last_break_font(0), - m_operator(0), m_blink_start_time(0), m_cursor_pos(0), m_hscroll_pos(0), m_vscroll_pos(0), m_max(0), - m_word_wrap(false), m_multiline(false), m_autoscroll(true), m_passwordbox(false), - m_passwordchar(L'*'), m_halign(EGUIA_UPPERLEFT), m_valign(EGUIA_CENTER), - m_current_text_rect(0, 0, 1, 1), m_frame_rect(rectangle), - m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable), - m_bg_color_used(false) +GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t *text, bool border, + IGUIEnvironment *environment, IGUIElement *parent, s32 id, + const core::rect<s32> &rectangle, bool writable, bool has_vscrollbar) : + IGUIEditBox(environment, parent, id, rectangle), + m_mouse_marking(false), m_border(border), m_background(true), + m_override_color_enabled(false), m_mark_begin(0), m_mark_end(0), + m_override_color(video::SColor(101, 255, 255, 255)), m_override_font(0), + m_last_break_font(0), m_operator(0), m_blink_start_time(0), + m_cursor_pos(0), m_hscroll_pos(0), m_vscroll_pos(0), m_max(0), + m_word_wrap(false), m_multiline(false), m_autoscroll(true), + m_passwordbox(false), m_passwordchar(L'*'), m_halign(EGUIA_UPPERLEFT), + m_valign(EGUIA_CENTER), m_current_text_rect(0, 0, 1, 1), + m_frame_rect(rectangle), m_scrollbar_width(0), m_vscrollbar(NULL), + m_writable(writable), m_bg_color_used(false) { #ifdef _DEBUG setDebugName("GUIEditBoxWithScrollBar"); #endif - Text = text; if (Environment) @@ -65,7 +64,6 @@ GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool borde setWritable(writable); } - //! destructor GUIEditBoxWithScrollBar::~GUIEditBoxWithScrollBar() { @@ -79,9 +77,8 @@ GUIEditBoxWithScrollBar::~GUIEditBoxWithScrollBar() m_vscrollbar->drop(); } - //! Sets another skin independent font. -void GUIEditBoxWithScrollBar::setOverrideFont(IGUIFont* font) +void GUIEditBoxWithScrollBar::setOverrideFont(IGUIFont *font) { if (m_override_font == font) return; @@ -98,17 +95,17 @@ void GUIEditBoxWithScrollBar::setOverrideFont(IGUIFont* font) } //! Gets the override font (if any) -IGUIFont * GUIEditBoxWithScrollBar::getOverrideFont() const +IGUIFont *GUIEditBoxWithScrollBar::getOverrideFont() const { return m_override_font; } //! Get the font which is used right now for drawing -IGUIFont* GUIEditBoxWithScrollBar::getActiveFont() const +IGUIFont *GUIEditBoxWithScrollBar::getActiveFont() const { if (m_override_font) return m_override_font; - IGUISkin* skin = Environment->getSkin(); + IGUISkin *skin = Environment->getSkin(); if (skin) return skin->getFont(); return 0; @@ -121,13 +118,11 @@ void GUIEditBoxWithScrollBar::setOverrideColor(video::SColor color) m_override_color_enabled = true; } - video::SColor GUIEditBoxWithScrollBar::getOverrideColor() const { return m_override_color; } - //! Turns the border on or off void GUIEditBoxWithScrollBar::setDrawBorder(bool border) { @@ -158,7 +153,6 @@ void GUIEditBoxWithScrollBar::setWordWrap(bool enable) breakText(); } - void GUIEditBoxWithScrollBar::updateAbsolutePosition() { core::rect<s32> old_absolute_rect(AbsoluteRect); @@ -176,21 +170,18 @@ bool GUIEditBoxWithScrollBar::isWordWrapEnabled() const return m_word_wrap; } - //! Enables or disables newlines. void GUIEditBoxWithScrollBar::setMultiLine(bool enable) { m_multiline = enable; } - //! Checks if multi line editing is enabled bool GUIEditBoxWithScrollBar::isMultiLineEnabled() const { return m_multiline; } - void GUIEditBoxWithScrollBar::setPasswordBox(bool password_box, wchar_t password_char) { m_passwordbox = password_box; @@ -202,27 +193,24 @@ void GUIEditBoxWithScrollBar::setPasswordBox(bool password_box, wchar_t password } } - bool GUIEditBoxWithScrollBar::isPasswordBox() const { return m_passwordbox; } - //! Sets text justification -void GUIEditBoxWithScrollBar::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) +void GUIEditBoxWithScrollBar::setTextAlignment( + EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) { m_halign = horizontal; m_valign = vertical; } - //! called if an event happened. -bool GUIEditBoxWithScrollBar::OnEvent(const SEvent& event) +bool GUIEditBoxWithScrollBar::OnEvent(const SEvent &event) { if (isEnabled()) { - switch (event.EventType) - { + switch (event.EventType) { case EET_GUI_EVENT: if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) { if (event.GUIEvent.Caller == this) { @@ -247,8 +235,7 @@ bool GUIEditBoxWithScrollBar::OnEvent(const SEvent& event) return IGUIElement::OnEvent(event); } - -bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) +bool GUIEditBoxWithScrollBar::processKey(const SEvent &event) { if (!m_writable) { return false; @@ -279,10 +266,13 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) break; case KEY_KEY_C: // copy to clipboard - if (!m_passwordbox && m_operator && m_mark_begin != m_mark_end) - { - const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end; - const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; + if (!m_passwordbox && m_operator && m_mark_begin != m_mark_end) { + const s32 realmbgn = m_mark_begin < m_mark_end + ? m_mark_begin + : m_mark_end; + const s32 realmend = m_mark_begin < m_mark_end + ? m_mark_end + : m_mark_begin; core::stringc s; s = Text.subString(realmbgn, realmend - realmbgn).c_str(); @@ -292,20 +282,25 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) case KEY_KEY_X: // cut to the clipboard if (!m_passwordbox && m_operator && m_mark_begin != m_mark_end) { - const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end; - const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; + const s32 realmbgn = m_mark_begin < m_mark_end + ? m_mark_begin + : m_mark_end; + const s32 realmend = m_mark_begin < m_mark_end + ? m_mark_end + : m_mark_begin; // copy core::stringc sc; - sc = Text.subString(realmbgn, realmend - realmbgn).c_str(); + sc = Text.subString(realmbgn, realmend - realmbgn) + .c_str(); m_operator->copyToClipboard(sc.c_str()); - if (isEnabled()) - { + if (isEnabled()) { // delete core::stringw s; s = Text.subString(0, realmbgn); - s.append(Text.subString(realmend, Text.size() - realmend)); + s.append(Text.subString(realmend, + Text.size() - realmend)); Text = s; m_cursor_pos = realmbgn; @@ -321,19 +316,28 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) // paste from the clipboard if (m_operator) { - const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end; - const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; + const s32 realmbgn = m_mark_begin < m_mark_end + ? m_mark_begin + : m_mark_end; + const s32 realmend = m_mark_begin < m_mark_end + ? m_mark_end + : m_mark_begin; // add new character - const c8* p = m_operator->getTextFromClipboard(); + const c8 *p = m_operator->getTextFromClipboard(); if (p) { if (m_mark_begin == m_mark_end) { // insert text - core::stringw s = Text.subString(0, m_cursor_pos); + core::stringw s = Text.subString( + 0, m_cursor_pos); s.append(p); - s.append(Text.subString(m_cursor_pos, Text.size() - m_cursor_pos)); + s.append(Text.subString(m_cursor_pos, + Text.size() - m_cursor_pos)); - if (!m_max || s.size() <= m_max) // thx to Fish FH for fix + if (!m_max || s.size() <= m_max) // thx to + // Fish + // FH for + // fix { Text = s; s = p; @@ -342,15 +346,21 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) } else { // replace text - core::stringw s = Text.subString(0, realmbgn); + core::stringw s = Text.subString( + 0, realmbgn); s.append(p); - s.append(Text.subString(realmend, Text.size() - realmend)); + s.append(Text.subString(realmend, + Text.size() - realmend)); - if (!m_max || s.size() <= m_max) // thx to Fish FH for fix + if (!m_max || s.size() <= m_max) // thx to + // Fish + // FH for + // fix { Text = s; s = p; - m_cursor_pos = realmbgn + s.size(); + m_cursor_pos = realmbgn + + s.size(); } } } @@ -390,14 +400,15 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) } // default keyboard handling else - switch (event.KeyInput.Key) { - case KEY_END: - { + switch (event.KeyInput.Key) { + case KEY_END: { s32 p = Text.size(); if (m_word_wrap || m_multiline) { p = getLineFromPos(m_cursor_pos); - p = m_broken_text_positions[p] + (s32)m_broken_text[p].size(); - if (p > 0 && (Text[p - 1] == L'\r' || Text[p - 1] == L'\n')) + p = m_broken_text_positions[p] + + (s32)m_broken_text[p].size(); + if (p > 0 && (Text[p - 1] == L'\r' || + Text[p - 1] == L'\n')) p -= 1; } @@ -412,10 +423,8 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) } m_cursor_pos = p; m_blink_start_time = porting::getTimeMs(); - } - break; - case KEY_HOME: - { + } break; + case KEY_HOME: { s32 p = 0; if (m_word_wrap || m_multiline) { @@ -433,8 +442,7 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) } m_cursor_pos = p; m_blink_start_time = porting::getTimeMs(); - } - break; + } break; case KEY_RETURN: if (m_multiline) { inputChar(L'\n'); @@ -482,13 +490,25 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) case KEY_UP: if (m_multiline || (m_word_wrap && m_broken_text.size() > 1)) { s32 lineNo = getLineFromPos(m_cursor_pos); - s32 mb = (m_mark_begin == m_mark_end) ? m_cursor_pos : (m_mark_begin > m_mark_end ? m_mark_begin : m_mark_end); - if (lineNo > 0) { - s32 cp = m_cursor_pos - m_broken_text_positions[lineNo]; + s32 mb = (m_mark_begin == m_mark_end) + ? m_cursor_pos + : (m_mark_begin > m_mark_end ? m_mark_begin + : m_mark_end); + if (lineNo > 0) { + s32 cp = m_cursor_pos - + m_broken_text_positions[lineNo]; if ((s32)m_broken_text[lineNo - 1].size() < cp) - m_cursor_pos = m_broken_text_positions[lineNo - 1] + core::max_((u32)1, m_broken_text[lineNo - 1].size()) - 1; + m_cursor_pos = m_broken_text_positions + [lineNo - 1] + + core::max_((u32)1, + m_broken_text[lineNo - + 1] + .size()) - + 1; else - m_cursor_pos = m_broken_text_positions[lineNo - 1] + cp; + m_cursor_pos = m_broken_text_positions + [lineNo - 1] + + cp; } if (event.KeyInput.Shift) { @@ -505,14 +525,25 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) case KEY_DOWN: if (m_multiline || (m_word_wrap && m_broken_text.size() > 1)) { s32 lineNo = getLineFromPos(m_cursor_pos); - s32 mb = (m_mark_begin == m_mark_end) ? m_cursor_pos : (m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end); - if (lineNo < (s32)m_broken_text.size() - 1) - { - s32 cp = m_cursor_pos - m_broken_text_positions[lineNo]; + s32 mb = (m_mark_begin == m_mark_end) + ? m_cursor_pos + : (m_mark_begin < m_mark_end ? m_mark_begin + : m_mark_end); + if (lineNo < (s32)m_broken_text.size() - 1) { + s32 cp = m_cursor_pos - + m_broken_text_positions[lineNo]; if ((s32)m_broken_text[lineNo + 1].size() < cp) - m_cursor_pos = m_broken_text_positions[lineNo + 1] + core::max_((u32)1, m_broken_text[lineNo + 1].size()) - 1; + m_cursor_pos = m_broken_text_positions + [lineNo + 1] + + core::max_((u32)1, + m_broken_text[lineNo + + 1] + .size()) - + 1; else - m_cursor_pos = m_broken_text_positions[lineNo + 1] + cp; + m_cursor_pos = m_broken_text_positions + [lineNo + 1] + + cp; } if (event.KeyInput.Shift) { @@ -537,11 +568,18 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) if (m_mark_begin != m_mark_end) { // delete marked text - const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end; - const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; + const s32 realmbgn = + m_mark_begin < m_mark_end + ? m_mark_begin + : m_mark_end; + const s32 realmend = + m_mark_begin < m_mark_end + ? m_mark_end + : m_mark_begin; s = Text.subString(0, realmbgn); - s.append(Text.subString(realmend, Text.size() - realmend)); + s.append(Text.subString(realmend, + Text.size() - realmend)); Text = s; m_cursor_pos = realmbgn; @@ -551,14 +589,16 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) s = Text.subString(0, m_cursor_pos - 1); else s = L""; - s.append(Text.subString(m_cursor_pos, Text.size() - m_cursor_pos)); + s.append(Text.subString(m_cursor_pos, + Text.size() - m_cursor_pos)); Text = s; --m_cursor_pos; } if (m_cursor_pos < 0) m_cursor_pos = 0; - m_blink_start_time = porting::getTimeMs(); // os::Timer::getTime(); + m_blink_start_time = porting:: + getTimeMs(); // os::Timer::getTime(); new_mark_begin = 0; new_mark_end = 0; text_changed = true; @@ -573,25 +613,34 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) if (m_mark_begin != m_mark_end) { // delete marked text - const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end; - const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; + const s32 realmbgn = + m_mark_begin < m_mark_end + ? m_mark_begin + : m_mark_end; + const s32 realmend = + m_mark_begin < m_mark_end + ? m_mark_end + : m_mark_begin; s = Text.subString(0, realmbgn); - s.append(Text.subString(realmend, Text.size() - realmend)); + s.append(Text.subString(realmend, + Text.size() - realmend)); Text = s; m_cursor_pos = realmbgn; } else { // delete text before cursor s = Text.subString(0, m_cursor_pos); - s.append(Text.subString(m_cursor_pos + 1, Text.size() - m_cursor_pos - 1)); + s.append(Text.subString(m_cursor_pos + 1, + Text.size() - m_cursor_pos - 1)); Text = s; } if (m_cursor_pos > (s32)Text.size()) m_cursor_pos = (s32)Text.size(); - m_blink_start_time = porting::getTimeMs(); // os::Timer::getTime(); + m_blink_start_time = porting:: + getTimeMs(); // os::Timer::getTime(); new_mark_begin = 0; new_mark_end = 0; text_changed = true; @@ -641,16 +690,13 @@ bool GUIEditBoxWithScrollBar::processKey(const SEvent& event) breakText(); calculateScrollPos(); sendGuiEvent(EGET_EDITBOX_CHANGED); - } - else - { + } else { calculateScrollPos(); } return true; } - //! draws the element and its children void GUIEditBoxWithScrollBar::draw() { @@ -659,7 +705,7 @@ void GUIEditBoxWithScrollBar::draw() const bool focus = Environment->hasFocus(this); - IGUISkin* skin = Environment->getSkin(); + IGUISkin *skin = Environment->getSkin(); if (!skin) return; @@ -670,7 +716,8 @@ void GUIEditBoxWithScrollBar::draw() bg_color = m_bg_color_used ? m_bg_color : default_bg_color; if (!m_border && m_background) { - skin->draw2DRectangle(this, bg_color, AbsoluteRect, &AbsoluteClippingRect); + skin->draw2DRectangle( + this, bg_color, AbsoluteRect, &AbsoluteClippingRect); } // draw the border @@ -679,7 +726,7 @@ void GUIEditBoxWithScrollBar::draw() if (m_writable) { skin->draw3DSunkenPane(this, bg_color, false, m_background, - AbsoluteRect, &AbsoluteClippingRect); + AbsoluteRect, &AbsoluteClippingRect); } calculateFrameRect(); @@ -690,7 +737,7 @@ void GUIEditBoxWithScrollBar::draw() // draw the text - IGUIFont* font = getActiveFont(); + IGUIFont *font = getActiveFont(); s32 cursor_line = 0; s32 charcursorpos = 0; @@ -709,10 +756,13 @@ void GUIEditBoxWithScrollBar::draw() // get mark position const bool ml = (!m_passwordbox && (m_word_wrap || m_multiline)); - const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end; - const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; + const s32 realmbgn = + m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end; + const s32 realmend = + m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; const s32 hline_start = ml ? getLineFromPos(realmbgn) : 0; - const s32 hline_count = ml ? getLineFromPos(realmend) - hline_start + 1 : 1; + const s32 hline_count = + ml ? getLineFromPos(realmend) - hline_start + 1 : 1; const s32 line_count = ml ? m_broken_text.size() : 1; // Save the override color information. @@ -729,7 +779,8 @@ void GUIEditBoxWithScrollBar::draw() for (s32 i = 0; i < line_count; ++i) { setTextRect(i); - // clipping test - don't draw anything outside the visible area + // clipping test - don't draw anything outside the visible + // area core::rect<s32> c = local_clip_rect; c.clipAgainst(m_current_text_rect); if (!c.isValid()) @@ -741,11 +792,11 @@ void GUIEditBoxWithScrollBar::draw() m_broken_text.clear(); m_broken_text.emplace_back(); } - if (m_broken_text[0].size() != Text.size()){ + if (m_broken_text[0].size() != Text.size()) { m_broken_text[0] = Text; - for (u32 q = 0; q < Text.size(); ++q) - { - m_broken_text[0][q] = m_passwordchar; + for (u32 q = 0; q < Text.size(); ++q) { + m_broken_text[0][q] = + m_passwordchar; } } txt_line = &m_broken_text[0]; @@ -755,55 +806,77 @@ void GUIEditBoxWithScrollBar::draw() start_pos = ml ? m_broken_text_positions[i] : 0; } - // draw normal text font->draw(txt_line->c_str(), m_current_text_rect, - m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT), - false, true, &local_clip_rect); + m_override_color_enabled + ? m_override_color + : skin->getColor(EGDC_BUTTON_TEXT), + false, true, &local_clip_rect); // draw mark and marked text - if (focus && m_mark_begin != m_mark_end && i >= hline_start && i < hline_start + hline_count) { + if (focus && m_mark_begin != m_mark_end && + i >= hline_start && + i < hline_start + hline_count) { s32 mbegin = 0, mend = 0; - s32 lineStartPos = 0, lineEndPos = txt_line->size(); + s32 lineStartPos = 0, + lineEndPos = txt_line->size(); if (i == hline_start) { // highlight start is on this line - s = txt_line->subString(0, realmbgn - start_pos); - mbegin = font->getDimension(s.c_str()).Width; + s = txt_line->subString( + 0, realmbgn - start_pos); + mbegin = font->getDimension(s.c_str()) + .Width; // deal with kerning mbegin += font->getKerningWidth( - &((*txt_line)[realmbgn - start_pos]), - realmbgn - start_pos > 0 ? &((*txt_line)[realmbgn - start_pos - 1]) : 0); + &((*txt_line)[realmbgn - + start_pos]), + realmbgn - start_pos > 0 + ? &((*txt_line)[realmbgn - + start_pos - + 1]) + : 0); lineStartPos = realmbgn - start_pos; } if (i == hline_start + hline_count - 1) { // highlight end is on this line - s2 = txt_line->subString(0, realmend - start_pos); - mend = font->getDimension(s2.c_str()).Width; + s2 = txt_line->subString( + 0, realmend - start_pos); + mend = font->getDimension(s2.c_str()) + .Width; lineEndPos = (s32)s2.size(); } else { - mend = font->getDimension(txt_line->c_str()).Width; + mend = font->getDimension(txt_line->c_str()) + .Width; } - m_current_text_rect.UpperLeftCorner.X += mbegin; - m_current_text_rect.LowerRightCorner.X = m_current_text_rect.UpperLeftCorner.X + mend - mbegin; - + m_current_text_rect.LowerRightCorner.X = + m_current_text_rect + .UpperLeftCorner + .X + + mend - mbegin; // draw mark - skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), m_current_text_rect, &local_clip_rect); + skin->draw2DRectangle(this, + skin->getColor(EGDC_HIGH_LIGHT), + m_current_text_rect, + &local_clip_rect); // draw marked text - s = txt_line->subString(lineStartPos, lineEndPos - lineStartPos); + s = txt_line->subString(lineStartPos, + lineEndPos - lineStartPos); if (s.size()) font->draw(s.c_str(), m_current_text_rect, - m_override_color_enabled ? m_override_color : skin->getColor(EGDC_HIGH_LIGHT_TEXT), - false, true, &local_clip_rect); - + m_override_color_enabled + ? m_override_color + : skin->getColor(EGDC_HIGH_LIGHT_TEXT), + false, true, + &local_clip_rect); } } @@ -821,15 +894,23 @@ void GUIEditBoxWithScrollBar::draw() } s = txt_line->subString(0, m_cursor_pos - start_pos); charcursorpos = font->getDimension(s.c_str()).Width + - font->getKerningWidth(L"_", m_cursor_pos - start_pos > 0 ? &((*txt_line)[m_cursor_pos - start_pos - 1]) : 0); - - if (focus && (porting::getTimeMs() - m_blink_start_time) % 700 < 350) { + font->getKerningWidth(L"_", + m_cursor_pos - start_pos > 0 + ? &((*txt_line)[m_cursor_pos - + start_pos - + 1]) + : 0); + + if (focus && (porting::getTimeMs() - m_blink_start_time) % 700 < + 350) { setTextRect(cursor_line); m_current_text_rect.UpperLeftCorner.X += charcursorpos; font->draw(L"_", m_current_text_rect, - m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT), - false, true, &local_clip_rect); + m_override_color_enabled + ? m_override_color + : skin->getColor(EGDC_BUTTON_TEXT), + false, true, &local_clip_rect); } } } @@ -838,9 +919,8 @@ void GUIEditBoxWithScrollBar::draw() IGUIElement::draw(); } - //! Sets the new caption of this element. -void GUIEditBoxWithScrollBar::setText(const wchar_t* text) +void GUIEditBoxWithScrollBar::setText(const wchar_t *text) { Text = text; if (u32(m_cursor_pos) > Text.size()) @@ -849,7 +929,6 @@ void GUIEditBoxWithScrollBar::setText(const wchar_t* text) breakText(); } - //! Enables or disables automatic scrolling with cursor position //! \param enable: If set to true, the text will move around with the cursor position void GUIEditBoxWithScrollBar::setAutoScroll(bool enable) @@ -857,7 +936,6 @@ void GUIEditBoxWithScrollBar::setAutoScroll(bool enable) m_autoscroll = enable; } - //! Checks to see if automatic scrolling is enabled //! \return true if automatic scrolling is enabled, false if not bool GUIEditBoxWithScrollBar::isAutoScrollEnabled() const @@ -865,7 +943,6 @@ bool GUIEditBoxWithScrollBar::isAutoScrollEnabled() const return m_autoscroll; } - //! Gets the area of the text in the edit box //! \return Returns the size in pixels of the text core::dimension2du GUIEditBoxWithScrollBar::getTextDimension() @@ -884,7 +961,6 @@ core::dimension2du GUIEditBoxWithScrollBar::getTextDimension() return core::dimension2du(ret.getSize()); } - //! Sets the maximum amount of characters which may be entered in the box. //! \param max: Maximum amount of characters. If 0, the character amount is //! infinity. @@ -896,21 +972,19 @@ void GUIEditBoxWithScrollBar::setMax(u32 max) Text = Text.subString(0, m_max); } - //! Returns maximum amount of characters, previously set by setMax(); u32 GUIEditBoxWithScrollBar::getMax() const { return m_max; } - -bool GUIEditBoxWithScrollBar::processMouse(const SEvent& event) +bool GUIEditBoxWithScrollBar::processMouse(const SEvent &event) { - switch (event.MouseInput.Event) - { + switch (event.MouseInput.Event) { case irr::EMIE_LMOUSE_LEFT_UP: if (Environment->hasFocus(this)) { - m_cursor_pos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + m_cursor_pos = getCursorPos( + event.MouseInput.X, event.MouseInput.Y); if (m_mouse_marking) { setTextMarkers(m_mark_begin, m_cursor_pos); } @@ -919,32 +993,33 @@ bool GUIEditBoxWithScrollBar::processMouse(const SEvent& event) return true; } break; - case irr::EMIE_MOUSE_MOVED: - { + case irr::EMIE_MOUSE_MOVED: { if (m_mouse_marking) { - m_cursor_pos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + m_cursor_pos = getCursorPos( + event.MouseInput.X, event.MouseInput.Y); setTextMarkers(m_mark_begin, m_cursor_pos); calculateScrollPos(); return true; } - } - break; + } break; case EMIE_LMOUSE_PRESSED_DOWN: if (!Environment->hasFocus(this)) { m_blink_start_time = porting::getTimeMs(); m_mouse_marking = true; - m_cursor_pos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + m_cursor_pos = getCursorPos( + event.MouseInput.X, event.MouseInput.Y); setTextMarkers(m_cursor_pos, m_cursor_pos); calculateScrollPos(); return true; } else { - if (!AbsoluteClippingRect.isPointInside( - core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y))) { + if (!AbsoluteClippingRect.isPointInside(core::position2d<s32>( + event.MouseInput.X, event.MouseInput.Y))) { return false; } else { // move cursor - m_cursor_pos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + m_cursor_pos = getCursorPos( + event.MouseInput.X, event.MouseInput.Y); s32 newMarkBegin = m_mark_begin; if (!m_mouse_marking) @@ -963,10 +1038,9 @@ bool GUIEditBoxWithScrollBar::processMouse(const SEvent& event) return false; } - s32 GUIEditBoxWithScrollBar::getCursorPos(s32 x, s32 y) { - IGUIFont* font = getActiveFont(); + IGUIFont *font = getActiveFont(); const u32 line_count = (m_word_wrap || m_multiline) ? m_broken_text.size() : 1; @@ -982,10 +1056,14 @@ s32 GUIEditBoxWithScrollBar::getCursorPos(s32 x, s32 y) y = m_current_text_rect.LowerRightCorner.Y; // is it inside this region? - if (y >= m_current_text_rect.UpperLeftCorner.Y && y <= m_current_text_rect.LowerRightCorner.Y) { + if (y >= m_current_text_rect.UpperLeftCorner.Y && + y <= m_current_text_rect.LowerRightCorner.Y) { // we've found the clicked line - txt_line = (m_word_wrap || m_multiline) ? &m_broken_text[i] : &Text; - start_pos = (m_word_wrap || m_multiline) ? m_broken_text_positions[i] : 0; + txt_line = (m_word_wrap || m_multiline) ? &m_broken_text[i] + : &Text; + start_pos = (m_word_wrap || m_multiline) + ? m_broken_text_positions[i] + : 0; break; } } @@ -996,7 +1074,8 @@ s32 GUIEditBoxWithScrollBar::getCursorPos(s32 x, s32 y) if (!txt_line) return 0; - s32 idx = font->getCharacterFromPos(txt_line->c_str(), x - m_current_text_rect.UpperLeftCorner.X); + s32 idx = font->getCharacterFromPos( + txt_line->c_str(), x - m_current_text_rect.UpperLeftCorner.X); // click was on or left of the line if (idx != -1) @@ -1006,7 +1085,6 @@ s32 GUIEditBoxWithScrollBar::getCursorPos(s32 x, s32 y) return txt_line->size() + start_pos; } - //! Breaks the single text line. void GUIEditBoxWithScrollBar::breakText() { @@ -1016,7 +1094,7 @@ void GUIEditBoxWithScrollBar::breakText() m_broken_text.clear(); // need to reallocate :/ m_broken_text_positions.clear(); - IGUIFont* font = getActiveFont(); + IGUIFont *font = getActiveFont(); if (!font) return; @@ -1040,9 +1118,11 @@ void GUIEditBoxWithScrollBar::breakText() line_break = true; c = 0; if (Text[i + 1] == L'\n') { // Windows breaks - // TODO: I (Michael) think that we shouldn't change the text given by the user for whatever reason. - // Instead rework the cursor positioning to be able to handle this (but not in stable release - // branch as users might already expect this behavior). + // TODO: I (Michael) think that we shouldn't change the + // text given by the user for whatever reason. Instead + // rework the cursor positioning to be able to handle this + // (but not in stable release branch as users might + // already expect this behavior). Text.erase(i + 1); --size; if (m_cursor_pos > i) @@ -1060,11 +1140,13 @@ void GUIEditBoxWithScrollBar::breakText() if (c == L' ' || c == 0 || i == (size - 1)) { // here comes the next whitespace, look if // we can break the last word to the next line - // We also break whitespace, otherwise cursor would vanish beside the right border. + // We also break whitespace, otherwise cursor would vanish beside + // the right border. s32 whitelgth = font->getDimension(whitespace.c_str()).Width; s32 worldlgth = font->getDimension(word.c_str()).Width; - if (m_word_wrap && length + worldlgth + whitelgth > el_width && line.size() > 0) { + if (m_word_wrap && length + worldlgth + whitelgth > el_width && + line.size() > 0) { // break to next line length = worldlgth; m_broken_text.push_back(line); @@ -1081,7 +1163,6 @@ void GUIEditBoxWithScrollBar::breakText() word = L""; whitespace = L""; - if (c) whitespace += c; @@ -1121,7 +1202,7 @@ void GUIEditBoxWithScrollBar::setTextRect(s32 line) if (line < 0) return; - IGUIFont* font = getActiveFont(); + IGUIFont *font = getActiveFont(); if (!font) return; @@ -1141,8 +1222,10 @@ void GUIEditBoxWithScrollBar::setTextRect(s32 line) switch (m_halign) { case EGUIA_CENTER: // align to h centre - m_current_text_rect.UpperLeftCorner.X = (m_frame_rect.getWidth() / 2) - (d.Width / 2); - m_current_text_rect.LowerRightCorner.X = (m_frame_rect.getWidth() / 2) + (d.Width / 2); + m_current_text_rect.UpperLeftCorner.X = + (m_frame_rect.getWidth() / 2) - (d.Width / 2); + m_current_text_rect.LowerRightCorner.X = + (m_frame_rect.getWidth() / 2) + (d.Width / 2); break; case EGUIA_LOWERRIGHT: // align to right edge @@ -1153,35 +1236,36 @@ void GUIEditBoxWithScrollBar::setTextRect(s32 line) // align to left edge m_current_text_rect.UpperLeftCorner.X = 0; m_current_text_rect.LowerRightCorner.X = d.Width; - } switch (m_valign) { case EGUIA_CENTER: // align to v centre - m_current_text_rect.UpperLeftCorner.Y = - (m_frame_rect.getHeight() / 2) - (line_count*d.Height) / 2 + d.Height*line; + m_current_text_rect.UpperLeftCorner.Y = (m_frame_rect.getHeight() / 2) - + (line_count * d.Height) / 2 + + d.Height * line; break; case EGUIA_LOWERRIGHT: // align to bottom edge - m_current_text_rect.UpperLeftCorner.Y = - m_frame_rect.getHeight() - line_count*d.Height + d.Height*line; + m_current_text_rect.UpperLeftCorner.Y = m_frame_rect.getHeight() - + line_count * d.Height + + d.Height * line; break; default: // align to top edge - m_current_text_rect.UpperLeftCorner.Y = d.Height*line; + m_current_text_rect.UpperLeftCorner.Y = d.Height * line; break; } m_current_text_rect.UpperLeftCorner.X -= m_hscroll_pos; m_current_text_rect.LowerRightCorner.X -= m_hscroll_pos; m_current_text_rect.UpperLeftCorner.Y -= m_vscroll_pos; - m_current_text_rect.LowerRightCorner.Y = m_current_text_rect.UpperLeftCorner.Y + d.Height; + m_current_text_rect.LowerRightCorner.Y = + m_current_text_rect.UpperLeftCorner.Y + d.Height; m_current_text_rect += m_frame_rect.UpperLeftCorner; } - s32 GUIEditBoxWithScrollBar::getLineFromPos(s32 pos) { if (!m_word_wrap && !m_multiline) @@ -1196,31 +1280,36 @@ s32 GUIEditBoxWithScrollBar::getLineFromPos(s32 pos) return (s32)m_broken_text_positions.size() - 1; } - void GUIEditBoxWithScrollBar::inputChar(wchar_t c) { if (!isEnabled()) return; - if (c != 0) { + if (c != 0) { if (Text.size() < m_max || m_max == 0) { core::stringw s; if (m_mark_begin != m_mark_end) { // replace marked text - const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end; - const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; + const s32 realmbgn = m_mark_begin < m_mark_end + ? m_mark_begin + : m_mark_end; + const s32 realmend = m_mark_begin < m_mark_end + ? m_mark_end + : m_mark_begin; s = Text.subString(0, realmbgn); s.append(c); - s.append(Text.subString(realmend, Text.size() - realmend)); + s.append(Text.subString( + realmend, Text.size() - realmend)); Text = s; m_cursor_pos = realmbgn + 1; } else { // add new character s = Text.subString(0, m_cursor_pos); s.append(c); - s.append(Text.subString(m_cursor_pos, Text.size() - m_cursor_pos)); + s.append(Text.subString(m_cursor_pos, + Text.size() - m_cursor_pos)); Text = s; ++m_cursor_pos; } @@ -1240,10 +1329,10 @@ void GUIEditBoxWithScrollBar::calculateScrollPos() if (!m_autoscroll) return; - IGUISkin* skin = Environment->getSkin(); + IGUISkin *skin = Environment->getSkin(); if (!skin) return; - IGUIFont* font = m_override_font ? m_override_font : skin->getFont(); + IGUIFont *font = m_override_font ? m_override_font : skin->getFont(); if (!font) return; @@ -1254,46 +1343,59 @@ void GUIEditBoxWithScrollBar::calculateScrollPos() const bool has_broken_text = m_multiline || m_word_wrap; // Check horizonal scrolling - // NOTE: Calculations different to vertical scrolling because setTextRect interprets VAlign relative to line but HAlign not relative to row + // NOTE: Calculations different to vertical scrolling because setTextRect + // interprets VAlign relative to line but HAlign not relative to row { // get cursor position - IGUIFont* font = getActiveFont(); + IGUIFont *font = getActiveFont(); if (!font) return; // get cursor area irr::u32 cursor_width = font->getDimension(L"_").Width; - core::stringw *txt_line = has_broken_text ? &m_broken_text[curs_line] : &Text; - s32 cpos = has_broken_text ? m_cursor_pos - m_broken_text_positions[curs_line] : m_cursor_pos; // column - s32 cstart = font->getDimension(txt_line->subString(0, cpos).c_str()).Width; // pixels from text-start + core::stringw *txt_line = + has_broken_text ? &m_broken_text[curs_line] : &Text; + s32 cpos = has_broken_text ? m_cursor_pos - m_broken_text_positions + [curs_line] + : m_cursor_pos; // column + s32 cstart = font->getDimension(txt_line->subString(0, cpos).c_str()) + .Width; // pixels from text-start s32 cend = cstart + cursor_width; s32 txt_width = font->getDimension(txt_line->c_str()).Width; if (txt_width < m_frame_rect.getWidth()) { - // TODO: Needs a clean left and right gap removal depending on HAlign, similar to vertical scrolling tests for top/bottom. - // This check just fixes the case where it was most noticable (text smaller than clipping area). + // TODO: Needs a clean left and right gap removal depending on + // HAlign, similar to vertical scrolling tests for top/bottom. + // This check just fixes the case where it was most noticable + // (text smaller than clipping area). m_hscroll_pos = 0; setTextRect(curs_line); } - if (m_current_text_rect.UpperLeftCorner.X + cstart < m_frame_rect.UpperLeftCorner.X) { + if (m_current_text_rect.UpperLeftCorner.X + cstart < + m_frame_rect.UpperLeftCorner.X) { // cursor to the left of the clipping area - m_hscroll_pos -= m_frame_rect.UpperLeftCorner.X - (m_current_text_rect.UpperLeftCorner.X + cstart); + m_hscroll_pos -= m_frame_rect.UpperLeftCorner.X - + (m_current_text_rect.UpperLeftCorner.X + cstart); setTextRect(curs_line); - // TODO: should show more characters to the left when we're scrolling left + // TODO: should show more characters to the left when we're + // scrolling left // and the cursor reaches the border. - } else if (m_current_text_rect.UpperLeftCorner.X + cend > m_frame_rect.LowerRightCorner.X) { + } else if (m_current_text_rect.UpperLeftCorner.X + cend > + m_frame_rect.LowerRightCorner.X) { // cursor to the right of the clipping area - m_hscroll_pos += (m_current_text_rect.UpperLeftCorner.X + cend) - m_frame_rect.LowerRightCorner.X; + m_hscroll_pos += (m_current_text_rect.UpperLeftCorner.X + cend) - + m_frame_rect.LowerRightCorner.X; setTextRect(curs_line); } } // calculate vertical scrolling if (has_broken_text) { - irr::u32 line_height = font->getDimension(L"A").Height + font->getKerningHeight(); + irr::u32 line_height = font->getDimension(L"A").Height + + font->getKerningHeight(); // only up to 1 line fits? if (line_height >= (irr::u32)m_frame_rect.getHeight()) { m_vscroll_pos = 0; @@ -1317,27 +1419,39 @@ void GUIEditBoxWithScrollBar::calculateScrollPos() } else { // First 2 checks are necessary when people delete lines setTextRect(0); - if (m_current_text_rect.UpperLeftCorner.Y > m_frame_rect.UpperLeftCorner.Y && m_valign != EGUIA_LOWERRIGHT) { + if (m_current_text_rect.UpperLeftCorner.Y > + m_frame_rect.UpperLeftCorner.Y && + m_valign != EGUIA_LOWERRIGHT) { // first line is leaving a gap on top m_vscroll_pos = 0; } else if (m_valign != EGUIA_UPPERLEFT) { - u32 lastLine = m_broken_text_positions.empty() ? 0 : m_broken_text_positions.size() - 1; + u32 lastLine = m_broken_text_positions.empty() + ? 0 + : m_broken_text_positions.size() - + 1; setTextRect(lastLine); - if (m_current_text_rect.LowerRightCorner.Y < m_frame_rect.LowerRightCorner.Y) - { + if (m_current_text_rect.LowerRightCorner.Y < + m_frame_rect.LowerRightCorner.Y) { // last line is leaving a gap on bottom - m_vscroll_pos -= m_frame_rect.LowerRightCorner.Y - m_current_text_rect.LowerRightCorner.Y; + m_vscroll_pos -= m_frame_rect.LowerRightCorner.Y - + m_current_text_rect + .LowerRightCorner + .Y; } } setTextRect(curs_line); - if (m_current_text_rect.UpperLeftCorner.Y < m_frame_rect.UpperLeftCorner.Y) { + if (m_current_text_rect.UpperLeftCorner.Y < + m_frame_rect.UpperLeftCorner.Y) { // text above valid area - m_vscroll_pos -= m_frame_rect.UpperLeftCorner.Y - m_current_text_rect.UpperLeftCorner.Y; + m_vscroll_pos -= m_frame_rect.UpperLeftCorner.Y - + m_current_text_rect.UpperLeftCorner.Y; setTextRect(curs_line); - } else if (m_current_text_rect.LowerRightCorner.Y > m_frame_rect.LowerRightCorner.Y){ + } else if (m_current_text_rect.LowerRightCorner.Y > + m_frame_rect.LowerRightCorner.Y) { // text below valid area - m_vscroll_pos += m_current_text_rect.LowerRightCorner.Y - m_frame_rect.LowerRightCorner.Y; + m_vscroll_pos += m_current_text_rect.LowerRightCorner.Y - + m_frame_rect.LowerRightCorner.Y; setTextRect(curs_line); } } @@ -1352,15 +1466,16 @@ void GUIEditBoxWithScrollBar::calculateFrameRect() { m_frame_rect = AbsoluteRect; - IGUISkin *skin = 0; if (Environment) skin = Environment->getSkin(); if (m_border && skin) { m_frame_rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; m_frame_rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; - m_frame_rect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; - m_frame_rect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; + m_frame_rect.LowerRightCorner.X -= + skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; + m_frame_rect.LowerRightCorner.Y -= + skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; } updateVScrollBar(); @@ -1403,8 +1518,8 @@ 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); + m_vscrollbar = new GUIScrollBar( + Environment, getParent(), -1, scrollbarrect, false, true); m_vscrollbar->setVisible(false); m_vscrollbar->setSmallStep(1); @@ -1436,7 +1551,7 @@ void GUIEditBoxWithScrollBar::updateVScrollBar() } // check if a vertical scrollbar is needed ? - if (getTextDimension().Height > (u32) m_frame_rect.getHeight()) { + if (getTextDimension().Height > (u32)m_frame_rect.getHeight()) { m_frame_rect.LowerRightCorner.X -= m_scrollbar_width; s32 scrollymax = getTextDimension().Height - m_frame_rect.getHeight(); @@ -1449,8 +1564,7 @@ void GUIEditBoxWithScrollBar::updateVScrollBar() m_vscrollbar->setVisible(true); } } else { - if (m_vscrollbar->isVisible()) - { + if (m_vscrollbar->isVisible()) { m_vscrollbar->setVisible(false); m_vscroll_pos = 0; m_vscrollbar->setPos(0); @@ -1458,7 +1572,6 @@ void GUIEditBoxWithScrollBar::updateVScrollBar() m_vscrollbar->setPageSize(s32(getTextDimension().Height)); } } - } //! set true if this editbox is writable @@ -1475,7 +1588,8 @@ void GUIEditBoxWithScrollBar::setBackgroundColor(const video::SColor &bg_color) } //! Writes attributes of the element. -void GUIEditBoxWithScrollBar::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options = 0) const +void GUIEditBoxWithScrollBar::serializeAttributes( + io::IAttributes *out, io::SAttributeReadWriteOptions *options = 0) const { // IGUIEditBox::serializeAttributes(out,options); @@ -1499,9 +1613,9 @@ void GUIEditBoxWithScrollBar::serializeAttributes(io::IAttributes* out, io::SAtt IGUIEditBox::serializeAttributes(out, options); } - //! Reads attributes of the element -void GUIEditBoxWithScrollBar::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options = 0) +void GUIEditBoxWithScrollBar::deserializeAttributes( + io::IAttributes *in, io::SAttributeReadWriteOptions *options = 0) { IGUIEditBox::deserializeAttributes(in, options); @@ -1520,16 +1634,34 @@ void GUIEditBoxWithScrollBar::deserializeAttributes(io::IAttributes* in, io::SAt else setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]); - setTextAlignment((EGUI_ALIGNMENT)in->getAttributeAsEnumeration("HTextAlign", GUIAlignmentNames), - (EGUI_ALIGNMENT)in->getAttributeAsEnumeration("VTextAlign", GUIAlignmentNames)); + setTextAlignment((EGUI_ALIGNMENT)in->getAttributeAsEnumeration( + "HTextAlign", GUIAlignmentNames), + (EGUI_ALIGNMENT)in->getAttributeAsEnumeration( + "VTextAlign", GUIAlignmentNames)); // setOverrideFont(in->getAttributeAsFont("OverrideFont")); setWritable(in->getAttributeAsBool("Writable")); } -bool GUIEditBoxWithScrollBar::isDrawBackgroundEnabled() const { return false; } -bool GUIEditBoxWithScrollBar::isDrawBorderEnabled() const { return false; } -void GUIEditBoxWithScrollBar::setCursorChar(const wchar_t cursorChar) { } -wchar_t GUIEditBoxWithScrollBar::getCursorChar() const { return '|'; } -void GUIEditBoxWithScrollBar::setCursorBlinkTime(irr::u32 timeMs) { } -irr::u32 GUIEditBoxWithScrollBar::getCursorBlinkTime() const { return 500; } +bool GUIEditBoxWithScrollBar::isDrawBackgroundEnabled() const +{ + return false; +} +bool GUIEditBoxWithScrollBar::isDrawBorderEnabled() const +{ + return false; +} +void GUIEditBoxWithScrollBar::setCursorChar(const wchar_t cursorChar) +{ +} +wchar_t GUIEditBoxWithScrollBar::getCursorChar() const +{ + return '|'; +} +void GUIEditBoxWithScrollBar::setCursorBlinkTime(irr::u32 timeMs) +{ +} +irr::u32 GUIEditBoxWithScrollBar::getCursorBlinkTime() const +{ + return 500; +} diff --git a/src/gui/guiEditBoxWithScrollbar.h b/src/gui/guiEditBoxWithScrollbar.h index 77538e2f7..ff98fe4cb 100644 --- a/src/gui/guiEditBoxWithScrollbar.h +++ b/src/gui/guiEditBoxWithScrollbar.h @@ -16,26 +16,26 @@ using namespace irr::gui; class GUIEditBoxWithScrollBar : public IGUIEditBox { 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); + 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); //! destructor virtual ~GUIEditBoxWithScrollBar(); //! Sets another skin independent font. - virtual void setOverrideFont(IGUIFont* font = 0); + virtual void setOverrideFont(IGUIFont *font = 0); //! Gets the override font (if any) /** \return The override font (may be 0) */ - virtual IGUIFont* getOverrideFont() const; + virtual IGUIFont *getOverrideFont() const; //! Get the font which is used right now for drawing /** Currently this is the override font when one is set and the font of the active skin otherwise */ - virtual IGUIFont* getActiveFont() const; + virtual IGUIFont *getActiveFont() const; //! Sets another color for the text. virtual void setOverrideColor(video::SColor color); @@ -74,7 +74,8 @@ public: virtual bool isMultiLineEnabled() const; //! Enables or disables automatic scrolling with cursor position - //! \param enable: If set to true, the text will move around with the cursor position + //! \param enable: If set to true, the text will move around with the cursor + //! position virtual void setAutoScroll(bool enable); //! Checks to see if automatic scrolling is enabled @@ -89,13 +90,13 @@ public: virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical); //! called if an event happened. - virtual bool OnEvent(const SEvent& event); + virtual bool OnEvent(const SEvent &event); //! draws the element and its children virtual void draw(); //! Sets the new caption of this element. - virtual void setText(const wchar_t* text); + virtual void setText(const wchar_t *text); //! Sets the maximum amount of characters which may be entered in the box. //! \param max: Maximum amount of characters. If 0, the character amount is @@ -123,10 +124,12 @@ public: virtual void setBackgroundColor(const video::SColor &bg_color); //! Writes attributes of the element. - virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const; + virtual void serializeAttributes(io::IAttributes *out, + io::SAttributeReadWriteOptions *options) const; //! Reads attributes of the element - virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options); + virtual void deserializeAttributes( + io::IAttributes *in, io::SAttributeReadWriteOptions *options); virtual bool isDrawBackgroundEnabled() const; virtual bool isDrawBorderEnabled() const; @@ -157,8 +160,8 @@ protected: //! update the vertical scrollBar (visibilty & position) void updateVScrollBar(); - bool processKey(const SEvent& event); - bool processMouse(const SEvent& event); + bool processKey(const SEvent &event); + bool processMouse(const SEvent &event); s32 getCursorPos(s32 x, s32 y); bool m_mouse_marking; @@ -170,7 +173,7 @@ protected: video::SColor m_override_color; gui::IGUIFont *m_override_font, *m_last_break_font; - IOSOperator* m_operator; + IOSOperator *m_operator; u32 m_blink_start_time; s32 m_cursor_pos; @@ -194,6 +197,4 @@ protected: video::SColor m_bg_color; }; - #endif // GUIEDITBOXWITHSCROLLBAR_HEADER - diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index b40707d01..2e1bc7fed 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -43,7 +43,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/tile.h" #endif - /******************************************************************************/ void TextDestGuiEngine::gotText(const StringMap &fields) { @@ -99,84 +98,72 @@ video::ITexture *MenuTextureSource::getTexture(const std::string &name, u32 *id) /** MenuMusicFetcher */ /******************************************************************************/ void MenuMusicFetcher::fetchSounds(const std::string &name, - std::set<std::string> &dst_paths, - std::set<std::string> &dst_datas) + std::set<std::string> &dst_paths, std::set<std::string> &dst_datas) { - if(m_fetched.count(name)) + if (m_fetched.count(name)) return; m_fetched.insert(name); std::string base; base = porting::path_share + DIR_DELIM + "sounds"; dst_paths.insert(base + DIR_DELIM + name + ".ogg"); int i; - for(i=0; i<10; i++) - dst_paths.insert(base + DIR_DELIM + name + "."+itos(i)+".ogg"); + for (i = 0; i < 10; i++) + dst_paths.insert(base + DIR_DELIM + name + "." + itos(i) + ".ogg"); base = porting::path_user + DIR_DELIM + "sounds"; dst_paths.insert(base + DIR_DELIM + name + ".ogg"); - for(i=0; i<10; i++) - dst_paths.insert(base + DIR_DELIM + name + "."+itos(i)+".ogg"); + for (i = 0; i < 10; i++) + dst_paths.insert(base + DIR_DELIM + name + "." + itos(i) + ".ogg"); } /******************************************************************************/ /** GUIEngine */ /******************************************************************************/ -GUIEngine::GUIEngine(JoystickController *joystick, - gui::IGUIElement *parent, - IMenuManager *menumgr, - MainMenuData *data, - bool &kill) : - m_parent(parent), - m_menumanager(menumgr), - m_smgr(RenderingEngine::get_scene_manager()), - m_data(data), - m_kill(kill) +GUIEngine::GUIEngine(JoystickController *joystick, gui::IGUIElement *parent, + IMenuManager *menumgr, MainMenuData *data, bool &kill) : + m_parent(parent), + m_menumanager(menumgr), m_smgr(RenderingEngine::get_scene_manager()), + m_data(data), m_kill(kill) { - //initialize texture pointers + // initialize texture pointers for (image_definition &texture : m_textures) { texture.texture = NULL; } // is deleted by guiformspec! m_buttonhandler = new TextDestGuiEngine(this); - //create texture source + // create texture source m_texture_source = new MenuTextureSource(RenderingEngine::get_video_driver()); - //create soundmanager + // create soundmanager MenuMusicFetcher soundfetcher; #if USE_SOUND if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get()) - m_sound_manager = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher); + m_sound_manager = createOpenALSoundManager( + g_sound_manager_singleton.get(), &soundfetcher); #endif if (!m_sound_manager) m_sound_manager = &dummySoundManager; - //create topleft header + // create topleft header m_toplefttext = L""; core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()), - g_fontengine->getTextHeight()); + g_fontengine->getTextHeight()); rect += v2s32(4, 0); m_irr_toplefttext = gui::StaticText::add(RenderingEngine::get_gui_env(), m_toplefttext, rect, false, true, 0, -1); - //create formspecsource + // create formspecsource m_formspecgui = new FormspecFormSource(""); /* Create menu */ - m_menu = new GUIFormSpecMenu(joystick, - m_parent, - -1, - m_menumanager, - NULL /* &client */, - m_texture_source, - m_formspecgui, - m_buttonhandler, - "", - false); + m_menu = new GUIFormSpecMenu(joystick, m_parent, -1, m_menumanager, + NULL /* &client */, m_texture_source, m_formspecgui, + m_buttonhandler, "", false); m_menu->allowClose(false); - m_menu->lockSize(true,v2u32(800,600)); + m_menu->lockSize(true, v2u32(800, 600)); // Initialize scripting @@ -210,18 +197,20 @@ bool GUIEngine::loadMainMenuScript() // Set main menu path (for core.get_mainmenu_path()) m_scriptdir = g_settings->get("main_menu_path"); if (m_scriptdir.empty()) { - m_scriptdir = porting::path_share + DIR_DELIM + "builtin" + DIR_DELIM + "mainmenu"; + m_scriptdir = porting::path_share + DIR_DELIM + "builtin" + DIR_DELIM + + "mainmenu"; } // Load builtin (which will load the main menu script) - std::string script = porting::path_share + DIR_DELIM "builtin" + DIR_DELIM "init.lua"; + std::string script = + porting::path_share + DIR_DELIM "builtin" + DIR_DELIM "init.lua"; try { m_script->loadScript(script); // Menu script loaded return true; } catch (const ModError &e) { - errorstream << "GUIEngine: execution of menu script failed: " - << e.what() << std::endl; + errorstream << "GUIEngine: execution of menu script failed: " << e.what() + << std::endl; } return false; @@ -238,8 +227,8 @@ void GUIEngine::run() unsigned int text_height = g_fontengine->getTextHeight(); - irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"), - g_settings->getU16("screen_h")); + irr::core::dimension2d<u32> previous_screen_size( + g_settings->getU16("screen_w"), g_settings->getU16("screen_h")); static const video::SColor sky_color(255, 140, 186, 250); @@ -262,19 +251,20 @@ void GUIEngine::run() while (RenderingEngine::run() && (!m_startgame) && (!m_kill)) { const irr::core::dimension2d<u32> ¤t_screen_size = - RenderingEngine::get_video_driver()->getScreenSize(); + RenderingEngine::get_video_driver()->getScreenSize(); // Verify if window size has changed and save it if it's the case // Ensure evaluating settings->getBool after verifying screensize // First condition is cheaper if (previous_screen_size != current_screen_size && - current_screen_size != irr::core::dimension2d<u32>(0,0) && + current_screen_size != + irr::core::dimension2d<u32>(0, 0) && g_settings->getBool("autosave_screensize")) { g_settings->setU16("screen_w", current_screen_size.Width); g_settings->setU16("screen_h", current_screen_size.Height); previous_screen_size = current_screen_size; } - //check if we need to update the "upper left corner"-text + // check if we need to update the "upper left corner"-text if (text_height != g_fontengine->getTextHeight()) { updateTopLeftTextSize(); text_height = g_fontengine->getTextHeight(); @@ -282,12 +272,10 @@ void GUIEngine::run() driver->beginScene(true, true, sky_color); - if (m_clouds_enabled) - { + if (m_clouds_enabled) { cloudPreProcess(); drawOverlay(driver); - } - else + } else drawBackground(driver); drawHeader(driver); @@ -313,20 +301,21 @@ void GUIEngine::run() /******************************************************************************/ GUIEngine::~GUIEngine() { - if (m_sound_manager != &dummySoundManager){ + if (m_sound_manager != &dummySoundManager) { delete m_sound_manager; m_sound_manager = NULL; } - infostream<<"GUIEngine: Deinitializing scripting"<<std::endl; + infostream << "GUIEngine: Deinitializing scripting" << std::endl; delete m_script; m_irr_toplefttext->setText(L""); - //clean up texture pointers + // clean up texture pointers for (image_definition &texture : m_textures) { if (texture.texture) - RenderingEngine::get_video_driver()->removeTexture(texture.texture); + RenderingEngine::get_video_driver()->removeTexture( + texture.texture); } delete m_texture_source; @@ -340,10 +329,9 @@ void GUIEngine::cloudInit() { m_cloud.clouds = new Clouds(m_smgr, -1, rand()); m_cloud.clouds->setHeight(100.0f); - m_cloud.clouds->update(v3f(0, 0, 0), video::SColor(255,240,240,255)); + m_cloud.clouds->update(v3f(0, 0, 0), video::SColor(255, 240, 240, 255)); - m_cloud.camera = m_smgr->addCameraSceneNode(0, - v3f(0,0,0), v3f(0, 60, 100)); + m_cloud.camera = m_smgr->addCameraSceneNode(0, v3f(0, 0, 0), v3f(0, 60, 100)); m_cloud.camera->setFarValue(10000); m_cloud.lasttime = RenderingEngine::get_timer_time(); @@ -354,14 +342,14 @@ void GUIEngine::cloudPreProcess() { u32 time = RenderingEngine::get_timer_time(); - if(time > m_cloud.lasttime) + if (time > m_cloud.lasttime) m_cloud.dtime = (time - m_cloud.lasttime) / 1000.0; else m_cloud.dtime = 0; m_cloud.lasttime = time; - m_cloud.clouds->step(m_cloud.dtime*3); + m_cloud.clouds->step(m_cloud.dtime * 3); m_cloud.clouds->render(); m_smgr->drawAll(); } @@ -375,13 +363,13 @@ void GUIEngine::cloudPostProcess() // not using getRealTime is necessary for wine u32 time = RenderingEngine::get_timer_time(); - if(time > m_cloud.lasttime) + if (time > m_cloud.lasttime) busytime_u32 = time - m_cloud.lasttime; else busytime_u32 = 0; // FPS limiter - u32 frametime_min = 1000./fps_max; + u32 frametime_min = 1000. / fps_max; if (busytime_u32 < frametime_min) { u32 sleeptime = frametime_min - busytime_u32; @@ -397,17 +385,16 @@ void GUIEngine::setFormspecPrepend(const std::string &fs) } } - /******************************************************************************/ void GUIEngine::drawBackground(video::IVideoDriver *driver) { v2u32 screensize = driver->getScreenSize(); - video::ITexture* texture = m_textures[TEX_LAYER_BACKGROUND].texture; + video::ITexture *texture = m_textures[TEX_LAYER_BACKGROUND].texture; /* If no texture, draw background of solid color */ - if(!texture){ - video::SColor color(255,80,58,37); + if (!texture) { + video::SColor color(255, 80, 58, 37); core::rect<s32> rect(0, 0, screensize.X, screensize.Y); driver->draw2DRectangle(color, rect, NULL); return; @@ -415,19 +402,19 @@ void GUIEngine::drawBackground(video::IVideoDriver *driver) v2u32 sourcesize = texture->getOriginalSize(); - if (m_textures[TEX_LAYER_BACKGROUND].tile) - { - v2u32 tilesize( - MYMAX(sourcesize.X,m_textures[TEX_LAYER_BACKGROUND].minsize), - MYMAX(sourcesize.Y,m_textures[TEX_LAYER_BACKGROUND].minsize)); - for (unsigned int x = 0; x < screensize.X; x += tilesize.X ) - { - for (unsigned int y = 0; y < screensize.Y; y += tilesize.Y ) - { + if (m_textures[TEX_LAYER_BACKGROUND].tile) { + v2u32 tilesize(MYMAX(sourcesize.X, + m_textures[TEX_LAYER_BACKGROUND].minsize), + MYMAX(sourcesize.Y, m_textures[TEX_LAYER_BACKGROUND] + .minsize)); + for (unsigned int x = 0; x < screensize.X; x += tilesize.X) { + for (unsigned int y = 0; y < screensize.Y; y += tilesize.Y) { draw2DImageFilterScaled(driver, texture, - core::rect<s32>(x, y, x+tilesize.X, y+tilesize.Y), - core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y), - NULL, NULL, true); + core::rect<s32>(x, y, x + tilesize.X, + y + tilesize.Y), + core::rect<s32>(0, 0, sourcesize.X, + sourcesize.Y), + NULL, NULL, true); } } return; @@ -435,9 +422,9 @@ void GUIEngine::drawBackground(video::IVideoDriver *driver) /* Draw background texture */ draw2DImageFilterScaled(driver, texture, - core::rect<s32>(0, 0, screensize.X, screensize.Y), - core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y), - NULL, NULL, true); + core::rect<s32>(0, 0, screensize.X, screensize.Y), + core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y), NULL, NULL, + true); } /******************************************************************************/ @@ -445,18 +432,18 @@ void GUIEngine::drawOverlay(video::IVideoDriver *driver) { v2u32 screensize = driver->getScreenSize(); - video::ITexture* texture = m_textures[TEX_LAYER_OVERLAY].texture; + video::ITexture *texture = m_textures[TEX_LAYER_OVERLAY].texture; /* If no texture, draw nothing */ - if(!texture) + if (!texture) return; /* Draw background texture */ v2u32 sourcesize = texture->getOriginalSize(); draw2DImageFilterScaled(driver, texture, - core::rect<s32>(0, 0, screensize.X, screensize.Y), - core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y), - NULL, NULL, true); + core::rect<s32>(0, 0, screensize.X, screensize.Y), + core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y), NULL, NULL, + true); } /******************************************************************************/ @@ -464,32 +451,33 @@ void GUIEngine::drawHeader(video::IVideoDriver *driver) { core::dimension2d<u32> screensize = driver->getScreenSize(); - video::ITexture* texture = m_textures[TEX_LAYER_HEADER].texture; + video::ITexture *texture = m_textures[TEX_LAYER_HEADER].texture; /* If no texture, draw nothing */ - if(!texture) + if (!texture) return; f32 mult = (((f32)screensize.Width / 2.0)) / - ((f32)texture->getOriginalSize().Width); + ((f32)texture->getOriginalSize().Width); v2s32 splashsize(((f32)texture->getOriginalSize().Width) * mult, ((f32)texture->getOriginalSize().Height) * mult); // Don't draw the header if there isn't enough room - s32 free_space = (((s32)screensize.Height)-320)/2; + s32 free_space = (((s32)screensize.Height) - 320) / 2; if (free_space > splashsize.Y) { core::rect<s32> splashrect(0, 0, splashsize.X, splashsize.Y); - splashrect += v2s32((screensize.Width/2)-(splashsize.X/2), - ((free_space/2)-splashsize.Y/2)+10); + splashrect += v2s32((screensize.Width / 2) - (splashsize.X / 2), + ((free_space / 2) - splashsize.Y / 2) + 10); - video::SColor bgcolor(255,50,50,50); + video::SColor bgcolor(255, 50, 50, 50); - draw2DImageFilterScaled(driver, texture, splashrect, - core::rect<s32>(core::position2d<s32>(0,0), - core::dimension2di(texture->getOriginalSize())), - NULL, NULL, true); + draw2DImageFilterScaled(driver, texture, splashrect, + core::rect<s32>(core::position2d<s32>(0, 0), + core::dimension2di( + texture->getOriginalSize())), + NULL, NULL, true); } } @@ -498,30 +486,30 @@ void GUIEngine::drawFooter(video::IVideoDriver *driver) { core::dimension2d<u32> screensize = driver->getScreenSize(); - video::ITexture* texture = m_textures[TEX_LAYER_FOOTER].texture; + video::ITexture *texture = m_textures[TEX_LAYER_FOOTER].texture; /* If no texture, draw nothing */ - if(!texture) + if (!texture) return; - f32 mult = (((f32)screensize.Width)) / - ((f32)texture->getOriginalSize().Width); + f32 mult = (((f32)screensize.Width)) / ((f32)texture->getOriginalSize().Width); v2s32 footersize(((f32)texture->getOriginalSize().Width) * mult, ((f32)texture->getOriginalSize().Height) * mult); // Don't draw the footer if there isn't enough room - s32 free_space = (((s32)screensize.Height)-320)/2; + s32 free_space = (((s32)screensize.Height) - 320) / 2; if (free_space > footersize.Y) { - core::rect<s32> rect(0,0,footersize.X,footersize.Y); - rect += v2s32(screensize.Width/2,screensize.Height-footersize.Y); - rect -= v2s32(footersize.X/2, 0); + core::rect<s32> rect(0, 0, footersize.X, footersize.Y); + rect += v2s32(screensize.Width / 2, screensize.Height - footersize.Y); + rect -= v2s32(footersize.X / 2, 0); draw2DImageFilterScaled(driver, texture, rect, - core::rect<s32>(core::position2d<s32>(0,0), - core::dimension2di(texture->getOriginalSize())), - NULL, NULL, true); + core::rect<s32>(core::position2d<s32>(0, 0), + core::dimension2di( + texture->getOriginalSize())), + NULL, NULL, true); } } @@ -541,7 +529,7 @@ bool GUIEngine::setTexture(texture_layer layer, const std::string &texturepath, } m_textures[layer].texture = driver->getTexture(texturepath.c_str()); - m_textures[layer].tile = tile_image; + m_textures[layer].tile = tile_image; m_textures[layer].minsize = minsize; if (!m_textures[layer].texture) { @@ -592,7 +580,7 @@ void GUIEngine::setTopleftText(const std::string &text) void GUIEngine::updateTopLeftTextSize() { core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()), - g_fontengine->getTextHeight()); + g_fontengine->getTextHeight()); rect += v2s32(4, 0); m_irr_toplefttext->remove(); @@ -614,8 +602,8 @@ void GUIEngine::stopSound(s32 handle) } /******************************************************************************/ -unsigned int GUIEngine::queueAsync(const std::string &serialized_func, - const std::string &serialized_params) +unsigned int GUIEngine::queueAsync( + const std::string &serialized_func, const std::string &serialized_params) { return m_script->queueAsync(serialized_func, serialized_params); } diff --git a/src/gui/guiEngine.h b/src/gui/guiEngine.h index f9ad0fb0a..b94bbef12 100644 --- a/src/gui/guiEngine.h +++ b/src/gui/guiEngine.h @@ -32,7 +32,8 @@ with this program; if not, write to the Free Software Foundation, Inc., /* Typedefs and macros */ /******************************************************************************/ /** texture layer ids */ -typedef enum { +typedef enum +{ TEX_LAYER_BACKGROUND = 0, TEX_LAYER_OVERLAY, TEX_LAYER_HEADER, @@ -40,10 +41,11 @@ typedef enum { TEX_LAYER_MAX } texture_layer; -typedef struct { +typedef struct +{ video::ITexture *texture = nullptr; - bool tile; - unsigned int minsize; + bool tile; + unsigned int minsize; } image_definition; /******************************************************************************/ @@ -66,7 +68,7 @@ public: * default constructor * @param engine the engine data is transmitted for further processing */ - TextDestGuiEngine(GUIEngine* engine) : m_engine(engine) {}; + TextDestGuiEngine(GUIEngine *engine) : m_engine(engine){}; /** * receive fields transmitted by guiFormSpecMenu @@ -93,7 +95,7 @@ public: * default constructor * @param driver the video driver to load textures from */ - MenuTextureSource(video::IVideoDriver *driver) : m_driver(driver) {}; + MenuTextureSource(video::IVideoDriver *driver) : m_driver(driver){}; /** * destructor, removes all loaded textures @@ -115,7 +117,7 @@ private: }; /** GUIEngine specific implementation of OnDemandSoundFetcher */ -class MenuMusicFetcher: public OnDemandSoundFetcher +class MenuMusicFetcher : public OnDemandSoundFetcher { public: /** @@ -124,8 +126,7 @@ public: * @param dst_paths receives possible paths to sound files * @param dst_datas receives binary sound data (not used here) */ - void fetchSounds(const std::string &name, - std::set<std::string> &dst_paths, + void fetchSounds(const std::string &name, std::set<std::string> &dst_paths, std::set<std::string> &dst_datas); private: @@ -134,7 +135,8 @@ private: }; /** implementation of main menu based uppon formspecs */ -class GUIEngine { +class GUIEngine +{ /** grant ModApiMainMenu access to private members */ friend class ModApiMainMenu; friend class ModApiSound; @@ -148,11 +150,8 @@ public: * @param smgr scene manager to add scene elements to * @param data struct to transfer data to main game handling */ - GUIEngine(JoystickController *joystick, - gui::IGUIElement *parent, - IMenuManager *menumgr, - MainMenuData *data, - bool &kill); + GUIEngine(JoystickController *joystick, gui::IGUIElement *parent, + IMenuManager *menumgr, MainMenuData *data, bool &kill); /** default destructor */ virtual ~GUIEngine(); @@ -160,25 +159,18 @@ public: /** * return MainMenuScripting interface */ - MainMenuScripting *getScriptIface() - { - return m_script; - } + MainMenuScripting *getScriptIface() { return m_script; } /** * return dir of current menuscript */ - std::string getScriptDir() - { - return m_scriptdir; - } + std::string getScriptDir() { return m_scriptdir; } /** pass async callback to scriptengine **/ unsigned int queueAsync(const std::string &serialized_fct, const std::string &serialized_params); private: - /** find and run the main menu script */ bool loadMainMenuScript(); @@ -189,36 +181,36 @@ private: void updateTopLeftTextSize(); /** parent gui element */ - gui::IGUIElement *m_parent = nullptr; + gui::IGUIElement *m_parent = nullptr; /** manager to add menus to */ - IMenuManager *m_menumanager = nullptr; + IMenuManager *m_menumanager = nullptr; /** scene manager to add scene elements to */ - scene::ISceneManager *m_smgr = nullptr; + scene::ISceneManager *m_smgr = nullptr; /** pointer to data beeing transfered back to main game handling */ - MainMenuData *m_data = nullptr; + MainMenuData *m_data = nullptr; /** pointer to texture source */ - ISimpleTextureSource *m_texture_source = nullptr; + ISimpleTextureSource *m_texture_source = nullptr; /** pointer to soundmanager*/ - ISoundManager *m_sound_manager = nullptr; + ISoundManager *m_sound_manager = nullptr; /** representation of form source to be used in mainmenu formspec */ - FormspecFormSource *m_formspecgui = nullptr; + FormspecFormSource *m_formspecgui = nullptr; /** formspec input receiver */ - TextDestGuiEngine *m_buttonhandler = nullptr; + TextDestGuiEngine *m_buttonhandler = nullptr; /** the formspec menu */ - GUIFormSpecMenu *m_menu = nullptr; + GUIFormSpecMenu *m_menu = nullptr; /** reference to kill variable managed by SIGINT handler */ - bool &m_kill; + bool &m_kill; /** variable used to abort menu and return back to main game handling */ - bool m_startgame = false; + bool m_startgame = false; /** scripting interface */ - MainMenuScripting *m_script = nullptr; + MainMenuScripting *m_script = nullptr; /** script basefolder */ - std::string m_scriptdir = ""; + std::string m_scriptdir = ""; void setFormspecPrepend(const std::string &fs); @@ -280,11 +272,12 @@ private: void cloudPostProcess(); /** internam data required for drawing clouds */ - struct clouddata { + struct clouddata + { /** delta time since last cloud processing */ - f32 dtime; + f32 dtime; /** absolute time of last cloud processing */ - u32 lasttime; + u32 lasttime; /** pointer to cloud class */ Clouds *clouds = nullptr; /** camera required for drawing clouds */ @@ -292,14 +285,12 @@ private: }; /** is drawing of clouds enabled atm */ - bool m_clouds_enabled = true; + bool m_clouds_enabled = true; /** data used to draw clouds */ - clouddata m_cloud; + clouddata m_cloud; /** start playing a sound and return handle */ s32 playSound(const SimpleSoundSpec &spec, bool looped); /** stop playing a sound started with playSound() */ void stopSound(s32 handle); - - }; diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 601c5c18e..5013ffe14 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -17,7 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - #include <cstdlib> #include <algorithm> #include <iterator> @@ -38,7 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/renderingengine.h" #include "log.h" #include "client/tile.h" // ITextureSource -#include "client/hud.h" // drawItemStack +#include "client/hud.h" // drawItemStack #include "filesys.h" #include "gettime.h" #include "gettext.h" @@ -66,18 +65,18 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "intlGUIEditBox.h" #include "guiHyperText.h" -#define MY_CHECKPOS(a,b) \ - if (v_pos.size() != 2) { \ - errorstream<< "Invalid pos for element " << a << "specified: \"" \ - << parts[b] << "\"" << std::endl; \ - return; \ +#define MY_CHECKPOS(a, b) \ + if (v_pos.size() != 2) { \ + errorstream << "Invalid pos for element " << a << "specified: \"" \ + << parts[b] << "\"" << std::endl; \ + return; \ } -#define MY_CHECKGEOM(a,b) \ - if (v_geom.size() != 2) { \ - errorstream<< "Invalid geometry for element " << a << \ - "specified: \"" << parts[b] << "\"" << std::endl; \ - return; \ +#define MY_CHECKGEOM(a, b) \ + if (v_geom.size() != 2) { \ + errorstream << "Invalid geometry for element " << a << "specified: \"" \ + << parts[b] << "\"" << std::endl; \ + return; \ } /* GUIFormSpecMenu @@ -89,21 +88,18 @@ static unsigned int font_line_height(gui::IGUIFont *font) inline u32 clamp_u8(s32 value) { - return (u32) MYMIN(MYMAX(value, 0), 255); + return (u32)MYMIN(MYMAX(value, 0), 255); } -GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick, - gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, - Client *client, ISimpleTextureSource *tsrc, IFormSource *fsrc, TextDest *tdst, - const std::string &formspecPrepend, bool remap_dbl_click): - GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr, remap_dbl_click), - m_invmgr(client), - m_tsrc(tsrc), - m_client(client), - m_formspec_prepend(formspecPrepend), - m_form_src(fsrc), - m_text_dst(tdst), - m_joystick(joystick) +GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick, gui::IGUIElement *parent, + s32 id, IMenuManager *menumgr, Client *client, ISimpleTextureSource *tsrc, + IFormSource *fsrc, TextDest *tdst, const std::string &formspecPrepend, + bool remap_dbl_click) : + GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr, + remap_dbl_click), + m_invmgr(client), m_tsrc(tsrc), m_client(client), + m_formspec_prepend(formspecPrepend), m_form_src(fsrc), m_text_dst(tdst), + m_joystick(joystick) { current_keys_pending.key_down = false; current_keys_pending.key_up = false; @@ -141,12 +137,13 @@ GUIFormSpecMenu::~GUIFormSpecMenu() } void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client, - JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest, - const std::string &formspecPrepend) + JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest, + const std::string &formspecPrepend) { if (cur_formspec == nullptr) { cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr, - client, client->getTextureSource(), fs_src, txt_dest, formspecPrepend); + client, client->getTextureSource(), fs_src, txt_dest, + formspecPrepend); cur_formspec->doPause = false; /* @@ -166,7 +163,7 @@ void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client, void GUIFormSpecMenu::removeChildren() { - const core::list<gui::IGUIElement*> &children = getChildren(); + const core::list<gui::IGUIElement *> &children = getChildren(); while (!children.empty()) { (*children.getLast())->remove(); @@ -189,10 +186,10 @@ void GUIFormSpecMenu::setInitialFocus() // 5. first focusable (not statictext, not tabheader) // 6. first child element - core::list<gui::IGUIElement*> children = getChildren(); + core::list<gui::IGUIElement *> children = getChildren(); // in case "children" contains any NULL elements, remove them - for (core::list<gui::IGUIElement*>::Iterator it = children.begin(); + for (core::list<gui::IGUIElement *>::Iterator it = children.begin(); it != children.end();) { if (*it) ++it; @@ -202,8 +199,7 @@ void GUIFormSpecMenu::setInitialFocus() // 1. first empty editbox for (gui::IGUIElement *it : children) { - if (it->getType() == gui::EGUIET_EDIT_BOX - && it->getText()[0] == 0) { + if (it->getType() == gui::EGUIET_EDIT_BOX && it->getText()[0] == 0) { Environment->setFocus(it); return; } @@ -226,7 +222,7 @@ void GUIFormSpecMenu::setInitialFocus() } // 4. last button - for (core::list<gui::IGUIElement*>::Iterator it = children.getLast(); + for (core::list<gui::IGUIElement *>::Iterator it = children.getLast(); it != children.end(); --it) { if ((*it)->getType() == gui::EGUIET_BUTTON) { Environment->setFocus(*it); @@ -237,7 +233,7 @@ void GUIFormSpecMenu::setInitialFocus() // 5. first focusable (not statictext, not tabheader) for (gui::IGUIElement *it : children) { if (it->getType() != gui::EGUIET_STATIC_TEXT && - it->getType() != gui::EGUIET_TAB_CONTROL) { + it->getType() != gui::EGUIET_TAB_CONTROL) { Environment->setFocus(it); return; } @@ -250,7 +246,7 @@ void GUIFormSpecMenu::setInitialFocus() Environment->setFocus(*(children.begin())); } -GUITable* GUIFormSpecMenu::getTable(const std::string &tablename) +GUITable *GUIFormSpecMenu::getTable(const std::string &tablename) { for (auto &table : m_tables) { if (tablename == table.first.fname) @@ -259,7 +255,7 @@ GUITable* GUIFormSpecMenu::getTable(const std::string &tablename) return 0; } -std::vector<std::string>* GUIFormSpecMenu::getDropDownValues(const std::string &name) +std::vector<std::string> *GUIFormSpecMenu::getDropDownValues(const std::string &name) { for (auto &dropdown : m_dropdowns) { if (name == dropdown.first.fname) @@ -281,7 +277,7 @@ v2s32 GUIFormSpecMenu::getElementBasePos(const std::vector<std::string> *v_pos) v2s32 GUIFormSpecMenu::getRealCoordinateBasePos(const std::vector<std::string> &v_pos) { return v2s32((stof(v_pos[0]) + pos_offset.X) * imgsize.X, - (stof(v_pos[1]) + pos_offset.Y) * imgsize.Y); + (stof(v_pos[1]) + pos_offset.Y) * imgsize.Y); } v2s32 GUIFormSpecMenu::getRealCoordinateGeometry(const std::vector<std::string> &v_geom) @@ -289,15 +285,15 @@ v2s32 GUIFormSpecMenu::getRealCoordinateGeometry(const std::vector<std::string> return v2s32(stof(v_geom[0]) * imgsize.X, stof(v_geom[1]) * imgsize.Y); } -void GUIFormSpecMenu::parseSize(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseSize(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,','); + std::vector<std::string> parts = split(element, ','); if (((parts.size() == 2) || parts.size() == 3) || - ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION))) - { + ((parts.size() > 3) && + (m_formspec_version > FORMSPEC_API_VERSION))) { if (parts[1].find(';') != std::string::npos) - parts[1] = parts[1].substr(0,parts[1].find(';')); + parts[1] = parts[1].substr(0, parts[1].find(';')); data->invsize.X = MYMAX(0, stof(parts[0])); data->invsize.Y = MYMAX(0, stof(parts[1])); @@ -306,17 +302,18 @@ void GUIFormSpecMenu::parseSize(parserData* data, const std::string &element) #ifndef __ANDROID__ if (parts.size() == 3) { if (parts[2] == "true") { - lockSize(true,v2u32(800,600)); + lockSize(true, v2u32(800, 600)); } } #endif data->explicit_size = true; return; } - errorstream<< "Invalid size element (" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid size element (" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseContainer(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseContainer(parserData *data, const std::string &element) { std::vector<std::string> parts = split(element, ','); @@ -329,13 +326,16 @@ void GUIFormSpecMenu::parseContainer(parserData* data, const std::string &elemen pos_offset.Y += stof(parts[1]); return; } - errorstream<< "Invalid container start element (" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid container start element (" << parts.size() << "): '" + << element << "'" << std::endl; } -void GUIFormSpecMenu::parseContainerEnd(parserData* data) +void GUIFormSpecMenu::parseContainerEnd(parserData *data) { if (container_stack.empty()) { - errorstream<< "Invalid container end element, no matching container start element" << std::endl; + errorstream << "Invalid container end element, no matching container " + "start element" + << std::endl; } else { pos_offset = container_stack.top(); container_stack.pop(); @@ -347,13 +347,14 @@ void GUIFormSpecMenu::parseScrollContainer(parserData *data, const std::string & std::vector<std::string> parts = split(element, ';'); if (parts.size() < 4 || - (parts.size() > 5 && m_formspec_version <= FORMSPEC_API_VERSION)) { + (parts.size() > 5 && + m_formspec_version <= FORMSPEC_API_VERSION)) { errorstream << "Invalid scroll_container start element (" << parts.size() - << "): '" << element << "'" << std::endl; + << "): '" << element << "'" << std::endl; return; } - std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_pos = split(parts[0], ','); std::vector<std::string> v_geom = split(parts[1], ','); std::string scrollbar_name = parts[2]; std::string orientation = parts[3]; @@ -373,8 +374,8 @@ void GUIFormSpecMenu::parseScrollContainer(parserData *data, const std::string & scroll_factor *= -imgsize.X; else warningstream << "GUIFormSpecMenu::parseScrollContainer(): " - << "Invalid scroll_container orientation: " << orientation - << std::endl; + << "Invalid scroll_container orientation: " << orientation + << std::endl; // old parent (at first: this) // ^ is parent of clipper @@ -388,17 +389,12 @@ void GUIFormSpecMenu::parseScrollContainer(parserData *data, const std::string & data->current_parent, 0, rect_clipper); // make mover - FieldSpec spec_mover( - "", - L"", - L"", - 258 + m_fields.size() - ); + FieldSpec spec_mover("", L"", L"", 258 + m_fields.size()); core::rect<s32> rect_mover = core::rect<s32>(0, 0, geom.X, geom.Y); - GUIScrollContainer *mover = new GUIScrollContainer(Environment, - clipper, spec_mover.fid, rect_mover, orientation, scroll_factor); + GUIScrollContainer *mover = new GUIScrollContainer(Environment, clipper, + spec_mover.fid, rect_mover, orientation, scroll_factor); data->current_parent = mover; @@ -419,7 +415,7 @@ void GUIFormSpecMenu::parseScrollContainerEnd(parserData *data) if (data->current_parent == this || data->current_parent->getParent() == this || container_stack.empty()) { errorstream << "Invalid scroll_container end element, " - << "no matching scroll_container start element" << std::endl; + << "no matching scroll_container start element" << std::endl; return; } @@ -429,7 +425,7 @@ void GUIFormSpecMenu::parseScrollContainerEnd(parserData *data) // not 0,0, it is a normal container that was opened last, not a // scroll_container errorstream << "Invalid scroll_container end element, " - << "an inner container was left open" << std::endl; + << "an inner container was left open" << std::endl; return; } @@ -441,25 +437,25 @@ void GUIFormSpecMenu::parseScrollContainerEnd(parserData *data) void GUIFormSpecMenu::parseList(parserData *data, const std::string &element) { if (m_client == 0) { - warningstream<<"invalid use of 'list' with m_client==0"<<std::endl; + warningstream << "invalid use of 'list' with m_client==0" << std::endl; return; } - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if (((parts.size() == 4) || (parts.size() == 5)) || - ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION))) - { + ((parts.size() > 5) && + (m_formspec_version > FORMSPEC_API_VERSION))) { std::string location = parts[0]; std::string listname = parts[1]; - std::vector<std::string> v_pos = split(parts[2],','); - std::vector<std::string> v_geom = split(parts[3],','); + std::vector<std::string> v_pos = split(parts[2], ','); + std::vector<std::string> v_geom = split(parts[3], ','); std::string startindex; if (parts.size() == 5) startindex = parts[4]; - MY_CHECKPOS("list",2); - MY_CHECKGEOM("list",3); + MY_CHECKPOS("list", 2); + MY_CHECKGEOM("list", 3); InventoryLocation loc; @@ -477,46 +473,47 @@ void GUIFormSpecMenu::parseList(parserData *data, const std::string &element) start_i = stoi(startindex); if (geom.X < 0 || geom.Y < 0 || start_i < 0) { - errorstream << "Invalid list element: '" << element << "'" << std::endl; + errorstream << "Invalid list element: '" << element << "'" + << std::endl; return; } if (!data->explicit_size) - warningstream << "invalid use of list without a size[] element" << std::endl; + warningstream << "invalid use of list without a size[] element" + << std::endl; - FieldSpec spec( - "", - L"", - L"", - 258 + m_fields.size(), - 3 - ); + FieldSpec spec("", L"", L"", 258 + m_fields.size(), 3); - v2f32 slot_spacing = data->real_coordinates ? - v2f32(imgsize.X * 1.25f, imgsize.Y * 1.25f) : spacing; + v2f32 slot_spacing = data->real_coordinates + ? v2f32(imgsize.X * 1.25f, + imgsize.Y * 1.25f) + : spacing; v2s32 pos = data->real_coordinates ? getRealCoordinateBasePos(v_pos) - : getElementBasePos(&v_pos); + : getElementBasePos(&v_pos); core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X + (geom.X - 1) * slot_spacing.X + imgsize.X, pos.Y + (geom.Y - 1) * slot_spacing.Y + imgsize.Y); - GUIInventoryList *e = new GUIInventoryList(Environment, data->current_parent, - spec.fid, rect, m_invmgr, loc, listname, geom, start_i, imgsize, - slot_spacing, this, data->inventorylist_options, m_font); + GUIInventoryList *e = new GUIInventoryList(Environment, + data->current_parent, spec.fid, rect, m_invmgr, loc, + listname, geom, start_i, imgsize, slot_spacing, this, + data->inventorylist_options, m_font); m_inventorylists.push_back(e); m_fields.push_back(spec); return; } - errorstream<< "Invalid list element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid list element(" << parts.size() << "): '" << element << "'" + << std::endl; } void GUIFormSpecMenu::parseListRing(parserData *data, const std::string &element) { if (m_client == 0) { - errorstream << "WARNING: invalid use of 'listring' with m_client==0" << std::endl; + errorstream << "WARNING: invalid use of 'listring' with m_client==0" + << std::endl; return; } @@ -542,23 +539,25 @@ void GUIFormSpecMenu::parseListRing(parserData *data, const std::string &element // insert the last two inv list elements into the list ring const GUIInventoryList *spa = m_inventorylists[siz - 2]; const GUIInventoryList *spb = m_inventorylists[siz - 1]; - m_inventory_rings.emplace_back(spa->getInventoryloc(), spa->getListname()); - m_inventory_rings.emplace_back(spb->getInventoryloc(), spb->getListname()); + m_inventory_rings.emplace_back( + spa->getInventoryloc(), spa->getListname()); + m_inventory_rings.emplace_back( + spb->getInventoryloc(), spb->getListname()); return; } - errorstream<< "Invalid list ring element(" << parts.size() << ", " - << m_inventorylists.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid list ring element(" << parts.size() << ", " + << m_inventorylists.size() << "): '" << element << "'" << std::endl; } -void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseCheckbox(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if (((parts.size() >= 3) && (parts.size() <= 4)) || - ((parts.size() > 4) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); + ((parts.size() > 4) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); std::string name = parts[1]; std::string label = parts[2]; std::string selected; @@ -566,15 +565,17 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element if (parts.size() >= 4) selected = parts[3]; - MY_CHECKPOS("checkbox",0); + MY_CHECKPOS("checkbox", 0); bool fselected = false; if (selected == "true") fselected = true; - std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label))); - const core::dimension2d<u32> label_size = m_font->getDimension(wlabel.c_str()); + std::wstring wlabel = + translate_string(utf8_to_wide(unescape_string(label))); + const core::dimension2d<u32> label_size = + m_font->getDimension(wlabel.c_str()); s32 cb_size = Environment->getSkin()->getSize(gui::EGDS_CHECK_BOX_WIDTH); s32 y_center = (std::max(label_size.Height, (u32)cb_size) + 1) / 2; @@ -584,28 +585,19 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element if (data->real_coordinates) { pos = getRealCoordinateBasePos(v_pos); - rect = core::rect<s32>( - pos.X, - pos.Y - y_center, + rect = core::rect<s32>(pos.X, pos.Y - y_center, pos.X + label_size.Width + cb_size + 7, - pos.Y + y_center - ); + pos.Y + y_center); } else { pos = getElementBasePos(&v_pos); - rect = core::rect<s32>( - pos.X, - pos.Y + imgsize.Y / 2 - y_center, + rect = core::rect<s32>(pos.X, pos.Y + imgsize.Y / 2 - y_center, pos.X + label_size.Width + cb_size + 7, - pos.Y + imgsize.Y / 2 + y_center - ); + pos.Y + imgsize.Y / 2 + y_center); } - FieldSpec spec( - name, - wlabel, //Needed for displaying text on MSVC - wlabel, - 258+m_fields.size() - ); + FieldSpec spec(name, + wlabel, // Needed for displaying text on MSVC + wlabel, 258 + m_fields.size()); spec.ftype = f_CheckBox; @@ -624,21 +616,22 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element m_fields.push_back(spec); return; } - errorstream<< "Invalid checkbox element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid checkbox element(" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseScrollBar(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if (parts.size() >= 5) { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string name = parts[3]; std::string value = parts[4]; - MY_CHECKPOS("scrollbar",0); - MY_CHECKGEOM("scrollbar",1); + MY_CHECKPOS("scrollbar", 0); + MY_CHECKGEOM("scrollbar", 1); v2s32 pos; v2s32 dim; @@ -652,15 +645,10 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &elemen dim.Y = stof(v_geom[1]) * spacing.Y; } - core::rect<s32> rect = - core::rect<s32>(pos.X, pos.Y, pos.X + dim.X, pos.Y + dim.Y); + core::rect<s32> rect = core::rect<s32>( + pos.X, pos.Y, pos.X + dim.X, pos.Y + dim.Y); - FieldSpec spec( - name, - L"", - L"", - 258+m_fields.size() - ); + FieldSpec spec(name, L"", L"", 258 + m_fields.size()); bool is_horizontal = true; @@ -668,7 +656,7 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &elemen is_horizontal = false; spec.ftype = f_ScrollBar; - spec.send = true; + spec.send = true; GUIScrollBar *e = new GUIScrollBar(Environment, data->current_parent, spec.fid, rect, is_horizontal, true); @@ -689,27 +677,28 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &elemen s32 scrollbar_size = is_horizontal ? dim.X : dim.Y; - e->setPageSize(scrollbar_size * (max - min + 1) / data->scrollbar_options.thumb_size); + e->setPageSize(scrollbar_size * (max - min + 1) / + data->scrollbar_options.thumb_size); if (spec.fname == m_focused_element) { Environment->setFocus(e); } - m_scrollbars.emplace_back(spec,e); + m_scrollbars.emplace_back(spec, e); m_fields.push_back(spec); return; } errorstream << "Invalid scrollbar element(" << parts.size() << "): '" << element - << "'" << std::endl; + << "'" << std::endl; } -void GUIFormSpecMenu::parseScrollBarOptions(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseScrollBarOptions(parserData *data, const std::string &element) { std::vector<std::string> parts = split(element, ';'); if (parts.size() == 0) { - warningstream << "Invalid scrollbaroptions element(" << parts.size() << "): '" << - element << "'" << std::endl; + warningstream << "Invalid scrollbaroptions element(" << parts.size() + << "): '" << element << "'" << std::endl; return; } @@ -717,8 +706,8 @@ void GUIFormSpecMenu::parseScrollBarOptions(parserData* data, const std::string std::vector<std::string> options = split(i, '='); if (options.size() != 2) { - warningstream << "Invalid scrollbaroptions option syntax: '" << - element << "'" << std::endl; + warningstream << "Invalid scrollbaroptions option syntax: '" + << element << "'" << std::endl; continue; // Go to next option } @@ -743,28 +732,31 @@ void GUIFormSpecMenu::parseScrollBarOptions(parserData* data, const std::string } else if (options[0] == "arrows") { std::string value = trim(options[1]); if (value == "hide") - data->scrollbar_options.arrow_visiblity = GUIScrollBar::HIDE; + data->scrollbar_options.arrow_visiblity = + GUIScrollBar::HIDE; else if (value == "show") - data->scrollbar_options.arrow_visiblity = GUIScrollBar::SHOW; + data->scrollbar_options.arrow_visiblity = + GUIScrollBar::SHOW; else // Auto hide/show - data->scrollbar_options.arrow_visiblity = GUIScrollBar::DEFAULT; + data->scrollbar_options.arrow_visiblity = + GUIScrollBar::DEFAULT; continue; } - warningstream << "Invalid scrollbaroptions option(" << options[0] << - "): '" << element << "'" << std::endl; + warningstream << "Invalid scrollbaroptions option(" << options[0] + << "): '" << element << "'" << std::endl; } } -void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseImage(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if ((parts.size() == 3) || - ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + ((parts.size() > 3) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string name = unescape_string(parts[2]); MY_CHECKPOS("image", 0); @@ -783,29 +775,27 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) } if (!data->explicit_size) - warningstream<<"invalid use of image without a size[] element"<<std::endl; + warningstream << "invalid use of image without a size[] element" + << std::endl; video::ITexture *texture = m_tsrc->getTexture(name); if (!texture) { - errorstream << "GUIFormSpecMenu::parseImage() Unable to load texture:" - << std::endl << "\t" << name << std::endl; + errorstream << "GUIFormSpecMenu::parseImage() Unable to load " + "texture:" + << std::endl + << "\t" << name << std::endl; return; } - FieldSpec spec( - name, - L"", - L"", - 258 + m_fields.size(), - 1 - ); + FieldSpec spec(name, L"", L"", 258 + m_fields.size(), 1); core::rect<s32> rect(pos, pos + geom); - gui::IGUIImage *e = Environment->addImage(rect, data->current_parent, - spec.fid, 0, true); + gui::IGUIImage *e = Environment->addImage( + rect, data->current_parent, spec.fid, 0, true); e->setImage(texture); e->setScaleImage(true); auto style = getDefaultStyleForElement("image", spec.fname); - e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); + e->setNotClipped( + style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); m_fields.push_back(spec); // images should let events through @@ -815,7 +805,7 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) } if (parts.size() == 2) { - std::vector<std::string> v_pos = split(parts[0],','); + std::vector<std::string> v_pos = split(parts[0], ','); std::string name = unescape_string(parts[1]); MY_CHECKPOS("image", 0); @@ -823,25 +813,24 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) v2s32 pos = getElementBasePos(&v_pos); if (!data->explicit_size) - warningstream<<"invalid use of image without a size[] element"<<std::endl; + warningstream << "invalid use of image without a size[] element" + << std::endl; video::ITexture *texture = m_tsrc->getTexture(name); if (!texture) { - errorstream << "GUIFormSpecMenu::parseImage() Unable to load texture:" - << std::endl << "\t" << name << std::endl; + errorstream << "GUIFormSpecMenu::parseImage() Unable to load " + "texture:" + << std::endl + << "\t" << name << std::endl; return; } - FieldSpec spec( - name, - L"", - L"", - 258 + m_fields.size() - ); - gui::IGUIImage *e = Environment->addImage(texture, pos, true, - data->current_parent, spec.fid, 0); + FieldSpec spec(name, L"", L"", 258 + m_fields.size()); + gui::IGUIImage *e = Environment->addImage( + texture, pos, true, data->current_parent, spec.fid, 0); auto style = getDefaultStyleForElement("image", spec.fname); - e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); + e->setNotClipped( + style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); m_fields.push_back(spec); // images should let events through @@ -849,7 +838,8 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) m_clickthrough_elements.push_back(e); return; } - errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid image element(" << parts.size() << "): '" << element + << "'" << std::endl; } void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &element) @@ -857,13 +847,14 @@ void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &el std::vector<std::string> parts = split(element, ';'); if (parts.size() != 6 && parts.size() != 7 && - !(parts.size() > 7 && m_formspec_version > FORMSPEC_API_VERSION)) { - errorstream << "Invalid animated_image element(" << parts.size() - << "): '" << element << "'" << std::endl; + !(parts.size() > 7 && + m_formspec_version > FORMSPEC_API_VERSION)) { + errorstream << "Invalid animated_image element(" << parts.size() << "): '" + << element << "'" << std::endl; return; } - std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_pos = split(parts[0], ','); std::vector<std::string> v_geom = split(parts[1], ','); std::string name = parts[2]; std::string texture_name = unescape_string(parts[3]); @@ -886,21 +877,17 @@ void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &el } if (!data->explicit_size) - warningstream << "Invalid use of animated_image without a size[] element" << std::endl; - - FieldSpec spec( - name, - L"", - L"", - 258 + m_fields.size() - ); + warningstream << "Invalid use of animated_image without a size[] element" + << std::endl; + + FieldSpec spec(name, L"", L"", 258 + m_fields.size()); spec.ftype = f_AnimatedImage; spec.send = true; core::rect<s32> rect = core::rect<s32>(pos, pos + geom); - GUIAnimatedImage *e = new GUIAnimatedImage(Environment, this, spec.fid, - rect, texture_name, frame_count, frame_duration, m_tsrc); + GUIAnimatedImage *e = new GUIAnimatedImage(Environment, this, spec.fid, rect, + texture_name, frame_count, frame_duration, m_tsrc); if (parts.size() >= 7) e->setFrameIndex(stoi(parts[6]) - 1); @@ -914,19 +901,19 @@ void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &el m_fields.push_back(spec); } -void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseItemImage(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if ((parts.size() == 3) || - ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + ((parts.size() > 3) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string name = parts[2]; - MY_CHECKPOS("itemimage",0); - MY_CHECKGEOM("itemimage",1); + MY_CHECKPOS("itemimage", 0); + MY_CHECKGEOM("itemimage", 1); v2s32 pos; v2s32 geom; @@ -940,20 +927,17 @@ void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &elemen geom.Y = stof(v_geom[1]) * (float)imgsize.Y; } - if(!data->explicit_size) - warningstream<<"invalid use of item_image without a size[] element"<<std::endl; + if (!data->explicit_size) + warningstream << "invalid use of item_image without a size[] " + "element" + << std::endl; - FieldSpec spec( - "", - L"", - L"", - 258 + m_fields.size(), - 2 - ); + FieldSpec spec("", L"", L"", 258 + m_fields.size(), 2); spec.ftype = f_ItemImage; - GUIItemImage *e = new GUIItemImage(Environment, data->current_parent, spec.fid, - core::rect<s32>(pos, pos + geom), name, m_font, m_client); + GUIItemImage *e = new GUIItemImage(Environment, data->current_parent, + spec.fid, core::rect<s32>(pos, pos + geom), name, m_font, + m_client); auto style = getDefaultStyleForElement("item_image", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); @@ -963,24 +947,25 @@ void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &elemen m_fields.push_back(spec); return; } - errorstream<< "Invalid ItemImage element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid ItemImage element(" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element, - const std::string &type) +void GUIFormSpecMenu::parseButton( + parserData *data, const std::string &element, const std::string &type) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if ((parts.size() == 4) || - ((parts.size() > 4) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + ((parts.size() > 4) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string name = parts[2]; std::string label = parts[3]; - MY_CHECKPOS("button",0); - MY_CHECKGEOM("button",1); + MY_CHECKPOS("button", 0); + MY_CHECKGEOM("button", 1); v2s32 pos; v2s32 geom; @@ -989,36 +974,34 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element, if (data->real_coordinates) { pos = getRealCoordinateBasePos(v_pos); geom = getRealCoordinateGeometry(v_geom); - rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, - pos.Y+geom.Y); + rect = core::rect<s32>( + pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); } else { pos = getElementBasePos(&v_pos); geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X); - pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2; + pos.Y += (stof(v_geom[1]) * (float)imgsize.Y) / 2; rect = core::rect<s32>(pos.X, pos.Y - m_btn_height, - pos.X + geom.X, pos.Y + m_btn_height); + pos.X + geom.X, pos.Y + m_btn_height); } - if(!data->explicit_size) - warningstream<<"invalid use of button without a size[] element"<<std::endl; + if (!data->explicit_size) + warningstream << "invalid use of button without a size[] element" + << std::endl; - std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label))); + std::wstring wlabel = + translate_string(utf8_to_wide(unescape_string(label))); - FieldSpec spec( - name, - wlabel, - L"", - 258 + m_fields.size() - ); + FieldSpec spec(name, wlabel, L"", 258 + m_fields.size()); spec.ftype = f_Button; - if(type == "button_exit") + if (type == "button_exit") spec.is_exit = true; GUIButton *e = GUIButton::addButton(Environment, rect, m_tsrc, data->current_parent, spec.fid, spec.flabel.c_str()); - auto style = getStyleForElement(type, name, (type != "button") ? "button" : ""); + auto style = getStyleForElement( + type, name, (type != "button") ? "button" : ""); e->setStyles(style); if (spec.fname == m_focused_element) { @@ -1028,21 +1011,22 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element, m_fields.push_back(spec); return; } - errorstream<< "Invalid button element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid button element(" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseBackground(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if ((parts.size() >= 3 && parts.size() <= 5) || (parts.size() > 5 && m_formspec_version > FORMSPEC_API_VERSION)) { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string name = unescape_string(parts[2]); - MY_CHECKPOS("background",0); - MY_CHECKGEOM("background",1); + MY_CHECKPOS("background", 0); + MY_CHECKGEOM("background", 1); v2s32 pos; v2s32 geom; @@ -1065,7 +1049,7 @@ void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &eleme pos = getRealCoordinateBasePos(v_pos) * -1; geom = v2s32(0, 0); } else { - pos.X = stoi(v_pos[0]); //acts as offset + pos.X = stoi(v_pos[0]); // acts as offset pos.Y = stoi(v_pos[1]); } clip = true; @@ -1080,27 +1064,28 @@ void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &eleme middle.LowerRightCorner = core::vector2di(-x, -x); } else if (v_middle.size() == 2) { s32 x = stoi(v_middle[0]); - s32 y = stoi(v_middle[1]); + s32 y = stoi(v_middle[1]); middle.UpperLeftCorner = core::vector2di(x, y); middle.LowerRightCorner = core::vector2di(-x, -y); // `-x` is interpreted as `w - x` } else if (v_middle.size() == 4) { - middle.UpperLeftCorner = core::vector2di(stoi(v_middle[0]), stoi(v_middle[1])); - middle.LowerRightCorner = core::vector2di(stoi(v_middle[2]), stoi(v_middle[3])); + middle.UpperLeftCorner = core::vector2di( + stoi(v_middle[0]), stoi(v_middle[1])); + middle.LowerRightCorner = core::vector2di( + stoi(v_middle[2]), stoi(v_middle[3])); } else { - warningstream << "Invalid rectangle given to middle param of background[] element" << std::endl; + warningstream << "Invalid rectangle given to middle " + "param of background[] element" + << std::endl; } } if (!data->explicit_size && !clip) - warningstream << "invalid use of unclipped background without a size[] element" << std::endl; + warningstream << "invalid use of unclipped background without a " + "size[] element" + << std::endl; - FieldSpec spec( - name, - L"", - L"", - 258 + m_fields.size() - ); + FieldSpec spec(name, L"", L"", 258 + m_fields.size()); core::rect<s32> rect; if (!clip) { @@ -1111,8 +1096,8 @@ void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &eleme rect = core::rect<s32>(-pos, pos); } - GUIBackgroundImage *e = new GUIBackgroundImage(Environment, this, spec.fid, - rect, name, middle, m_tsrc, clip); + GUIBackgroundImage *e = new GUIBackgroundImage(Environment, this, + spec.fid, rect, name, middle, m_tsrc, clip); FATAL_ERROR_IF(!e, "Failed to create background formspec element"); @@ -1124,12 +1109,13 @@ void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &eleme m_fields.push_back(spec); return; } - errorstream<< "Invalid background element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid background element(" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseTableOptions(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseTableOptions(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); data->table_options.clear(); for (const std::string &part : parts) { @@ -1139,13 +1125,13 @@ void GUIFormSpecMenu::parseTableOptions(parserData* data, const std::string &ele } } -void GUIFormSpecMenu::parseTableColumns(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseTableColumns(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); data->table_columns.clear(); for (const std::string &part : parts) { - std::vector<std::string> col_parts = split(part,','); + std::vector<std::string> col_parts = split(part, ','); GUITable::TableColumn column; // Parse column type if (!col_parts.empty()) @@ -1159,25 +1145,25 @@ void GUIFormSpecMenu::parseTableColumns(parserData* data, const std::string &ele } } -void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseTable(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if (((parts.size() == 4) || (parts.size() == 5)) || - ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + ((parts.size() > 5) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string name = parts[2]; - std::vector<std::string> items = split(parts[3],','); + std::vector<std::string> items = split(parts[3], ','); std::string str_initial_selection; std::string str_transparent = "false"; if (parts.size() >= 5) str_initial_selection = parts[4]; - MY_CHECKPOS("table",0); - MY_CHECKGEOM("table",1); + MY_CHECKPOS("table", 0); + MY_CHECKGEOM("table", 1); v2s32 pos; v2s32 geom; @@ -1191,22 +1177,19 @@ void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element) geom.Y = stof(v_geom[1]) * spacing.Y; } - core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); + core::rect<s32> rect = core::rect<s32>( + pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); - FieldSpec spec( - name, - L"", - L"", - 258 + m_fields.size() - ); + FieldSpec spec(name, L"", L"", 258 + m_fields.size()); spec.ftype = f_Table; for (std::string &item : items) { - item = wide_to_utf8(unescape_translate(utf8_to_wide(unescape_string(item)))); + item = wide_to_utf8(unescape_translate( + utf8_to_wide(unescape_string(item)))); } - //now really show table + // now really show table GUITable *e = new GUITable(Environment, data->current_parent, spec.fid, rect, m_tsrc); @@ -1230,20 +1213,21 @@ void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element) m_fields.push_back(spec); return; } - errorstream<< "Invalid table element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid table element(" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseTextList(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if (((parts.size() == 4) || (parts.size() == 5) || (parts.size() == 6)) || - ((parts.size() > 6) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + ((parts.size() > 6) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string name = parts[2]; - std::vector<std::string> items = split(parts[3],','); + std::vector<std::string> items = split(parts[3], ','); std::string str_initial_selection; std::string str_transparent = "false"; @@ -1253,8 +1237,8 @@ void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element if (parts.size() >= 6) str_transparent = parts[5]; - MY_CHECKPOS("textlist",0); - MY_CHECKGEOM("textlist",1); + MY_CHECKPOS("textlist", 0); + MY_CHECKGEOM("textlist", 1); v2s32 pos; v2s32 geom; @@ -1268,22 +1252,19 @@ void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element geom.Y = stof(v_geom[1]) * spacing.Y; } - core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); + core::rect<s32> rect = core::rect<s32>( + pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); - FieldSpec spec( - name, - L"", - L"", - 258 + m_fields.size() - ); + FieldSpec spec(name, L"", L"", 258 + m_fields.size()); spec.ftype = f_Table; for (std::string &item : items) { - item = wide_to_utf8(unescape_translate(utf8_to_wide(unescape_string(item)))); + item = wide_to_utf8(unescape_translate( + utf8_to_wide(unescape_string(item)))); } - //now really show list + // now really show list GUITable *e = new GUITable(Environment, data->current_parent, spec.fid, rect, m_tsrc); @@ -1307,16 +1288,16 @@ void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element m_fields.push_back(spec); return; } - errorstream<< "Invalid textlist element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid textlist element(" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseDropDown(parserData *data, const std::string &element) { std::vector<std::string> parts = split(element, ';'); if (parts.size() == 5 || parts.size() == 6 || - (parts.size() > 6 && m_formspec_version > FORMSPEC_API_VERSION)) - { + (parts.size() > 6 && m_formspec_version > FORMSPEC_API_VERSION)) { std::vector<std::string> v_pos = split(parts[0], ','); std::string name = parts[2]; std::vector<std::string> items = split(parts[3], ','); @@ -1325,57 +1306,53 @@ void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element if (parts.size() >= 6 && is_yes(parts[5])) m_dropdown_index_event[name] = true; - MY_CHECKPOS("dropdown",0); + MY_CHECKPOS("dropdown", 0); v2s32 pos; v2s32 geom; core::rect<s32> rect; if (data->real_coordinates) { - std::vector<std::string> v_geom = split(parts[1],','); + std::vector<std::string> v_geom = split(parts[1], ','); if (v_geom.size() == 1) v_geom.emplace_back("1"); - MY_CHECKGEOM("dropdown",1); + MY_CHECKGEOM("dropdown", 1); pos = getRealCoordinateBasePos(v_pos); geom = getRealCoordinateGeometry(v_geom); - rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); + rect = core::rect<s32>( + pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); } else { pos = getElementBasePos(&v_pos); s32 width = stof(parts[1]) * spacing.Y; - rect = core::rect<s32>(pos.X, pos.Y, - pos.X + width, pos.Y + (m_btn_height * 2)); + rect = core::rect<s32>(pos.X, pos.Y, pos.X + width, + pos.Y + (m_btn_height * 2)); } - FieldSpec spec( - name, - L"", - L"", - 258 + m_fields.size() - ); + FieldSpec spec(name, L"", L"", 258 + m_fields.size()); spec.ftype = f_DropDown; spec.send = true; - //now really show list - gui::IGUIComboBox *e = Environment->addComboBox(rect, data->current_parent, - spec.fid); + // now really show list + gui::IGUIComboBox *e = Environment->addComboBox( + rect, data->current_parent, spec.fid); if (spec.fname == m_focused_element) { Environment->setFocus(e); } for (const std::string &item : items) { - e->addItem(unescape_translate(unescape_string( - utf8_to_wide(item))).c_str()); + e->addItem(unescape_translate(unescape_string(utf8_to_wide(item))) + .c_str()); } if (!str_initial_selection.empty()) - e->setSelected(stoi(str_initial_selection)-1); + e->setSelected(stoi(str_initial_selection) - 1); auto style = getDefaultStyleForElement("dropdown", name); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); @@ -1391,32 +1368,31 @@ void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element return; } errorstream << "Invalid dropdown element(" << parts.size() << "): '" << element - << "'" << std::endl; + << "'" << std::endl; } void GUIFormSpecMenu::parseFieldCloseOnEnter(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if (parts.size() == 2 || (parts.size() > 2 && m_formspec_version > FORMSPEC_API_VERSION)) { field_close_on_enter[parts[0]] = is_yes(parts[1]); } } -void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element) +void GUIFormSpecMenu::parsePwdField(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if (parts.size() == 4 || - (parts.size() > 4 && m_formspec_version > FORMSPEC_API_VERSION)) - { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + (parts.size() > 4 && m_formspec_version > FORMSPEC_API_VERSION)) { + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string name = parts[2]; std::string label = parts[3]; - MY_CHECKPOS("pwdfield",0); - MY_CHECKGEOM("pwdfield",1); + MY_CHECKPOS("pwdfield", 0); + MY_CHECKGEOM("pwdfield", 1); v2s32 pos; v2s32 geom; @@ -1430,27 +1406,22 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X); - pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2; + pos.Y += (stof(v_geom[1]) * (float)imgsize.Y) / 2; pos.Y -= m_btn_height; - geom.Y = m_btn_height*2; + geom.Y = m_btn_height * 2; } - core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); + core::rect<s32> rect = core::rect<s32>( + pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); - std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label))); + std::wstring wlabel = + translate_string(utf8_to_wide(unescape_string(label))); - FieldSpec spec( - name, - wlabel, - L"", - 258 + m_fields.size(), - 0, - ECI_IBEAM - ); + FieldSpec spec(name, wlabel, L"", 258 + m_fields.size(), 0, ECI_IBEAM); spec.send = true; - gui::IGUIEditBox *e = Environment->addEditBox(0, rect, true, - data->current_parent, spec.fid); + gui::IGUIEditBox *e = Environment->addEditBox( + 0, rect, true, data->current_parent, spec.fid); if (spec.fname == m_focused_element) { Environment->setFocus(e); @@ -1460,24 +1431,25 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element int font_height = g_fontengine->getTextHeight(); rect.UpperLeftCorner.Y -= font_height; rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height; - gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true, - data->current_parent, 0); + gui::StaticText::add(Environment, spec.flabel.c_str(), rect, + false, true, data->current_parent, 0); } - e->setPasswordBox(true,L'*'); + e->setPasswordBox(true, L'*'); auto style = getDefaultStyleForElement("pwdfield", name, "field"); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); e->setDrawBorder(style.getBool(StyleSpec::BORDER, true)); - e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); + e->setOverrideColor(style.getColor( + StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); e->setOverrideFont(style.getFont()); irr::SEvent evt; - evt.EventType = EET_KEY_INPUT_EVENT; - evt.KeyInput.Key = KEY_END; - evt.KeyInput.Char = 0; - evt.KeyInput.Control = false; - evt.KeyInput.Shift = false; + evt.EventType = EET_KEY_INPUT_EVENT; + evt.KeyInput.Key = KEY_END; + evt.KeyInput.Char = 0; + evt.KeyInput.Control = false; + evt.KeyInput.Shift = false; evt.KeyInput.PressedDown = true; e->OnEvent(evt); @@ -1487,15 +1459,17 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element m_fields.push_back(spec); return; } - errorstream<< "Invalid pwdfield element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid pwdfield element(" << parts.size() << "): '" << element + << "'" << std::endl; } void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, - core::rect<s32> &rect, bool is_multiline) + core::rect<s32> &rect, bool is_multiline) { bool is_editable = !spec.fname.empty(); if (!is_editable && !is_multiline) { - // spec field id to 0, this stops submit searching for a value that isn't there + // spec field id to 0, this stops submit searching for a value that isn't + // there gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true, data->current_parent, 0); return; @@ -1503,23 +1477,25 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, if (is_editable) { spec.send = true; - } else if (is_multiline && - spec.fdefault.empty() && !spec.flabel.empty()) { + } else if (is_multiline && spec.fdefault.empty() && !spec.flabel.empty()) { // Multiline textareas: swap default and label for backwards compat spec.flabel.swap(spec.fdefault); } gui::IGUIEditBox *e = nullptr; static constexpr bool use_intl_edit_box = USE_FREETYPE && - IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9; + IRRLICHT_VERSION_MAJOR == 1 && + IRRLICHT_VERSION_MINOR < 9; if (use_intl_edit_box && g_settings->getBool("freetype")) { e = new gui::intlGUIEditBox(spec.fdefault.c_str(), true, Environment, - data->current_parent, spec.fid, rect, is_editable, is_multiline); + data->current_parent, spec.fid, rect, is_editable, + is_multiline); } else { if (is_multiline) { - e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, Environment, - data->current_parent, spec.fid, rect, is_editable, true); + e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, + Environment, data->current_parent, spec.fid, rect, + is_editable, true); } else if (is_editable) { e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, data->current_parent, spec.fid); @@ -1527,7 +1503,8 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, } } - auto style = getDefaultStyleForElement(is_multiline ? "textarea" : "field", spec.fname); + auto style = getDefaultStyleForElement( + is_multiline ? "textarea" : "field", spec.fname); if (e) { if (is_editable && spec.fname == m_focused_element) @@ -1539,18 +1516,19 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT); } else { irr::SEvent evt; - evt.EventType = EET_KEY_INPUT_EVENT; - evt.KeyInput.Key = KEY_END; - evt.KeyInput.Char = 0; - evt.KeyInput.Control = 0; - evt.KeyInput.Shift = 0; + evt.EventType = EET_KEY_INPUT_EVENT; + evt.KeyInput.Key = KEY_END; + evt.KeyInput.Char = 0; + evt.KeyInput.Control = 0; + evt.KeyInput.Shift = 0; evt.KeyInput.PressedDown = true; e->OnEvent(evt); } e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); e->setDrawBorder(style.getBool(StyleSpec::BORDER, true)); - e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); + e->setOverrideColor(style.getColor( + StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); if (style.get(StyleSpec::BGCOLOR, "") == "transparent") { e->setDrawBackground(false); } @@ -1571,8 +1549,7 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, } } -void GUIFormSpecMenu::parseSimpleField(parserData *data, - std::vector<std::string> &parts) +void GUIFormSpecMenu::parseSimpleField(parserData *data, std::vector<std::string> &parts) { std::string name = parts[0]; std::string label = parts[1]; @@ -1581,32 +1558,23 @@ void GUIFormSpecMenu::parseSimpleField(parserData *data, core::rect<s32> rect; if (data->explicit_size) - warningstream << "invalid use of unpositioned \"field\" in inventory" << std::endl; + warningstream << "invalid use of unpositioned \"field\" in inventory" + << std::endl; v2s32 pos = getElementBasePos(nullptr); pos.Y = (data->simple_field_count + 2) * 60; v2s32 size = DesiredRect.getSize(); - rect = core::rect<s32>( - size.X / 2 - 150, pos.Y, - size.X / 2 - 150 + 300, pos.Y + m_btn_height * 2 - ); - + rect = core::rect<s32>(size.X / 2 - 150, pos.Y, size.X / 2 - 150 + 300, + pos.Y + m_btn_height * 2); if (m_form_src) default_val = m_form_src->resolveText(default_val); - std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label))); - FieldSpec spec( - name, - wlabel, - utf8_to_wide(unescape_string(default_val)), - 258 + m_fields.size(), - 0, - ECI_IBEAM - ); + FieldSpec spec(name, wlabel, utf8_to_wide(unescape_string(default_val)), + 258 + m_fields.size(), 0, ECI_IBEAM); createTextField(data, spec, rect, false); @@ -1615,17 +1583,17 @@ void GUIFormSpecMenu::parseSimpleField(parserData *data, data->simple_field_count++; } -void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>& parts, +void GUIFormSpecMenu::parseTextArea(parserData *data, std::vector<std::string> &parts, const std::string &type) { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string name = parts[2]; std::string label = parts[3]; std::string default_val = parts[4]; - MY_CHECKPOS(type,0); - MY_CHECKGEOM(type,1); + MY_CHECKPOS(type, 0); + MY_CHECKGEOM(type, 1); v2s32 pos; v2s32 geom; @@ -1639,38 +1607,31 @@ void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>& geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X); - if (type == "textarea") - { - geom.Y = (stof(v_geom[1]) * (float)imgsize.Y) - (spacing.Y-imgsize.Y); + if (type == "textarea") { + geom.Y = (stof(v_geom[1]) * (float)imgsize.Y) - + (spacing.Y - imgsize.Y); pos.Y += m_btn_height; - } - else - { - pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2; + } else { + pos.Y += (stof(v_geom[1]) * (float)imgsize.Y) / 2; pos.Y -= m_btn_height; - geom.Y = m_btn_height*2; + geom.Y = m_btn_height * 2; } } - core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); + core::rect<s32> rect = + core::rect<s32>(pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); - if(!data->explicit_size) - warningstream<<"invalid use of positioned "<<type<<" without a size[] element"<<std::endl; + if (!data->explicit_size) + warningstream << "invalid use of positioned " << type + << " without a size[] element" << std::endl; - if(m_form_src) + if (m_form_src) default_val = m_form_src->resolveText(default_val); - std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label))); - FieldSpec spec( - name, - wlabel, - utf8_to_wide(unescape_string(default_val)), - 258 + m_fields.size(), - 0, - ECI_IBEAM - ); + FieldSpec spec(name, wlabel, utf8_to_wide(unescape_string(default_val)), + 258 + m_fields.size(), 0, ECI_IBEAM); createTextField(data, spec, rect, type == "textarea"); @@ -1680,23 +1641,24 @@ void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>& m_fields.push_back(spec); } -void GUIFormSpecMenu::parseField(parserData* data, const std::string &element, - const std::string &type) +void GUIFormSpecMenu::parseField( + parserData *data, const std::string &element, const std::string &type) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if (parts.size() == 3 || parts.size() == 4) { - parseSimpleField(data,parts); + parseSimpleField(data, parts); return; } if ((parts.size() == 5) || - ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - parseTextArea(data,parts,type); + ((parts.size() > 5) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + parseTextArea(data, parts, type); return; } - errorstream<< "Invalid field element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid field element(" << parts.size() << "): '" << element + << "'" << std::endl; } void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &element) @@ -1704,7 +1666,8 @@ void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &elemen std::vector<std::string> parts = split(element, ';'); if (parts.size() != 4 && m_formspec_version < FORMSPEC_API_VERSION) { - errorstream << "Invalid text element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid text element(" << parts.size() << "): '" + << element << "'" << std::endl; return; } @@ -1731,17 +1694,14 @@ void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &elemen pos.Y += m_btn_height; } - core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); + core::rect<s32> rect = + core::rect<s32>(pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); - if(m_form_src) + if (m_form_src) text = m_form_src->resolveText(text); - FieldSpec spec( - name, - utf8_to_wide(unescape_string(text)), - L"", - 258 + m_fields.size() - ); + FieldSpec spec(name, utf8_to_wide(unescape_string(text)), L"", + 258 + m_fields.size()); spec.ftype = f_HyperText; GUIHyperText *e = new GUIHyperText(spec.flabel.c_str(), Environment, @@ -1751,20 +1711,21 @@ void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &elemen m_fields.push_back(spec); } -void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseLabel(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if ((parts.size() == 2) || - ((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); + ((parts.size() > 2) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); std::string text = parts[1]; - MY_CHECKPOS("label",0); + MY_CHECKPOS("label", 0); - if(!data->explicit_size) - warningstream<<"invalid use of label without a size[] element"<<std::endl; + if (!data->explicit_size) + warningstream << "invalid use of label without a size[] element" + << std::endl; std::vector<std::string> lines = split(text, '\n'); @@ -1775,7 +1736,7 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element) for (unsigned int i = 0; i != lines.size(); i++) { std::wstring wlabel_colors = translate_string( - utf8_to_wide(unescape_string(lines[i]))); + utf8_to_wide(unescape_string(lines[i]))); // Without color escapes to get the font dimensions std::wstring wlabel_plain = unescape_enriched(wlabel_colors); @@ -1790,12 +1751,13 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element) v2s32 pos = getRealCoordinateBasePos(v_pos); // Labels are positioned by their center, not their top. - pos.Y += (((float) imgsize.Y) / -2) + (((float) imgsize.Y) * i / 2); + pos.Y += (((float)imgsize.Y) / -2) + + (((float)imgsize.Y) * i / 2); - rect = core::rect<s32>( - pos.X, pos.Y, - pos.X + font->getDimension(wlabel_plain.c_str()).Width, - pos.Y + imgsize.Y); + rect = core::rect<s32>(pos.X, pos.Y, + pos.X + font->getDimension(wlabel_plain.c_str()) + .Width, + pos.Y + imgsize.Y); } else { // Lines are spaced at the nominal distance of @@ -1812,28 +1774,23 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element) pos.X += stof(v_pos[0]) * spacing.X; pos.Y += (stof(v_pos[1]) + 7.0f / 30.0f) * spacing.Y; - pos.Y += ((float) i) * spacing.Y * 2.0 / 5.0; + pos.Y += ((float)i) * spacing.Y * 2.0 / 5.0; - rect = core::rect<s32>( - pos.X, pos.Y - m_btn_height, - pos.X + font->getDimension(wlabel_plain.c_str()).Width, - pos.Y + m_btn_height); + rect = core::rect<s32>(pos.X, pos.Y - m_btn_height, + pos.X + font->getDimension(wlabel_plain.c_str()) + .Width, + pos.Y + m_btn_height); } - FieldSpec spec( - "", - wlabel_colors, - L"", - 258 + m_fields.size(), - 4 - ); + FieldSpec spec("", wlabel_colors, L"", 258 + m_fields.size(), 4); gui::IGUIStaticText *e = gui::StaticText::add(Environment, - spec.flabel.c_str(), rect, false, false, data->current_parent, - spec.fid); + spec.flabel.c_str(), rect, false, false, + data->current_parent, spec.fid); e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); - e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); + e->setOverrideColor(style.getColor( + StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); e->setOverrideFont(font); m_fields.push_back(spec); @@ -1846,21 +1803,21 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element) return; } errorstream << "Invalid label element(" << parts.size() << "): '" << element - << "'" << std::endl; + << "'" << std::endl; } -void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseVertLabel(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if ((parts.size() == 2) || - ((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); + ((parts.size() > 2) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); std::wstring text = unescape_translate( - unescape_string(utf8_to_wide(parts[1]))); + unescape_string(utf8_to_wide(parts[1]))); - MY_CHECKPOS("vertlabel",1); + MY_CHECKPOS("vertlabel", 1); auto style = getDefaultStyleForElement("vertlabel", "", "label"); gui::IGUIFont *font = style.getFont(); @@ -1878,10 +1835,10 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen // We use text.length + 1 because without it, the rect // isn't quite tall enough and cuts off the text. - rect = core::rect<s32>(pos.X, pos.Y, - pos.X + imgsize.X, - pos.Y + font_line_height(font) * - (text.length() + 1)); + rect = core::rect<s32>(pos.X, pos.Y, pos.X + imgsize.X, + pos.Y + font_line_height(font) * + (text.length() + + 1)); } else { pos = getElementBasePos(&v_pos); @@ -1889,16 +1846,19 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen // As above, the length must be one longer. The width of // the rect (15 pixels) seems rather arbitrary, but // changing it might break something. - rect = core::rect<s32>( - pos.X, pos.Y+((imgsize.Y/2) - m_btn_height), - pos.X+15, pos.Y + - font_line_height(font) * - (text.length() + 1) + - ((imgsize.Y/2) - m_btn_height)); + rect = core::rect<s32>(pos.X, + pos.Y + ((imgsize.Y / 2) - m_btn_height), + pos.X + 15, + pos.Y + + font_line_height(font) * + (text.length() + + 1) + + ((imgsize.Y / 2) - m_btn_height)); } - if(!data->explicit_size) - warningstream<<"invalid use of label without a size[] element"<<std::endl; + if (!data->explicit_size) + warningstream << "invalid use of label without a size[] element" + << std::endl; std::wstring label; @@ -1907,18 +1867,15 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen label += L"\n"; } - FieldSpec spec( - "", - label, - L"", - 258 + m_fields.size() - ); - gui::IGUIStaticText *e = gui::StaticText::add(Environment, spec.flabel.c_str(), - rect, false, false, data->current_parent, spec.fid); + FieldSpec spec("", label, L"", 258 + m_fields.size()); + gui::IGUIStaticText *e = gui::StaticText::add(Environment, + spec.flabel.c_str(), rect, false, false, + data->current_parent, spec.fid); e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); - e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); + e->setOverrideColor(style.getColor( + StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); e->setOverrideFont(font); m_fields.push_back(spec); @@ -1928,25 +1885,26 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen m_clickthrough_elements.push_back(e); return; } - errorstream<< "Invalid vertlabel element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid vertlabel element(" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &element, - const std::string &type) +void GUIFormSpecMenu::parseImageButton( + parserData *data, const std::string &element, const std::string &type) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if ((((parts.size() >= 5) && (parts.size() <= 8)) && (parts.size() != 6)) || - ((parts.size() > 8) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + ((parts.size() > 8) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string image_name = parts[2]; std::string name = parts[3]; std::string label = parts[4]; - MY_CHECKPOS("imagebutton",0); - MY_CHECKGEOM("imagebutton",1); + MY_CHECKPOS("imagebutton", 0); + MY_CHECKGEOM("imagebutton", 1); std::string pressed_image_name; @@ -1966,23 +1924,21 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem geom.Y = (stof(v_geom[1]) * spacing.Y) - (spacing.Y - imgsize.Y); } - core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, - pos.Y+geom.Y); + core::rect<s32> rect = core::rect<s32>( + pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); if (!data->explicit_size) - warningstream<<"invalid use of image_button without a size[] element"<<std::endl; + warningstream << "invalid use of image_button without a size[] " + "element" + << std::endl; image_name = unescape_string(image_name); pressed_image_name = unescape_string(pressed_image_name); std::wstring wlabel = utf8_to_wide(unescape_string(label)); - FieldSpec spec( - name, - wlabel, - utf8_to_wide(image_name), - 258 + m_fields.size() - ); + FieldSpec spec(name, wlabel, utf8_to_wide(image_name), + 258 + m_fields.size()); spec.ftype = f_Button; if (type == "image_button_exit") spec.is_exit = true; @@ -2001,7 +1957,8 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem style[StyleSpec::STATE_DEFAULT].set(StyleSpec::FGIMG, image_name); if (!pressed_image_name.empty()) - style[StyleSpec::STATE_PRESSED].set(StyleSpec::FGIMG, pressed_image_name); + style[StyleSpec::STATE_PRESSED].set( + StyleSpec::FGIMG, pressed_image_name); if (parts.size() >= 7) { style[StyleSpec::STATE_DEFAULT].set(StyleSpec::NOCLIP, parts[5]); @@ -2015,18 +1972,19 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem return; } - errorstream<< "Invalid imagebutton element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid imagebutton element(" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseTabHeader(parserData *data, const std::string &element) { std::vector<std::string> parts = split(element, ';'); - if (((parts.size() == 4) || (parts.size() == 6)) || (parts.size() == 7 && - data->real_coordinates) || ((parts.size() > 6) && - (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); + if (((parts.size() == 4) || (parts.size() == 6)) || + (parts.size() == 7 && data->real_coordinates) || + ((parts.size() > 6) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); // If we're using real coordinates, add an extra field for height. // Width is not here because tabs are the width of the text, and @@ -2044,9 +2002,9 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen auto_width = false; } - std::string name = parts[i+1]; - std::vector<std::string> buttons = split(parts[i+2], ','); - std::string str_index = parts[i+3]; + std::string name = parts[i + 1]; + std::vector<std::string> buttons = split(parts[i + 2], ','); + std::string str_index = parts[i + 3]; bool show_background = true; bool show_border = true; int tab_index = stoi(str_index) - 1; @@ -2054,18 +2012,13 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen MY_CHECKPOS("tabheader", 0); if (parts.size() == 6 + i) { - if (parts[4+i] == "true") + if (parts[4 + i] == "true") show_background = false; - if (parts[5+i] == "false") + if (parts[5 + i] == "false") show_border = false; } - FieldSpec spec( - name, - L"", - L"", - 258 + m_fields.size() - ); + FieldSpec spec(name, L"", L"", 258 + m_fields.size()); spec.ftype = f_TabHeader; @@ -2094,11 +2047,12 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen geom.X = DesiredRect.getWidth(); } - core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, - pos.Y+geom.Y); + core::rect<s32> rect = core::rect<s32>( + pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); - gui::IGUITabControl *e = Environment->addTabControl(rect, - data->current_parent, show_background, show_border, spec.fid); + gui::IGUITabControl *e = + Environment->addTabControl(rect, data->current_parent, + show_background, show_border, spec.fid); e->setAlignment(irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_LOWERRIGHT); e->setTabHeight(geom.Y); @@ -2107,41 +2061,45 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen e->setNotClipped(style.getBool(StyleSpec::NOCLIP, true)); for (const std::string &button : buttons) { - auto tab = e->addTab(unescape_translate(unescape_string( - utf8_to_wide(button))).c_str(), -1); + auto tab = e->addTab( + unescape_translate(unescape_string(utf8_to_wide( + button))) + .c_str(), + -1); if (style.isNotDefault(StyleSpec::BGCOLOR)) - tab->setBackgroundColor(style.getColor(StyleSpec::BGCOLOR)); + tab->setBackgroundColor( + style.getColor(StyleSpec::BGCOLOR)); - tab->setTextColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); + tab->setTextColor(style.getColor( + StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); } - if ((tab_index >= 0) && - (buttons.size() < INT_MAX) && - (tab_index < (int) buttons.size())) + if ((tab_index >= 0) && (buttons.size() < INT_MAX) && + (tab_index < (int)buttons.size())) e->setActiveTab(tab_index); m_fields.push_back(spec); return; } - errorstream << "Invalid TabHeader element(" << parts.size() << "): '" - << element << "'" << std::endl; + errorstream << "Invalid TabHeader element(" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseItemImageButton(parserData *data, const std::string &element) { if (m_client == 0) { warningstream << "invalid use of item_image_button with m_client==0" - << std::endl; + << std::endl; return; } - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if ((parts.size() == 5) || - ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + ((parts.size() > 5) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); std::string item_name = parts[2]; std::string name = parts[3]; std::string label = parts[4]; @@ -2149,8 +2107,8 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string & label = unescape_string(label); item_name = unescape_string(item_name); - MY_CHECKPOS("itemimagebutton",0); - MY_CHECKGEOM("itemimagebutton",1); + MY_CHECKPOS("itemimagebutton", 0); + MY_CHECKGEOM("itemimagebutton", 1); v2s32 pos; v2s32 geom; @@ -2164,34 +2122,32 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string & geom.Y = (stof(v_geom[1]) * spacing.Y) - (spacing.Y - imgsize.Y); } - core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); + core::rect<s32> rect = core::rect<s32>( + pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y); - if(!data->explicit_size) - warningstream<<"invalid use of item_image_button without a size[] element"<<std::endl; + if (!data->explicit_size) + warningstream << "invalid use of item_image_button without a " + "size[] element" + << std::endl; IItemDefManager *idef = m_client->idef(); ItemStack item; item.deSerialize(item_name, idef); - m_tooltips[name] = - TooltipSpec(utf8_to_wide(item.getDefinition(idef).description), - m_default_tooltip_bgcolor, - m_default_tooltip_color); + m_tooltips[name] = TooltipSpec( + utf8_to_wide(item.getDefinition(idef).description), + m_default_tooltip_bgcolor, m_default_tooltip_color); // the spec for the button - FieldSpec spec_btn( - name, - utf8_to_wide(label), - utf8_to_wide(item_name), - 258 + m_fields.size(), - 2 - ); + FieldSpec spec_btn(name, utf8_to_wide(label), utf8_to_wide(item_name), + 258 + m_fields.size(), 2); GUIButtonItemImage *e_btn = GUIButtonItemImage::addButton(Environment, - rect, m_tsrc, data->current_parent, spec_btn.fid, spec_btn.flabel.c_str(), - item_name, m_client); + rect, m_tsrc, data->current_parent, spec_btn.fid, + spec_btn.flabel.c_str(), item_name, m_client); - auto style = getStyleForElement("item_image_button", spec_btn.fname, "image_button"); + auto style = getStyleForElement( + "item_image_button", spec_btn.fname, "image_button"); e_btn->setStyles(style); if (spec_btn.fname == m_focused_element) { @@ -2199,26 +2155,27 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string & } spec_btn.ftype = f_Button; - rect += data->basepos-padding; + rect += data->basepos - padding; spec_btn.rect = rect; m_fields.push_back(spec_btn); return; } - errorstream<< "Invalid ItemImagebutton element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid ItemImagebutton element(" << parts.size() << "): '" + << element << "'" << std::endl; } -void GUIFormSpecMenu::parseBox(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseBox(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if ((parts.size() == 3) || - ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION))) - { - std::vector<std::string> v_pos = split(parts[0],','); - std::vector<std::string> v_geom = split(parts[1],','); + ((parts.size() > 3) && + (m_formspec_version > FORMSPEC_API_VERSION))) { + std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_geom = split(parts[1], ','); - MY_CHECKPOS("box",0); - MY_CHECKGEOM("box",1); + MY_CHECKPOS("box", 0); + MY_CHECKGEOM("box", 1); v2s32 pos; v2s32 geom; @@ -2235,44 +2192,42 @@ void GUIFormSpecMenu::parseBox(parserData* data, const std::string &element) video::SColor tmp_color; if (parseColorString(parts[2], tmp_color, false, 0x8C)) { - FieldSpec spec( - "", - L"", - L"", - 258 + m_fields.size(), - -2 - ); + FieldSpec spec("", L"", L"", 258 + m_fields.size(), -2); spec.ftype = f_Box; core::rect<s32> rect(pos, pos + geom); - GUIBox *e = new GUIBox(Environment, data->current_parent, spec.fid, - rect, tmp_color); + GUIBox *e = new GUIBox(Environment, data->current_parent, + spec.fid, rect, tmp_color); auto style = getDefaultStyleForElement("box", spec.fname); - e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); + e->setNotClipped(style.getBool( + StyleSpec::NOCLIP, m_formspec_version < 3)); e->drop(); m_fields.push_back(spec); } else { - errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "' INVALID COLOR" << std::endl; + errorstream << "Invalid Box element(" << parts.size() << "): '" + << element << "' INVALID COLOR" << std::endl; } return; } - errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid Box element(" << parts.size() << "): '" << element << "'" + << std::endl; } -void GUIFormSpecMenu::parseBackgroundColor(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseBackgroundColor(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); const u32 parameter_count = parts.size(); if ((parameter_count > 2 && m_formspec_version < 3) || - (parameter_count > 3 && m_formspec_version <= FORMSPEC_API_VERSION)) { + (parameter_count > 3 && + m_formspec_version <= FORMSPEC_API_VERSION)) { errorstream << "Invalid bgcolor element(" << parameter_count << "): '" - << element << "'" << std::endl; + << element << "'" << std::endl; return; } @@ -2299,19 +2254,20 @@ void GUIFormSpecMenu::parseBackgroundColor(parserData* data, const std::string & parseColorString(parts[2], m_fullscreen_bgcolor, false); } -void GUIFormSpecMenu::parseListColors(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseListColors(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if (((parts.size() == 2) || (parts.size() == 3) || (parts.size() == 5)) || - ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION))) - { + ((parts.size() > 5) && + (m_formspec_version > FORMSPEC_API_VERSION))) { parseColorString(parts[0], data->inventorylist_options.slotbg_n, false); parseColorString(parts[1], data->inventorylist_options.slotbg_h, false); if (parts.size() >= 3) { - if (parseColorString(parts[2], data->inventorylist_options.slotbordercolor, - false)) { + if (parseColorString(parts[2], + data->inventorylist_options.slotbordercolor, + false)) { data->inventorylist_options.slotborder = true; } } @@ -2333,15 +2289,16 @@ void GUIFormSpecMenu::parseListColors(parserData* data, const std::string &eleme } return; } - errorstream<< "Invalid listcolors element(" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid listcolors element(" << parts.size() << "): '" << element + << "'" << std::endl; } -void GUIFormSpecMenu::parseTooltip(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseTooltip(parserData *data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); if (parts.size() < 2) { errorstream << "Invalid tooltip element(" << parts.size() << "): '" - << element << "'" << std::endl; + << element << "'" << std::endl; return; } @@ -2350,18 +2307,19 @@ void GUIFormSpecMenu::parseTooltip(parserData* data, const std::string &element) size_t base_size = rect_mode ? 3 : 2; if (parts.size() != base_size && parts.size() != base_size + 2) { errorstream << "Invalid tooltip element(" << parts.size() << "): '" - << element << "'" << std::endl; + << element << "'" << std::endl; return; } // Read colors video::SColor bgcolor = m_default_tooltip_bgcolor; - video::SColor color = m_default_tooltip_color; + video::SColor color = m_default_tooltip_color; if (parts.size() == base_size + 2 && (!parseColorString(parts[base_size], bgcolor, false) || - !parseColorString(parts[base_size + 1], color, false))) { + !parseColorString(parts[base_size + 1], color, + false))) { errorstream << "Invalid color in tooltip element(" << parts.size() - << "): '" << element << "'" << std::endl; + << "): '" << element << "'" << std::endl; return; } @@ -2371,7 +2329,7 @@ void GUIFormSpecMenu::parseTooltip(parserData* data, const std::string &element) // Add tooltip if (rect_mode) { - std::vector<std::string> v_pos = split(parts[0], ','); + std::vector<std::string> v_pos = split(parts[0], ','); std::vector<std::string> v_geom = split(parts[1], ','); MY_CHECKPOS("tooltip", 0); @@ -2389,12 +2347,7 @@ void GUIFormSpecMenu::parseTooltip(parserData* data, const std::string &element) geom.Y = stof(v_geom[1]) * spacing.Y; } - FieldSpec fieldspec( - "", - L"", - L"", - 258 + m_fields.size() - ); + FieldSpec fieldspec("", L"", L"", 258 + m_fields.size()); core::rect<s32> rect(pos, pos + geom); @@ -2414,11 +2367,11 @@ void GUIFormSpecMenu::parseTooltip(parserData* data, const std::string &element) bool GUIFormSpecMenu::parseVersionDirect(const std::string &data) { - //some prechecks + // some prechecks if (data.empty()) return false; - std::vector<std::string> parts = split(data,'['); + std::vector<std::string> parts = split(data, '['); if (parts.size() < 2) { return false; @@ -2436,12 +2389,12 @@ bool GUIFormSpecMenu::parseVersionDirect(const std::string &data) return false; } -bool GUIFormSpecMenu::parseSizeDirect(parserData* data, const std::string &element) +bool GUIFormSpecMenu::parseSizeDirect(parserData *data, const std::string &element) { if (element.empty()) return false; - std::vector<std::string> parts = split(element,'['); + std::vector<std::string> parts = split(element, '['); if (parts.size() < 2) return false; @@ -2453,7 +2406,8 @@ bool GUIFormSpecMenu::parseSizeDirect(parserData* data, const std::string &eleme return false; if (type == "invsize") - warningstream << "Deprecated formspec element \"invsize\" is used" << std::endl; + warningstream << "Deprecated formspec element \"invsize\" is used" + << std::endl; parseSize(data, description); @@ -2491,7 +2445,8 @@ void GUIFormSpecMenu::parsePosition(parserData *data, const std::string &element return; } - errorstream << "Invalid position element (" << parts.size() << "): '" << element << "'" << std::endl; + errorstream << "Invalid position element (" << parts.size() << "): '" << element + << "'" << std::endl; } bool GUIFormSpecMenu::parseAnchorDirect(parserData *data, const std::string &element) @@ -2526,16 +2481,17 @@ void GUIFormSpecMenu::parseAnchor(parserData *data, const std::string &element) } errorstream << "Invalid anchor element (" << parts.size() << "): '" << element - << "'" << std::endl; + << "'" << std::endl; } -bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, bool style_type) +bool GUIFormSpecMenu::parseStyle( + parserData *data, const std::string &element, bool style_type) { std::vector<std::string> parts = split(element, ';'); if (parts.size() < 2) { - errorstream << "Invalid style element (" << parts.size() << "): '" << element - << "'" << std::endl; + errorstream << "Invalid style element (" << parts.size() << "): '" + << element << "'" << std::endl; return false; } @@ -2545,22 +2501,24 @@ bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, b for (size_t i = 1; i < parts.size(); i++) { size_t equal_pos = parts[i].find('='); if (equal_pos == std::string::npos) { - errorstream << "Invalid style element (Property missing value): '" << element - << "'" << std::endl; + errorstream << "Invalid style element (Property missing value): '" + << element << "'" << std::endl; return false; } std::string propname = trim(parts[i].substr(0, equal_pos)); - std::string value = trim(unescape_string(parts[i].substr(equal_pos + 1))); + std::string value = trim(unescape_string(parts[i].substr(equal_pos + 1))); - std::transform(propname.begin(), propname.end(), propname.begin(), ::tolower); + std::transform(propname.begin(), propname.end(), propname.begin(), + ::tolower); StyleSpec::Property prop = StyleSpec::GetPropertyByName(propname); if (prop == StyleSpec::NONE) { if (property_warned.find(propname) != property_warned.end()) { - warningstream << "Invalid style element (Unknown property " << propname << "): '" - << element - << "'" << std::endl; + warningstream << "Invalid style element (Unknown " + "property " + << propname << "): '" << element << "'" + << std::endl; property_warned.insert(propname); } continue; @@ -2585,16 +2543,18 @@ bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, b selector = selector.substr(0, state_pos); if (state_str.empty()) { - errorstream << "Invalid style element (Invalid state): '" << element - << "'" << std::endl; + errorstream << "Invalid style element (Invalid state): '" + << element << "'" << std::endl; state_valid = false; } else { std::vector<std::string> states = split(state_str, '+'); for (std::string &state : states) { - StyleSpec::State converted = StyleSpec::getStateByName(state); + StyleSpec::State converted = + StyleSpec::getStateByName(state); if (converted == StyleSpec::STATE_INVALID) { - infostream << "Unknown style state " << state << - " in element '" << element << "'" << std::endl; + infostream << "Unknown style state " + << state << " in element '" + << element << "'" << std::endl; state_valid = false; break; } @@ -2616,20 +2576,29 @@ bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, b } // Backwards-compatibility for existing _hovered/_pressed properties - if (selector_spec.hasProperty(StyleSpec::BGCOLOR_HOVERED) - || selector_spec.hasProperty(StyleSpec::BGIMG_HOVERED) - || selector_spec.hasProperty(StyleSpec::FGIMG_HOVERED)) { + if (selector_spec.hasProperty(StyleSpec::BGCOLOR_HOVERED) || + selector_spec.hasProperty(StyleSpec::BGIMG_HOVERED) || + selector_spec.hasProperty(StyleSpec::FGIMG_HOVERED)) { StyleSpec hover_spec; hover_spec.addState(StyleSpec::STATE_HOVERED); if (selector_spec.hasProperty(StyleSpec::BGCOLOR_HOVERED)) { - hover_spec.set(StyleSpec::BGCOLOR, selector_spec.get(StyleSpec::BGCOLOR_HOVERED, "")); + hover_spec.set(StyleSpec::BGCOLOR, + selector_spec.get( + StyleSpec::BGCOLOR_HOVERED, + "")); } if (selector_spec.hasProperty(StyleSpec::BGIMG_HOVERED)) { - hover_spec.set(StyleSpec::BGIMG, selector_spec.get(StyleSpec::BGIMG_HOVERED, "")); + hover_spec.set(StyleSpec::BGIMG, + selector_spec.get( + StyleSpec::BGIMG_HOVERED, + "")); } if (selector_spec.hasProperty(StyleSpec::FGIMG_HOVERED)) { - hover_spec.set(StyleSpec::FGIMG, selector_spec.get(StyleSpec::FGIMG_HOVERED, "")); + hover_spec.set(StyleSpec::FGIMG, + selector_spec.get( + StyleSpec::FGIMG_HOVERED, + "")); } if (style_type) { @@ -2638,20 +2607,29 @@ bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, b theme_by_name[selector].push_back(hover_spec); } } - if (selector_spec.hasProperty(StyleSpec::BGCOLOR_PRESSED) - || selector_spec.hasProperty(StyleSpec::BGIMG_PRESSED) - || selector_spec.hasProperty(StyleSpec::FGIMG_PRESSED)) { + if (selector_spec.hasProperty(StyleSpec::BGCOLOR_PRESSED) || + selector_spec.hasProperty(StyleSpec::BGIMG_PRESSED) || + selector_spec.hasProperty(StyleSpec::FGIMG_PRESSED)) { StyleSpec press_spec; press_spec.addState(StyleSpec::STATE_PRESSED); if (selector_spec.hasProperty(StyleSpec::BGCOLOR_PRESSED)) { - press_spec.set(StyleSpec::BGCOLOR, selector_spec.get(StyleSpec::BGCOLOR_PRESSED, "")); + press_spec.set(StyleSpec::BGCOLOR, + selector_spec.get( + StyleSpec::BGCOLOR_PRESSED, + "")); } if (selector_spec.hasProperty(StyleSpec::BGIMG_PRESSED)) { - press_spec.set(StyleSpec::BGIMG, selector_spec.get(StyleSpec::BGIMG_PRESSED, "")); + press_spec.set(StyleSpec::BGIMG, + selector_spec.get( + StyleSpec::BGIMG_PRESSED, + "")); } if (selector_spec.hasProperty(StyleSpec::FGIMG_PRESSED)) { - press_spec.set(StyleSpec::FGIMG, selector_spec.get(StyleSpec::FGIMG_PRESSED, "")); + press_spec.set(StyleSpec::FGIMG, + selector_spec.get( + StyleSpec::FGIMG_PRESSED, + "")); } if (style_type) { @@ -2670,8 +2648,7 @@ void GUIFormSpecMenu::parseSetFocus(const std::string &element) std::vector<std::string> parts = split(element, ';'); if (parts.size() <= 2 || - (parts.size() > 2 && m_formspec_version > FORMSPEC_API_VERSION)) - { + (parts.size() > 2 && m_formspec_version > FORMSPEC_API_VERSION)) { if (m_is_form_regenerated) return; // Never focus on resizing @@ -2683,12 +2660,12 @@ void GUIFormSpecMenu::parseSetFocus(const std::string &element) } errorstream << "Invalid set_focus element (" << parts.size() << "): '" << element - << "'" << std::endl; + << "'" << std::endl; } -void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element) +void GUIFormSpecMenu::parseElement(parserData *data, const std::string &element) { - //some prechecks + // some prechecks if (element.empty()) return; @@ -2700,7 +2677,7 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element) return; std::string type = trim(element.substr(0, pos)); - std::string description = element.substr(pos+1); + std::string description = element.substr(pos + 1); if (type == "container") { parseContainer(data, description); @@ -2752,28 +2729,28 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element) return; } - if (type == "tableoptions"){ - parseTableOptions(data,description); + if (type == "tableoptions") { + parseTableOptions(data, description); return; } - if (type == "tablecolumns"){ - parseTableColumns(data,description); + if (type == "tablecolumns") { + parseTableColumns(data, description); return; } - if (type == "table"){ - parseTable(data,description); + if (type == "table") { + parseTable(data, description); return; } - if (type == "textlist"){ - parseTextList(data,description); + if (type == "textlist") { + parseTextList(data, description); return; } - if (type == "dropdown"){ - parseDropDown(data,description); + if (type == "dropdown") { + parseDropDown(data, description); return; } @@ -2783,62 +2760,62 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element) } if (type == "pwdfield") { - parsePwdField(data,description); + parsePwdField(data, description); return; } - if ((type == "field") || (type == "textarea")){ - parseField(data,description,type); + if ((type == "field") || (type == "textarea")) { + parseField(data, description, type); return; } if (type == "hypertext") { - parseHyperText(data,description); + parseHyperText(data, description); return; } if (type == "label") { - parseLabel(data,description); + parseLabel(data, description); return; } if (type == "vertlabel") { - parseVertLabel(data,description); + parseVertLabel(data, description); return; } if (type == "item_image_button") { - parseItemImageButton(data,description); + parseItemImageButton(data, description); return; } if ((type == "image_button") || (type == "image_button_exit")) { - parseImageButton(data,description,type); + parseImageButton(data, description, type); return; } if (type == "tabheader") { - parseTabHeader(data,description); + parseTabHeader(data, description); return; } if (type == "box") { - parseBox(data,description); + parseBox(data, description); return; } if (type == "bgcolor") { - parseBackgroundColor(data,description); + parseBackgroundColor(data, description); return; } if (type == "listcolors") { - parseListColors(data,description); + parseListColors(data, description); return; } if (type == "tooltip") { - parseTooltip(data,description); + parseTooltip(data, description); return; } @@ -2883,8 +2860,8 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element) } // Ignore others - infostream << "Unknown DrawSpec: type=" << type << ", data=\"" << description << "\"" - << std::endl; + infostream << "Unknown DrawSpec: type=" << type << ", data=\"" << description + << "\"" << std::endl; } void GUIFormSpecMenu::regenerateGui(v2u32 screensize) @@ -2979,33 +2956,33 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) { v3f formspec_bgcolor = g_settings->getV3F("formspec_default_bg_color"); - m_bgcolor = video::SColor( - (u8) clamp_u8(g_settings->getS32("formspec_default_bg_opacity")), - clamp_u8(myround(formspec_bgcolor.X)), - clamp_u8(myround(formspec_bgcolor.Y)), - clamp_u8(myround(formspec_bgcolor.Z)) - ); + m_bgcolor = video::SColor((u8)clamp_u8(g_settings->getS32( + "formspec_default_bg_opacity")), + clamp_u8(myround(formspec_bgcolor.X)), + clamp_u8(myround(formspec_bgcolor.Y)), + clamp_u8(myround(formspec_bgcolor.Z))); } { v3f formspec_bgcolor = g_settings->getV3F("formspec_fullscreen_bg_color"); m_fullscreen_bgcolor = video::SColor( - (u8) clamp_u8(g_settings->getS32("formspec_fullscreen_bg_opacity")), - clamp_u8(myround(formspec_bgcolor.X)), - clamp_u8(myround(formspec_bgcolor.Y)), - clamp_u8(myround(formspec_bgcolor.Z)) - ); + (u8)clamp_u8(g_settings->getS32( + "formspec_fullscreen_bg_opacity")), + clamp_u8(myround(formspec_bgcolor.X)), + clamp_u8(myround(formspec_bgcolor.Y)), + clamp_u8(myround(formspec_bgcolor.Z))); } - m_default_tooltip_bgcolor = video::SColor(255,110,130,60); - m_default_tooltip_color = video::SColor(255,255,255,255); + m_default_tooltip_bgcolor = video::SColor(255, 110, 130, 60); + m_default_tooltip_color = video::SColor(255, 255, 255, 255); // Add tooltip { assert(!m_tooltip_element); - // Note: parent != this so that the tooltip isn't clipped by the menu rectangle - m_tooltip_element = gui::StaticText::add(Environment, L"", - core::rect<s32>(0, 0, 110, 18)); + // Note: parent != this so that the tooltip isn't clipped by the menu + // rectangle + m_tooltip_element = gui::StaticText::add( + Environment, L"", core::rect<s32>(0, 0, 110, 18)); m_tooltip_element->enableOverrideColor(true); m_tooltip_element->setBackgroundColor(m_default_tooltip_bgcolor); m_tooltip_element->setDrawBackground(true); @@ -3013,11 +2990,11 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) m_tooltip_element->setOverrideColor(m_default_tooltip_color); m_tooltip_element->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); m_tooltip_element->setWordWrap(false); - //we're not parent so no autograb for this one! + // we're not parent so no autograb for this one! m_tooltip_element->grab(); } - std::vector<std::string> elements = split(m_formspec_string,']'); + std::vector<std::string> elements = split(m_formspec_string, ']'); unsigned int i = 0; /* try to read version from first element only */ @@ -3029,27 +3006,28 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) /* we need size first in order to calculate image scale */ mydata.explicit_size = false; - for (; i< elements.size(); i++) { + for (; i < elements.size(); i++) { if (!parseSizeDirect(&mydata, elements[i])) { break; } } /* "position" element is always after "size" element if it used */ - for (; i< elements.size(); i++) { + for (; i < elements.size(); i++) { if (!parsePositionDirect(&mydata, elements[i])) { break; } } /* "anchor" element is always after "position" (or "size" element) if it used */ - for (; i< elements.size(); i++) { + for (; i < elements.size(); i++) { if (!parseAnchorDirect(&mydata, elements[i])) { break; } } - /* "no_prepend" element is always after "position" (or "size" element) if it used */ + /* "no_prepend" element is always after "position" (or "size" element) if it used + */ bool enable_prepends = true; for (; i < elements.size(); i++) { if (elements[i].empty()) @@ -3076,7 +3054,8 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) if (mydata.explicit_size) { // compute scaling for specified form size if (m_lock) { - v2u32 current_screensize = RenderingEngine::get_video_driver()->getScreenSize(); + v2u32 current_screensize = RenderingEngine::get_video_driver() + ->getScreenSize(); v2u32 delta = current_screensize - m_lockscreensize; if (current_screensize.Y > m_lockscreensize.Y) @@ -3089,11 +3068,11 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) else delta.X = 0; - offset = v2s32(delta.X,delta.Y); + offset = v2s32(delta.X, delta.Y); mydata.screensize = m_lockscreensize; } else { - offset = v2s32(0,0); + offset = v2s32(0, 0); } double gui_scaling = g_settings->getFloat("gui_scaling"); @@ -3130,21 +3109,23 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) // maximum screen space available. double prefer_imgsize = mydata.screensize.Y / 10 * gui_scaling; double fitx_imgsize = mydata.screensize.X / - ((12.0 / 8.0) * (0.5 + mydata.invsize.X)); + ((12.0 / 8.0) * (0.5 + mydata.invsize.X)); double fity_imgsize = mydata.screensize.Y / - ((15.0 / 11.0) * (0.85 + mydata.invsize.Y)); + ((15.0 / 11.0) * (0.85 + mydata.invsize.Y)); use_imgsize = MYMIN(prefer_imgsize, MYMIN(fitx_imgsize, fity_imgsize)); #else double prefer_imgsize = mydata.screensize.Y / 15 * gui_scaling; double fitx_imgsize = mydata.screensize.X / - ((5.0 / 4.0) * (0.5 + mydata.invsize.X)); + ((5.0 / 4.0) * (0.5 + mydata.invsize.X)); double fity_imgsize = mydata.screensize.Y / - ((15.0 / 13.0) * (0.85 * mydata.invsize.Y)); + ((15.0 / 13.0) * (0.85 * mydata.invsize.Y)); double screen_dpi = RenderingEngine::getDisplayDensity() * 96; double min_imgsize = 0.3 * screen_dpi * gui_scaling; - use_imgsize = MYMAX(min_imgsize, MYMIN(prefer_imgsize, - MYMIN(fitx_imgsize, fity_imgsize))); + use_imgsize = MYMAX(min_imgsize, + MYMIN(prefer_imgsize, + MYMIN(fitx_imgsize, + fity_imgsize))); #endif } @@ -3157,30 +3138,45 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) // is 2/5 vertical inventory slot spacing, and button // half-height is 7/8 of font height. imgsize = v2s32(use_imgsize, use_imgsize); - spacing = v2f32(use_imgsize*5.0/4, use_imgsize*15.0/13); - padding = v2s32(use_imgsize*3.0/8, use_imgsize*3.0/8); - m_btn_height = use_imgsize*15.0/13 * 0.35; + spacing = v2f32(use_imgsize * 5.0 / 4, use_imgsize * 15.0 / 13); + padding = v2s32(use_imgsize * 3.0 / 8, use_imgsize * 3.0 / 8); + m_btn_height = use_imgsize * 15.0 / 13 * 0.35; m_font = g_fontengine->getFont(); if (mydata.real_coordinates) { - mydata.size = v2s32( - mydata.invsize.X*imgsize.X, - mydata.invsize.Y*imgsize.Y - ); + mydata.size = v2s32(mydata.invsize.X * imgsize.X, + mydata.invsize.Y * imgsize.Y); } else { mydata.size = v2s32( - padding.X*2+spacing.X*(mydata.invsize.X-1.0)+imgsize.X, - padding.Y*2+spacing.Y*(mydata.invsize.Y-1.0)+imgsize.Y + m_btn_height*2.0/3.0 - ); + padding.X * 2 + + spacing.X * (mydata.invsize.X - + 1.0) + + imgsize.X, + padding.Y * 2 + + spacing.Y * (mydata.invsize.Y - + 1.0) + + imgsize.Y + + m_btn_height * 2.0 / 3.0); } DesiredRect = mydata.rect = core::rect<s32>( - (s32)((f32)mydata.screensize.X * mydata.offset.X) - (s32)(mydata.anchor.X * (f32)mydata.size.X) + offset.X, - (s32)((f32)mydata.screensize.Y * mydata.offset.Y) - (s32)(mydata.anchor.Y * (f32)mydata.size.Y) + offset.Y, - (s32)((f32)mydata.screensize.X * mydata.offset.X) + (s32)((1.0 - mydata.anchor.X) * (f32)mydata.size.X) + offset.X, - (s32)((f32)mydata.screensize.Y * mydata.offset.Y) + (s32)((1.0 - mydata.anchor.Y) * (f32)mydata.size.Y) + offset.Y - ); + (s32)((f32)mydata.screensize.X * mydata.offset.X) - + (s32)(mydata.anchor.X * + (f32)mydata.size.X) + + offset.X, + (s32)((f32)mydata.screensize.Y * mydata.offset.Y) - + (s32)(mydata.anchor.Y * + (f32)mydata.size.Y) + + offset.Y, + (s32)((f32)mydata.screensize.X * mydata.offset.X) + + (s32)((1.0 - mydata.anchor.X) * + (f32)mydata.size.X) + + offset.X, + (s32)((f32)mydata.screensize.Y * mydata.offset.Y) + + (s32)((1.0 - mydata.anchor.Y) * + (f32)mydata.size.Y) + + offset.Y); } else { // Non-size[] form must consist only of text fields and // implicit "Proceed" button. Use default font, and @@ -3188,11 +3184,14 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) m_font = g_fontengine->getFont(); m_btn_height = font_line_height(m_font) * 0.875; DesiredRect = core::rect<s32>( - (s32)((f32)mydata.screensize.X * mydata.offset.X) - (s32)(mydata.anchor.X * 580.0), - (s32)((f32)mydata.screensize.Y * mydata.offset.Y) - (s32)(mydata.anchor.Y * 300.0), - (s32)((f32)mydata.screensize.X * mydata.offset.X) + (s32)((1.0 - mydata.anchor.X) * 580.0), - (s32)((f32)mydata.screensize.Y * mydata.offset.Y) + (s32)((1.0 - mydata.anchor.Y) * 300.0) - ); + (s32)((f32)mydata.screensize.X * mydata.offset.X) - + (s32)(mydata.anchor.X * 580.0), + (s32)((f32)mydata.screensize.Y * mydata.offset.Y) - + (s32)(mydata.anchor.Y * 300.0), + (s32)((f32)mydata.screensize.X * mydata.offset.X) + + (s32)((1.0 - mydata.anchor.X) * 580.0), + (s32)((f32)mydata.screensize.Y * mydata.offset.Y) + + (s32)((1.0 - mydata.anchor.Y) * 300.0)); } recalculateAbsolutePosition(false); mydata.basepos = getBasePos(); @@ -3209,12 +3208,14 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) core::list<IGUIElement *>::Iterator legacy_sort_start = Children.getLast(); if (enable_prepends) { - // Backup the coordinates so that prepends can use the coordinates of choice. + // Backup the coordinates so that prepends can use the coordinates of + // choice. bool rc_backup = mydata.real_coordinates; u16 version_backup = m_formspec_version; mydata.real_coordinates = false; // Old coordinates by default. - std::vector<std::string> prepend_elements = split(m_formspec_prepend, ']'); + std::vector<std::string> prepend_elements = + split(m_formspec_prepend, ']'); for (const auto &element : prepend_elements) parseElement(&mydata, element); @@ -3230,20 +3231,22 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) mydata.real_coordinates = rc_backup; // Restore coordinates } - for (; i< elements.size(); i++) { + for (; i < elements.size(); i++) { parseElement(&mydata, elements[i]); } if (mydata.current_parent != this) { - errorstream << "Invalid formspec string: scroll_container was never closed!" - << std::endl; + errorstream << "Invalid formspec string: scroll_container was never " + "closed!" + << std::endl; } else if (!container_stack.empty()) { errorstream << "Invalid formspec string: container was never closed!" - << std::endl; + << std::endl; } // get the scrollbar elements for scroll_containers - for (const std::pair<std::string, GUIScrollContainer *> &c : m_scroll_containers) { + for (const std::pair<std::string, GUIScrollContainer *> &c : + m_scroll_containers) { for (const std::pair<FieldSpec, GUIScrollBar *> &b : m_scrollbars) { if (c.first == b.first.fname) { c.second->setScrollBar(b.second); @@ -3255,12 +3258,11 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) // If there are fields without explicit size[], add a "Proceed" // button and adjust size to fit all the fields. if (mydata.simple_field_count > 0 && !mydata.explicit_size) { - mydata.rect = core::rect<s32>( - mydata.screensize.X / 2 - 580 / 2, + mydata.rect = core::rect<s32>(mydata.screensize.X / 2 - 580 / 2, mydata.screensize.Y / 2 - 300 / 2, mydata.screensize.X / 2 + 580 / 2, - mydata.screensize.Y / 2 + 240 / 2 + mydata.simple_field_count * 60 - ); + mydata.screensize.Y / 2 + 240 / 2 + + mydata.simple_field_count * 60); DesiredRect = mydata.rect; recalculateAbsolutePosition(false); @@ -3271,21 +3273,19 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) pos.Y = (mydata.simple_field_count + 2) * 60; v2s32 size = DesiredRect.getSize(); - mydata.rect = core::rect<s32>( - size.X / 2 - 70, pos.Y, - size.X / 2 - 70 + 140, pos.Y + m_btn_height * 2 - ); + mydata.rect = core::rect<s32>(size.X / 2 - 70, pos.Y, + size.X / 2 - 70 + 140, pos.Y + m_btn_height * 2); const wchar_t *text = wgettext("Proceed"); - GUIButton::addButton(Environment, mydata.rect, m_tsrc, this, 257, text); + GUIButton::addButton(Environment, mydata.rect, m_tsrc, this, 257, + text); delete[] text; } } // Set initial focus if parser didn't set it gui::IGUIElement *focused_element = Environment->getFocus(); - if (!focused_element - || !isMyChild(focused_element) - || focused_element->getType() == gui::EGUIET_TAB_CONTROL) + if (!focused_element || !isMyChild(focused_element) || + focused_element->getType() == gui::EGUIET_TAB_CONTROL) setInitialFocus(); skin->setFont(old_font); @@ -3329,12 +3329,12 @@ void GUIFormSpecMenu::legacySortElements(core::list<IGUIElement *>::Iterator fro // 2: Sort the container std::stable_sort(elements.begin(), elements.end(), - [this] (const IGUIElement *a, const IGUIElement *b) -> bool { - const FieldSpec *spec_a = getSpecByID(a->getID()); - const FieldSpec *spec_b = getSpecByID(b->getID()); - return spec_a && spec_b && - spec_a->priority < spec_b->priority; - }); + [this](const IGUIElement *a, const IGUIElement *b) -> bool { + const FieldSpec *spec_a = getSpecByID(a->getID()); + const FieldSpec *spec_b = getSpecByID(b->getID()); + return spec_a && spec_b && + spec_a->priority < spec_b->priority; + }); // 3: Re-assign the pointers for (auto e : elements) { @@ -3379,8 +3379,8 @@ GUIInventoryList::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const for (const GUIInventoryList *e : m_inventorylists) { s32 item_index = e->getItemIndexAtPos(p); if (item_index != -1) - return GUIInventoryList::ItemSpec(e->getInventoryloc(), e->getListname(), - item_index); + return GUIInventoryList::ItemSpec(e->getInventoryloc(), + e->getListname(), item_index); } return GUIInventoryList::ItemSpec(InventoryLocation(), "", -1); @@ -3388,13 +3388,13 @@ GUIInventoryList::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const void GUIFormSpecMenu::drawSelectedItem() { - video::IVideoDriver* driver = Environment->getVideoDriver(); + video::IVideoDriver *driver = Environment->getVideoDriver(); if (!m_selected_item) { // reset rotation time drawItemStack(driver, m_font, ItemStack(), - core::rect<s32>(v2s32(0, 0), v2s32(0, 0)), NULL, - m_client, IT_ROT_DRAGGED); + core::rect<s32>(v2s32(0, 0), v2s32(0, 0)), NULL, m_client, + IT_ROT_DRAGGED); return; } @@ -3405,7 +3405,7 @@ void GUIFormSpecMenu::drawSelectedItem() ItemStack stack = list->getItem(m_selected_item->i); stack.count = m_selected_amount; - core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y); + core::rect<s32> imgrect(0, 0, imgsize.X, imgsize.Y); core::rect<s32> rect = imgrect + (m_pointer - imgrect.getCenter()); rect.constrainTo(driver->getViewPort()); drawItemStack(driver, m_font, stack, rect, NULL, m_client, IT_ROT_DRAGGED); @@ -3422,7 +3422,7 @@ void GUIFormSpecMenu::drawMenu() } } - gui::IGUISkin* skin = Environment->getSkin(); + gui::IGUISkin *skin = Environment->getSkin(); sanity_check(skin != NULL); gui::IGUIFont *old_font = skin->getFont(); skin->setFont(m_font); @@ -3431,7 +3431,7 @@ void GUIFormSpecMenu::drawMenu() updateSelectedItem(); - video::IVideoDriver* driver = Environment->getVideoDriver(); + video::IVideoDriver *driver = Environment->getVideoDriver(); /* Draw background color @@ -3491,8 +3491,8 @@ void GUIFormSpecMenu::drawMenu() if (m_hovered_item_tooltips.empty()) { // reset rotation time drawItemStack(driver, m_font, ItemStack(), - core::rect<s32>(v2s32(0, 0), v2s32(0, 0)), - NULL, m_client, IT_ROT_HOVERED); + core::rect<s32>(v2s32(0, 0), v2s32(0, 0)), NULL, m_client, + IT_ROT_HOVERED); } /* TODO find way to show tooltips on touchscreen */ @@ -3507,8 +3507,8 @@ void GUIFormSpecMenu::drawMenu() Environment->getRootGUIElement()->getElementFromPoint(m_pointer); #ifndef HAVE_TOUCHSCREENGUI - gui::ICursorControl *cursor_control = RenderingEngine::get_raw_device()-> - getCursorControl(); + gui::ICursorControl *cursor_control = + RenderingEngine::get_raw_device()->getCursorControl(); gui::ECURSOR_ICON current_cursor_icon = cursor_control->getActiveIcon(); #endif bool hovered_element_found = false; @@ -3525,7 +3525,8 @@ void GUIFormSpecMenu::drawMenu() m_old_tooltip_id = id; } else { if (id == m_old_tooltip_id) { - delta = porting::getDeltaMs(m_hovered_time, porting::getTimeMs()); + delta = porting::getDeltaMs( + m_hovered_time, porting::getTimeMs()); } else { m_hovered_time = porting::getTimeMs(); m_old_tooltip_id = id; @@ -3540,14 +3541,19 @@ void GUIFormSpecMenu::drawMenu() continue; if (delta >= m_tooltip_show_delay) { - const std::wstring &text = m_tooltips[field.fname].tooltip; + const std::wstring &text = + m_tooltips[field.fname].tooltip; if (!text.empty()) - showTooltip(text, m_tooltips[field.fname].color, - m_tooltips[field.fname].bgcolor); + showTooltip(text, + m_tooltips[field.fname] + .color, + m_tooltips[field.fname] + .bgcolor); } #ifndef HAVE_TOUCHSCREENGUI - if (field.ftype != f_HyperText && // Handled directly in guiHyperText + if (field.ftype != f_HyperText && // Handled directly in + // guiHyperText current_cursor_icon != field.fcursor_icon) cursor_control->setActiveIcon(field.fcursor_icon); #endif @@ -3577,9 +3583,8 @@ void GUIFormSpecMenu::drawMenu() skin->setFont(old_font); } - void GUIFormSpecMenu::showTooltip(const std::wstring &text, - const irr::video::SColor &color, const irr::video::SColor &bgcolor) + const irr::video::SColor &color, const irr::video::SColor &bgcolor) { EnrichedString ntext(text); ntext.setDefaultColor(color); @@ -3596,7 +3601,7 @@ void GUIFormSpecMenu::showTooltip(const std::wstring &text, int tooltip_offset_y = m_btn_height; #ifdef __ANDROID__ tooltip_offset_x *= 3; - tooltip_offset_y = 0; + tooltip_offset_y = 0; if (m_pointer.X > (s32)screenSize.X / 2) tooltip_offset_x = -(tooltip_offset_x + tooltip_width); @@ -3609,16 +3614,13 @@ void GUIFormSpecMenu::showTooltip(const std::wstring &text, s32 tooltip_x = m_pointer.X + tooltip_offset_x; s32 tooltip_y = m_pointer.Y + tooltip_offset_y; if (tooltip_x + tooltip_width > (s32)screenSize.X) - tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height; + tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height; if (tooltip_y + tooltip_height > (s32)screenSize.Y) tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height; - m_tooltip_element->setRelativePosition( - core::rect<s32>( + m_tooltip_element->setRelativePosition(core::rect<s32>( core::position2d<s32>(tooltip_x, tooltip_y), - core::dimension2d<s32>(tooltip_width, tooltip_height) - ) - ); + core::dimension2d<s32>(tooltip_width, tooltip_height))); // Display the tooltip m_tooltip_element->setVisible(true); @@ -3673,17 +3675,23 @@ ItemStack GUIFormSpecMenu::verifySelectedItem() if (m_selected_item) { if (m_selected_item->isValid()) { - Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc); + Inventory *inv = m_invmgr->getInventory( + m_selected_item->inventoryloc); if (inv) { - InventoryList *list = inv->getList(m_selected_item->listname); - if (list && (u32) m_selected_item->i < list->getSize()) { - ItemStack stack = list->getItem(m_selected_item->i); + InventoryList *list = + inv->getList(m_selected_item->listname); + if (list && (u32)m_selected_item->i < list->getSize()) { + ItemStack stack = + list->getItem(m_selected_item->i); if (!m_selected_swap.empty()) { if (m_selected_swap.name == stack.name && - m_selected_swap.count == stack.count) + m_selected_swap.count == + stack.count) m_selected_swap.clear(); } else { - m_selected_amount = std::min(m_selected_amount, stack.count); + m_selected_amount = std::min( + m_selected_amount, + stack.count); } if (!stack.empty()) @@ -3701,10 +3709,9 @@ ItemStack GUIFormSpecMenu::verifySelectedItem() return ItemStack(); } -void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no) +void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode = quit_mode_no) { - if(m_text_dst) - { + if (m_text_dst) { StringMap fields; if (quitmode == quit_mode_accept) { @@ -3753,50 +3760,74 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no) fields[name] = table->checkEvent(); } } else if (s.ftype == f_DropDown) { - // No dynamic cast possible due to some distributions shipped - // without rtti support in Irrlicht - IGUIElement *element = getElementFromId(s.fid, true); + // No dynamic cast possible due to some + // distributions shipped without rtti support in + // Irrlicht + IGUIElement *element = + getElementFromId(s.fid, true); gui::IGUIComboBox *e = NULL; - if ((element) && (element->getType() == gui::EGUIET_COMBO_BOX)) { - e = static_cast<gui::IGUIComboBox *>(element); + if ((element) && + (element->getType() == + gui::EGUIET_COMBO_BOX)) { + e = static_cast<gui::IGUIComboBox *>( + element); } else { - warningstream << "GUIFormSpecMenu::acceptInput: dropdown " - << "field without dropdown element" << std::endl; + warningstream << "GUIFormSpecMenu::" + "acceptInput: dropdown " + << "field without dropdown " + "element" + << std::endl; continue; } s32 selected = e->getSelected(); if (selected >= 0) { - if (m_dropdown_index_event.find(s.fname) != - m_dropdown_index_event.end()) { - fields[name] = std::to_string(selected + 1); + if (m_dropdown_index_event.find( + s.fname) != + m_dropdown_index_event + .end()) { + fields[name] = std::to_string( + selected + 1); } else { std::vector<std::string> *dropdown_values = - getDropDownValues(s.fname); - if (dropdown_values && selected < (s32)dropdown_values->size()) - fields[name] = (*dropdown_values)[selected]; + getDropDownValues( + s.fname); + if (dropdown_values && + selected < (s32)dropdown_values->size()) + fields[name] = (*dropdown_values) + [selected]; } } } else if (s.ftype == f_TabHeader) { - // No dynamic cast possible due to some distributions shipped - // without rtti support in Irrlicht - IGUIElement *element = getElementFromId(s.fid, true); + // No dynamic cast possible due to some + // distributions shipped without rtti support in + // Irrlicht + IGUIElement *element = + getElementFromId(s.fid, true); gui::IGUITabControl *e = nullptr; - if ((element) && (element->getType() == gui::EGUIET_TAB_CONTROL)) { - e = static_cast<gui::IGUITabControl *>(element); + if ((element) && + (element->getType() == + gui::EGUIET_TAB_CONTROL)) { + e = static_cast<gui::IGUITabControl *>( + element); } if (e != 0) { std::stringstream ss; - ss << (e->getActiveTab() +1); + ss << (e->getActiveTab() + 1); fields[name] = ss.str(); } } else if (s.ftype == f_CheckBox) { - // No dynamic cast possible due to some distributions shipped - // without rtti support in Irrlicht - IGUIElement *element = getElementFromId(s.fid, true); + // No dynamic cast possible due to some + // distributions shipped without rtti support in + // Irrlicht + IGUIElement *element = + getElementFromId(s.fid, true); gui::IGUICheckBox *e = nullptr; - if ((element) && (element->getType() == gui::EGUIET_CHECK_BOX)) { - e = static_cast<gui::IGUICheckBox*>(element); + if ((element) && + (element->getType() == + gui::EGUIET_CHECK_BOX)) { + e = static_cast<gui::IGUICheckBox *>( + element); } if (e != 0) { @@ -3806,11 +3837,14 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no) fields[name] = "false"; } } else if (s.ftype == f_ScrollBar) { - // No dynamic cast possible due to some distributions shipped - // without rtti support in Irrlicht - IGUIElement *element = getElementFromId(s.fid, true); + // No dynamic cast possible due to some + // distributions shipped without rtti support in + // Irrlicht + IGUIElement *element = + getElementFromId(s.fid, true); GUIScrollBar *e = nullptr; - if (element && element->getType() == gui::EGUIET_ELEMENT) + if (element && element->getType() == + gui::EGUIET_ELEMENT) e = static_cast<GUIScrollBar *>(element); if (e) { @@ -3820,17 +3854,22 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no) fields[name] = "CHG:" + os.str(); else fields[name] = "VAL:" + os.str(); - } + } } else if (s.ftype == f_AnimatedImage) { - // No dynamic cast possible due to some distributions shipped - // without rtti support in Irrlicht - IGUIElement *element = getElementFromId(s.fid, true); + // No dynamic cast possible due to some + // distributions shipped without rtti support in + // Irrlicht + IGUIElement *element = + getElementFromId(s.fid, true); GUIAnimatedImage *e = nullptr; - if (element && element->getType() == gui::EGUIET_ELEMENT) - e = static_cast<GUIAnimatedImage *>(element); + if (element && element->getType() == + gui::EGUIET_ELEMENT) + e = static_cast<GUIAnimatedImage *>( + element); if (e) - fields[name] = std::to_string(e->getFrameIndex() + 1); + fields[name] = std::to_string( + e->getFrameIndex() + 1); } else { IGUIElement *e = getElementFromId(s.fid, true); if (e) @@ -3843,7 +3882,7 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no) } } -bool GUIFormSpecMenu::preprocessEvent(const SEvent& event) +bool GUIFormSpecMenu::preprocessEvent(const SEvent &event) { // The IGUITabControl renders visually using the skin's selected // font, which we override for the duration of form drawing, @@ -3856,11 +3895,11 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event) s32 x = event.MouseInput.X; s32 y = event.MouseInput.Y; gui::IGUIElement *hovered = - Environment->getRootGUIElement()->getElementFromPoint( - core::position2d<s32>(x, y)); + Environment->getRootGUIElement()->getElementFromPoint( + core::position2d<s32>(x, y)); if (hovered && isMyChild(hovered) && hovered->getType() == gui::EGUIET_TAB_CONTROL) { - gui::IGUISkin* skin = Environment->getSkin(); + gui::IGUISkin *skin = Environment->getSkin(); sanity_check(skin != NULL); gui::IGUIFont *old_font = skin->getFont(); skin->setFont(m_font); @@ -3872,16 +3911,19 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event) // Fix Esc/Return key being eaten by checkboxen and tables if (event.EventType == EET_KEY_INPUT_EVENT) { - KeyPress kp(event.KeyInput); - if (kp == EscapeKey || kp == CancelKey - || kp == getKeySetting("keymap_inventory") - || event.KeyInput.Key==KEY_RETURN) { + KeyPress kp(event.KeyInput); + if (kp == EscapeKey || kp == CancelKey || + kp == getKeySetting("keymap_inventory") || + event.KeyInput.Key == KEY_RETURN) { gui::IGUIElement *focused = Environment->getFocus(); if (focused && isMyChild(focused) && (focused->getType() == gui::EGUIET_LIST_BOX || - focused->getType() == gui::EGUIET_CHECK_BOX) && - (focused->getParent()->getType() != gui::EGUIET_COMBO_BOX || - event.KeyInput.Key != KEY_RETURN)) { + focused->getType() == + gui::EGUIET_CHECK_BOX) && + (focused->getParent()->getType() != + gui::EGUIET_COMBO_BOX || + event.KeyInput.Key != + KEY_RETURN)) { OnEvent(event); return true; } @@ -3890,13 +3932,14 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event) // Mouse wheel and move events: send to hovered element instead of focused if (event.EventType == EET_MOUSE_INPUT_EVENT && (event.MouseInput.Event == EMIE_MOUSE_WHEEL || - (event.MouseInput.Event == EMIE_MOUSE_MOVED && - event.MouseInput.ButtonStates == 0))) { + (event.MouseInput.Event == EMIE_MOUSE_MOVED && + event.MouseInput.ButtonStates == + 0))) { s32 x = event.MouseInput.X; s32 y = event.MouseInput.Y; gui::IGUIElement *hovered = - Environment->getRootGUIElement()->getElementFromPoint( - core::position2d<s32>(x, y)); + Environment->getRootGUIElement()->getElementFromPoint( + core::position2d<s32>(x, y)); if (hovered && isMyChild(hovered)) { hovered->OnEvent(event); return event.MouseInput.Event == EMIE_MOUSE_WHEEL; @@ -3949,13 +3992,19 @@ enum ButtonEventType : u8 BET_OTHER }; -bool GUIFormSpecMenu::OnEvent(const SEvent& event) +bool GUIFormSpecMenu::OnEvent(const SEvent &event) { - if (event.EventType==EET_KEY_INPUT_EVENT) { + if (event.EventType == EET_KEY_INPUT_EVENT) { KeyPress kp(event.KeyInput); - if (event.KeyInput.PressedDown && ( - (kp == EscapeKey) || (kp == CancelKey) || - ((m_client != NULL) && (kp == getKeySetting("keymap_inventory"))))) { + if (event.KeyInput.PressedDown && + ((kp == EscapeKey) || (kp == CancelKey) || + ((m_client != NULL) && + (kp == getKeySetting("key" + "map" + "_in" + "ven" + "tor" + "y"))))) { tryClose(); return true; } @@ -3965,29 +4014,30 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) m_client->makeScreenshot(); } - if (event.KeyInput.PressedDown && kp == getKeySetting("keymap_toggle_debug")) + if (event.KeyInput.PressedDown && + kp == getKeySetting("keymap_toggle_debug")) m_show_debug = !m_show_debug; if (event.KeyInput.PressedDown && - (event.KeyInput.Key==KEY_RETURN || - event.KeyInput.Key==KEY_UP || - event.KeyInput.Key==KEY_DOWN) - ) { + (event.KeyInput.Key == KEY_RETURN || + event.KeyInput.Key == KEY_UP || + event.KeyInput.Key == KEY_DOWN)) { switch (event.KeyInput.Key) { - case KEY_RETURN: - current_keys_pending.key_enter = true; - break; - case KEY_UP: - current_keys_pending.key_up = true; - break; - case KEY_DOWN: - current_keys_pending.key_down = true; - break; + case KEY_RETURN: + current_keys_pending.key_enter = true; + break; + case KEY_UP: + current_keys_pending.key_up = true; + break; + case KEY_DOWN: + current_keys_pending.key_down = true; + break; + break; + default: + // can't happen at all! + FATAL_ERROR("Reached a source line that can't ever been " + "reached"); break; - default: - //can't happen at all! - FATAL_ERROR("Reached a source line that can't ever been reached"); - break; } if (current_keys_pending.key_enter && m_allowclose) { acceptInput(quit_mode_accept); @@ -3997,7 +4047,6 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) } return true; } - } /* Mouse event other than movement, or crossing the border of inventory @@ -4005,9 +4054,11 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) */ if (event.EventType == EET_MOUSE_INPUT_EVENT && (event.MouseInput.Event != EMIE_MOUSE_MOVED || - (event.MouseInput.Event == EMIE_MOUSE_MOVED && - event.MouseInput.isRightPressed() && - getItemAtPos(m_pointer).i != getItemAtPos(m_old_pointer).i))) { + (event.MouseInput.Event == EMIE_MOUSE_MOVED && + event.MouseInput.isRightPressed() && + getItemAtPos(m_pointer).i != + getItemAtPos(m_old_pointer) + .i))) { // Get selected item and hovered/clicked item (s) @@ -4020,74 +4071,88 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) InventoryList *list_s = NULL; if (m_selected_item) { - inv_selected = m_invmgr->getInventory(m_selected_item->inventoryloc); + inv_selected = m_invmgr->getInventory( + m_selected_item->inventoryloc); sanity_check(inv_selected); - sanity_check(inv_selected->getList(m_selected_item->listname) != NULL); + sanity_check(inv_selected->getList(m_selected_item->listname) != + NULL); } u32 s_count = 0; if (s.isValid()) - do { // breakable - inv_s = m_invmgr->getInventory(s.inventoryloc); - - if (!inv_s) { - errorstream << "InventoryMenu: The selected inventory location " - << "\"" << s.inventoryloc.dump() << "\" doesn't exist" - << std::endl; - s.i = -1; // make it invalid again - break; - } + do { // breakable + inv_s = m_invmgr->getInventory(s.inventoryloc); + + if (!inv_s) { + errorstream << "InventoryMenu: The selected " + "inventory location " + << "\"" << s.inventoryloc.dump() + << "\" doesn't exist" << std::endl; + s.i = -1; // make it invalid again + break; + } - list_s = inv_s->getList(s.listname); - if (list_s == NULL) { - verbosestream << "InventoryMenu: The selected inventory list \"" - << s.listname << "\" does not exist" << std::endl; - s.i = -1; // make it invalid again - break; - } + list_s = inv_s->getList(s.listname); + if (list_s == NULL) { + verbosestream << "InventoryMenu: The selected " + "inventory list \"" + << s.listname << "\" does not exist" + << std::endl; + s.i = -1; // make it invalid again + break; + } - if ((u32)s.i >= list_s->getSize()) { - infostream << "InventoryMenu: The selected inventory list \"" - << s.listname << "\" is too small (i=" << s.i << ", size=" - << list_s->getSize() << ")" << std::endl; - s.i = -1; // make it invalid again - break; - } + if ((u32)s.i >= list_s->getSize()) { + infostream << "InventoryMenu: The selected " + "inventory list \"" + << s.listname + << "\" is too small (i=" << s.i + << ", size=" << list_s->getSize() + << ")" << std::endl; + s.i = -1; // make it invalid again + break; + } - s_count = list_s->getItem(s.i).count; - } while(0); + s_count = list_s->getItem(s.i).count; + } while (0); bool identical = m_selected_item && s.isValid() && - (inv_selected == inv_s) && - (m_selected_item->listname == s.listname) && - (m_selected_item->i == s.i); + (inv_selected == inv_s) && + (m_selected_item->listname == s.listname) && + (m_selected_item->i == s.i); ButtonEventType button = BET_LEFT; ButtonEventType updown = BET_OTHER; switch (event.MouseInput.Event) { case EMIE_LMOUSE_PRESSED_DOWN: - button = BET_LEFT; updown = BET_DOWN; + button = BET_LEFT; + updown = BET_DOWN; break; case EMIE_RMOUSE_PRESSED_DOWN: - button = BET_RIGHT; updown = BET_DOWN; + button = BET_RIGHT; + updown = BET_DOWN; break; case EMIE_MMOUSE_PRESSED_DOWN: - button = BET_MIDDLE; updown = BET_DOWN; + button = BET_MIDDLE; + updown = BET_DOWN; break; case EMIE_MOUSE_WHEEL: - button = (event.MouseInput.Wheel > 0) ? - BET_WHEEL_UP : BET_WHEEL_DOWN; + button = (event.MouseInput.Wheel > 0) ? BET_WHEEL_UP + : BET_WHEEL_DOWN; updown = BET_DOWN; break; case EMIE_LMOUSE_LEFT_UP: - button = BET_LEFT; updown = BET_UP; + button = BET_LEFT; + updown = BET_UP; break; case EMIE_RMOUSE_LEFT_UP: - button = BET_RIGHT; updown = BET_UP; + button = BET_RIGHT; + updown = BET_UP; break; case EMIE_MMOUSE_LEFT_UP: - button = BET_MIDDLE; updown = BET_UP; + button = BET_MIDDLE; + updown = BET_UP; break; case EMIE_MOUSE_MOVED: updown = BET_MOVE; @@ -4115,7 +4180,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) case BET_DOWN: // Some mouse button has been pressed - //infostream << "Mouse button " << button << " pressed at p=(" + // infostream << "Mouse button " << button << " pressed at p=(" // << event.MouseInput.X << "," << event.MouseInput.Y << ")" // << std::endl; @@ -4126,8 +4191,10 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) craft_amount = (button == BET_MIDDLE ? 10 : 1); } else if (!m_selected_item) { if (s_count && button != BET_WHEEL_UP) { - // Non-empty stack has been clicked: select or shift-move it - m_selected_item = new GUIInventoryList::ItemSpec(s); + // Non-empty stack has been clicked: select or + // shift-move it + m_selected_item = + new GUIInventoryList::ItemSpec(s); u32 count; if (button == BET_RIGHT) @@ -4136,17 +4203,22 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) count = MYMIN(s_count, 10); else if (button == BET_WHEEL_DOWN) count = 1; - else // left + else // left count = s_count; if (!event.MouseInput.Shift) { // no shift: select item m_selected_amount = count; - m_selected_dragging = button != BET_WHEEL_DOWN; + m_selected_dragging = + button != BET_WHEEL_DOWN; m_auto_place = false; } else { - // shift pressed: move item, right click moves 1 - shift_move_amount = button == BET_RIGHT ? 1 : count; + // shift pressed: move item, right click + // moves 1 + shift_move_amount = + button == BET_RIGHT + ? 1 + : count; } } } else { // m_selected_item != NULL @@ -4157,7 +4229,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) if (button == BET_RIGHT || button == BET_WHEEL_UP) move_amount = 1; else if (button == BET_MIDDLE) - move_amount = MYMIN(m_selected_amount, 10); + move_amount = MYMIN( + m_selected_amount, 10); else if (button == BET_LEFT) move_amount = m_selected_amount; // else wheeldown @@ -4167,38 +4240,44 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) if (m_selected_amount < s_count) ++m_selected_amount; } else { - if (move_amount >= m_selected_amount) + if (move_amount >= + m_selected_amount) m_selected_amount = 0; else - m_selected_amount -= move_amount; + m_selected_amount -= + move_amount; move_amount = 0; } } - } else if (!getAbsoluteClippingRect().isPointInside(m_pointer) - && button != BET_WHEEL_DOWN) { + } else if (!getAbsoluteClippingRect().isPointInside( + m_pointer) && + button != BET_WHEEL_DOWN) { // Clicked outside of the window: drop if (button == BET_RIGHT || button == BET_WHEEL_UP) drop_amount = 1; else if (button == BET_MIDDLE) - drop_amount = MYMIN(m_selected_amount, 10); - else // left + drop_amount = MYMIN( + m_selected_amount, 10); + else // left drop_amount = m_selected_amount; } } - break; + break; case BET_UP: // Some mouse button has been released - //infostream<<"Mouse button "<<button<<" released at p=(" + // infostream<<"Mouse button "<<button<<" released at p=(" // <<p.X<<","<<p.Y<<")"<<std::endl; if (m_selected_dragging && m_selected_item) { if (s.isValid()) { if (!identical) { - // Dragged to different slot: move all selected + // Dragged to different slot: move all + // selected move_amount = m_selected_amount; } - } else if (!getAbsoluteClippingRect().isPointInside(m_pointer)) { + } else if (!getAbsoluteClippingRect().isPointInside( + m_pointer)) { // Dragged outside of window: drop all selected drop_amount = m_selected_amount; } @@ -4210,28 +4289,32 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) // + click changes to drop item when moved mode if (m_selected_item) m_auto_place = true; - break; + break; case BET_MOVE: // Mouse has been moved and rmb is down and mouse pointer just // entered a new inventory field (checked in the entry-if, this // is the only action here that is generated by mouse movement) - if (m_selected_item && s.isValid() && s.listname != "craftpreview") { + if (m_selected_item && s.isValid() && + s.listname != "craftpreview") { // Move 1 item // TODO: middle mouse to move 10 items might be handy if (m_auto_place) { - // Only move an item if the destination slot is empty - // or contains the same item type as what is going to be - // moved - InventoryList *list_from = inv_selected->getList(m_selected_item->listname); + // Only move an item if the destination slot is + // empty or contains the same item type as what is + // going to be moved + InventoryList *list_from = inv_selected->getList( + m_selected_item->listname); InventoryList *list_to = list_s; assert(list_from && list_to); - ItemStack stack_from = list_from->getItem(m_selected_item->i); + ItemStack stack_from = list_from->getItem( + m_selected_item->i); ItemStack stack_to = list_to->getItem(s.i); - if (stack_to.empty() || stack_to.name == stack_from.name) + if (stack_to.empty() || + stack_to.name == stack_from.name) move_amount = 1; } } - break; + break; default: break; } @@ -4244,15 +4327,18 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) assert(s.isValid()); assert(inv_selected && inv_s); - InventoryList *list_from = inv_selected->getList(m_selected_item->listname); + InventoryList *list_from = + inv_selected->getList(m_selected_item->listname); InventoryList *list_to = list_s; assert(list_from && list_to); ItemStack stack_from = list_from->getItem(m_selected_item->i); ItemStack stack_to = list_to->getItem(s.i); // Check how many items can be moved - move_amount = stack_from.count = MYMIN(move_amount, stack_from.count); - ItemStack leftover = stack_to.addItem(stack_from, m_client->idef()); + move_amount = stack_from.count = + MYMIN(move_amount, stack_from.count); + ItemStack leftover = + stack_to.addItem(stack_from, m_client->idef()); bool move = true; // If source stack cannot be added to destination stack at all, // they are swapped @@ -4264,7 +4350,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) m_selected_dragging = false; // WARNING: BLACK MAGIC, BUT IN A REDUCED SET - // Skip next validation checks due async inventory calls + // Skip next validation checks due async inventory + // calls m_selected_swap = stack_to; } else { move = false; @@ -4281,7 +4368,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) } if (move) { - infostream << "Handing IAction::Move to manager" << std::endl; + infostream << "Handing IAction::Move to manager" + << std::endl; IMoveAction *a = new IMoveAction(); a->count = move_amount; a->from_inv = m_selected_item->inventoryloc; @@ -4297,28 +4385,32 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) u32 i = 0; for (; i < mis; i++) { const ListRingSpec &sp = m_inventory_rings[i]; - if (sp.inventoryloc == s.inventoryloc - && sp.listname == s.listname) + if (sp.inventoryloc == s.inventoryloc && + sp.listname == s.listname) break; } do { if (i >= mis) // if not found break; u32 to_inv_ind = (i + 1) % mis; - const ListRingSpec &to_inv_sp = m_inventory_rings[to_inv_ind]; + const ListRingSpec &to_inv_sp = + m_inventory_rings[to_inv_ind]; InventoryList *list_from = list_s; if (!s.isValid()) break; - Inventory *inv_to = m_invmgr->getInventory(to_inv_sp.inventoryloc); + Inventory *inv_to = m_invmgr->getInventory( + to_inv_sp.inventoryloc); if (!inv_to) break; - InventoryList *list_to = inv_to->getList(to_inv_sp.listname); + InventoryList *list_to = + inv_to->getList(to_inv_sp.listname); if (!list_to) break; ItemStack stack_from = list_from->getItem(s.i); assert(shift_move_amount <= stack_from.count); - infostream << "Handing IAction::Move to manager" << std::endl; + infostream << "Handing IAction::Move to manager" + << std::endl; IMoveAction *a = new IMoveAction(); a->count = shift_move_amount; a->from_inv = s.inventoryloc; @@ -4334,12 +4426,14 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) assert(m_selected_item && m_selected_item->isValid()); assert(inv_selected); - InventoryList *list_from = inv_selected->getList(m_selected_item->listname); + InventoryList *list_from = + inv_selected->getList(m_selected_item->listname); assert(list_from); ItemStack stack_from = list_from->getItem(m_selected_item->i); // Check how many items can be dropped - drop_amount = stack_from.count = MYMIN(drop_amount, stack_from.count); + drop_amount = stack_from.count = + MYMIN(drop_amount, stack_from.count); assert(drop_amount > 0 && drop_amount <= m_selected_amount); m_selected_amount -= drop_amount; @@ -4355,13 +4449,14 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) // if there are no items selected or the selected item // belongs to craftresult list, proceed with crafting - if (!m_selected_item || - !m_selected_item->isValid() || m_selected_item->listname == "craftresult") { + if (!m_selected_item || !m_selected_item->isValid() || + m_selected_item->listname == "craftresult") { assert(inv_s); // Send IACTION_CRAFT - infostream << "Handing IACTION_CRAFT to manager" << std::endl; + infostream << "Handing IACTION_CRAFT to manager" + << std::endl; ICraftAction *a = new ICraftAction(); a->count = craft_amount; a->craft_inv = s.inventoryloc; @@ -4381,8 +4476,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) } if (event.EventType == EET_GUI_EVENT) { - if (event.GUIEvent.EventType == gui::EGET_TAB_CHANGED - && isVisible()) { + if (event.GUIEvent.EventType == gui::EGET_TAB_CHANGED && isVisible()) { // find the element that was clicked for (GUIFormSpecMenu::FieldSpec &s : m_fields) { if ((s.ftype == f_TabHeader) && @@ -4394,19 +4488,23 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) } } } - if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST - && isVisible()) { + if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && + isVisible()) { if (!canTakeFocus(event.GUIEvent.Element)) { - infostream<<"GUIFormSpecMenu: Not allowing focus change." - <<std::endl; + infostream << "GUIFormSpecMenu: Not allowing focus " + "change." + << std::endl; // Returning true disables focus change return true; } } if ((event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) || - (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED) || - (event.GUIEvent.EventType == gui::EGET_COMBO_BOX_CHANGED) || - (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED)) { + (event.GUIEvent.EventType == + gui::EGET_CHECKBOX_CHANGED) || + (event.GUIEvent.EventType == + gui::EGET_COMBO_BOX_CHANGED) || + (event.GUIEvent.EventType == + gui::EGET_SCROLL_BAR_CHANGED)) { s32 caller_id = event.GUIEvent.Caller->getID(); if (caller_id == 257) { @@ -4436,7 +4534,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) acceptInput(quit_mode_accept); quitMenu(); } else { - m_text_dst->gotText(L"ExitButton"); + m_text_dst->gotText( + L"ExitButton"); } return true; } @@ -4455,8 +4554,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) s.send = true; acceptInput(quit_mode_no); - // revert configuration to make sure dropdowns are sent on - // regular button click + // revert configuration to make sure dropdowns are + // sent on regular button click for (GUIFormSpecMenu::FieldSpec &s2 : m_fields) { if (s2.ftype == f_DropDown) { s2.send = true; @@ -4467,7 +4566,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) s.fdefault = L"Changed"; acceptInput(quit_mode_no); s.fdefault = L""; - } else if (s.ftype == f_Unknown || s.ftype == f_HyperText) { + } else if (s.ftype == f_Unknown || + s.ftype == f_HyperText) { s.send = true; acceptInput(); s.send = false; @@ -4477,7 +4577,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) if (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED) { // move scroll_containers - for (const std::pair<std::string, GUIScrollContainer *> &c : m_scroll_containers) + for (const std::pair<std::string, GUIScrollContainer *> &c : + m_scroll_containers) c.second->onScrollEvent(event.GUIEvent.Caller); } @@ -4488,8 +4589,10 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) if (s.ftype == f_Unknown && s.fid == event.GUIEvent.Caller->getID()) { current_field_enter_pending = s.fname; - std::unordered_map<std::string, bool>::const_iterator it = - field_close_on_enter.find(s.fname); + std::unordered_map<std::string, + bool>::const_iterator it = + field_close_on_enter.find( + s.fname); if (it != field_close_on_enter.end()) close_on_enter = (*it).second; @@ -4517,10 +4620,11 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) for (GUIFormSpecMenu::FieldSpec &s : m_fields) { // if it's a table, set the send field // so lua knows which table was changed - if ((s.ftype == f_Table) && (s.fid == current_id)) { + if ((s.ftype == f_Table) && + (s.fid == current_id)) { s.send = true; acceptInput(); - s.send=false; + s.send = false; } } return true; @@ -4545,7 +4649,6 @@ std::string GUIFormSpecMenu::getNameByID(s32 id) return ""; } - const GUIFormSpecMenu::FieldSpec *GUIFormSpecMenu::getSpecByID(s32 id) { for (FieldSpec &spec : m_fields) { @@ -4570,12 +4673,14 @@ std::wstring GUIFormSpecMenu::getLabelByID(s32 id) } StyleSpec GUIFormSpecMenu::getDefaultStyleForElement(const std::string &type, - const std::string &name, const std::string &parent_type) { + const std::string &name, const std::string &parent_type) +{ return getStyleForElement(type, name, parent_type)[StyleSpec::STATE_DEFAULT]; } std::array<StyleSpec, StyleSpec::NUM_STATES> GUIFormSpecMenu::getStyleForElement( - const std::string &type, const std::string &name, const std::string &parent_type) + const std::string &type, const std::string &name, + const std::string &parent_type) { std::array<StyleSpec, StyleSpec::NUM_STATES> ret; diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h index 613acaa04..ea9731258 100644 --- a/src/gui/guiFormSpecMenu.h +++ b/src/gui/guiFormSpecMenu.h @@ -41,7 +41,8 @@ class Client; class TexturePool; class GUIScrollContainer; -typedef enum { +typedef enum +{ f_Button, f_Table, f_TabHeader, @@ -55,7 +56,8 @@ typedef enum { f_Unknown } FormspecFieldType; -typedef enum { +typedef enum +{ quit_mode_no, quit_mode_accept, quit_mode_cancel @@ -88,9 +90,9 @@ class GUIFormSpecMenu : public GUIModalMenu ListRingSpec() = default; ListRingSpec(const InventoryLocation &a_inventoryloc, - const std::string &a_listname): - inventoryloc(a_inventoryloc), - listname(a_listname) + const std::string &a_listname) : + inventoryloc(a_inventoryloc), + listname(a_listname) { } @@ -103,17 +105,15 @@ class GUIFormSpecMenu : public GUIModalMenu FieldSpec() = default; FieldSpec(const std::string &name, const std::wstring &label, - const std::wstring &default_text, s32 id, int priority = 0, + const std::wstring &default_text, s32 id, + int priority = 0, gui::ECURSOR_ICON cursor_icon = ECI_NORMAL) : - fname(name), - flabel(label), - fdefault(unescape_enriched(translate_string(default_text))), - fid(id), - send(false), - ftype(f_Unknown), - is_exit(false), - priority(priority), - fcursor_icon(cursor_icon) + fname(name), + flabel(label), + fdefault(unescape_enriched( + translate_string(default_text))), + fid(id), send(false), ftype(f_Unknown), is_exit(false), + priority(priority), fcursor_icon(cursor_icon) { } @@ -134,10 +134,9 @@ class GUIFormSpecMenu : public GUIModalMenu { TooltipSpec() = default; TooltipSpec(const std::wstring &a_tooltip, irr::video::SColor a_bgcolor, - irr::video::SColor a_color): - tooltip(translate_string(a_tooltip)), - bgcolor(a_bgcolor), - color(a_color) + irr::video::SColor a_color) : + tooltip(translate_string(a_tooltip)), + bgcolor(a_bgcolor), color(a_color) { } @@ -147,21 +146,16 @@ class GUIFormSpecMenu : public GUIModalMenu }; public: - GUIFormSpecMenu(JoystickController *joystick, - gui::IGUIElement* parent, s32 id, - IMenuManager *menumgr, - Client *client, - ISimpleTextureSource *tsrc, - IFormSource* fs_src, - TextDest* txt_dst, - const std::string &formspecPrepend, - bool remap_dbl_click = true); + GUIFormSpecMenu(JoystickController *joystick, gui::IGUIElement *parent, s32 id, + IMenuManager *menumgr, Client *client, ISimpleTextureSource *tsrc, + IFormSource *fs_src, TextDest *txt_dst, + const std::string &formspecPrepend, bool remap_dbl_click = true); ~GUIFormSpecMenu(); static void create(GUIFormSpecMenu *&cur_formspec, Client *client, - JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest, - const std::string &formspecPrepend); + JoystickController *joystick, IFormSource *fs_src, + TextDest *txt_dest, const std::string &formspecPrepend); void setFormSpec(const std::string &formspec_string, const InventoryLocation ¤t_inventory_location) @@ -196,12 +190,9 @@ public: m_text_dst = text_dst; } - void allowClose(bool value) - { - m_allowclose = value; - } + void allowClose(bool value) { m_allowclose = value; } - void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) + void lockSize(bool lock, v2u32 basescreensize = v2u32(0, 0)) { m_lock = lock; m_lockscreensize = basescreensize; @@ -210,30 +201,18 @@ public: void removeChildren(); void setInitialFocus(); - void setFocus(const std::string &elementname) - { - m_focused_element = elementname; - } + void setFocus(const std::string &elementname) { m_focused_element = elementname; } - Client *getClient() const - { - return m_client; - } + Client *getClient() const { return m_client; } const GUIInventoryList::ItemSpec *getSelectedItem() const { return m_selected_item; } - const u16 getSelectedAmount() const - { - return m_selected_amount; - } + const u16 getSelectedAmount() const { return m_selected_amount; } - bool doTooltipAppendItemname() const - { - return m_tooltip_append_itemname; - } + bool doTooltipAppendItemname() const { return m_tooltip_append_itemname; } void addHoveredItemTooltip(const std::string &name) { @@ -252,13 +231,13 @@ public: ItemStack verifySelectedItem(); void acceptInput(FormspecQuitMode quitmode); - bool preprocessEvent(const SEvent& event); - bool OnEvent(const SEvent& event); + bool preprocessEvent(const SEvent &event); + bool OnEvent(const SEvent &event); bool doPause; bool pausesGame() { return doPause; } - GUITable* getTable(const std::string &tablename); - std::vector<std::string>* getDropDownValues(const std::string &name); + GUITable *getTable(const std::string &tablename); + std::vector<std::string> *getDropDownValues(const std::string &name); #ifdef __ANDROID__ bool getAndroidUIInput(); @@ -267,7 +246,7 @@ public: protected: v2s32 getBasePos() const { - return padding + offset + AbsoluteRect.UpperLeftCorner; + return padding + offset + AbsoluteRect.UpperLeftCorner; } std::wstring getLabelByID(s32 id); std::string getNameByID(s32 id); @@ -281,9 +260,11 @@ protected: std::unordered_set<std::string> property_warned; StyleSpec getDefaultStyleForElement(const std::string &type, - const std::string &name="", const std::string &parent_type=""); - std::array<StyleSpec, StyleSpec::NUM_STATES> getStyleForElement(const std::string &type, - const std::string &name="", const std::string &parent_type=""); + const std::string &name = "", + const std::string &parent_type = ""); + std::array<StyleSpec, StyleSpec::NUM_STATES> getStyleForElement( + const std::string &type, const std::string &name = "", + const std::string &parent_type = ""); v2s32 padding; v2f32 spacing; @@ -345,15 +326,16 @@ protected: video::SColor m_default_tooltip_color; private: - IFormSource *m_form_src; - TextDest *m_text_dst; - std::string m_last_formname; - u16 m_formspec_version = 1; - std::string m_focused_element = ""; + IFormSource *m_form_src; + TextDest *m_text_dst; + std::string m_last_formname; + u16 m_formspec_version = 1; + std::string m_focused_element = ""; JoystickController *m_joystick; bool m_show_debug = false; - typedef struct { + typedef struct + { bool explicit_size; bool real_coordinates; u8 simple_field_count; @@ -370,20 +352,23 @@ private: GUIInventoryList::Options inventorylist_options; - struct { + struct + { s32 max = 1000; s32 min = 0; s32 small_step = 10; s32 large_step = 100; s32 thumb_size = 1; - GUIScrollBar::ArrowVisibility arrow_visiblity = GUIScrollBar::DEFAULT; + GUIScrollBar::ArrowVisibility arrow_visiblity = + GUIScrollBar::DEFAULT; } scrollbar_options; // used to restore table selection/scroll/treeview state std::unordered_map<std::string, GUITable::DynamicData> table_dyndata; } parserData; - typedef struct { + typedef struct + { bool key_up; bool key_down; bool key_enter; @@ -394,49 +379,50 @@ private: std::string current_field_enter_pending = ""; std::vector<std::string> m_hovered_item_tooltips; - void parseElement(parserData* data, const std::string &element); + void parseElement(parserData *data, const std::string &element); - void parseSize(parserData* data, const std::string &element); - void parseContainer(parserData* data, const std::string &element); - void parseContainerEnd(parserData* data); + void parseSize(parserData *data, const std::string &element); + void parseContainer(parserData *data, const std::string &element); + void parseContainerEnd(parserData *data); void parseScrollContainer(parserData *data, const std::string &element); void parseScrollContainerEnd(parserData *data); - void parseList(parserData* data, const std::string &element); - void parseListRing(parserData* data, const std::string &element); - void parseCheckbox(parserData* data, const std::string &element); - void parseImage(parserData* data, const std::string &element); + void parseList(parserData *data, const std::string &element); + void parseListRing(parserData *data, const std::string &element); + void parseCheckbox(parserData *data, const std::string &element); + void parseImage(parserData *data, const std::string &element); void parseAnimatedImage(parserData *data, const std::string &element); - void parseItemImage(parserData* data, const std::string &element); - void parseButton(parserData* data, const std::string &element, + void parseItemImage(parserData *data, const std::string &element); + void parseButton(parserData *data, const std::string &element, const std::string &typ); - void parseBackground(parserData* data, const std::string &element); - void parseTableOptions(parserData* data, const std::string &element); - void parseTableColumns(parserData* data, const std::string &element); - void parseTable(parserData* data, const std::string &element); - void parseTextList(parserData* data, const std::string &element); - void parseDropDown(parserData* data, const std::string &element); + void parseBackground(parserData *data, const std::string &element); + void parseTableOptions(parserData *data, const std::string &element); + void parseTableColumns(parserData *data, const std::string &element); + void parseTable(parserData *data, const std::string &element); + void parseTextList(parserData *data, const std::string &element); + void parseDropDown(parserData *data, const std::string &element); void parseFieldCloseOnEnter(parserData *data, const std::string &element); - void parsePwdField(parserData* data, const std::string &element); - void parseField(parserData* data, const std::string &element, const std::string &type); - void createTextField(parserData *data, FieldSpec &spec, - core::rect<s32> &rect, bool is_multiline); - void parseSimpleField(parserData* data,std::vector<std::string> &parts); - void parseTextArea(parserData* data,std::vector<std::string>& parts, + void parsePwdField(parserData *data, const std::string &element); + void parseField(parserData *data, const std::string &element, + const std::string &type); + void createTextField(parserData *data, FieldSpec &spec, core::rect<s32> &rect, + bool is_multiline); + void parseSimpleField(parserData *data, std::vector<std::string> &parts); + void parseTextArea(parserData *data, std::vector<std::string> &parts, const std::string &type); void parseHyperText(parserData *data, const std::string &element); - void parseLabel(parserData* data, const std::string &element); - void parseVertLabel(parserData* data, const std::string &element); - void parseImageButton(parserData* data, const std::string &element, + void parseLabel(parserData *data, const std::string &element); + void parseVertLabel(parserData *data, const std::string &element); + void parseImageButton(parserData *data, const std::string &element, const std::string &type); - void parseItemImageButton(parserData* data, const std::string &element); - void parseTabHeader(parserData* data, const std::string &element); - void parseBox(parserData* data, const std::string &element); - void parseBackgroundColor(parserData* data, const std::string &element); - void parseListColors(parserData* data, const std::string &element); - void parseTooltip(parserData* data, const std::string &element); + void parseItemImageButton(parserData *data, const std::string &element); + void parseTabHeader(parserData *data, const std::string &element); + void parseBox(parserData *data, const std::string &element); + void parseBackgroundColor(parserData *data, const std::string &element); + void parseListColors(parserData *data, const std::string &element); + void parseTooltip(parserData *data, const std::string &element); bool parseVersionDirect(const std::string &data); - bool parseSizeDirect(parserData* data, const std::string &element); - void parseScrollBar(parserData* data, const std::string &element); + bool parseSizeDirect(parserData *data, const std::string &element); + void parseScrollBar(parserData *data, const std::string &element); void parseScrollBarOptions(parserData *data, const std::string &element); bool parsePositionDirect(parserData *data, const std::string &element); void parsePosition(parserData *data, const std::string &element); @@ -448,7 +434,7 @@ private: void tryClose(); void showTooltip(const std::wstring &text, const irr::video::SColor &color, - const irr::video::SColor &bgcolor); + const irr::video::SColor &bgcolor); /** * In formspec version < 2 the elements were not ordered properly. Some element @@ -461,25 +447,16 @@ private: gui::IGUIFont *m_font = nullptr; }; -class FormspecFormSource: public IFormSource +class FormspecFormSource : public IFormSource { public: - FormspecFormSource(const std::string &formspec): - m_formspec(formspec) - { - } + FormspecFormSource(const std::string &formspec) : m_formspec(formspec) {} ~FormspecFormSource() = default; - void setForm(const std::string &formspec) - { - m_formspec = formspec; - } + void setForm(const std::string &formspec) { m_formspec = formspec; } - const std::string &getForm() const - { - return m_formspec; - } + const std::string &getForm() const { return m_formspec; } std::string m_formspec; }; diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 88931cdf9..70c5d3f66 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -71,8 +71,8 @@ void ParsedText::Element::setStyle(StyleList &style) if (style["fontstyle"] == "mono") font_mode = FM_Mono; - FontSpec spec(font_size, font_mode, - is_yes(style["bold"]), is_yes(style["italic"])); + FontSpec spec(font_size, font_mode, is_yes(style["bold"]), + is_yes(style["italic"])); // TODO: find a way to check font validity // Build a new fontengine ? @@ -247,8 +247,9 @@ void ParsedText::endParagraph(EndReason reason) EndReason previous = m_end_paragraph_reason; m_end_paragraph_reason = reason; - if (m_empty_paragraph && (reason == ER_TAG || - (reason == ER_NEWLINE && previous == ER_TAG))) { + if (m_empty_paragraph && + (reason == ER_TAG || + (reason == ER_NEWLINE && previous == ER_TAG))) { // Ignore last empty paragraph m_paragraph = nullptr; m_paragraphs.pop_back(); @@ -539,10 +540,13 @@ u32 ParsedText::parseTag(const wchar_t *text, u32 cursor) std::string str = attrs["rotate"]; std::vector<std::string> parts = split(str, ','); if (parts.size() == 3) { - m_element->rotation = v3s16 ( - rangelim(stoi(parts[0]), -1000, 1000), - rangelim(stoi(parts[1]), -1000, 1000), - rangelim(stoi(parts[2]), -1000, 1000)); + m_element->rotation = v3s16( + rangelim(stoi(parts[0]), -1000, + 1000), + rangelim(stoi(parts[1]), -1000, + 1000), + rangelim(stoi(parts[2]), -1000, + 1000)); } } } @@ -614,12 +618,14 @@ TextDrawer::TextDrawer(const wchar_t *text, Client *client, case ParsedText::ELEMENT_SEPARATOR: case ParsedText::ELEMENT_TEXT: if (e.font) { - e.dim.Width = e.font->getDimension(e.text.c_str()).Width; + e.dim.Width = e.font->getDimension(e.text.c_str()) + .Width; e.dim.Height = e.font->getDimension(L"Yy").Height; #if USE_FREETYPE if (e.font->getType() == irr::gui::EGFT_CUSTOM) { e.baseline = e.dim.Height - 1 - - ((irr::gui::CGUITTFont *)e.font)->getAscender() / 64; + ((irr::gui::CGUITTFont *)e.font)->getAscender() / + 64; } #endif } else { @@ -638,8 +644,8 @@ TextDrawer::TextDrawer(const wchar_t *text, Client *client, if (e.type == ParsedText::ELEMENT_IMAGE) { video::ITexture *texture = - m_client->getTextureSource()-> - getTexture(stringw_to_utf8(e.text)); + m_client->getTextureSource()->getTexture( + stringw_to_utf8(e.text)); if (texture) dim = texture->getOriginalSize(); } @@ -649,10 +655,10 @@ TextDrawer::TextDrawer(const wchar_t *text, Client *client, e.dim = dim; else e.dim.Height = dim.Height * e.dim.Width / - dim.Width; + dim.Width; else e.dim.Width = dim.Width * e.dim.Height / - dim.Height; + dim.Height; break; } } @@ -706,7 +712,7 @@ void TextDrawer::place(const core::rect<s32> &dest_rect) e->pos.X = m_text.margin; if (e->floating == ParsedText::FLOAT_RIGHT) e->pos.X = dest_rect.getWidth() - e->dim.Width - - m_text.margin; + m_text.margin; RectWithMargin floating; floating.rect = core::rect<s32>(e->pos, e->dim); @@ -739,38 +745,54 @@ void TextDrawer::place(const core::rect<s32> &dest_rect) for (const auto &f : m_floating) { // Does floating rect intersect paragraph y line? if (f.rect.UpperLeftCorner.Y - f.margin <= y && - f.rect.LowerRightCorner.Y + f.margin >= y) { + f.rect.LowerRightCorner.Y + f.margin >= + y) { // Next Y to try if no room left - if (!nexty || f.rect.LowerRightCorner.Y + - std::max(f.margin, p.margin) < nexty) { - nexty = f.rect.LowerRightCorner.Y + - std::max(f.margin, p.margin) + 1; + if (!nexty || f.rect.LowerRightCorner.Y + std::max(f.margin, + p.margin) < + nexty) { + nexty = f.rect.LowerRightCorner + .Y + + std::max(f.margin, + p.margin) + + 1; } - if (f.rect.UpperLeftCorner.X - f.margin <= left && - f.rect.LowerRightCorner.X + f.margin < right) { + if (f.rect.UpperLeftCorner.X - f.margin <= + left && + f.rect.LowerRightCorner.X + f.margin < + right) { // float on left - if (f.rect.LowerRightCorner.X + - std::max(f.margin, p.margin) > left) { - left = f.rect.LowerRightCorner.X + - std::max(f.margin, p.margin); + if (f.rect.LowerRightCorner.X + std::max(f.margin, + p.margin) > + left) { + left = f.rect.LowerRightCorner + .X + + std::max(f.margin, + p.margin); } - } else if (f.rect.LowerRightCorner.X + f.margin >= right && - f.rect.UpperLeftCorner.X - f.margin > left) { + } else if (f.rect.LowerRightCorner.X + f.margin >= + right && + f.rect.UpperLeftCorner.X - f.margin > + left) { // float on right - if (f.rect.UpperLeftCorner.X - - std::max(f.margin, p.margin) < right) - right = f.rect.UpperLeftCorner.X - - std::max(f.margin, p.margin); - - } else if (f.rect.UpperLeftCorner.X - f.margin <= left && - f.rect.LowerRightCorner.X + f.margin >= right) { + if (f.rect.UpperLeftCorner.X - std::max(f.margin, + p.margin) < + right) + right = f.rect.UpperLeftCorner + .X - + std::max(f.margin, + p.margin); + + } else if (f.rect.UpperLeftCorner.X - f.margin <= + left && + f.rect.LowerRightCorner.X + f.margin >= + right) { // float taking all space left = right; - } - else - { // float in the middle -- should not occure yet, see that later + } else { // float in the middle -- should + // not occure yet, see that later } } } @@ -796,12 +818,14 @@ void TextDrawer::place(const core::rect<s32> &dest_rect) } std::vector<ParsedText::Element>::iterator linestart = el; - std::vector<ParsedText::Element>::iterator lineend = p.elements.end(); + std::vector<ParsedText::Element>::iterator lineend = + p.elements.end(); // First pass, find elements fitting into line // (or at least one element) - while (el != p.elements.end() && (charswidth == 0 || - charswidth + el->dim.Width <= linewidth)) { + while (el != p.elements.end() && + (charswidth == 0 || charswidth + el->dim.Width <= + linewidth)) { if (el->floating == ParsedText::FLOAT_NONE) { if (el->type != ParsedText::ELEMENT_SEPARATOR) { lineend = el; @@ -844,9 +868,14 @@ void TextDrawer::place(const core::rect<s32> &dest_rect) x += (linewidth - charswidth) / 2.f; break; case ParsedText::HALIGN_JUSTIFY: - if (wordcount > 1 && // Justification only if at least two words - !(lineend == p.elements.end())) // Don't justify last line - extraspace = ((float)(linewidth - charswidth)) / (wordcount - 1); + if (wordcount > 1 && // Justification only if at least two + // words + !(lineend == p.elements.end())) // Don't + // justify + // last + // line + extraspace = ((float)(linewidth - charswidth)) / + (wordcount - 1); break; case ParsedText::HALIGN_RIGHT: x += linewidth - charswidth; @@ -889,7 +918,7 @@ void TextDrawer::place(const core::rect<s32> &dest_rect) } y += charsheight; } // Elements (actually lines) - } // Paragraph + } // Paragraph // Check if float goes under paragraph for (const auto &f : m_floating) { @@ -949,16 +978,18 @@ void TextDrawer::draw(const core::rect<s32> &clip_rect, el.font->draw(el.text, rect, color, false, true, &clip_rect); - if (el.underline && el.drawwidth) { + if (el.underline && el.drawwidth) { s32 linepos = el.pos.Y + offset.Y + - el.dim.Height - (el.baseline >> 1); + el.dim.Height - (el.baseline >> 1); core::rect<s32> linerect(el.pos.X + offset.X, linepos - (el.baseline >> 3) - 1, - el.pos.X + offset.X + el.drawwidth, + el.pos.X + offset.X + + el.drawwidth, linepos + (el.baseline >> 3)); - driver->draw2DRectangle(color, linerect, &clip_rect); + driver->draw2DRectangle( + color, linerect, &clip_rect); } } break; @@ -970,7 +1001,10 @@ void TextDrawer::draw(const core::rect<s32> &clip_rect, m_environment->getVideoDriver()->draw2DImage( texture, rect, irr::core::rect<s32>( - core::position2d<s32>(0, 0), + core::position2d< + s32>( + 0, + 0), texture->getOriginalSize()), &clip_rect, 0, true); } break; @@ -980,11 +1014,10 @@ void TextDrawer::draw(const core::rect<s32> &clip_rect, ItemStack item; item.deSerialize(stringw_to_utf8(el.text), idef); - drawItemStack( - m_environment->getVideoDriver(), - g_fontengine->getFont(), item, rect, &clip_rect, - m_client, IT_ROT_OTHER, el.angle, el.rotation - ); + drawItemStack(m_environment->getVideoDriver(), + g_fontengine->getFont(), item, rect, + &clip_rect, m_client, IT_ROT_OTHER, + el.angle, el.rotation); } break; } } @@ -1089,8 +1122,10 @@ bool GUIHyperText::OnEvent(const SEvent &event) checkHover(event.MouseInput.X, event.MouseInput.Y); if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) { - m_vscrollbar->setPos(m_vscrollbar->getPos() - - event.MouseInput.Wheel * m_vscrollbar->getSmallStep()); + m_vscrollbar->setPos( + m_vscrollbar->getPos() - + event.MouseInput.Wheel * + m_vscrollbar->getSmallStep()); m_text_scrollpos.Y = -m_vscrollbar->getPos(); m_drawer.draw(m_display_text_rect, m_text_scrollpos); checkHover(event.MouseInput.X, event.MouseInput.Y); @@ -1104,13 +1139,16 @@ bool GUIHyperText::OnEvent(const SEvent &event) for (auto &tag : element->tags) { if (tag->name == "action") { Text = core::stringw(L"action:") + - utf8_to_stringw(tag->attrs["name"]); + utf8_to_stringw(tag->attrs["nam" + "e"]); if (Parent) { SEvent newEvent; - newEvent.EventType = EET_GUI_EVENT; + newEvent.EventType = + EET_GUI_EVENT; newEvent.GUIEvent.Caller = this; newEvent.GUIEvent.Element = 0; - newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED; + newEvent.GUIEvent.EventType = + EGET_BUTTON_CLICKED; Parent->OnEvent(newEvent); } break; @@ -1137,7 +1175,8 @@ void GUIHyperText::draw() if (m_drawer.getHeight() > m_display_text_rect.getHeight()) { m_vscrollbar->setSmallStep(m_display_text_rect.getHeight() * 0.1f); m_vscrollbar->setLargeStep(m_display_text_rect.getHeight() * 0.5f); - m_vscrollbar->setMax(m_drawer.getHeight() - m_display_text_rect.getHeight()); + m_vscrollbar->setMax( + m_drawer.getHeight() - m_display_text_rect.getHeight()); m_vscrollbar->setVisible(true); diff --git a/src/gui/guiHyperText.h b/src/gui/guiHyperText.h index 5b936262e..8371157e2 100644 --- a/src/gui/guiHyperText.h +++ b/src/gui/guiHyperText.h @@ -134,7 +134,12 @@ public: Tag m_root_tag; protected: - typedef enum { ER_NONE, ER_TAG, ER_NEWLINE } EndReason; + typedef enum + { + ER_NONE, + ER_TAG, + ER_NEWLINE + } EndReason; // Parser functions void enterElement(ElementType type); diff --git a/src/gui/guiInventoryList.cpp b/src/gui/guiInventoryList.cpp index 58d7ae771..a0fef4073 100644 --- a/src/gui/guiInventoryList.cpp +++ b/src/gui/guiInventoryList.cpp @@ -19,33 +19,17 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/hud.h" #include "client/client.h" -GUIInventoryList::GUIInventoryList(gui::IGUIEnvironment *env, - gui::IGUIElement *parent, - s32 id, - const core::rect<s32> &rectangle, - InventoryManager *invmgr, - const InventoryLocation &inventoryloc, - const std::string &listname, - const v2s32 &geom, - const s32 start_item_i, - const v2s32 &slot_size, - const v2f32 &slot_spacing, - GUIFormSpecMenu *fs_menu, - const Options &options, - gui::IGUIFont *font) : - gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), - m_invmgr(invmgr), - m_inventoryloc(inventoryloc), - m_listname(listname), - m_geom(geom), - m_start_item_i(start_item_i), - m_slot_size(slot_size), - m_slot_spacing(slot_spacing), - m_fs_menu(fs_menu), - m_options(options), - m_font(font), - m_hovered_i(-1), - m_already_warned(false) +GUIInventoryList::GUIInventoryList(gui::IGUIEnvironment *env, gui::IGUIElement *parent, + s32 id, const core::rect<s32> &rectangle, InventoryManager *invmgr, + const InventoryLocation &inventoryloc, const std::string &listname, + const v2s32 &geom, const s32 start_item_i, const v2s32 &slot_size, + const v2f32 &slot_spacing, GUIFormSpecMenu *fs_menu, + const Options &options, gui::IGUIFont *font) : + gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), + m_invmgr(invmgr), m_inventoryloc(inventoryloc), m_listname(listname), + m_geom(geom), m_start_item_i(start_item_i), m_slot_size(slot_size), + m_slot_spacing(slot_spacing), m_fs_menu(fs_menu), m_options(options), + m_font(font), m_hovered_i(-1), m_already_warned(false) { } @@ -58,9 +42,9 @@ void GUIInventoryList::draw() if (!inv) { if (!m_already_warned) { warningstream << "GUIInventoryList::draw(): " - << "The inventory location " - << "\"" << m_inventoryloc.dump() << "\" doesn't exist" - << std::endl; + << "The inventory location " + << "\"" << m_inventoryloc.dump() + << "\" doesn't exist" << std::endl; m_already_warned = true; } return; @@ -69,9 +53,9 @@ void GUIInventoryList::draw() if (!ilist) { if (!m_already_warned) { warningstream << "GUIInventoryList::draw(): " - << "The inventory list \"" << m_listname << "\" @ \"" - << m_inventoryloc.dump() << "\" doesn't exist" - << std::endl; + << "The inventory list \"" << m_listname + << "\" @ \"" << m_inventoryloc.dump() + << "\" doesn't exist" << std::endl; m_already_warned = true; } return; @@ -97,21 +81,25 @@ void GUIInventoryList::draw() core::rect<s32> rect = imgrect + base_pos + p; ItemStack item = ilist->getItem(item_i); - bool selected = selected_item - && m_invmgr->getInventory(selected_item->inventoryloc) == inv - && selected_item->listname == m_listname - && selected_item->i == item_i; + bool selected = selected_item && + m_invmgr->getInventory(selected_item->inventoryloc) == + inv && + selected_item->listname == m_listname && + selected_item->i == item_i; core::rect<s32> clipped_rect(rect); clipped_rect.clipAgainst(AbsoluteClippingRect); bool hovering = m_hovered_i == item_i; - ItemRotationKind rotation_kind = selected ? IT_ROT_SELECTED : - (hovering ? IT_ROT_HOVERED : IT_ROT_NONE); + ItemRotationKind rotation_kind = + selected ? IT_ROT_SELECTED + : (hovering ? IT_ROT_HOVERED : IT_ROT_NONE); // layer 0 if (hovering) { - driver->draw2DRectangle(m_options.slotbg_h, rect, &AbsoluteClippingRect); + driver->draw2DRectangle( + m_options.slotbg_h, rect, &AbsoluteClippingRect); } else { - driver->draw2DRectangle(m_options.slotbg_n, rect, &AbsoluteClippingRect); + driver->draw2DRectangle( + m_options.slotbg_n, rect, &AbsoluteClippingRect); } // Draw inv slot borders @@ -121,21 +109,27 @@ void GUIInventoryList::draw() s32 x2 = rect.LowerRightCorner.X; s32 y2 = rect.LowerRightCorner.Y; s32 border = 1; - core::rect<s32> clipping_rect = Parent ? Parent->getAbsoluteClippingRect() - : core::rect<s32>(); - core::rect<s32> *clipping_rect_ptr = Parent ? &clipping_rect : nullptr; + core::rect<s32> clipping_rect = + Parent ? Parent->getAbsoluteClippingRect() + : core::rect<s32>(); + core::rect<s32> *clipping_rect_ptr = + Parent ? &clipping_rect : nullptr; driver->draw2DRectangle(m_options.slotbordercolor, - core::rect<s32>(v2s32(x1 - border, y1 - border), - v2s32(x2 + border, y1)), clipping_rect_ptr); + core::rect<s32>(v2s32(x1 - border, y1 - border), + v2s32(x2 + border, y1)), + clipping_rect_ptr); driver->draw2DRectangle(m_options.slotbordercolor, - core::rect<s32>(v2s32(x1 - border, y2), - v2s32(x2 + border, y2 + border)), clipping_rect_ptr); + core::rect<s32>(v2s32(x1 - border, y2), + v2s32(x2 + border, y2 + border)), + clipping_rect_ptr); driver->draw2DRectangle(m_options.slotbordercolor, - core::rect<s32>(v2s32(x1 - border, y1), - v2s32(x1, y2)), clipping_rect_ptr); + core::rect<s32>(v2s32(x1 - border, y1), + v2s32(x1, y2)), + clipping_rect_ptr); driver->draw2DRectangle(m_options.slotbordercolor, - core::rect<s32>(v2s32(x2, y1), - v2s32(x2 + border, y2)), clipping_rect_ptr); + core::rect<s32>(v2s32(x2, y1), + v2s32(x2 + border, y2)), + clipping_rect_ptr); } // layer 1 @@ -179,8 +173,7 @@ bool GUIInventoryList::OnEvent(const SEvent &event) // find the element that would be hovered if this inventorylist was invisible bool was_visible = IsVisible; IsVisible = false; - IGUIElement *hovered = - Environment->getRootGUIElement()->getElementFromPoint( + IGUIElement *hovered = Environment->getRootGUIElement()->getElementFromPoint( core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)); // if the player clicks outside of the formspec window, hovered is not @@ -216,11 +209,10 @@ s32 GUIInventoryList::getItemIndexAtPos(v2s32 p) const v2s32 base_pos = AbsoluteRect.UpperLeftCorner; // instead of looping through each slot, we look where p would be in the grid - s32 i = (p.X - base_pos.X) / (s32)m_slot_spacing.X - + m_geom.X * ((p.Y - base_pos.Y) / (s32)m_slot_spacing.Y); + s32 i = (p.X - base_pos.X) / (s32)m_slot_spacing.X + + m_geom.X * ((p.Y - base_pos.Y) / (s32)m_slot_spacing.Y); - v2s32 p0((i % m_geom.X) * m_slot_spacing.X, - (i / m_geom.X) * m_slot_spacing.Y); + v2s32 p0((i % m_geom.X) * m_slot_spacing.X, (i / m_geom.X) * m_slot_spacing.Y); core::rect<s32> rect = imgrect + base_pos + p0; diff --git a/src/gui/guiInventoryList.h b/src/gui/guiInventoryList.h index 934d9ea3a..58d71cabf 100644 --- a/src/gui/guiInventoryList.h +++ b/src/gui/guiInventoryList.h @@ -30,11 +30,9 @@ public: ItemSpec() = default; ItemSpec(const InventoryLocation &a_inventoryloc, - const std::string &a_listname, - s32 a_i) : - inventoryloc(a_inventoryloc), - listname(a_listname), - i(a_i) + const std::string &a_listname, s32 a_i) : + inventoryloc(a_inventoryloc), + listname(a_listname), i(a_i) { } @@ -46,7 +44,8 @@ public: }; // options for inventorylists that are setable with the lua api - struct Options { + struct Options + { // whether a one-pixel border for the slots should be drawn and its color bool slotborder = false; video::SColor slotbordercolor = video::SColor(200, 0, 0, 0); @@ -55,34 +54,21 @@ public: video::SColor slotbg_h = video::SColor(255, 192, 192, 192); }; - GUIInventoryList(gui::IGUIEnvironment *env, - gui::IGUIElement *parent, - s32 id, - const core::rect<s32> &rectangle, - InventoryManager *invmgr, - const InventoryLocation &inventoryloc, - const std::string &listname, - const v2s32 &geom, - const s32 start_item_i, - const v2s32 &slot_size, - const v2f32 &slot_spacing, - GUIFormSpecMenu *fs_menu, - const Options &options, - gui::IGUIFont *font); + GUIInventoryList(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, + const core::rect<s32> &rectangle, InventoryManager *invmgr, + const InventoryLocation &inventoryloc, + const std::string &listname, const v2s32 &geom, + const s32 start_item_i, const v2s32 &slot_size, + const v2f32 &slot_spacing, GUIFormSpecMenu *fs_menu, + const Options &options, gui::IGUIFont *font); virtual void draw() override; virtual bool OnEvent(const SEvent &event) override; - const InventoryLocation &getInventoryloc() const - { - return m_inventoryloc; - } + const InventoryLocation &getInventoryloc() const { return m_inventoryloc; } - const std::string &getListname() const - { - return m_listname; - } + const std::string &getListname() const { return m_listname; } void setSlotBGColors(const video::SColor &slotbg_n, const video::SColor &slotbg_h) { diff --git a/src/gui/guiItemImage.cpp b/src/gui/guiItemImage.cpp index f93d5476c..95775dbba 100644 --- a/src/gui/guiItemImage.cpp +++ b/src/gui/guiItemImage.cpp @@ -20,11 +20,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiItemImage.h" #include "client/client.h" -GUIItemImage::GUIItemImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, - s32 id, const core::rect<s32> &rectangle, const std::string &item_name, - gui::IGUIFont *font, Client *client) : - gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), - m_item_name(item_name), m_font(font), m_client(client), m_label(core::stringw()) +GUIItemImage::GUIItemImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, + const core::rect<s32> &rectangle, const std::string &item_name, + gui::IGUIFont *font, Client *client) : + gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), + m_item_name(item_name), m_font(font), m_client(client), + m_label(core::stringw()) { } diff --git a/src/gui/guiItemImage.h b/src/gui/guiItemImage.h index 6fede6564..ced693ee2 100644 --- a/src/gui/guiItemImage.h +++ b/src/gui/guiItemImage.h @@ -28,15 +28,12 @@ class GUIItemImage : public gui::IGUIElement { public: GUIItemImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, - const core::rect<s32> &rectangle, const std::string &item_name, - gui::IGUIFont *font, Client *client); + const core::rect<s32> &rectangle, const std::string &item_name, + gui::IGUIFont *font, Client *client); virtual void draw() override; - virtual void setText(const wchar_t *text) override - { - m_label = text; - } + virtual void setText(const wchar_t *text) override { m_label = text; } private: std::string m_item_name; diff --git a/src/gui/guiKeyChangeMenu.cpp b/src/gui/guiKeyChangeMenu.cpp index 94fe0074a..e65a8311c 100644 --- a/src/gui/guiKeyChangeMenu.cpp +++ b/src/gui/guiKeyChangeMenu.cpp @@ -32,7 +32,7 @@ #include "settings.h" #include <algorithm> -#include "mainmenumanager.h" // for g_gamecallback +#include "mainmenumanager.h" // for g_gamecallback #define KMaxButtonPerColumns 12 @@ -40,7 +40,9 @@ extern MainGameCallback *g_gamecallback; enum { - GUI_ID_BACK_BUTTON = 101, GUI_ID_ABORT_BUTTON, GUI_ID_SCROLL_BAR, + GUI_ID_BACK_BUTTON = 101, + GUI_ID_ABORT_BUTTON, + GUI_ID_SCROLL_BAR, // buttons GUI_ID_KEY_FORWARD_BUTTON, GUI_ID_KEY_BACKWARD_BUTTON, @@ -92,9 +94,8 @@ enum GUI_ID_CB_AUTOJUMP, }; -GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env, - gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, - ISimpleTextureSource *tsrc) : +GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, + s32 id, IMenuManager *menumgr, ISimpleTextureSource *tsrc) : GUIModalMenu(env, parent, id, menumgr), m_tsrc(tsrc) { @@ -114,9 +115,9 @@ GUIKeyChangeMenu::~GUIKeyChangeMenu() void GUIKeyChangeMenu::removeChildren() { - const core::list<gui::IGUIElement*> &children = getChildren(); - core::list<gui::IGUIElement*> children_copy; - for (gui::IGUIElement*i : children) { + const core::list<gui::IGUIElement *> &children = getChildren(); + core::list<gui::IGUIElement *> children_copy; + for (gui::IGUIElement *i : children) { children_copy.push_back(i); } @@ -131,12 +132,9 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) removeChildren(); const float s = m_gui_scale; - DesiredRect = core::rect<s32>( - screensize.X / 2 - 1113 * s / 2, - screensize.Y / 2 - 430 * s / 2, - screensize.X / 2 + 1113 * s / 2, - screensize.Y / 2 + 430 * s / 2 - ); + DesiredRect = core::rect<s32>(screensize.X / 2 - 1113 * s / 2, + screensize.Y / 2 - 430 * s / 2, screensize.X / 2 + 1113 * s / 2, + screensize.Y / 2 + 430 * s / 2); recalculateAbsolutePosition(false); v2s32 size = DesiredRect.getSize(); @@ -145,32 +143,33 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) { core::rect<s32> rect(0, 0, 600 * s, 40 * s); rect += topleft + v2s32(25 * s, 3 * s); - //gui::IGUIStaticText *t = - const wchar_t *text = wgettext("Keybindings. (If this menu screws up, remove stuff from minetest.conf)"); - Environment->addStaticText(text, - rect, false, true, this, -1); + // gui::IGUIStaticText *t = + const wchar_t *text = wgettext("Keybindings. (If this menu screws up, " + "remove stuff from minetest.conf)"); + Environment->addStaticText(text, rect, false, true, this, -1); delete[] text; - //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); + // t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); } // Build buttons v2s32 offset(25 * s, 60 * s); - for(size_t i = 0; i < key_settings.size(); i++) - { + for (size_t i = 0; i < key_settings.size(); i++) { key_setting *k = key_settings.at(i); { core::rect<s32> rect(0, 0, 150 * s, 20 * s); rect += topleft + v2s32(offset.X, offset.Y); - Environment->addStaticText(k->button_name, rect, false, true, this, -1); + Environment->addStaticText( + k->button_name, rect, false, true, this, -1); } { core::rect<s32> rect(0, 0, 100 * s, 30 * s); rect += topleft + v2s32(offset.X + 150 * s, offset.Y - 5 * s); const wchar_t *text = wgettext(k->key.name()); - k->button = GUIButton::addButton(Environment, rect, m_tsrc, this, k->id, text); + k->button = GUIButton::addButton( + Environment, rect, m_tsrc, this, k->id, text); delete[] text; } if ((i + 1) % KMaxButtonPerColumns == 0) { @@ -189,8 +188,8 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) core::rect<s32> rect(0, 0, option_w, 30 * s); rect += topleft + v2s32(option_x, option_y); const wchar_t *text = wgettext("\"Special\" = climb down"); - Environment->addCheckBox(g_settings->getBool("aux1_descends"), rect, this, - GUI_ID_CB_AUX1_DESCENDS, text); + Environment->addCheckBox(g_settings->getBool("aux1_descends"), + rect, this, GUI_ID_CB_AUX1_DESCENDS, text); delete[] text; } offset += v2s32(0, 25 * s); @@ -203,9 +202,10 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) { core::rect<s32> rect(0, 0, option_w, 30 * s); rect += topleft + v2s32(option_x, option_y); - const wchar_t *text = wgettext("Double tap \"jump\" to toggle fly"); - Environment->addCheckBox(g_settings->getBool("doubletap_jump"), rect, this, - GUI_ID_CB_DOUBLETAP_JUMP, text); + const wchar_t *text = + wgettext("Double tap \"jump\" to toggle fly"); + Environment->addCheckBox(g_settings->getBool("doubletap_jump"), + rect, this, GUI_ID_CB_DOUBLETAP_JUMP, text); delete[] text; } offset += v2s32(0, 25 * s); @@ -219,8 +219,8 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) core::rect<s32> rect(0, 0, option_w, 30 * s); rect += topleft + v2s32(option_x, option_y); const wchar_t *text = wgettext("Automatic jumping"); - Environment->addCheckBox(g_settings->getBool("autojump"), rect, this, - GUI_ID_CB_AUTOJUMP, text); + Environment->addCheckBox(g_settings->getBool("autojump"), rect, + this, GUI_ID_CB_AUTOJUMP, text); delete[] text; } offset += v2s32(0, 25); @@ -229,25 +229,27 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) { core::rect<s32> rect(0, 0, 100 * s, 30 * s); rect += topleft + v2s32(size.X / 2 - 105 * s, size.Y - 40 * s); - const wchar_t *text = wgettext("Save"); - GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_BACK_BUTTON, text); + const wchar_t *text = wgettext("Save"); + GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_BACK_BUTTON, + text); delete[] text; } { core::rect<s32> rect(0, 0, 100 * s, 30 * s); rect += topleft + v2s32(size.X / 2 + 5 * s, size.Y - 40 * s); const wchar_t *text = wgettext("Cancel"); - GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_ABORT_BUTTON, text); + GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_ABORT_BUTTON, + text); delete[] text; } } void GUIKeyChangeMenu::drawMenu() { - gui::IGUISkin* skin = Environment->getSkin(); + gui::IGUISkin *skin = Environment->getSkin(); if (!skin) return; - video::IVideoDriver* driver = Environment->getVideoDriver(); + video::IVideoDriver *driver = Environment->getVideoDriver(); video::SColor bgcolor(140, 0, 0, 0); driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect); @@ -269,18 +271,21 @@ bool GUIKeyChangeMenu::acceptInput() { gui::IGUIElement *e = getElementFromId(GUI_ID_CB_AUX1_DESCENDS); - if(e && e->getType() == gui::EGUIET_CHECK_BOX) - g_settings->setBool("aux1_descends", ((gui::IGUICheckBox*)e)->isChecked()); + if (e && e->getType() == gui::EGUIET_CHECK_BOX) + g_settings->setBool("aux1_descends", + ((gui::IGUICheckBox *)e)->isChecked()); } { gui::IGUIElement *e = getElementFromId(GUI_ID_CB_DOUBLETAP_JUMP); - if(e && e->getType() == gui::EGUIET_CHECK_BOX) - g_settings->setBool("doubletap_jump", ((gui::IGUICheckBox*)e)->isChecked()); + if (e && e->getType() == gui::EGUIET_CHECK_BOX) + g_settings->setBool("doubletap_jump", + ((gui::IGUICheckBox *)e)->isChecked()); } { gui::IGUIElement *e = getElementFromId(GUI_ID_CB_AUTOJUMP); - if(e && e->getType() == gui::EGUIET_CHECK_BOX) - g_settings->setBool("autojump", ((gui::IGUICheckBox*)e)->isChecked()); + if (e && e->getType() == gui::EGUIET_CHECK_BOX) + g_settings->setBool("autojump", + ((gui::IGUICheckBox *)e)->isChecked()); } clearKeyCache(); @@ -301,10 +306,10 @@ bool GUIKeyChangeMenu::resetMenu() } return true; } -bool GUIKeyChangeMenu::OnEvent(const SEvent& event) +bool GUIKeyChangeMenu::OnEvent(const SEvent &event) { - if (event.EventType == EET_KEY_INPUT_EVENT && active_key - && event.KeyInput.PressedDown) { + if (event.EventType == EET_KEY_INPUT_EVENT && active_key && + event.KeyInput.PressedDown) { bool prefer_character = shift_down; KeyPress kp(event.KeyInput, prefer_character); @@ -315,10 +320,10 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) kp = active_key->key; // Cancel bool shift_went_down = false; - if(!shift_down && + if (!shift_down && (event.KeyInput.Key == irr::KEY_SHIFT || - event.KeyInput.Key == irr::KEY_LSHIFT || - event.KeyInput.Key == irr::KEY_RSHIFT)) + event.KeyInput.Key == irr::KEY_LSHIFT || + event.KeyInput.Key == irr::KEY_RSHIFT)) shift_went_down = true; // Display Key already in use message @@ -336,8 +341,8 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) core::rect<s32> rect(0, 0, 600, 40); rect += v2s32(0, 0) + v2s32(25, 30); const wchar_t *text = wgettext("Key already in use"); - this->key_used_text = Environment->addStaticText(text, - rect, false, true, this, -1); + this->key_used_text = Environment->addStaticText( + text, rect, false, true, this, -1); delete[] text; } else if (!key_in_use && this->key_used_text) { this->key_used_text->remove(); @@ -352,7 +357,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) delete[] text; // Allow characters made with shift - if (shift_went_down){ + if (shift_went_down) { shift_down = true; return false; } @@ -360,49 +365,46 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) active_key = nullptr; return true; } - } else if (event.EventType == EET_KEY_INPUT_EVENT && !active_key - && event.KeyInput.PressedDown - && event.KeyInput.Key == irr::KEY_ESCAPE) { + } else if (event.EventType == EET_KEY_INPUT_EVENT && !active_key && + event.KeyInput.PressedDown && + event.KeyInput.Key == irr::KEY_ESCAPE) { quitMenu(); return true; } else if (event.EventType == EET_GUI_EVENT) { - if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST - && isVisible()) - { - if (!canTakeFocus(event.GUIEvent.Element)) - { - infostream << "GUIKeyChangeMenu: Not allowing focus change." - << std::endl; + if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && + isVisible()) { + if (!canTakeFocus(event.GUIEvent.Element)) { + infostream << "GUIKeyChangeMenu: Not allowing focus " + "change." + << std::endl; // Returning true disables focus change return true; } } - if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) - { - switch (event.GUIEvent.Caller->getID()) - { - case GUI_ID_BACK_BUTTON: //back - acceptInput(); - quitMenu(); - return true; - case GUI_ID_ABORT_BUTTON: //abort - quitMenu(); - return true; - default: - resetMenu(); - for (key_setting *ks : key_settings) { - if (ks->id == event.GUIEvent.Caller->getID()) { - active_key = ks; - break; - } + if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) { + switch (event.GUIEvent.Caller->getID()) { + case GUI_ID_BACK_BUTTON: // back + acceptInput(); + quitMenu(); + return true; + case GUI_ID_ABORT_BUTTON: // abort + quitMenu(); + return true; + default: + resetMenu(); + for (key_setting *ks : key_settings) { + if (ks->id == event.GUIEvent.Caller->getID()) { + active_key = ks; + break; } - FATAL_ERROR_IF(!active_key, "Key setting not found"); + } + FATAL_ERROR_IF(!active_key, "Key setting not found"); - shift_down = false; - const wchar_t *text = wgettext("press key"); - active_key->button->setText(text); - delete[] text; - break; + shift_down = false; + const wchar_t *text = wgettext("press key"); + active_key->button->setText(text); + delete[] text; + break; } Environment->setFocus(this); } @@ -410,7 +412,8 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) return Parent ? Parent->OnEvent(event) : false; } -void GUIKeyChangeMenu::add_key(int id, const wchar_t *button_name, const std::string &setting_name) +void GUIKeyChangeMenu::add_key( + int id, const wchar_t *button_name, const std::string &setting_name) { key_setting *k = new key_setting; k->id = id; @@ -423,48 +426,76 @@ void GUIKeyChangeMenu::add_key(int id, const wchar_t *button_name, const std::st void GUIKeyChangeMenu::init_keys() { - this->add_key(GUI_ID_KEY_FORWARD_BUTTON, wgettext("Forward"), "keymap_forward"); - this->add_key(GUI_ID_KEY_BACKWARD_BUTTON, wgettext("Backward"), "keymap_backward"); - this->add_key(GUI_ID_KEY_LEFT_BUTTON, wgettext("Left"), "keymap_left"); - this->add_key(GUI_ID_KEY_RIGHT_BUTTON, wgettext("Right"), "keymap_right"); - this->add_key(GUI_ID_KEY_USE_BUTTON, wgettext("Special"), "keymap_special1"); - this->add_key(GUI_ID_KEY_JUMP_BUTTON, wgettext("Jump"), "keymap_jump"); - this->add_key(GUI_ID_KEY_SNEAK_BUTTON, wgettext("Sneak"), "keymap_sneak"); - this->add_key(GUI_ID_KEY_DROP_BUTTON, wgettext("Drop"), "keymap_drop"); - this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"), "keymap_inventory"); - this->add_key(GUI_ID_KEY_ENDERCHEST_BUTTON,wgettext("Enderchest"), "keymap_enderchest"); - this->add_key(GUI_ID_KEY_HOTBAR_PREV_BUTTON,wgettext("Prev. item"), "keymap_hotbar_previous"); - this->add_key(GUI_ID_KEY_HOTBAR_NEXT_BUTTON,wgettext("Next item"), "keymap_hotbar_next"); - this->add_key(GUI_ID_KEY_ZOOM_BUTTON, wgettext("Zoom"), "keymap_zoom"); - this->add_key(GUI_ID_KEY_CAMERA_BUTTON, wgettext("Change camera"), "keymap_camera_mode"); - this->add_key(GUI_ID_KEY_MINIMAP_BUTTON, wgettext("Toggle minimap"), "keymap_minimap"); - this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove"); - this->add_key(GUI_ID_KEY_PITCH_MOVE, wgettext("Toggle pitchmove"), "keymap_pitchmove"); - this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove"); - this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), "keymap_noclip"); - this->add_key(GUI_ID_KEY_MUTE_BUTTON, wgettext("Mute"), "keymap_mute"); - this->add_key(GUI_ID_KEY_DEC_VOLUME_BUTTON,wgettext("Dec. volume"), "keymap_decrease_volume"); - this->add_key(GUI_ID_KEY_INC_VOLUME_BUTTON,wgettext("Inc. volume"), "keymap_increase_volume"); - this->add_key(GUI_ID_KEY_AUTOFWD_BUTTON, wgettext("Autoforward"), "keymap_autoforward"); - this->add_key(GUI_ID_KEY_CHAT_BUTTON, wgettext("Chat"), "keymap_chat"); - this->add_key(GUI_ID_KEY_SCREENSHOT_BUTTON,wgettext("Screenshot"), "keymap_screenshot"); - this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), "keymap_rangeselect"); - this->add_key(GUI_ID_KEY_DEC_RANGE_BUTTON, wgettext("Dec. range"), "keymap_decrease_viewing_range_min"); - this->add_key(GUI_ID_KEY_INC_RANGE_BUTTON, wgettext("Inc. range"), "keymap_increase_viewing_range_min"); - this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console"); - this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd"); - this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"), "keymap_cmd_local"); - this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud"); - this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), "keymap_toggle_chat"); - this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog"); - this->add_key(GUI_ID_KEY_CHEAT_MENU_BUTTON,wgettext("Toggle C. Menu"),"keymap_toggle_cheat_menu"); - this->add_key(GUI_ID_KEY_KILLAURA_BUTTON, wgettext("Killaura"), "keymap_toggle_killaura"); - this->add_key(GUI_ID_KEY_FREECAM_BUTTON, wgettext("Freecam"), "keymap_toggle_freecam"); - this->add_key(GUI_ID_KEY_SCAFFOLD_BUTTON, wgettext("Scaffold"), "keymap_toggle_scaffold"); - this->add_key(GUI_ID_KEY_NEXT_ITEM_BUTTON, wgettext("NextItem"), "keymap_toggle_next_item"); - this->add_key(GUI_ID_KEY_SELECT_UP_BUTTON, wgettext("C. Menu Up"), "keymap_select_up"); - this->add_key(GUI_ID_KEY_SELECT_DOWN_BUTTON,wgettext("C. Menu Down"), "keymap_select_down"); - this->add_key(GUI_ID_KEY_SELECT_LEFT_BUTTON,wgettext("C. Menu Left"), "keymap_select_left"); - this->add_key(GUI_ID_KEY_SELECT_RIGHT_BUTTON,wgettext("C. Menu Right"),"keymap_select_right"); - this->add_key(GUI_ID_KEY_SELECT_CONFIRM_BUTTON,wgettext("C. Menu Enter"),"keymap_select_confirm"); + this->add_key(GUI_ID_KEY_FORWARD_BUTTON, wgettext("Forward"), "keymap_forward"); + this->add_key(GUI_ID_KEY_BACKWARD_BUTTON, wgettext("Backward"), + "keymap_backward"); + this->add_key(GUI_ID_KEY_LEFT_BUTTON, wgettext("Left"), "keymap_left"); + this->add_key(GUI_ID_KEY_RIGHT_BUTTON, wgettext("Right"), "keymap_right"); + this->add_key(GUI_ID_KEY_USE_BUTTON, wgettext("Special"), "keymap_special1"); + this->add_key(GUI_ID_KEY_JUMP_BUTTON, wgettext("Jump"), "keymap_jump"); + this->add_key(GUI_ID_KEY_SNEAK_BUTTON, wgettext("Sneak"), "keymap_sneak"); + this->add_key(GUI_ID_KEY_DROP_BUTTON, wgettext("Drop"), "keymap_drop"); + this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"), + "keymap_inventory"); + this->add_key(GUI_ID_KEY_ENDERCHEST_BUTTON, wgettext("Enderchest"), + "keymap_enderchest"); + this->add_key(GUI_ID_KEY_HOTBAR_PREV_BUTTON, wgettext("Prev. item"), + "keymap_hotbar_previous"); + this->add_key(GUI_ID_KEY_HOTBAR_NEXT_BUTTON, wgettext("Next item"), + "keymap_hotbar_next"); + this->add_key(GUI_ID_KEY_ZOOM_BUTTON, wgettext("Zoom"), "keymap_zoom"); + this->add_key(GUI_ID_KEY_CAMERA_BUTTON, wgettext("Change camera"), + "keymap_camera_mode"); + this->add_key(GUI_ID_KEY_MINIMAP_BUTTON, wgettext("Toggle minimap"), + "keymap_minimap"); + this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove"); + this->add_key(GUI_ID_KEY_PITCH_MOVE, wgettext("Toggle pitchmove"), + "keymap_pitchmove"); + this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove"); + this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), + "keymap_noclip"); + this->add_key(GUI_ID_KEY_MUTE_BUTTON, wgettext("Mute"), "keymap_mute"); + this->add_key(GUI_ID_KEY_DEC_VOLUME_BUTTON, wgettext("Dec. volume"), + "keymap_decrease_volume"); + this->add_key(GUI_ID_KEY_INC_VOLUME_BUTTON, wgettext("Inc. volume"), + "keymap_increase_volume"); + this->add_key(GUI_ID_KEY_AUTOFWD_BUTTON, wgettext("Autoforward"), + "keymap_autoforward"); + this->add_key(GUI_ID_KEY_CHAT_BUTTON, wgettext("Chat"), "keymap_chat"); + this->add_key(GUI_ID_KEY_SCREENSHOT_BUTTON, wgettext("Screenshot"), + "keymap_screenshot"); + this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), + "keymap_rangeselect"); + this->add_key(GUI_ID_KEY_DEC_RANGE_BUTTON, wgettext("Dec. range"), + "keymap_decrease_viewing_range_min"); + this->add_key(GUI_ID_KEY_INC_RANGE_BUTTON, wgettext("Inc. range"), + "keymap_increase_viewing_range_min"); + this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console"); + this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd"); + this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"), + "keymap_cmd_local"); + this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud"); + this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), + "keymap_toggle_chat"); + this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog"); + this->add_key(GUI_ID_KEY_CHEAT_MENU_BUTTON, wgettext("Toggle C. Menu"), + "keymap_toggle_cheat_menu"); + this->add_key(GUI_ID_KEY_KILLAURA_BUTTON, wgettext("Killaura"), + "keymap_toggle_killaura"); + this->add_key(GUI_ID_KEY_FREECAM_BUTTON, wgettext("Freecam"), + "keymap_toggle_freecam"); + this->add_key(GUI_ID_KEY_SCAFFOLD_BUTTON, wgettext("Scaffold"), + "keymap_toggle_scaffold"); + this->add_key(GUI_ID_KEY_NEXT_ITEM_BUTTON, wgettext("NextItem"), + "keymap_toggle_next_item"); + this->add_key(GUI_ID_KEY_SELECT_UP_BUTTON, wgettext("C. Menu Up"), + "keymap_select_up"); + this->add_key(GUI_ID_KEY_SELECT_DOWN_BUTTON, wgettext("C. Menu Down"), + "keymap_select_down"); + this->add_key(GUI_ID_KEY_SELECT_LEFT_BUTTON, wgettext("C. Menu Left"), + "keymap_select_left"); + this->add_key(GUI_ID_KEY_SELECT_RIGHT_BUTTON, wgettext("C. Menu Right"), + "keymap_select_right"); + this->add_key(GUI_ID_KEY_SELECT_CONFIRM_BUTTON, wgettext("C. Menu Enter"), + "keymap_select_confirm"); } diff --git a/src/gui/guiMainMenu.h b/src/gui/guiMainMenu.h index 1dca8bf2d..957ffbc41 100644 --- a/src/gui/guiMainMenu.h +++ b/src/gui/guiMainMenu.h @@ -23,7 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <string> #include <list> -struct MainMenuDataForScript { +struct MainMenuDataForScript +{ MainMenuDataForScript() = default; @@ -32,7 +33,8 @@ struct MainMenuDataForScript { std::string errormessage = ""; }; -struct MainMenuData { +struct MainMenuData +{ // Client options std::string servername; std::string serverdescription; diff --git a/src/gui/guiPasswordChange.cpp b/src/gui/guiPasswordChange.cpp index 5311c6fef..5eb777173 100644 --- a/src/gui/guiPasswordChange.cpp +++ b/src/gui/guiPasswordChange.cpp @@ -35,15 +35,11 @@ const int ID_change = 259; const int ID_message = 260; const int ID_cancel = 261; -GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env, - gui::IGUIElement* parent, s32 id, - IMenuManager *menumgr, - Client* client, - ISimpleTextureSource *tsrc -): - GUIModalMenu(env, parent, id, menumgr), - m_client(client), - m_tsrc(tsrc) +GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment *env, gui::IGUIElement *parent, + s32 id, IMenuManager *menumgr, Client *client, + ISimpleTextureSource *tsrc) : + GUIModalMenu(env, parent, id, menumgr), + m_client(client), m_tsrc(tsrc) { } @@ -80,12 +76,9 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize) Calculate new sizes and positions */ const float s = m_gui_scale; - DesiredRect = core::rect<s32>( - screensize.X / 2 - 580 * s / 2, - screensize.Y / 2 - 300 * s / 2, - screensize.X / 2 + 580 * s / 2, - screensize.Y / 2 + 300 * s / 2 - ); + DesiredRect = core::rect<s32>(screensize.X / 2 - 580 * s / 2, + screensize.Y / 2 - 300 * s / 2, screensize.X / 2 + 580 * s / 2, + screensize.Y / 2 + 300 * s / 2); recalculateAbsolutePosition(false); v2s32 size = DesiredRect.getSize(); @@ -138,8 +131,8 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize) { core::rect<s32> rect(0, 0, 230 * s, 30 * s); rect += topleft_client + v2s32(160 * s, ypos); - gui::IGUIEditBox *e = Environment->addEditBox( - m_newpass_confirm.c_str(), rect, true, this, ID_newPassword2); + gui::IGUIEditBox *e = Environment->addEditBox(m_newpass_confirm.c_str(), + rect, true, this, ID_newPassword2); e->setPasswordBox(true); } @@ -164,9 +157,8 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize) core::rect<s32> rect(0, 0, 300 * s, 20 * s); rect += topleft_client + v2s32(35 * s, ypos); text = wgettext("Passwords do not match!"); - IGUIElement *e = - Environment->addStaticText( - text, rect, false, true, this, ID_message); + IGUIElement *e = Environment->addStaticText( + text, rect, false, true, this, ID_message); e->setVisible(false); delete[] text; } @@ -236,8 +228,9 @@ bool GUIPasswordChange::OnEvent(const SEvent &event) if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) { if (!canTakeFocus(event.GUIEvent.Element)) { - infostream << "GUIPasswordChange: Not allowing focus change." - << std::endl; + infostream << "GUIPasswordChange: Not allowing focus " + "change." + << std::endl; // Returning true disables focus change return true; } diff --git a/src/gui/guiPathSelectMenu.cpp b/src/gui/guiPathSelectMenu.cpp index 489927a11..562778894 100644 --- a/src/gui/guiPathSelectMenu.cpp +++ b/src/gui/guiPathSelectMenu.cpp @@ -19,14 +19,12 @@ #include "guiPathSelectMenu.h" -GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env, - gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, - const std::string &title, const std::string &formname, - bool is_file_select) : - GUIModalMenu(env, parent, id, menumgr), - m_title(utf8_to_wide(title)), - m_formname(formname), - m_file_select_dialog(is_file_select) +GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, + s32 id, IMenuManager *menumgr, const std::string &title, + const std::string &formname, bool is_file_select) : + GUIModalMenu(env, parent, id, menumgr), + m_title(utf8_to_wide(title)), m_formname(formname), + m_file_select_dialog(is_file_select) { } diff --git a/src/gui/guiScrollBar.cpp b/src/gui/guiScrollBar.cpp index b04ccb9d5..4f4b555ab 100644 --- a/src/gui/guiScrollBar.cpp +++ b/src/gui/guiScrollBar.cpp @@ -21,7 +21,8 @@ GUIScrollBar::GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s3 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), last_change(0), drag_offset(0), page_size(100), border_size(0) + large_step(50), last_change(0), drag_offset(0), page_size(100), + border_size(0) { refreshControls(); setNotClipped(false); @@ -115,8 +116,10 @@ bool GUIScrollBar::OnEvent(const SEvent &event) if (is_inside) { is_dragging = true; dragged_by_slider = slider_rect.isPointInside(p); - core::vector2di corner = slider_rect.UpperLeftCorner; - drag_offset = is_horizontal ? p.X - corner.X : p.Y - corner.Y; + core::vector2di corner = + slider_rect.UpperLeftCorner; + drag_offset = is_horizontal ? p.X - corner.X + : p.Y - corner.Y; tray_clicked = !dragged_by_slider; if (tray_clicked) { const s32 new_pos = getPosFromMousePos(p); @@ -130,7 +133,8 @@ bool GUIScrollBar::OnEvent(const SEvent &event) e.EventType = EET_GUI_EVENT; e.GUIEvent.Caller = this; e.GUIEvent.Element = nullptr; - e.GUIEvent.EventType = EGET_SCROLL_BAR_CHANGED; + e.GUIEvent.EventType = + EGET_SCROLL_BAR_CHANGED; Parent->OnEvent(e); } } @@ -247,7 +251,8 @@ s32 GUIScrollBar::getPosFromMousePos(const core::position2di &pos) const w = RelativeRect.getHeight() - border_size * 2 - thumb_size; p = pos.Y - AbsoluteRect.UpperLeftCorner.Y - border_size - offset; } - return core::isnotzero(range()) ? s32(f32(p) / f32(w) * range() + 0.5f) + min_pos : 0; + return core::isnotzero(range()) ? s32(f32(p) / f32(w) * range() + 0.5f) + min_pos + : 0; } void GUIScrollBar::setPos(const s32 &pos) @@ -273,7 +278,7 @@ void GUIScrollBar::setPos(const s32 &pos) f32 f = core::isnotzero(range()) ? (f32(thumb_area) - f32(thumb_size)) / range() : 1.0f; draw_center = s32((f32(scroll_pos - min_pos) * f) + (f32(thumb_size) * 0.5f)) + - border_size; + border_size; } void GUIScrollBar::setSmallStep(const s32 &step) diff --git a/src/gui/guiSkin.cpp b/src/gui/guiSkin.cpp index 8892a00b4..e2a6af5fd 100644 --- a/src/gui/guiSkin.cpp +++ b/src/gui/guiSkin.cpp @@ -18,41 +18,39 @@ namespace irr namespace gui
{
-GUISkin::GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver)
-: SpriteBank(0), Driver(driver), Type(type)
+GUISkin::GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver *driver) :
+ SpriteBank(0), Driver(driver), Type(type)
{
- #ifdef _DEBUG
+#ifdef _DEBUG
setDebugName("GUISkin");
- #endif
-
- if ((Type == EGST_WINDOWS_CLASSIC) || (Type == EGST_WINDOWS_METALLIC))
- {
- Colors[EGDC_3D_DARK_SHADOW] = video::SColor(101,50,50,50);
- Colors[EGDC_3D_SHADOW] = video::SColor(101,130,130,130);
- Colors[EGDC_3D_FACE] = video::SColor(101,210,210,210);
- Colors[EGDC_3D_HIGH_LIGHT] = video::SColor(101,255,255,255);
- Colors[EGDC_3D_LIGHT] = video::SColor(101,210,210,210);
- Colors[EGDC_ACTIVE_BORDER] = video::SColor(101,16,14,115);
- Colors[EGDC_ACTIVE_CAPTION] = video::SColor(255,255,255,255);
- Colors[EGDC_APP_WORKSPACE] = video::SColor(101,100,100,100);
- Colors[EGDC_BUTTON_TEXT] = video::SColor(240,10,10,10);
- Colors[EGDC_GRAY_TEXT] = video::SColor(240,130,130,130);
- Colors[EGDC_HIGH_LIGHT] = video::SColor(101,8,36,107);
- Colors[EGDC_HIGH_LIGHT_TEXT] = video::SColor(240,255,255,255);
- Colors[EGDC_INACTIVE_BORDER] = video::SColor(101,165,165,165);
- Colors[EGDC_INACTIVE_CAPTION] = video::SColor(255,30,30,30);
- Colors[EGDC_TOOLTIP] = video::SColor(200,0,0,0);
- Colors[EGDC_TOOLTIP_BACKGROUND] = video::SColor(200,255,255,225);
- Colors[EGDC_SCROLLBAR] = video::SColor(101,230,230,230);
- Colors[EGDC_WINDOW] = video::SColor(101,255,255,255);
- Colors[EGDC_WINDOW_SYMBOL] = video::SColor(200,10,10,10);
- Colors[EGDC_ICON] = video::SColor(200,255,255,255);
- Colors[EGDC_ICON_HIGH_LIGHT] = video::SColor(200,8,36,107);
- Colors[EGDC_GRAY_WINDOW_SYMBOL] = video::SColor(240,100,100,100);
- Colors[EGDC_EDITABLE] = video::SColor(255,255,255,255);
- Colors[EGDC_GRAY_EDITABLE] = video::SColor(255,120,120,120);
- Colors[EGDC_FOCUSED_EDITABLE] = video::SColor(255,240,240,255);
-
+#endif
+
+ if ((Type == EGST_WINDOWS_CLASSIC) || (Type == EGST_WINDOWS_METALLIC)) {
+ Colors[EGDC_3D_DARK_SHADOW] = video::SColor(101, 50, 50, 50);
+ Colors[EGDC_3D_SHADOW] = video::SColor(101, 130, 130, 130);
+ Colors[EGDC_3D_FACE] = video::SColor(101, 210, 210, 210);
+ Colors[EGDC_3D_HIGH_LIGHT] = video::SColor(101, 255, 255, 255);
+ Colors[EGDC_3D_LIGHT] = video::SColor(101, 210, 210, 210);
+ Colors[EGDC_ACTIVE_BORDER] = video::SColor(101, 16, 14, 115);
+ Colors[EGDC_ACTIVE_CAPTION] = video::SColor(255, 255, 255, 255);
+ Colors[EGDC_APP_WORKSPACE] = video::SColor(101, 100, 100, 100);
+ Colors[EGDC_BUTTON_TEXT] = video::SColor(240, 10, 10, 10);
+ Colors[EGDC_GRAY_TEXT] = video::SColor(240, 130, 130, 130);
+ Colors[EGDC_HIGH_LIGHT] = video::SColor(101, 8, 36, 107);
+ Colors[EGDC_HIGH_LIGHT_TEXT] = video::SColor(240, 255, 255, 255);
+ Colors[EGDC_INACTIVE_BORDER] = video::SColor(101, 165, 165, 165);
+ Colors[EGDC_INACTIVE_CAPTION] = video::SColor(255, 30, 30, 30);
+ Colors[EGDC_TOOLTIP] = video::SColor(200, 0, 0, 0);
+ Colors[EGDC_TOOLTIP_BACKGROUND] = video::SColor(200, 255, 255, 225);
+ Colors[EGDC_SCROLLBAR] = video::SColor(101, 230, 230, 230);
+ Colors[EGDC_WINDOW] = video::SColor(101, 255, 255, 255);
+ Colors[EGDC_WINDOW_SYMBOL] = video::SColor(200, 10, 10, 10);
+ Colors[EGDC_ICON] = video::SColor(200, 255, 255, 255);
+ Colors[EGDC_ICON_HIGH_LIGHT] = video::SColor(200, 8, 36, 107);
+ Colors[EGDC_GRAY_WINDOW_SYMBOL] = video::SColor(240, 100, 100, 100);
+ Colors[EGDC_EDITABLE] = video::SColor(255, 255, 255, 255);
+ Colors[EGDC_GRAY_EDITABLE] = video::SColor(255, 120, 120, 120);
+ Colors[EGDC_FOCUSED_EDITABLE] = video::SColor(255, 240, 240, 255);
Sizes[EGDS_SCROLLBAR_SIZE] = 14;
Sizes[EGDS_MENU_HEIGHT] = 30;
@@ -68,36 +66,36 @@ GUISkin::GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) Sizes[EGDS_TITLEBARTEXT_DISTANCE_X] = 2;
Sizes[EGDS_TITLEBARTEXT_DISTANCE_Y] = 0;
- }
- else
- {
- //0x80a6a8af
- Colors[EGDC_3D_DARK_SHADOW] = 0x60767982;
- //Colors[EGDC_3D_FACE] = 0xc0c9ccd4; // tab background
- Colors[EGDC_3D_FACE] = 0xc0cbd2d9; // tab background
- Colors[EGDC_3D_SHADOW] = 0x50e4e8f1; // tab background, and left-top highlight
- Colors[EGDC_3D_HIGH_LIGHT] = 0x40c7ccdc;
- Colors[EGDC_3D_LIGHT] = 0x802e313a;
- Colors[EGDC_ACTIVE_BORDER] = 0x80404040; // window title
- Colors[EGDC_ACTIVE_CAPTION] = 0xffd0d0d0;
- Colors[EGDC_APP_WORKSPACE] = 0xc0646464; // unused
- Colors[EGDC_BUTTON_TEXT] = 0xd0161616;
- Colors[EGDC_GRAY_TEXT] = 0x3c141414;
- Colors[EGDC_HIGH_LIGHT] = 0x6c606060;
- Colors[EGDC_HIGH_LIGHT_TEXT] = 0xd0e0e0e0;
- Colors[EGDC_INACTIVE_BORDER] = 0xf0a5a5a5;
- Colors[EGDC_INACTIVE_CAPTION] = 0xffd2d2d2;
- Colors[EGDC_TOOLTIP] = 0xf00f2033;
- Colors[EGDC_TOOLTIP_BACKGROUND] = 0xc0cbd2d9;
- Colors[EGDC_SCROLLBAR] = 0xf0e0e0e0;
- Colors[EGDC_WINDOW] = 0xf0f0f0f0;
- Colors[EGDC_WINDOW_SYMBOL] = 0xd0161616;
- Colors[EGDC_ICON] = 0xd0161616;
- Colors[EGDC_ICON_HIGH_LIGHT] = 0xd0606060;
- Colors[EGDC_GRAY_WINDOW_SYMBOL] = 0x3c101010;
- Colors[EGDC_EDITABLE] = 0xf0ffffff;
- Colors[EGDC_GRAY_EDITABLE] = 0xf0cccccc;
- Colors[EGDC_FOCUSED_EDITABLE] = 0xf0fffff0;
+ } else {
+ // 0x80a6a8af
+ Colors[EGDC_3D_DARK_SHADOW] = 0x60767982;
+ // Colors[EGDC_3D_FACE] = 0xc0c9ccd4; // tab
+ // background
+ Colors[EGDC_3D_FACE] = 0xc0cbd2d9; // tab background
+ Colors[EGDC_3D_SHADOW] =
+ 0x50e4e8f1; // tab background, and left-top highlight
+ Colors[EGDC_3D_HIGH_LIGHT] = 0x40c7ccdc;
+ Colors[EGDC_3D_LIGHT] = 0x802e313a;
+ Colors[EGDC_ACTIVE_BORDER] = 0x80404040; // window title
+ Colors[EGDC_ACTIVE_CAPTION] = 0xffd0d0d0;
+ Colors[EGDC_APP_WORKSPACE] = 0xc0646464; // unused
+ Colors[EGDC_BUTTON_TEXT] = 0xd0161616;
+ Colors[EGDC_GRAY_TEXT] = 0x3c141414;
+ Colors[EGDC_HIGH_LIGHT] = 0x6c606060;
+ Colors[EGDC_HIGH_LIGHT_TEXT] = 0xd0e0e0e0;
+ Colors[EGDC_INACTIVE_BORDER] = 0xf0a5a5a5;
+ Colors[EGDC_INACTIVE_CAPTION] = 0xffd2d2d2;
+ Colors[EGDC_TOOLTIP] = 0xf00f2033;
+ Colors[EGDC_TOOLTIP_BACKGROUND] = 0xc0cbd2d9;
+ Colors[EGDC_SCROLLBAR] = 0xf0e0e0e0;
+ Colors[EGDC_WINDOW] = 0xf0f0f0f0;
+ Colors[EGDC_WINDOW_SYMBOL] = 0xd0161616;
+ Colors[EGDC_ICON] = 0xd0161616;
+ Colors[EGDC_ICON_HIGH_LIGHT] = 0xd0606060;
+ Colors[EGDC_GRAY_WINDOW_SYMBOL] = 0x3c101010;
+ Colors[EGDC_EDITABLE] = 0xf0ffffff;
+ Colors[EGDC_GRAY_EDITABLE] = 0xf0cccccc;
+ Colors[EGDC_FOCUSED_EDITABLE] = 0xf0fffff0;
Sizes[EGDS_SCROLLBAR_SIZE] = 14;
Sizes[EGDS_MENU_HEIGHT] = 48;
@@ -160,18 +158,16 @@ GUISkin::GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) Icons[EGDI_FILE] = 245;
Icons[EGDI_DIRECTORY] = 246;
- for (u32 i=0; i<EGDF_COUNT; ++i)
+ for (u32 i = 0; i < EGDF_COUNT; ++i)
Fonts[i] = 0;
- UseGradient = (Type == EGST_WINDOWS_METALLIC) || (Type == EGST_BURNING_SKIN) ;
+ UseGradient = (Type == EGST_WINDOWS_METALLIC) || (Type == EGST_BURNING_SKIN);
}
-
//! destructor
GUISkin::~GUISkin()
{
- for (u32 i=0; i<EGDF_COUNT; ++i)
- {
+ for (u32 i = 0; i < EGDF_COUNT; ++i) {
if (Fonts[i])
Fonts[i]->drop();
}
@@ -180,7 +176,6 @@ GUISkin::~GUISkin() SpriteBank->drop();
}
-
//! returns default color
video::SColor GUISkin::getColor(EGUI_DEFAULT_COLOR color) const
{
@@ -190,7 +185,6 @@ video::SColor GUISkin::getColor(EGUI_DEFAULT_COLOR color) const return video::SColor();
}
-
//! sets a default color
void GUISkin::setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor)
{
@@ -198,7 +192,6 @@ void GUISkin::setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor) Colors[which] = newColor;
}
-
//! returns size for the given size type
s32 GUISkin::getSize(EGUI_DEFAULT_SIZE size) const
{
@@ -208,7 +201,6 @@ s32 GUISkin::getSize(EGUI_DEFAULT_SIZE size) const return 0;
}
-
//! sets a default size
void GUISkin::setSize(EGUI_DEFAULT_SIZE which, s32 size)
{
@@ -216,9 +208,8 @@ void GUISkin::setSize(EGUI_DEFAULT_SIZE which, s32 size) Sizes[which] = size;
}
-
//! returns the default font
-IGUIFont* GUISkin::getFont(EGUI_DEFAULT_FONT which) const
+IGUIFont *GUISkin::getFont(EGUI_DEFAULT_FONT which) const
{
if (((u32)which < EGDF_COUNT) && Fonts[which])
return Fonts[which];
@@ -226,15 +217,13 @@ IGUIFont* GUISkin::getFont(EGUI_DEFAULT_FONT which) const return Fonts[EGDF_DEFAULT];
}
-
//! sets a default font
-void GUISkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT which)
+void GUISkin::setFont(IGUIFont *font, EGUI_DEFAULT_FONT which)
{
if ((u32)which >= EGDF_COUNT)
return;
- if (font)
- {
+ if (font) {
font->grab();
if (Fonts[which])
Fonts[which]->drop();
@@ -243,16 +232,14 @@ void GUISkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT which) }
}
-
//! gets the sprite bank stored
-IGUISpriteBank* GUISkin::getSpriteBank() const
+IGUISpriteBank *GUISkin::getSpriteBank() const
{
return SpriteBank;
}
-
//! set a new sprite bank or remove one by passing 0
-void GUISkin::setSpriteBank(IGUISpriteBank* bank)
+void GUISkin::setSpriteBank(IGUISpriteBank *bank)
{
if (bank)
bank->grab();
@@ -263,7 +250,6 @@ void GUISkin::setSpriteBank(IGUISpriteBank* bank) SpriteBank = bank;
}
-
//! Returns a default icon
u32 GUISkin::getIcon(EGUI_DEFAULT_ICON icon) const
{
@@ -273,7 +259,6 @@ u32 GUISkin::getIcon(EGUI_DEFAULT_ICON icon) const return 0;
}
-
//! Sets a default icon
void GUISkin::setIcon(EGUI_DEFAULT_ICON icon, u32 index)
{
@@ -281,10 +266,9 @@ void GUISkin::setIcon(EGUI_DEFAULT_ICON icon, u32 index) Icons[icon] = index;
}
-
//! Returns a default text. For example for Message box button captions:
//! "OK", "Cancel", "Yes", "No" and so on.
-const wchar_t* GUISkin::getDefaultText(EGUI_DEFAULT_TEXT text) const
+const wchar_t *GUISkin::getDefaultText(EGUI_DEFAULT_TEXT text) const
{
if ((u32)text < EGDT_COUNT)
return Texts[text].c_str();
@@ -292,16 +276,14 @@ const wchar_t* GUISkin::getDefaultText(EGUI_DEFAULT_TEXT text) const return Texts[0].c_str();
}
-
//! Sets a default text. For example for Message box button captions:
//! "OK", "Cancel", "Yes", "No" and so on.
-void GUISkin::setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText)
+void GUISkin::setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t *newText)
{
if ((u32)which < EGDT_COUNT)
Texts[which] = newText;
}
-
//! draws a standard 3d button pane
/** Used for drawing for example buttons in normal state.
It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
@@ -312,10 +294,9 @@ EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. is usually not used by ISkin, but can be used for example by more complex
implementations to find out how to draw the part exactly. */
// PATCH
-void GUISkin::drawColored3DButtonPaneStandard(IGUIElement* element,
- const core::rect<s32>& r,
- const core::rect<s32>* clip,
- const video::SColor* colors)
+void GUISkin::drawColored3DButtonPaneStandard(IGUIElement *element,
+ const core::rect<s32> &r, const core::rect<s32> *clip,
+ const video::SColor *colors)
{
if (!Driver)
return;
@@ -325,15 +306,14 @@ void GUISkin::drawColored3DButtonPaneStandard(IGUIElement* element, core::rect<s32> rect = r;
- if ( Type == EGST_BURNING_SKIN )
- {
+ if (Type == EGST_BURNING_SKIN) {
rect.UpperLeftCorner.X -= 1;
rect.UpperLeftCorner.Y -= 1;
rect.LowerRightCorner.X += 1;
rect.LowerRightCorner.Y += 1;
draw3DSunkenPane(element,
- colors[ EGDC_WINDOW ].getInterpolated( 0xFFFFFFFF, 0.9f )
- ,false, true, rect, clip);
+ colors[EGDC_WINDOW].getInterpolated(0xFFFFFFFF, 0.9f),
+ false, true, rect, clip);
return;
}
@@ -350,20 +330,17 @@ void GUISkin::drawColored3DButtonPaneStandard(IGUIElement* element, rect.LowerRightCorner.X -= 1;
rect.LowerRightCorner.Y -= 1;
- if (!UseGradient)
- {
+ if (!UseGradient) {
Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip);
- }
- else
- {
+ } else {
const video::SColor c1 = colors[EGDC_3D_FACE];
- const video::SColor c2 = c1.getInterpolated(colors[EGDC_3D_DARK_SHADOW], 0.4f);
+ const video::SColor c2 =
+ c1.getInterpolated(colors[EGDC_3D_DARK_SHADOW], 0.4f);
Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip);
}
}
// END PATCH
-
//! draws a pressed 3d button pane
/** Used for drawing for example buttons in pressed state.
It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
@@ -374,10 +351,9 @@ EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details. is usually not used by ISkin, but can be used for example by more complex
implementations to find out how to draw the part exactly. */
// PATCH
-void GUISkin::drawColored3DButtonPanePressed(IGUIElement* element,
- const core::rect<s32>& r,
- const core::rect<s32>* clip,
- const video::SColor* colors)
+void GUISkin::drawColored3DButtonPanePressed(IGUIElement *element,
+ const core::rect<s32> &r, const core::rect<s32> *clip,
+ const video::SColor *colors)
{
if (!Driver)
return;
@@ -399,20 +375,17 @@ void GUISkin::drawColored3DButtonPanePressed(IGUIElement* element, rect.UpperLeftCorner.X += 1;
rect.UpperLeftCorner.Y += 1;
- if (!UseGradient)
- {
+ if (!UseGradient) {
Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip);
- }
- else
- {
+ } else {
const video::SColor c1 = colors[EGDC_3D_FACE];
- const video::SColor c2 = c1.getInterpolated(colors[EGDC_3D_DARK_SHADOW], 0.4f);
+ const video::SColor c2 =
+ c1.getInterpolated(colors[EGDC_3D_DARK_SHADOW], 0.4f);
Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip);
}
}
// END PATCH
-
//! draws a sunken 3d pane
/** Used for drawing the background of edit, combo or check boxes.
\param element: Pointer to the element which wishes to draw this. This parameter
@@ -424,11 +397,9 @@ deep into the ground. \param rect: Defining area where to draw.
\param clip: Clip area. */
// PATCH
-void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolor,
- bool flat, bool fillBackGround,
- const core::rect<s32>& r,
- const core::rect<s32>* clip,
- const video::SColor* colors)
+void GUISkin::drawColored3DSunkenPane(IGUIElement *element, video::SColor bgcolor,
+ bool flat, bool fillBackGround, const core::rect<s32> &r,
+ const core::rect<s32> *clip, const video::SColor *colors)
{
if (!Driver)
return;
@@ -441,34 +412,31 @@ void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolo if (fillBackGround)
Driver->draw2DRectangle(bgcolor, rect, clip);
- if (flat)
- {
+ if (flat) {
// draw flat sunken pane
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1;
- Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // top
+ Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // top
++rect.UpperLeftCorner.Y;
rect.LowerRightCorner.Y = r.LowerRightCorner.Y;
rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1;
- Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // left
+ Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // left
rect = r;
++rect.UpperLeftCorner.Y;
rect.UpperLeftCorner.X = rect.LowerRightCorner.X - 1;
- Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // right
+ Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // right
rect = r;
++rect.UpperLeftCorner.X;
rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1;
--rect.LowerRightCorner.X;
- Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // bottom
- }
- else
- {
+ Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // bottom
+ } else {
// draw deep sunken pane
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1;
- Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // top
+ Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // top
++rect.UpperLeftCorner.X;
++rect.UpperLeftCorner.Y;
--rect.LowerRightCorner.X;
@@ -476,10 +444,10 @@ void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolo Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip);
rect.UpperLeftCorner.X = r.UpperLeftCorner.X;
- rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y+1;
+ rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y + 1;
rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1;
rect.LowerRightCorner.Y = r.LowerRightCorner.Y;
- Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // left
+ Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip); // left
++rect.UpperLeftCorner.X;
++rect.UpperLeftCorner.Y;
++rect.LowerRightCorner.X;
@@ -489,7 +457,7 @@ void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolo rect = r;
rect.UpperLeftCorner.X = rect.LowerRightCorner.X - 1;
++rect.UpperLeftCorner.Y;
- Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // right
+ Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // right
--rect.UpperLeftCorner.X;
++rect.UpperLeftCorner.Y;
--rect.LowerRightCorner.X;
@@ -500,7 +468,7 @@ void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolo ++rect.UpperLeftCorner.X;
rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1;
--rect.LowerRightCorner.X;
- Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // bottom
+ Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip); // bottom
++rect.UpperLeftCorner.X;
--rect.UpperLeftCorner.Y;
--rect.LowerRightCorner.X;
@@ -513,17 +481,13 @@ void GUISkin::drawColored3DSunkenPane(IGUIElement* element, video::SColor bgcolo //! draws a window background
// return where to draw title bar text.
// PATCH
-core::rect<s32> GUISkin::drawColored3DWindowBackground(IGUIElement* element,
- bool drawTitleBar, video::SColor titleBarColor,
- const core::rect<s32>& r,
- const core::rect<s32>* clip,
- core::rect<s32>* checkClientArea,
- const video::SColor* colors)
+core::rect<s32> GUISkin::drawColored3DWindowBackground(IGUIElement *element,
+ bool drawTitleBar, video::SColor titleBarColor, const core::rect<s32> &r,
+ const core::rect<s32> *clip, core::rect<s32> *checkClientArea,
+ const video::SColor *colors)
{
- if (!Driver)
- {
- if ( checkClientArea )
- {
+ if (!Driver) {
+ if (checkClientArea) {
*checkClientArea = r;
}
return r;
@@ -536,16 +500,14 @@ core::rect<s32> GUISkin::drawColored3DWindowBackground(IGUIElement* element, // top border
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1;
- if ( !checkClientArea )
- {
+ if (!checkClientArea) {
Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip);
}
// left border
rect.LowerRightCorner.Y = r.LowerRightCorner.Y;
rect.LowerRightCorner.X = rect.UpperLeftCorner.X + 1;
- if ( !checkClientArea )
- {
+ if (!checkClientArea) {
Driver->draw2DRectangle(colors[EGDC_3D_HIGH_LIGHT], rect, clip);
}
@@ -554,8 +516,7 @@ core::rect<s32> GUISkin::drawColored3DWindowBackground(IGUIElement* element, rect.LowerRightCorner.X = r.LowerRightCorner.X;
rect.UpperLeftCorner.Y = r.UpperLeftCorner.Y;
rect.LowerRightCorner.Y = r.LowerRightCorner.Y;
- if ( !checkClientArea )
- {
+ if (!checkClientArea) {
Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip);
}
@@ -564,8 +525,7 @@ core::rect<s32> GUISkin::drawColored3DWindowBackground(IGUIElement* element, rect.LowerRightCorner.X -= 1;
rect.UpperLeftCorner.Y += 1;
rect.LowerRightCorner.Y -= 1;
- if ( !checkClientArea )
- {
+ if (!checkClientArea) {
Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip);
}
@@ -574,8 +534,7 @@ core::rect<s32> GUISkin::drawColored3DWindowBackground(IGUIElement* element, rect.UpperLeftCorner.Y = r.LowerRightCorner.Y - 1;
rect.LowerRightCorner.Y = r.LowerRightCorner.Y;
rect.LowerRightCorner.X = r.LowerRightCorner.X;
- if ( !checkClientArea )
- {
+ if (!checkClientArea) {
Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], rect, clip);
}
@@ -584,37 +543,31 @@ core::rect<s32> GUISkin::drawColored3DWindowBackground(IGUIElement* element, rect.LowerRightCorner.X -= 1;
rect.UpperLeftCorner.Y -= 1;
rect.LowerRightCorner.Y -= 1;
- if ( !checkClientArea )
- {
+ if (!checkClientArea) {
Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip);
}
// client area for background
rect = r;
- rect.UpperLeftCorner.X +=1;
- rect.UpperLeftCorner.Y +=1;
+ rect.UpperLeftCorner.X += 1;
+ rect.UpperLeftCorner.Y += 1;
rect.LowerRightCorner.X -= 2;
rect.LowerRightCorner.Y -= 2;
- if (checkClientArea)
- {
+ if (checkClientArea) {
*checkClientArea = rect;
}
- if ( !checkClientArea )
- {
- if (!UseGradient)
- {
+ if (!checkClientArea) {
+ if (!UseGradient) {
Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip);
- }
- else if ( Type == EGST_BURNING_SKIN )
- {
- const video::SColor c1 = colors[EGDC_WINDOW].getInterpolated ( 0xFFFFFFFF, 0.9f );
- const video::SColor c2 = colors[EGDC_WINDOW].getInterpolated ( 0xFFFFFFFF, 0.8f );
+ } else if (Type == EGST_BURNING_SKIN) {
+ const video::SColor c1 = colors[EGDC_WINDOW].getInterpolated(
+ 0xFFFFFFFF, 0.9f);
+ const video::SColor c2 = colors[EGDC_WINDOW].getInterpolated(
+ 0xFFFFFFFF, 0.8f);
Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip);
- }
- else
- {
+ } else {
const video::SColor c2 = colors[EGDC_3D_SHADOW];
const video::SColor c1 = colors[EGDC_3D_FACE];
Driver->draw2DRectangle(rect, c1, c1, c1, c2, clip);
@@ -626,29 +579,31 @@ core::rect<s32> GUISkin::drawColored3DWindowBackground(IGUIElement* element, rect.UpperLeftCorner.X += 2;
rect.UpperLeftCorner.Y += 2;
rect.LowerRightCorner.X -= 2;
- rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + getSize(EGDS_WINDOW_BUTTON_WIDTH) + 2;
+ rect.LowerRightCorner.Y =
+ rect.UpperLeftCorner.Y + getSize(EGDS_WINDOW_BUTTON_WIDTH) + 2;
- if (drawTitleBar )
- {
- if (checkClientArea)
- {
+ if (drawTitleBar) {
+ if (checkClientArea) {
(*checkClientArea).UpperLeftCorner.Y = rect.LowerRightCorner.Y;
- }
- else
- {
+ } else {
// draw title bar
- //if (!UseGradient)
+ // if (!UseGradient)
// Driver->draw2DRectangle(titleBarColor, rect, clip);
- //else
- if ( Type == EGST_BURNING_SKIN )
- {
- const video::SColor c = titleBarColor.getInterpolated( video::SColor(titleBarColor.getAlpha(),255,255,255), 0.8f);
- Driver->draw2DRectangle(rect, titleBarColor, titleBarColor, c, c, clip);
- }
- else
- {
- const video::SColor c = titleBarColor.getInterpolated(video::SColor(titleBarColor.getAlpha(),0,0,0), 0.2f);
- Driver->draw2DRectangle(rect, titleBarColor, c, titleBarColor, c, clip);
+ // else
+ if (Type == EGST_BURNING_SKIN) {
+ const video::SColor c = titleBarColor.getInterpolated(
+ video::SColor(titleBarColor.getAlpha(),
+ 255, 255, 255),
+ 0.8f);
+ Driver->draw2DRectangle(rect, titleBarColor,
+ titleBarColor, c, c, clip);
+ } else {
+ const video::SColor c = titleBarColor.getInterpolated(
+ video::SColor(titleBarColor.getAlpha(), 0,
+ 0, 0),
+ 0.2f);
+ Driver->draw2DRectangle(rect, titleBarColor, c,
+ titleBarColor, c, clip);
}
}
}
@@ -657,7 +612,6 @@ core::rect<s32> GUISkin::drawColored3DWindowBackground(IGUIElement* element, }
// END PATCH
-
//! draws a standard 3d menu pane
/** Used for drawing for menus and context menus.
It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
@@ -668,9 +622,8 @@ implementations to find out how to draw the part exactly. \param rect: Defining area where to draw.
\param clip: Clip area. */
// PATCH
-void GUISkin::drawColored3DMenuPane(IGUIElement* element,
- const core::rect<s32>& r, const core::rect<s32>* clip,
- const video::SColor* colors)
+void GUISkin::drawColored3DMenuPane(IGUIElement *element, const core::rect<s32> &r,
+ const core::rect<s32> *clip, const video::SColor *colors)
{
if (!Driver)
return;
@@ -680,8 +633,7 @@ void GUISkin::drawColored3DMenuPane(IGUIElement* element, core::rect<s32> rect = r;
- if ( Type == EGST_BURNING_SKIN )
- {
+ if (Type == EGST_BURNING_SKIN) {
rect.UpperLeftCorner.Y -= 3;
draw3DButtonPaneStandard(element, rect, clip);
return;
@@ -727,15 +679,14 @@ void GUISkin::drawColored3DMenuPane(IGUIElement* element, Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], rect, clip);
rect = r;
- rect.UpperLeftCorner.X +=1;
- rect.UpperLeftCorner.Y +=1;
+ rect.UpperLeftCorner.X += 1;
+ rect.UpperLeftCorner.Y += 1;
rect.LowerRightCorner.X -= 2;
rect.LowerRightCorner.Y -= 2;
if (!UseGradient)
Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip);
- else
- {
+ else {
const video::SColor c1 = colors[EGDC_3D_FACE];
const video::SColor c2 = colors[EGDC_3D_SHADOW];
Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip);
@@ -743,7 +694,6 @@ void GUISkin::drawColored3DMenuPane(IGUIElement* element, }
// END PATCH
-
//! draws a standard 3d tool bar
/** Used for drawing for toolbars and menus.
\param element: Pointer to the element which wishes to draw this. This parameter
@@ -752,10 +702,8 @@ implementations to find out how to draw the part exactly. \param rect: Defining area where to draw.
\param clip: Clip area. */
// PATCH
-void GUISkin::drawColored3DToolBar(IGUIElement* element,
- const core::rect<s32>& r,
- const core::rect<s32>* clip,
- const video::SColor* colors)
+void GUISkin::drawColored3DToolBar(IGUIElement *element, const core::rect<s32> &r,
+ const core::rect<s32> *clip, const video::SColor *colors)
{
if (!Driver)
return;
@@ -774,21 +722,15 @@ void GUISkin::drawColored3DToolBar(IGUIElement* element, rect = r;
rect.LowerRightCorner.Y -= 1;
- if (!UseGradient)
- {
+ if (!UseGradient) {
Driver->draw2DRectangle(colors[EGDC_3D_FACE], rect, clip);
- }
- else
- if ( Type == EGST_BURNING_SKIN )
- {
+ } else if (Type == EGST_BURNING_SKIN) {
const video::SColor c1 = 0xF0000000 | colors[EGDC_3D_FACE].color;
const video::SColor c2 = 0xF0000000 | colors[EGDC_3D_SHADOW].color;
rect.LowerRightCorner.Y += 1;
Driver->draw2DRectangle(rect, c1, c2, c1, c2, clip);
- }
- else
- {
+ } else {
const video::SColor c1 = colors[EGDC_3D_FACE];
const video::SColor c2 = colors[EGDC_3D_SHADOW];
Driver->draw2DRectangle(rect, c1, c1, c2, c2, clip);
@@ -805,9 +747,9 @@ implementations to find out how to draw the part exactly. \param rect: Defining area where to draw.
\param clip: Clip area. */
// PATCH
-void GUISkin::drawColored3DTabButton(IGUIElement* element, bool active,
- const core::rect<s32>& frameRect, const core::rect<s32>* clip, EGUI_ALIGNMENT alignment,
- const video::SColor* colors)
+void GUISkin::drawColored3DTabButton(IGUIElement *element, bool active,
+ const core::rect<s32> &frameRect, const core::rect<s32> *clip,
+ EGUI_ALIGNMENT alignment, const video::SColor *colors)
{
if (!Driver)
return;
@@ -817,8 +759,7 @@ void GUISkin::drawColored3DTabButton(IGUIElement* element, bool active, core::rect<s32> tr = frameRect;
- if ( alignment == EGUIA_UPPERLEFT )
- {
+ if (alignment == EGUIA_UPPERLEFT) {
tr.LowerRightCorner.X -= 2;
tr.LowerRightCorner.Y = tr.UpperLeftCorner.Y + 1;
tr.UpperLeftCorner.X += 1;
@@ -846,9 +787,7 @@ void GUISkin::drawColored3DTabButton(IGUIElement* element, bool active, tr.UpperLeftCorner.X += 1;
tr.UpperLeftCorner.Y += 1;
Driver->draw2DRectangle(colors[EGDC_3D_DARK_SHADOW], tr, clip);
- }
- else
- {
+ } else {
tr.LowerRightCorner.X -= 2;
tr.UpperLeftCorner.Y = tr.LowerRightCorner.Y - 1;
tr.UpperLeftCorner.X += 1;
@@ -871,7 +810,7 @@ void GUISkin::drawColored3DTabButton(IGUIElement* element, bool active, // draw right middle gray shadow
tr.LowerRightCorner.X += 1;
tr.UpperLeftCorner.X = tr.LowerRightCorner.X - 1;
- //tr.LowerRightCorner.Y -= 1;
+ // tr.LowerRightCorner.Y -= 1;
Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip);
tr.LowerRightCorner.X += 1;
@@ -882,7 +821,6 @@ void GUISkin::drawColored3DTabButton(IGUIElement* element, bool active, }
// END PATCH
-
//! draws a tab control body
/** \param element: Pointer to the element which wishes to draw this. This parameter
is usually not used by ISkin, but can be used for example by more complex
@@ -892,9 +830,9 @@ implementations to find out how to draw the part exactly. \param rect: Defining area where to draw.
\param clip: Clip area. */
// PATCH
-void GUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool background,
- const core::rect<s32>& rect, const core::rect<s32>* clip, s32 tabHeight, EGUI_ALIGNMENT alignment,
- const video::SColor* colors)
+void GUISkin::drawColored3DTabBody(IGUIElement *element, bool border, bool background,
+ const core::rect<s32> &rect, const core::rect<s32> *clip, s32 tabHeight,
+ EGUI_ALIGNMENT alignment, const video::SColor *colors)
{
if (!Driver)
return;
@@ -904,14 +842,12 @@ void GUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool backg core::rect<s32> tr = rect;
- if ( tabHeight == -1 )
+ if (tabHeight == -1)
tabHeight = getSize(gui::EGDS_BUTTON_HEIGHT);
// draw border.
- if (border)
- {
- if ( alignment == EGUIA_UPPERLEFT )
- {
+ if (border) {
+ if (alignment == EGUIA_UPPERLEFT) {
// draw left hightlight
tr.UpperLeftCorner.Y += tabHeight + 2;
tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1;
@@ -926,9 +862,7 @@ void GUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool backg tr = rect;
tr.UpperLeftCorner.Y = tr.LowerRightCorner.Y - 1;
Driver->draw2DRectangle(colors[EGDC_3D_SHADOW], tr, clip);
- }
- else
- {
+ } else {
// draw left hightlight
tr.LowerRightCorner.Y -= tabHeight + 2;
tr.LowerRightCorner.X = tr.UpperLeftCorner.X + 1;
@@ -946,30 +880,25 @@ void GUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool backg }
}
- if (background)
- {
- if ( alignment == EGUIA_UPPERLEFT )
- {
+ if (background) {
+ if (alignment == EGUIA_UPPERLEFT) {
tr = rect;
tr.UpperLeftCorner.Y += tabHeight + 2;
tr.LowerRightCorner.X -= 1;
tr.UpperLeftCorner.X += 1;
tr.LowerRightCorner.Y -= 1;
- }
- else
- {
+ } else {
tr = rect;
tr.UpperLeftCorner.X += 1;
tr.UpperLeftCorner.Y -= 1;
tr.LowerRightCorner.X -= 1;
tr.LowerRightCorner.Y -= tabHeight + 2;
- //tr.UpperLeftCorner.X += 1;
+ // tr.UpperLeftCorner.X += 1;
}
if (!UseGradient)
Driver->draw2DRectangle(colors[EGDC_3D_FACE], tr, clip);
- else
- {
+ else {
video::SColor c1 = colors[EGDC_3D_FACE];
video::SColor c2 = colors[EGDC_3D_SHADOW];
Driver->draw2DRectangle(tr, c1, c1, c2, c2, clip);
@@ -978,7 +907,6 @@ void GUISkin::drawColored3DTabBody(IGUIElement* element, bool border, bool backg }
// END PATCH
-
//! draws an icon, usually from the skin's sprite bank
/** \param parent: Pointer to the element which wishes to draw this icon.
This parameter is usually not used by IGUISkin, but can be used for example
@@ -990,11 +918,9 @@ by more complex implementations to find out how to draw the part exactly. \param loop: Whether the animation should loop or not
\param clip: Clip area. */
// PATCH
-void GUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon,
- const core::position2di position,
- u32 starttime, u32 currenttime,
- bool loop, const core::rect<s32>* clip,
- const video::SColor* colors)
+void GUISkin::drawColoredIcon(IGUIElement *element, EGUI_DEFAULT_ICON icon,
+ const core::position2di position, u32 starttime, u32 currenttime,
+ bool loop, const core::rect<s32> *clip, const video::SColor *colors)
{
if (!SpriteBank)
return;
@@ -1004,74 +930,71 @@ void GUISkin::drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon, bool gray = element && !element->isEnabled();
SpriteBank->draw2DSprite(Icons[icon], position, clip,
- colors[gray? EGDC_GRAY_WINDOW_SYMBOL : EGDC_WINDOW_SYMBOL], starttime, currenttime, loop, true);
+ colors[gray ? EGDC_GRAY_WINDOW_SYMBOL : EGDC_WINDOW_SYMBOL],
+ starttime, currenttime, loop, true);
}
// END PATCH
-
EGUI_SKIN_TYPE GUISkin::getType() const
{
return Type;
}
-
//! draws a 2d rectangle.
-void GUISkin::draw2DRectangle(IGUIElement* element,
- const video::SColor &color, const core::rect<s32>& pos,
- const core::rect<s32>* clip)
+void GUISkin::draw2DRectangle(IGUIElement *element, const video::SColor &color,
+ const core::rect<s32> &pos, const core::rect<s32> *clip)
{
Driver->draw2DRectangle(color, pos, clip);
}
-
//! Writes attributes of the object.
//! Implement this to expose the attributes of your scene node animator for
//! scripting languages, editors, debuggers or xml serialization purposes.
-void GUISkin::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
+void GUISkin::serializeAttributes(
+ io::IAttributes *out, io::SAttributeReadWriteOptions *options) const
{
u32 i;
- for (i=0; i<EGDC_COUNT; ++i)
+ for (i = 0; i < EGDC_COUNT; ++i)
out->addColor(GUISkinColorNames[i], Colors[i]);
- for (i=0; i<EGDS_COUNT; ++i)
+ for (i = 0; i < EGDS_COUNT; ++i)
out->addInt(GUISkinSizeNames[i], Sizes[i]);
- for (i=0; i<EGDT_COUNT; ++i)
+ for (i = 0; i < EGDT_COUNT; ++i)
out->addString(GUISkinTextNames[i], Texts[i].c_str());
- for (i=0; i<EGDI_COUNT; ++i)
+ for (i = 0; i < EGDI_COUNT; ++i)
out->addInt(GUISkinIconNames[i], Icons[i]);
}
-
//! Reads attributes of the object.
//! Implement this to set the attributes of your scene node animator for
//! scripting languages, editors, debuggers or xml deserialization purposes.
-void GUISkin::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
+void GUISkin::deserializeAttributes(
+ io::IAttributes *in, io::SAttributeReadWriteOptions *options)
{
- // TODO: This is not nice code for downward compatibility, whenever new values are added and users
- // load an old skin the corresponding values will be set to 0.
+ // TODO: This is not nice code for downward compatibility, whenever new values are
+ // added and users load an old skin the corresponding values will be set to 0.
u32 i;
- for (i=0; i<EGDC_COUNT; ++i)
+ for (i = 0; i < EGDC_COUNT; ++i)
Colors[i] = in->getAttributeAsColor(GUISkinColorNames[i]);
- for (i=0; i<EGDS_COUNT; ++i)
+ for (i = 0; i < EGDS_COUNT; ++i)
Sizes[i] = in->getAttributeAsInt(GUISkinSizeNames[i]);
- for (i=0; i<EGDT_COUNT; ++i)
+ for (i = 0; i < EGDT_COUNT; ++i)
Texts[i] = in->getAttributeAsStringW(GUISkinTextNames[i]);
- for (i=0; i<EGDI_COUNT; ++i)
+ for (i = 0; i < EGDI_COUNT; ++i)
Icons[i] = in->getAttributeAsInt(GUISkinIconNames[i]);
}
-
//! gets the colors
// PATCH
-void GUISkin::getColors(video::SColor* colors)
+void GUISkin::getColors(video::SColor *colors)
{
u32 i;
- for (i=0; i<EGDC_COUNT; ++i)
+ for (i = 0; i < EGDC_COUNT; ++i)
colors[i] = Colors[i];
}
// END PATCH
@@ -1079,6 +1002,4 @@ void GUISkin::getColors(video::SColor* colors) } // end namespace gui
} // end namespace irr
-
#endif // _IRR_COMPILE_WITH_GUI_
-
diff --git a/src/gui/guiSkin.h b/src/gui/guiSkin.h index bbb900f9f..4937b1f9a 100644 --- a/src/gui/guiSkin.h +++ b/src/gui/guiSkin.h @@ -17,350 +17,335 @@ namespace irr {
namespace video
{
- class IVideoDriver;
+class IVideoDriver;
}
namespace gui
{
- class GUISkin : public IGUISkin
+class GUISkin : public IGUISkin
+{
+public:
+ GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver *driver);
+
+ //! destructor
+ virtual ~GUISkin();
+
+ //! returns default color
+ virtual video::SColor getColor(EGUI_DEFAULT_COLOR color) const;
+
+ //! sets a default color
+ virtual void setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor);
+
+ //! returns size for the given size type
+ virtual s32 getSize(EGUI_DEFAULT_SIZE size) const;
+
+ //! sets a default size
+ virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size);
+
+ //! returns the default font
+ virtual IGUIFont *getFont(EGUI_DEFAULT_FONT which = EGDF_DEFAULT) const;
+
+ //! sets a default font
+ virtual void setFont(IGUIFont *font, EGUI_DEFAULT_FONT which = EGDF_DEFAULT);
+
+ //! sets the sprite bank used for drawing icons
+ virtual void setSpriteBank(IGUISpriteBank *bank);
+
+ //! gets the sprite bank used for drawing icons
+ virtual IGUISpriteBank *getSpriteBank() const;
+
+ //! Returns a default icon
+ /** Returns the sprite index within the sprite bank */
+ virtual u32 getIcon(EGUI_DEFAULT_ICON icon) const;
+
+ //! Sets a default icon
+ /** Sets the sprite index used for drawing icons like arrows,
+ close buttons and ticks in checkboxes
+ \param icon: Enum specifying which icon to change
+ \param index: The sprite index used to draw this icon */
+ virtual void setIcon(EGUI_DEFAULT_ICON icon, u32 index);
+
+ //! Returns a default text.
+ /** For example for Message box button captions:
+ "OK", "Cancel", "Yes", "No" and so on. */
+ virtual const wchar_t *getDefaultText(EGUI_DEFAULT_TEXT text) const;
+
+ //! Sets a default text.
+ /** For example for Message box button captions:
+ "OK", "Cancel", "Yes", "No" and so on. */
+ virtual void setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t *newText);
+
+ //! draws a standard 3d button pane
+ /** Used for drawing for example buttons in normal state.
+ It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
+ EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
+ \param rect: Defining area where to draw.
+ \param clip: Clip area.
+ \param element: Pointer to the element which wishes to draw this. This parameter
+ is usually not used by ISkin, but can be used for example by more complex
+ implementations to find out how to draw the part exactly. */
+ virtual void draw3DButtonPaneStandard(IGUIElement *element,
+ const core::rect<s32> &rect, const core::rect<s32> *clip = 0)
+ {
+ drawColored3DButtonPaneStandard(element, rect, clip);
+ }
+
+ virtual void drawColored3DButtonPaneStandard(IGUIElement *element,
+ const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
+ const video::SColor *colors = 0);
+
+ //! draws a pressed 3d button pane
+ /** Used for drawing for example buttons in pressed state.
+ It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
+ EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
+ \param rect: Defining area where to draw.
+ \param clip: Clip area.
+ \param element: Pointer to the element which wishes to draw this. This parameter
+ is usually not used by ISkin, but can be used for example by more complex
+ implementations to find out how to draw the part exactly. */
+ virtual void draw3DButtonPanePressed(IGUIElement *element,
+ const core::rect<s32> &rect, const core::rect<s32> *clip = 0)
+ {
+ drawColored3DButtonPanePressed(element, rect, clip);
+ }
+
+ virtual void drawColored3DButtonPanePressed(IGUIElement *element,
+ const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
+ const video::SColor *colors = 0);
+
+ //! draws a sunken 3d pane
+ /** Used for drawing the background of edit, combo or check boxes.
+ \param element: Pointer to the element which wishes to draw this. This parameter
+ is usually not used by ISkin, but can be used for example by more complex
+ implementations to find out how to draw the part exactly.
+ \param bgcolor: Background color.
+ \param flat: Specifies if the sunken pane should be flat or displayed as sunken
+ deep into the ground.
+ \param rect: Defining area where to draw.
+ \param clip: Clip area. */
+ virtual void draw3DSunkenPane(IGUIElement *element, video::SColor bgcolor,
+ bool flat, bool fillBackGround, const core::rect<s32> &rect,
+ const core::rect<s32> *clip = 0)
+ {
+ drawColored3DSunkenPane(
+ element, bgcolor, flat, fillBackGround, rect, clip);
+ }
+
+ virtual void drawColored3DSunkenPane(IGUIElement *element, video::SColor bgcolor,
+ bool flat, bool fillBackGround, const core::rect<s32> &rect,
+ const core::rect<s32> *clip = 0, const video::SColor *colors = 0);
+
+ //! draws a window background
+ /** Used for drawing the background of dialogs and windows.
+ \param element: Pointer to the element which wishes to draw this. This parameter
+ is usually not used by ISkin, but can be used for example by more complex
+ implementations to find out how to draw the part exactly.
+ \param titleBarColor: Title color.
+ \param drawTitleBar: True to enable title drawing.
+ \param rect: Defining area where to draw.
+ \param clip: Clip area.
+ \param checkClientArea: When set to non-null the function will not draw anything,
+ but will instead return the clientArea which can be used for drawing by the
+ calling window. That is the area without borders and without titlebar. \return
+ Returns rect where it would be good to draw title bar text. This will work even
+ when checkClientArea is set to a non-null value.*/
+ virtual core::rect<s32> draw3DWindowBackground(IGUIElement *element,
+ bool drawTitleBar, video::SColor titleBarColor,
+ const core::rect<s32> &rect, const core::rect<s32> *clip,
+ core::rect<s32> *checkClientArea)
{
- public:
-
- GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver);
-
- //! destructor
- virtual ~GUISkin();
-
- //! returns default color
- virtual video::SColor getColor(EGUI_DEFAULT_COLOR color) const;
-
- //! sets a default color
- virtual void setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor);
-
- //! returns size for the given size type
- virtual s32 getSize(EGUI_DEFAULT_SIZE size) const;
-
- //! sets a default size
- virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size);
-
- //! returns the default font
- virtual IGUIFont* getFont(EGUI_DEFAULT_FONT which=EGDF_DEFAULT) const;
-
- //! sets a default font
- virtual void setFont(IGUIFont* font, EGUI_DEFAULT_FONT which=EGDF_DEFAULT);
-
- //! sets the sprite bank used for drawing icons
- virtual void setSpriteBank(IGUISpriteBank* bank);
-
- //! gets the sprite bank used for drawing icons
- virtual IGUISpriteBank* getSpriteBank() const;
-
- //! Returns a default icon
- /** Returns the sprite index within the sprite bank */
- virtual u32 getIcon(EGUI_DEFAULT_ICON icon) const;
-
- //! Sets a default icon
- /** Sets the sprite index used for drawing icons like arrows,
- close buttons and ticks in checkboxes
- \param icon: Enum specifying which icon to change
- \param index: The sprite index used to draw this icon */
- virtual void setIcon(EGUI_DEFAULT_ICON icon, u32 index);
-
- //! Returns a default text.
- /** For example for Message box button captions:
- "OK", "Cancel", "Yes", "No" and so on. */
- virtual const wchar_t* getDefaultText(EGUI_DEFAULT_TEXT text) const;
-
- //! Sets a default text.
- /** For example for Message box button captions:
- "OK", "Cancel", "Yes", "No" and so on. */
- virtual void setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText);
-
- //! draws a standard 3d button pane
- /** Used for drawing for example buttons in normal state.
- It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
- EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
- \param rect: Defining area where to draw.
- \param clip: Clip area.
- \param element: Pointer to the element which wishes to draw this. This parameter
- is usually not used by ISkin, but can be used for example by more complex
- implementations to find out how to draw the part exactly. */
- virtual void draw3DButtonPaneStandard(IGUIElement* element,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip=0)
- {
- drawColored3DButtonPaneStandard(element, rect,clip);
- }
-
- virtual void drawColored3DButtonPaneStandard(IGUIElement* element,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip=0,
- const video::SColor* colors=0);
-
- //! draws a pressed 3d button pane
- /** Used for drawing for example buttons in pressed state.
- It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
- EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
- \param rect: Defining area where to draw.
- \param clip: Clip area.
- \param element: Pointer to the element which wishes to draw this. This parameter
- is usually not used by ISkin, but can be used for example by more complex
- implementations to find out how to draw the part exactly. */
- virtual void draw3DButtonPanePressed(IGUIElement* element,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip=0)
- {
- drawColored3DButtonPanePressed(element, rect, clip);
- }
-
- virtual void drawColored3DButtonPanePressed(IGUIElement* element,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip=0,
- const video::SColor* colors=0);
-
- //! draws a sunken 3d pane
- /** Used for drawing the background of edit, combo or check boxes.
- \param element: Pointer to the element which wishes to draw this. This parameter
- is usually not used by ISkin, but can be used for example by more complex
- implementations to find out how to draw the part exactly.
- \param bgcolor: Background color.
- \param flat: Specifies if the sunken pane should be flat or displayed as sunken
- deep into the ground.
- \param rect: Defining area where to draw.
- \param clip: Clip area. */
- virtual void draw3DSunkenPane(IGUIElement* element,
- video::SColor bgcolor, bool flat,
- bool fillBackGround,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip=0)
- {
- drawColored3DSunkenPane(element, bgcolor, flat, fillBackGround, rect, clip);
- }
-
- virtual void drawColored3DSunkenPane(IGUIElement* element,
- video::SColor bgcolor, bool flat,
- bool fillBackGround,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip=0,
- const video::SColor* colors=0);
-
- //! draws a window background
- /** Used for drawing the background of dialogs and windows.
- \param element: Pointer to the element which wishes to draw this. This parameter
- is usually not used by ISkin, but can be used for example by more complex
- implementations to find out how to draw the part exactly.
- \param titleBarColor: Title color.
- \param drawTitleBar: True to enable title drawing.
- \param rect: Defining area where to draw.
- \param clip: Clip area.
- \param checkClientArea: When set to non-null the function will not draw anything,
- but will instead return the clientArea which can be used for drawing by the calling window.
- That is the area without borders and without titlebar.
- \return Returns rect where it would be good to draw title bar text. This will
- work even when checkClientArea is set to a non-null value.*/
- virtual core::rect<s32> draw3DWindowBackground(IGUIElement* element,
- bool drawTitleBar, video::SColor titleBarColor,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip,
- core::rect<s32>* checkClientArea)
- {
- return drawColored3DWindowBackground(element, drawTitleBar, titleBarColor,
+ return drawColored3DWindowBackground(element, drawTitleBar, titleBarColor,
rect, clip, checkClientArea);
- }
-
- virtual core::rect<s32> drawColored3DWindowBackground(IGUIElement* element,
- bool drawTitleBar, video::SColor titleBarColor,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip,
- core::rect<s32>* checkClientArea,
- const video::SColor* colors=0);
-
- //! draws a standard 3d menu pane
- /** Used for drawing for menus and context menus.
- It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
- EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
- \param element: Pointer to the element which wishes to draw this. This parameter
- is usually not used by ISkin, but can be used for example by more complex
- implementations to find out how to draw the part exactly.
- \param rect: Defining area where to draw.
- \param clip: Clip area. */
- virtual void draw3DMenuPane(IGUIElement* element,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip=0)
- {
- drawColored3DMenuPane(element, rect, clip);
- }
-
- virtual void drawColored3DMenuPane(IGUIElement* element,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip=0,
- const video::SColor* colors=0);
-
- //! draws a standard 3d tool bar
- /** Used for drawing for toolbars and menus.
- \param element: Pointer to the element which wishes to draw this. This parameter
- is usually not used by ISkin, but can be used for example by more complex
- implementations to find out how to draw the part exactly.
- \param rect: Defining area where to draw.
- \param clip: Clip area. */
- virtual void draw3DToolBar(IGUIElement* element,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip=0)
- {
- drawColored3DToolBar(element, rect, clip);
- }
-
- virtual void drawColored3DToolBar(IGUIElement* element,
- const core::rect<s32>& rect,
- const core::rect<s32>* clip=0,
- const video::SColor* colors=0);
-
- //! draws a tab button
- /** Used for drawing for tab buttons on top of tabs.
- \param element: Pointer to the element which wishes to draw this. This parameter
- is usually not used by ISkin, but can be used for example by more complex
- implementations to find out how to draw the part exactly.
- \param active: Specifies if the tab is currently active.
- \param rect: Defining area where to draw.
- \param clip: Clip area. */
- virtual void draw3DTabButton(IGUIElement* element, bool active,
- const core::rect<s32>& rect, const core::rect<s32>* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT)
- {
- drawColored3DTabButton(element, active, rect, clip, alignment);
- }
-
- virtual void drawColored3DTabButton(IGUIElement* element, bool active,
- const core::rect<s32>& rect, const core::rect<s32>* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT,
- const video::SColor* colors=0);
-
- //! draws a tab control body
- /** \param element: Pointer to the element which wishes to draw this. This parameter
- is usually not used by ISkin, but can be used for example by more complex
- implementations to find out how to draw the part exactly.
- \param border: Specifies if the border should be drawn.
- \param background: Specifies if the background should be drawn.
- \param rect: Defining area where to draw.
- \param clip: Clip area. */
- virtual void draw3DTabBody(IGUIElement* element, bool border, bool background,
- const core::rect<s32>& rect, const core::rect<s32>* clip=0, s32 tabHeight=-1, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT)
- {
- drawColored3DTabBody(element, border, background, rect, clip, tabHeight, alignment);
- }
-
- virtual void drawColored3DTabBody(IGUIElement* element, bool border, bool background,
- const core::rect<s32>& rect, const core::rect<s32>* clip=0, s32 tabHeight=-1, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT,
- const video::SColor* colors=0);
-
- //! draws an icon, usually from the skin's sprite bank
- /** \param element: Pointer to the element which wishes to draw this icon.
- This parameter is usually not used by IGUISkin, but can be used for example
- by more complex implementations to find out how to draw the part exactly.
- \param icon: Specifies the icon to be drawn.
- \param position: The position to draw the icon
- \param starttime: The time at the start of the animation
- \param currenttime: The present time, used to calculate the frame number
- \param loop: Whether the animation should loop or not
- \param clip: Clip area. */
- virtual void drawIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon,
- const core::position2di position,
- u32 starttime=0, u32 currenttime=0,
- bool loop=false, const core::rect<s32>* clip=0)
- {
- drawColoredIcon(element, icon, position, starttime, currenttime, loop, clip);
- }
-
- virtual void drawColoredIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon,
- const core::position2di position,
- u32 starttime=0, u32 currenttime=0,
- bool loop=false, const core::rect<s32>* clip=0,
- const video::SColor* colors=0);
-
- //! draws a 2d rectangle.
- /** \param element: Pointer to the element which wishes to draw this icon.
- This parameter is usually not used by IGUISkin, but can be used for example
- by more complex implementations to find out how to draw the part exactly.
- \param color: Color of the rectangle to draw. The alpha component specifies how
- transparent the rectangle will be.
- \param pos: Position of the rectangle.
- \param clip: Pointer to rectangle against which the rectangle will be clipped.
- If the pointer is null, no clipping will be performed. */
- virtual void draw2DRectangle(IGUIElement* element, const video::SColor &color,
- const core::rect<s32>& pos, const core::rect<s32>* clip = 0);
-
-
- //! get the type of this skin
- virtual EGUI_SKIN_TYPE getType() const;
-
- //! Writes attributes of the object.
- //! Implement this to expose the attributes of your scene node animator for
- //! scripting languages, editors, debuggers or xml serialization purposes.
- virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const;
-
- //! Reads attributes of the object.
- //! Implement this to set the attributes of your scene node animator for
- //! scripting languages, editors, debuggers or xml deserialization purposes.
- virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
-
- //! gets the colors
- virtual void getColors(video::SColor* colors); // ::PATCH:
-
- private:
-
- video::SColor Colors[EGDC_COUNT];
- s32 Sizes[EGDS_COUNT];
- u32 Icons[EGDI_COUNT];
- IGUIFont* Fonts[EGDF_COUNT];
- IGUISpriteBank* SpriteBank;
- core::stringw Texts[EGDT_COUNT];
- video::IVideoDriver* Driver;
- bool UseGradient;
-
- EGUI_SKIN_TYPE Type;
- };
-
- #define set3DSkinColors(skin, button_color) \
- { \
- skin->setColor(EGDC_3D_FACE, button_color); \
- skin->setColor(EGDC_3D_DARK_SHADOW, button_color, 0.25f); \
- skin->setColor(EGDC_3D_SHADOW, button_color, 0.5f); \
- skin->setColor(EGDC_3D_LIGHT, button_color); \
- skin->setColor(EGDC_3D_HIGH_LIGHT, button_color, 1.5f); \
- }
-
- #define getElementSkinColor(color) \
- { \
- if (!Colors) \
- { \
- IGUISkin* skin = Environment->getSkin(); \
- if (skin) \
- return skin->getColor(color); \
- } \
- return Colors[color]; \
- }
-
- #define setElementSkinColor(which, newColor, shading) \
- { \
- if (!Colors) \
- { \
- Colors = new video::SColor[EGDC_COUNT]; \
- GUISkin* skin = (GUISkin *)Environment->getSkin(); \
- if (skin) \
- skin->getColors(Colors); \
- } \
- Colors[which] = newColor; \
- setShading(Colors[which],shading); \
- }
+ }
+
+ virtual core::rect<s32> drawColored3DWindowBackground(IGUIElement *element,
+ bool drawTitleBar, video::SColor titleBarColor,
+ const core::rect<s32> &rect, const core::rect<s32> *clip,
+ core::rect<s32> *checkClientArea,
+ const video::SColor *colors = 0);
+
+ //! draws a standard 3d menu pane
+ /** Used for drawing for menus and context menus.
+ It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
+ EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
+ \param element: Pointer to the element which wishes to draw this. This parameter
+ is usually not used by ISkin, but can be used for example by more complex
+ implementations to find out how to draw the part exactly.
+ \param rect: Defining area where to draw.
+ \param clip: Clip area. */
+ virtual void draw3DMenuPane(IGUIElement *element, const core::rect<s32> &rect,
+ const core::rect<s32> *clip = 0)
+ {
+ drawColored3DMenuPane(element, rect, clip);
+ }
+
+ virtual void drawColored3DMenuPane(IGUIElement *element,
+ const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
+ const video::SColor *colors = 0);
+
+ //! draws a standard 3d tool bar
+ /** Used for drawing for toolbars and menus.
+ \param element: Pointer to the element which wishes to draw this. This parameter
+ is usually not used by ISkin, but can be used for example by more complex
+ implementations to find out how to draw the part exactly.
+ \param rect: Defining area where to draw.
+ \param clip: Clip area. */
+ virtual void draw3DToolBar(IGUIElement *element, const core::rect<s32> &rect,
+ const core::rect<s32> *clip = 0)
+ {
+ drawColored3DToolBar(element, rect, clip);
+ }
+
+ virtual void drawColored3DToolBar(IGUIElement *element,
+ const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
+ const video::SColor *colors = 0);
+
+ //! draws a tab button
+ /** Used for drawing for tab buttons on top of tabs.
+ \param element: Pointer to the element which wishes to draw this. This parameter
+ is usually not used by ISkin, but can be used for example by more complex
+ implementations to find out how to draw the part exactly.
+ \param active: Specifies if the tab is currently active.
+ \param rect: Defining area where to draw.
+ \param clip: Clip area. */
+ virtual void draw3DTabButton(IGUIElement *element, bool active,
+ const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
+ EGUI_ALIGNMENT alignment = EGUIA_UPPERLEFT)
+ {
+ drawColored3DTabButton(element, active, rect, clip, alignment);
+ }
+
+ virtual void drawColored3DTabButton(IGUIElement *element, bool active,
+ const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
+ EGUI_ALIGNMENT alignment = EGUIA_UPPERLEFT,
+ const video::SColor *colors = 0);
+
+ //! draws a tab control body
+ /** \param element: Pointer to the element which wishes to draw this. This
+ parameter is usually not used by ISkin, but can be used for example by more
+ complex implementations to find out how to draw the part exactly. \param border:
+ Specifies if the border should be drawn. \param background: Specifies if the
+ background should be drawn. \param rect: Defining area where to draw.
+ \param clip: Clip area. */
+ virtual void draw3DTabBody(IGUIElement *element, bool border, bool background,
+ const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
+ s32 tabHeight = -1, EGUI_ALIGNMENT alignment = EGUIA_UPPERLEFT)
+ {
+ drawColored3DTabBody(element, border, background, rect, clip, tabHeight,
+ alignment);
+ }
+
+ virtual void drawColored3DTabBody(IGUIElement *element, bool border,
+ bool background, const core::rect<s32> &rect,
+ const core::rect<s32> *clip = 0, s32 tabHeight = -1,
+ EGUI_ALIGNMENT alignment = EGUIA_UPPERLEFT,
+ const video::SColor *colors = 0);
+
+ //! draws an icon, usually from the skin's sprite bank
+ /** \param element: Pointer to the element which wishes to draw this icon.
+ This parameter is usually not used by IGUISkin, but can be used for example
+ by more complex implementations to find out how to draw the part exactly.
+ \param icon: Specifies the icon to be drawn.
+ \param position: The position to draw the icon
+ \param starttime: The time at the start of the animation
+ \param currenttime: The present time, used to calculate the frame number
+ \param loop: Whether the animation should loop or not
+ \param clip: Clip area. */
+ virtual void drawIcon(IGUIElement *element, EGUI_DEFAULT_ICON icon,
+ const core::position2di position, u32 starttime = 0,
+ u32 currenttime = 0, bool loop = false,
+ const core::rect<s32> *clip = 0)
+ {
+ drawColoredIcon(element, icon, position, starttime, currenttime, loop,
+ clip);
+ }
+
+ virtual void drawColoredIcon(IGUIElement *element, EGUI_DEFAULT_ICON icon,
+ const core::position2di position, u32 starttime = 0,
+ u32 currenttime = 0, bool loop = false,
+ const core::rect<s32> *clip = 0, const video::SColor *colors = 0);
+
+ //! draws a 2d rectangle.
+ /** \param element: Pointer to the element which wishes to draw this icon.
+ This parameter is usually not used by IGUISkin, but can be used for example
+ by more complex implementations to find out how to draw the part exactly.
+ \param color: Color of the rectangle to draw. The alpha component specifies how
+ transparent the rectangle will be.
+ \param pos: Position of the rectangle.
+ \param clip: Pointer to rectangle against which the rectangle will be clipped.
+ If the pointer is null, no clipping will be performed. */
+ virtual void draw2DRectangle(IGUIElement *element, const video::SColor &color,
+ const core::rect<s32> &pos, const core::rect<s32> *clip = 0);
+
+ //! get the type of this skin
+ virtual EGUI_SKIN_TYPE getType() const;
+
+ //! Writes attributes of the object.
+ //! Implement this to expose the attributes of your scene node animator for
+ //! scripting languages, editors, debuggers or xml serialization purposes.
+ virtual void serializeAttributes(io::IAttributes *out,
+ io::SAttributeReadWriteOptions *options = 0) const;
+
+ //! Reads attributes of the object.
+ //! Implement this to set the attributes of your scene node animator for
+ //! scripting languages, editors, debuggers or xml deserialization purposes.
+ virtual void deserializeAttributes(
+ io::IAttributes *in, io::SAttributeReadWriteOptions *options = 0);
+
+ //! gets the colors
+ virtual void getColors(video::SColor *colors); // ::PATCH:
+
+private:
+ video::SColor Colors[EGDC_COUNT];
+ s32 Sizes[EGDS_COUNT];
+ u32 Icons[EGDI_COUNT];
+ IGUIFont *Fonts[EGDF_COUNT];
+ IGUISpriteBank *SpriteBank;
+ core::stringw Texts[EGDT_COUNT];
+ video::IVideoDriver *Driver;
+ bool UseGradient;
+
+ EGUI_SKIN_TYPE Type;
+};
+
+#define set3DSkinColors(skin, button_color) \
+ { \
+ skin->setColor(EGDC_3D_FACE, button_color); \
+ skin->setColor(EGDC_3D_DARK_SHADOW, button_color, 0.25f); \
+ skin->setColor(EGDC_3D_SHADOW, button_color, 0.5f); \
+ skin->setColor(EGDC_3D_LIGHT, button_color); \
+ skin->setColor(EGDC_3D_HIGH_LIGHT, button_color, 1.5f); \
+ }
+
+#define getElementSkinColor(color) \
+ { \
+ if (!Colors) { \
+ IGUISkin *skin = Environment->getSkin(); \
+ if (skin) \
+ return skin->getColor(color); \
+ } \
+ return Colors[color]; \
+ }
+
+#define setElementSkinColor(which, newColor, shading) \
+ { \
+ if (!Colors) { \
+ Colors = new video::SColor[EGDC_COUNT]; \
+ GUISkin *skin = (GUISkin *)Environment->getSkin(); \
+ if (skin) \
+ skin->getColors(Colors); \
+ } \
+ Colors[which] = newColor; \
+ setShading(Colors[which], shading); \
+ }
} // end namespace gui
//! Sets the shading
-inline void setShading(video::SColor &color,f32 s) // :PATCH:
+inline void setShading(video::SColor &color, f32 s) // :PATCH:
{
- if (s < 1.0f)
- {
+ if (s < 1.0f) {
color.setRed(color.getRed() * s);
color.setGreen(color.getGreen() * s);
color.setBlue(color.getBlue() * s);
- }
- else if (s > 1.0f)
- {
+ } else if (s > 1.0f) {
s -= 1.0f;
color.setRed(color.getRed() + (255 - color.getRed()) * s);
@@ -370,7 +355,6 @@ inline void setShading(video::SColor &color,f32 s) // :PATCH: }
} // end namespace irr
-
#endif // _IRR_COMPILE_WITH_GUI_
#endif
diff --git a/src/gui/guiTable.cpp b/src/gui/guiTable.cpp index c705e17fb..2f761cc77 100644 --- a/src/gui/guiTable.cpp +++ b/src/gui/guiTable.cpp @@ -17,7 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - #include "guiTable.h" #include <queue> #include <sstream> @@ -33,25 +32,22 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include "util/numeric.h" #include "util/string.h" // for parseColorString() -#include "settings.h" // for settings -#include "porting.h" // for dpi +#include "settings.h" // for settings +#include "porting.h" // for dpi #include "client/guiscalingfilter.h" /* GUITable */ -GUITable::GUITable(gui::IGUIEnvironment *env, - gui::IGUIElement* parent, s32 id, - core::rect<s32> rectangle, - ISimpleTextureSource *tsrc -): - gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), - m_tsrc(tsrc) +GUITable::GUITable(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, + core::rect<s32> rectangle, ISimpleTextureSource *tsrc) : + gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), + m_tsrc(tsrc) { assert(tsrc != NULL); - gui::IGUISkin* skin = Environment->getSkin(); + gui::IGUISkin *skin = Environment->getSkin(); m_font = skin->getFont(); if (m_font) { @@ -62,8 +58,7 @@ GUITable::GUITable(gui::IGUIEnvironment *env, const s32 s = skin->getSize(gui::EGDS_SCROLLBAR_SIZE); m_scrollbar = new GUIScrollBar(Environment, this, -1, - core::rect<s32>(RelativeRect.getWidth() - s, - 0, + core::rect<s32>(RelativeRect.getWidth() - s, 0, RelativeRect.getWidth(), RelativeRect.getHeight()), false, true); @@ -83,11 +78,11 @@ GUITable::GUITable(gui::IGUIEnvironment *env, #endif core::rect<s32> relative_rect = m_scrollbar->getRelativePosition(); s32 width = (relative_rect.getWidth() / (2.0 / 3.0)) * density * - g_settings->getFloat("gui_scaling"); + g_settings->getFloat("gui_scaling"); m_scrollbar->setRelativePosition(core::rect<s32>( - relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y, - relative_rect.LowerRightCorner.X,relative_rect.LowerRightCorner.Y - )); + relative_rect.LowerRightCorner.X - width, + relative_rect.UpperLeftCorner.Y, relative_rect.LowerRightCorner.X, + relative_rect.LowerRightCorner.Y)); } GUITable::~GUITable() @@ -108,12 +103,10 @@ GUITable::Option GUITable::splitOption(const std::string &str) if (equal_pos == std::string::npos) return GUITable::Option(str, ""); - return GUITable::Option(str.substr(0, equal_pos), - str.substr(equal_pos + 1)); + return GUITable::Option(str.substr(0, equal_pos), str.substr(equal_pos + 1)); } -void GUITable::setTextList(const std::vector<std::string> &content, - bool transparent) +void GUITable::setTextList(const std::vector<std::string> &content, bool transparent) { clear(); @@ -127,7 +120,7 @@ void GUITable::setTextList(const std::vector<std::string> &content, s32 empty_string_index = allocString(""); m_rows.resize(content.size()); - for (s32 i = 0; i < (s32) content.size(); ++i) { + for (s32 i = 0; i < (s32)content.size(); ++i) { Row *row = &m_rows[i]; row->cells = new Cell[1]; row->cellcount = 1; @@ -137,7 +130,7 @@ void GUITable::setTextList(const std::vector<std::string> &content, Cell *cell = row->cells; cell->xmin = 0; - cell->xmax = 0x7fff; // something large enough + cell->xmax = 0x7fff; // something large enough cell->xpos = 6; cell->content_type = COLUMN_TYPE_TEXT; cell->content_index = empty_string_index; @@ -151,19 +144,15 @@ void GUITable::setTextList(const std::vector<std::string> &content, if (s[0] == '#' && s[1] == '#') { // double # to escape cell->content_index = allocString(s.substr(2)); - } - else if (s[0] == '#' && s.size() >= 7 && - parseColorString( - s.substr(0,7), cell->color, false)) { + } else if (s[0] == '#' && s.size() >= 7 && + parseColorString(s.substr(0, 7), cell->color, false)) { // single # for color cell->color_defined = true; cell->content_index = allocString(s.substr(7)); - } - else { + } else { // no #, just text cell->content_index = allocString(s); } - } allocationComplete(); @@ -172,8 +161,7 @@ void GUITable::setTextList(const std::vector<std::string> &content, updateScrollBar(); } -void GUITable::setTable(const TableOptions &options, - const TableColumns &columns, +void GUITable::setTable(const TableOptions &options, const TableColumns &columns, std::vector<std::string> &content) { clear(); @@ -212,8 +200,8 @@ void GUITable::setTable(const TableOptions &options, else if (name == "opendepth") opendepth = stoi(value); else - errorstream<<"Invalid table option: \""<<name<<"\"" - <<" (value=\""<<value<<"\")"<<std::endl; + errorstream << "Invalid table option: \"" << name << "\"" + << " (value=\"" << value << "\")" << std::endl; } // Get number of columns and rows @@ -225,11 +213,12 @@ void GUITable::setTable(const TableOptions &options, assert(rowcount >= 0); // Append empty strings to content if there is an incomplete row s32 cellcount = rowcount * colcount; - while (content.size() < (u32) cellcount) + while (content.size() < (u32)cellcount) content.emplace_back(""); // Create temporary rows (for processing columns) - struct TempRow { + struct TempRow + { // Current horizontal position (may different between rows due // to indent/tree columns, or text/image columns with width<0) s32 x; @@ -242,9 +231,9 @@ void GUITable::setTable(const TableOptions &options, // Vector of completed cells in this row std::vector<Cell> cells; // Stores colors and how long they last (maximum column index) - std::vector<std::pair<video::SColor, s32> > colors; + std::vector<std::pair<video::SColor, s32>> colors; - TempRow(): x(0), indent(0), content_index(0), content_width(0) {} + TempRow() : x(0), indent(0), content_index(0), content_width(0) {} }; TempRow *rows = new TempRow[rowcount]; @@ -273,8 +262,8 @@ void GUITable::setTable(const TableOptions &options, else if (columns[j].type == "tree") columntype = COLUMN_TYPE_TREE; else - errorstream<<"Invalid table column type: \"" - <<columns[j].type<<"\""<<std::endl; + errorstream << "Invalid table column type: \"" << columns[j].type + << "\"" << std::endl; // Process column options s32 padding = myround(0.5 * em); @@ -286,8 +275,7 @@ void GUITable::setTable(const TableOptions &options, if (columntype == COLUMN_TYPE_INDENT) { padding = 0; // default indent padding } - if (columntype == COLUMN_TYPE_INDENT || - columntype == COLUMN_TYPE_TREE) { + if (columntype == COLUMN_TYPE_INDENT || columntype == COLUMN_TYPE_TREE) { width = myround(em * 1.5); // default indent width } @@ -310,17 +298,16 @@ void GUITable::setTable(const TableOptions &options, width = myround(stof(value) * em); else if (name == "span" && columntype == COLUMN_TYPE_COLOR) span = stoi(value); - else if (columntype == COLUMN_TYPE_IMAGE && - !name.empty() && + else if (columntype == COLUMN_TYPE_IMAGE && !name.empty() && string_allowed(name, "0123456789")) { s32 content_index = allocImage(value); active_image_indices.insert(std::make_pair( - stoi(name), - content_index)); - } - else { - errorstream<<"Invalid table column option: \""<<name<<"\"" - <<" (value=\""<<value<<"\")"<<std::endl; + stoi(name), content_index)); + } else { + errorstream << "Invalid table column option: \"" << name + << "\"" + << " (value=\"" << value << "\")" + << std::endl; } } @@ -329,7 +316,8 @@ void GUITable::setTable(const TableOptions &options, if (columntype == COLUMN_TYPE_TEXT) { for (s32 i = 0; i < rowcount; ++i) { TempRow *row = &rows[i]; - while (!row->colors.empty() && row->colors.back().second < j) + while (!row->colors.empty() && + row->colors.back().second < j) row->colors.pop_back(); } } @@ -338,17 +326,20 @@ void GUITable::setTable(const TableOptions &options, Cell newcell; newcell.content_type = columntype; newcell.tooltip_index = tooltip_index; - newcell.reported_column = j+1; + newcell.reported_column = j + 1; if (columntype == COLUMN_TYPE_TEXT) { // Find right edge of column s32 xmax = 0; for (s32 i = 0; i < rowcount; ++i) { TempRow *row = &rows[i]; - row->content_index = allocString(content[i * colcount + j]); + row->content_index = + allocString(content[i * colcount + j]); const core::stringw &text = m_strings[row->content_index]; - row->content_width = m_font ? - m_font->getDimension(text.c_str()).Width : 0; + row->content_width = + m_font ? m_font->getDimension(text.c_str()) + .Width + : 0; row->content_width = MYMAX(row->content_width, width); s32 row_xmax = row->x + padding + row->content_width; xmax = MYMAX(xmax, row_xmax); @@ -356,7 +347,8 @@ void GUITable::setTable(const TableOptions &options, // Add a new cell (of text type) to each row for (s32 i = 0; i < rowcount; ++i) { newcell.xmin = rows[i].x + padding; - alignContent(&newcell, xmax, rows[i].content_width, align); + alignContent(&newcell, xmax, rows[i].content_width, + align); newcell.content_index = rows[i].content_index; newcell.color_defined = !rows[i].colors.empty(); if (newcell.color_defined) @@ -364,8 +356,7 @@ void GUITable::setTable(const TableOptions &options, rows[i].cells.push_back(newcell); rows[i].x = newcell.xmax; } - } - else if (columntype == COLUMN_TYPE_IMAGE) { + } else if (columntype == COLUMN_TYPE_IMAGE) { // Find right edge of column s32 xmax = 0; for (s32 i = 0; i < rowcount; ++i) { @@ -376,7 +367,7 @@ void GUITable::setTable(const TableOptions &options, // column options so check active_image_indices. s32 image_index = stoi(content[i * colcount + j]); std::map<s32, s32>::iterator image_iter = - active_image_indices.find(image_index); + active_image_indices.find(image_index); if (image_iter != active_image_indices.end()) row->content_index = image_iter->second; @@ -386,7 +377,9 @@ void GUITable::setTable(const TableOptions &options, image = m_images[row->content_index]; // Get content width and update xmax - row->content_width = image ? image->getOriginalSize().Width : 0; + row->content_width = + image ? image->getOriginalSize().Width + : 0; row->content_width = MYMAX(row->content_width, width); s32 row_xmax = row->x + padding + row->content_width; xmax = MYMAX(xmax, row_xmax); @@ -394,27 +387,28 @@ void GUITable::setTable(const TableOptions &options, // Add a new cell (of image type) to each row for (s32 i = 0; i < rowcount; ++i) { newcell.xmin = rows[i].x + padding; - alignContent(&newcell, xmax, rows[i].content_width, align); + alignContent(&newcell, xmax, rows[i].content_width, + align); newcell.content_index = rows[i].content_index; rows[i].cells.push_back(newcell); rows[i].x = newcell.xmax; } active_image_indices.clear(); - } - else if (columntype == COLUMN_TYPE_COLOR) { + } else if (columntype == COLUMN_TYPE_COLOR) { for (s32 i = 0; i < rowcount; ++i) { video::SColor cellcolor(255, 255, 255, 255); - if (parseColorString(content[i * colcount + j], cellcolor, true)) - rows[i].colors.emplace_back(cellcolor, j+span); + if (parseColorString(content[i * colcount + j], cellcolor, + true)) + rows[i].colors.emplace_back(cellcolor, j + span); } - } - else if (columntype == COLUMN_TYPE_INDENT || + } else if (columntype == COLUMN_TYPE_INDENT || columntype == COLUMN_TYPE_TREE) { // For column type "tree", reserve additional space for +/- // Also enable special processing for treeview-type tables s32 content_width = 0; if (columntype == COLUMN_TYPE_TREE) { - content_width = m_font ? m_font->getDimension(L"+").Width : 0; + content_width = m_font ? m_font->getDimension(L"+").Width + : 0; m_has_tree_column = true; } // Add a new cell (of indent or tree type) to each row @@ -446,7 +440,7 @@ void GUITable::setTable(const TableOptions &options, Row *row = &m_rows[i]; row->cellcount = rows[i].cells.size(); row->cells = new Cell[row->cellcount]; - memcpy((void*) row->cells, (void*) &rows[i].cells[0], + memcpy((void *)row->cells, (void *)&rows[i].cells[0], row->cellcount * sizeof(Cell)); row->indent = rows[i].indent; row->visible_index = i; @@ -457,10 +451,12 @@ void GUITable::setTable(const TableOptions &options, if (m_has_tree_column) { // Treeview: convert tree to indent cells on leaf rows for (s32 i = 0; i < rowcount; ++i) { - if (i == rowcount-1 || m_rows[i].indent >= m_rows[i+1].indent) + if (i == rowcount - 1 || m_rows[i].indent >= m_rows[i + 1].indent) for (s32 j = 0; j < m_rows[i].cellcount; ++j) - if (m_rows[i].cells[j].content_type == COLUMN_TYPE_TREE) - m_rows[i].cells[j].content_type = COLUMN_TYPE_INDENT; + if (m_rows[i].cells[j].content_type == + COLUMN_TYPE_TREE) + m_rows[i].cells[j].content_type = + COLUMN_TYPE_INDENT; } // Treeview: close rows according to opendepth option @@ -489,9 +485,9 @@ void GUITable::clear() // Get colors from skin gui::IGUISkin *skin = Environment->getSkin(); - m_color = skin->getColor(gui::EGDC_BUTTON_TEXT); - m_background = skin->getColor(gui::EGDC_3D_HIGH_LIGHT); - m_highlight = skin->getColor(gui::EGDC_HIGH_LIGHT); + m_color = skin->getColor(gui::EGDC_BUTTON_TEXT); + m_background = skin->getColor(gui::EGDC_3D_HIGH_LIGHT); + m_highlight = skin->getColor(gui::EGDC_HIGH_LIGHT); m_highlight_text = skin->getColor(gui::EGDC_HIGH_LIGHT_TEXT); // Reset members @@ -520,15 +516,14 @@ std::string GUITable::checkEvent() std::ostringstream os(std::ios::binary); if (m_sel_doubleclick) { - os<<"DCL:"; + os << "DCL:"; m_sel_doubleclick = false; + } else { + os << "CHG:"; } - else { - os<<"CHG:"; - } - os<<sel; + os << sel; if (!m_is_textlist) { - os<<":"<<m_sel_column; + os << ":" << m_sel_column; } return os.str(); } @@ -538,7 +533,7 @@ s32 GUITable::getSelected() const if (m_selected < 0) return 0; - assert(m_selected >= 0 && m_selected < (s32) m_visible_rows.size()); + assert(m_selected >= 0 && m_selected < (s32)m_visible_rows.size()); return m_visible_rows[m_selected] + 1; } @@ -578,7 +573,7 @@ void GUITable::setSelected(s32 index) if (index >= 0) { m_selected = m_rows[index].visible_index; - assert(m_selected >= 0 && m_selected < (s32) m_visible_rows.size()); + assert(m_selected >= 0 && m_selected < (s32)m_visible_rows.size()); } if (m_selected != old_selected || selection_invisible) { @@ -613,7 +608,7 @@ void GUITable::setDynamicData(const DynamicData &dyndata) m_scrollbar->setPos(dyndata.scrollpos); } -const c8* GUITable::getTypeName() const +const c8 *GUITable::getTypeName() const { return "GUITable"; } @@ -635,12 +630,11 @@ void GUITable::draw() bool draw_background = m_background.getAlpha() > 0; if (m_border) - skin->draw3DSunkenPane(this, m_background, - true, draw_background, + skin->draw3DSunkenPane(this, m_background, true, draw_background, AbsoluteRect, &AbsoluteClippingRect); else if (draw_background) - skin->draw2DRectangle(this, m_background, - AbsoluteRect, &AbsoluteClippingRect); + skin->draw2DRectangle( + this, m_background, AbsoluteRect, &AbsoluteClippingRect); // get clipping rect @@ -659,14 +653,12 @@ void GUITable::draw() s32 scrollpos = m_scrollbar->getPos(); s32 row_min = scrollpos / m_rowheight; - s32 row_max = (scrollpos + AbsoluteRect.getHeight() - 1) - / m_rowheight + 1; - row_max = MYMIN(row_max, (s32) m_visible_rows.size()); + s32 row_max = (scrollpos + AbsoluteRect.getHeight() - 1) / m_rowheight + 1; + row_max = MYMIN(row_max, (s32)m_visible_rows.size()); core::rect<s32> row_rect(AbsoluteRect); if (m_scrollbar->isVisible()) - row_rect.LowerRightCorner.X -= - skin->getSize(gui::EGDS_SCROLLBAR_SIZE); + row_rect.LowerRightCorner.X -= skin->getSize(gui::EGDS_SCROLLBAR_SIZE); row_rect.UpperLeftCorner.Y += row_min * m_rowheight - scrollpos; row_rect.LowerRightCorner.Y = row_rect.UpperLeftCorner.Y + m_rowheight; @@ -692,33 +684,27 @@ void GUITable::draw() } void GUITable::drawCell(const Cell *cell, video::SColor color, - const core::rect<s32> &row_rect, - const core::rect<s32> &client_clip) + const core::rect<s32> &row_rect, const core::rect<s32> &client_clip) { - if ((cell->content_type == COLUMN_TYPE_TEXT) - || (cell->content_type == COLUMN_TYPE_TREE)) { + if ((cell->content_type == COLUMN_TYPE_TEXT) || + (cell->content_type == COLUMN_TYPE_TREE)) { core::rect<s32> text_rect = row_rect; - text_rect.UpperLeftCorner.X = row_rect.UpperLeftCorner.X - + cell->xpos; - text_rect.LowerRightCorner.X = row_rect.UpperLeftCorner.X - + cell->xmax; + text_rect.UpperLeftCorner.X = row_rect.UpperLeftCorner.X + cell->xpos; + text_rect.LowerRightCorner.X = row_rect.UpperLeftCorner.X + cell->xmax; if (cell->color_defined) color = cell->color; if (m_font) { if (cell->content_type == COLUMN_TYPE_TEXT) - m_font->draw(m_strings[cell->content_index], - text_rect, color, - false, true, &client_clip); + m_font->draw(m_strings[cell->content_index], text_rect, + color, false, true, &client_clip); else // tree - m_font->draw(cell->content_index ? L"+" : L"-", - text_rect, color, - false, true, &client_clip); + m_font->draw(cell->content_index ? L"+" : L"-", text_rect, + color, false, true, &client_clip); } - } - else if (cell->content_type == COLUMN_TYPE_IMAGE) { + } else if (cell->content_type == COLUMN_TYPE_IMAGE) { if (cell->content_index < 0) return; @@ -727,11 +713,9 @@ void GUITable::drawCell(const Cell *cell, video::SColor color, video::ITexture *image = m_images[cell->content_index]; if (image) { - core::position2d<s32> dest_pos = - row_rect.UpperLeftCorner; + core::position2d<s32> dest_pos = row_rect.UpperLeftCorner; dest_pos.X += cell->xpos; - core::rect<s32> source_rect( - core::position2d<s32>(0, 0), + core::rect<s32> source_rect(core::position2d<s32>(0, 0), image->getOriginalSize()); s32 imgh = source_rect.LowerRightCorner.Y; s32 rowh = row_rect.getHeight(); @@ -742,8 +726,8 @@ void GUITable::drawCell(const Cell *cell, video::SColor color, video::SColor color(255, 255, 255, 255); - driver->draw2DImage(image, dest_pos, source_rect, - &client_clip, color, true); + driver->draw2DImage(image, dest_pos, source_rect, &client_clip, + color, true); } } } @@ -754,40 +738,41 @@ bool GUITable::OnEvent(const SEvent &event) return IGUIElement::OnEvent(event); if (event.EventType == EET_KEY_INPUT_EVENT) { - if (event.KeyInput.PressedDown && ( - event.KeyInput.Key == KEY_DOWN || - event.KeyInput.Key == KEY_UP || - event.KeyInput.Key == KEY_HOME || - event.KeyInput.Key == KEY_END || - event.KeyInput.Key == KEY_NEXT || - event.KeyInput.Key == KEY_PRIOR)) { + if (event.KeyInput.PressedDown && + (event.KeyInput.Key == KEY_DOWN || + event.KeyInput.Key == KEY_UP || + event.KeyInput.Key == KEY_HOME || + event.KeyInput.Key == KEY_END || + event.KeyInput.Key == KEY_NEXT || + event.KeyInput.Key == KEY_PRIOR)) { s32 offset = 0; switch (event.KeyInput.Key) { - case KEY_DOWN: - offset = 1; - break; - case KEY_UP: - offset = -1; - break; - case KEY_HOME: - offset = - (s32) m_visible_rows.size(); - break; - case KEY_END: - offset = m_visible_rows.size(); - break; - case KEY_NEXT: - offset = AbsoluteRect.getHeight() / m_rowheight; - break; - case KEY_PRIOR: - offset = - (s32) (AbsoluteRect.getHeight() / m_rowheight); - break; - default: - break; + case KEY_DOWN: + offset = 1; + break; + case KEY_UP: + offset = -1; + break; + case KEY_HOME: + offset = -(s32)m_visible_rows.size(); + break; + case KEY_END: + offset = m_visible_rows.size(); + break; + case KEY_NEXT: + offset = AbsoluteRect.getHeight() / m_rowheight; + break; + case KEY_PRIOR: + offset = -(s32)(AbsoluteRect.getHeight() / m_rowheight); + break; + default: + break; } s32 old_selected = m_selected; s32 rowcount = m_visible_rows.size(); if (rowcount != 0) { - m_selected = rangelim(m_selected + offset, 0, rowcount-1); + m_selected = rangelim( + m_selected + offset, 0, rowcount - 1); autoScroll(); } @@ -797,27 +782,24 @@ bool GUITable::OnEvent(const SEvent &event) return true; } - if (event.KeyInput.PressedDown && ( - event.KeyInput.Key == KEY_LEFT || - event.KeyInput.Key == KEY_RIGHT)) { + if (event.KeyInput.PressedDown && + (event.KeyInput.Key == KEY_LEFT || + event.KeyInput.Key == KEY_RIGHT)) { // Open/close subtree via keyboard if (m_selected >= 0) { int dir = event.KeyInput.Key == KEY_LEFT ? -1 : 1; toggleVisibleTree(m_selected, dir, true); } return true; - } - else if (!event.KeyInput.PressedDown && ( - event.KeyInput.Key == KEY_RETURN || - event.KeyInput.Key == KEY_SPACE)) { + } else if (!event.KeyInput.PressedDown && + (event.KeyInput.Key == KEY_RETURN || + event.KeyInput.Key == KEY_SPACE)) { sendTableEvent(0, true); return true; - } - else if (event.KeyInput.Key == KEY_ESCAPE || + } else if (event.KeyInput.Key == KEY_ESCAPE || event.KeyInput.Key == KEY_SPACE) { // pass to parent - } - else if (event.KeyInput.PressedDown && event.KeyInput.Char) { + } else if (event.KeyInput.PressedDown && event.KeyInput.Char) { // change selection based on text as it is typed u64 now = porting::getTimeMs(); if (now - m_keynav_time >= 500) @@ -826,12 +808,13 @@ bool GUITable::OnEvent(const SEvent &event) // add to key buffer if not a key repeat if (!(m_keynav_buffer.size() == 1 && - m_keynav_buffer[0] == event.KeyInput.Char)) { + m_keynav_buffer[0] == event.KeyInput.Char)) { m_keynav_buffer.append(event.KeyInput.Char); } // find the selected item, starting at the current selection - // don't change selection if the key buffer matches the current item + // don't change selection if the key buffer matches the current + // item s32 old_selected = m_selected; s32 start = MYMAX(m_selected, 0); s32 rowcount = m_visible_rows.size(); @@ -856,8 +839,8 @@ bool GUITable::OnEvent(const SEvent &event) if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) { m_scrollbar->setPos(m_scrollbar->getPos() + - (event.MouseInput.Wheel < 0 ? -3 : 3) * - - (s32) m_rowheight / 2); + (event.MouseInput.Wheel < 0 ? -3 : 3) * + -(s32)m_rowheight / 2); return true; } @@ -878,24 +861,24 @@ bool GUITable::OnEvent(const SEvent &event) // IGUIScrollBar passes double click events to its parent, // which we don't want. Detect this case and discard the event if (event.MouseInput.Event != EMIE_MOUSE_MOVED && - m_scrollbar->isVisible() && - m_scrollbar->isPointInside(p)) + m_scrollbar->isVisible() && m_scrollbar->isPointInside(p)) return true; if (event.MouseInput.isLeftPressed() && - (isPointInside(p) || - event.MouseInput.Event == EMIE_MOUSE_MOVED)) { + (isPointInside(p) || event.MouseInput.Event == + EMIE_MOUSE_MOVED)) { s32 sel_column = 0; - bool sel_doubleclick = (event.MouseInput.Event - == EMIE_LMOUSE_DOUBLE_CLICK); + bool sel_doubleclick = (event.MouseInput.Event == + EMIE_LMOUSE_DOUBLE_CLICK); bool plusminus_clicked = false; // For certain events (left click), report column // Also open/close subtrees when the +/- is clicked - if (cell && ( - event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN || - event.MouseInput.Event == EMIE_LMOUSE_DOUBLE_CLICK || - event.MouseInput.Event == EMIE_LMOUSE_TRIPLE_CLICK)) { + if (cell && (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN || + event.MouseInput.Event == + EMIE_LMOUSE_DOUBLE_CLICK || + event.MouseInput.Event == + EMIE_LMOUSE_TRIPLE_CLICK)) { sel_column = cell->reported_column; if (cell->content_type == COLUMN_TYPE_TREE) plusminus_clicked = true; @@ -905,15 +888,13 @@ bool GUITable::OnEvent(const SEvent &event) if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) { toggleVisibleTree(row_i, 0, false); } - } - else { + } else { // Normal selection s32 old_selected = m_selected; m_selected = row_i; autoScroll(); - if (m_selected != old_selected || - sel_column >= 1 || + if (m_selected != old_selected || sel_column >= 1 || sel_doubleclick) { sendTableEvent(sel_column, sel_doubleclick); } @@ -975,9 +956,9 @@ void GUITable::allocationComplete() m_alloc_images.clear(); } -const GUITable::Row* GUITable::getRow(s32 i) const +const GUITable::Row *GUITable::getRow(s32 i) const { - if (i >= 0 && i < (s32) m_visible_rows.size()) + if (i >= 0 && i < (s32)m_visible_rows.size()) return &m_rows[m_visible_rows[i]]; return NULL; @@ -993,7 +974,8 @@ bool GUITable::doesRowStartWith(const Row *row, const core::stringw &str) const if (cell->content_type == COLUMN_TYPE_TEXT) { const core::stringw &cellstr = m_strings[cell->content_index]; if (cellstr.size() >= str.size() && - str.equals_ignore_case(cellstr.subString(0, str.size()))) + str.equals_ignore_case( + cellstr.subString(0, str.size()))) return true; } } @@ -1046,8 +1028,7 @@ s32 GUITable::getCellAt(s32 x, s32 row_i) const jmin = pivot + 1; } - if (jmin >= 0 && jmin < row->cellcount && - rel_x >= row->cells[jmin].xmin && + if (jmin >= 0 && jmin < row->cellcount && rel_x >= row->cells[jmin].xmin && rel_x <= row->cells[jmin].xmax) return jmin; @@ -1098,8 +1079,8 @@ void GUITable::getOpenedTrees(std::set<s32> &opened_trees) const opened_trees.clear(); s32 rowcount = m_rows.size(); for (s32 i = 0; i < rowcount - 1; ++i) { - if (m_rows[i].indent < m_rows[i+1].indent && - m_rows[i+1].visible_index != -2) + if (m_rows[i].indent < m_rows[i + 1].indent && + m_rows[i + 1].visible_index != -2) opened_trees.insert(i); } } @@ -1131,18 +1112,16 @@ void GUITable::setOpenedTrees(const std::set<s32> &opened_trees) // Visible row row->visible_index = m_visible_rows.size(); m_visible_rows.push_back(i); - } - else if (parents.back() == closed_parents.back()) { + } else if (parents.back() == closed_parents.back()) { // Invisible row, direct parent is closed row->visible_index = -2; - } - else { + } else { // Invisible row, direct parent is open, some ancestor is closed row->visible_index = -1; } // If not a leaf, add to parents list - if (i < m_rows.size()-1 && row->indent < m_rows[i+1].indent) { + if (i < m_rows.size() - 1 && row->indent < m_rows[i + 1].indent) { parents.push_back(i); s32 content_index = 0; // "-", open @@ -1220,14 +1199,13 @@ void GUITable::toggleVisibleTree(s32 row_i, int dir, bool move_selection) const Row *maybe_child = getRow(sel + 1); if (maybe_child && maybe_child->indent > row->indent) sel++; - } - else if (!was_open && !do_open) { + } else if (!was_open && !do_open) { // Move selection to parent assert(getRow(sel) != NULL); while (sel > 0 && getRow(sel - 1)->indent >= row->indent) sel--; sel--; - if (sel < 0) // was root already selected? + if (sel < 0) // was root already selected? sel = row_i; } if (sel != m_selected) { @@ -1245,16 +1223,13 @@ void GUITable::alignContent(Cell *cell, s32 xmax, s32 content_width, s32 align) if (align == 0) { cell->xpos = cell->xmin; cell->xmax = xmax; - } - else if (align == 1) { + } else if (align == 1) { cell->xpos = (cell->xmin + xmax - content_width) / 2; cell->xmax = xmax; - } - else if (align == 2) { + } else if (align == 2) { cell->xpos = xmax - content_width; cell->xmax = xmax; - } - else { + } else { // inline alignment: the cells of the column don't have an aligned // right border, the right border of each cell depends on the content cell->xpos = cell->xmin; diff --git a/src/gui/guiTable.h b/src/gui/guiTable.h index 11093ea72..95cf05922 100644 --- a/src/gui/guiTable.h +++ b/src/gui/guiTable.h @@ -67,9 +67,9 @@ public: std::string value; Option(const std::string &name_, const std::string &value_) : - name(name_), - value(value_) - {} + name(name_), value(value_) + { + } }; /* @@ -87,11 +87,8 @@ public: }; typedef std::vector<TableColumn> TableColumns; - - GUITable(gui::IGUIEnvironment *env, - gui::IGUIElement *parent, s32 id, - core::rect<s32> rectangle, - ISimpleTextureSource *tsrc); + GUITable(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, + core::rect<s32> rectangle, ISimpleTextureSource *tsrc); virtual ~GUITable(); @@ -99,13 +96,11 @@ public: static Option splitOption(const std::string &str); /* Set textlist-like options, columns and data */ - void setTextList(const std::vector<std::string> &content, - bool transparent); + void setTextList(const std::vector<std::string> &content, bool transparent); /* Set generic table options, columns and content */ // Adds empty strings to end of content if there is an incomplete row - void setTable(const TableOptions &options, - const TableColumns &columns, + void setTable(const TableOptions &options, const TableColumns &columns, std::vector<std::string> &content); /* Clear the table */ @@ -130,7 +125,7 @@ public: void setDynamicData(const DynamicData &dyndata); /* Returns "GUITable" */ - virtual const c8* getTypeName() const; + virtual const c8 *getTypeName() const; /* Must be called when position or size changes */ virtual void updateAbsolutePosition(); @@ -142,7 +137,8 @@ public: virtual bool OnEvent(const SEvent &event); protected: - enum ColumnType { + enum ColumnType + { COLUMN_TYPE_TEXT, COLUMN_TYPE_IMAGE, COLUMN_TYPE_COLOR, @@ -150,7 +146,8 @@ protected: COLUMN_TYPE_TREE, }; - struct Cell { + struct Cell + { s32 xmin; s32 xmax; s32 xpos; @@ -162,7 +159,8 @@ protected: s32 reported_column; }; - struct Row { + struct Row + { Cell *cells; s32 cellcount; s32 indent; @@ -203,7 +201,7 @@ protected: // Allocated strings and images std::vector<core::stringw> m_strings; - std::vector<video::ITexture*> m_images; + std::vector<video::ITexture *> m_images; std::map<std::string, s32> m_alloc_strings; std::map<std::string, s32> m_alloc_images; @@ -252,6 +250,5 @@ protected: // Aligns cell content in column according to alignment specification // align = 0: left aligned, 1: centered, 2: right aligned, 3: inline - static void alignContent(Cell *cell, s32 xmax, s32 content_width, - s32 align); + static void alignContent(Cell *cell, s32 xmax, s32 content_width, s32 align); }; diff --git a/src/gui/guiVolumeChange.cpp b/src/gui/guiVolumeChange.cpp index f17cfa986..12874594e 100644 --- a/src/gui/guiVolumeChange.cpp +++ b/src/gui/guiVolumeChange.cpp @@ -36,12 +36,10 @@ const int ID_soundExitButton = 264; const int ID_soundSlider = 265; const int ID_soundMuteButton = 266; -GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env, - gui::IGUIElement* parent, s32 id, - IMenuManager *menumgr, ISimpleTextureSource *tsrc -): - GUIModalMenu(env, parent, id, menumgr), - m_tsrc(tsrc) +GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment *env, gui::IGUIElement *parent, + s32 id, IMenuManager *menumgr, ISimpleTextureSource *tsrc) : + GUIModalMenu(env, parent, id, menumgr), + m_tsrc(tsrc) { } @@ -75,12 +73,9 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize) Calculate new sizes and positions */ const float s = m_gui_scale; - DesiredRect = core::rect<s32>( - screensize.X / 2 - 380 * s / 2, - screensize.Y / 2 - 200 * s / 2, - screensize.X / 2 + 380 * s / 2, - screensize.Y / 2 + 200 * s / 2 - ); + DesiredRect = core::rect<s32>(screensize.X / 2 - 380 * s / 2, + screensize.Y / 2 - 200 * s / 2, screensize.X / 2 + 380 * s / 2, + screensize.Y / 2 + 200 * s / 2); recalculateAbsolutePosition(false); v2s32 size = DesiredRect.getSize(); @@ -95,24 +90,25 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize) const wchar_t *text = wgettext("Sound Volume: "); core::stringw volume_text = text; - delete [] text; + delete[] text; volume_text += core::stringw(volume) + core::stringw("%"); - Environment->addStaticText(volume_text.c_str(), rect, false, - true, this, ID_soundText); + Environment->addStaticText(volume_text.c_str(), rect, false, true, this, + ID_soundText); } { core::rect<s32> rect(0, 0, 80 * s, 30 * s); rect = rect + v2s32(size.X / 2 - 80 * s / 2, size.Y / 2 + 55 * s); const wchar_t *text = wgettext("Exit"); - GUIButton::addButton(Environment, rect, m_tsrc, this, ID_soundExitButton, text); + GUIButton::addButton(Environment, rect, m_tsrc, this, ID_soundExitButton, + text); delete[] text; } { core::rect<s32> rect(0, 0, 300 * s, 20 * s); rect = rect + v2s32(size.X / 2 - 150 * s, size.Y / 2); - gui::IGUIScrollBar *e = Environment->addScrollBar(true, - rect, this, ID_soundSlider); + gui::IGUIScrollBar *e = Environment->addScrollBar( + true, rect, this, ID_soundSlider); e->setMax(100); e->setPos(volume); } @@ -128,16 +124,16 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize) void GUIVolumeChange::drawMenu() { - gui::IGUISkin* skin = Environment->getSkin(); + gui::IGUISkin *skin = Environment->getSkin(); if (!skin) return; - video::IVideoDriver* driver = Environment->getVideoDriver(); + video::IVideoDriver *driver = Environment->getVideoDriver(); video::SColor bgcolor(140, 0, 0, 0); driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect); gui::IGUIElement::draw(); } -bool GUIVolumeChange::OnEvent(const SEvent& event) +bool GUIVolumeChange::OnEvent(const SEvent &event) { if (event.EventType == EET_KEY_INPUT_EVENT) { if (event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown) { @@ -153,7 +149,8 @@ bool GUIVolumeChange::OnEvent(const SEvent& event) if (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED) { gui::IGUIElement *e = getElementFromId(ID_soundMuteButton); if (e != NULL && e->getType() == gui::EGUIET_CHECK_BOX) { - g_settings->setBool("mute_sound", ((gui::IGUICheckBox*)e)->isChecked()); + g_settings->setBool("mute_sound", + ((gui::IGUICheckBox *)e)->isChecked()); } Environment->setFocus(this); @@ -168,31 +165,32 @@ bool GUIVolumeChange::OnEvent(const SEvent& event) Environment->setFocus(this); } - if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST - && isVisible()) { + if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && + isVisible()) { if (!canTakeFocus(event.GUIEvent.Element)) { - infostream << "GUIVolumeChange: Not allowing focus change." - << std::endl; + infostream << "GUIVolumeChange: Not allowing focus " + "change." + << std::endl; // Returning true disables focus change return true; } } if (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED) { if (event.GUIEvent.Caller->getID() == ID_soundSlider) { - s32 pos = ((gui::IGUIScrollBar*)event.GUIEvent.Caller)->getPos(); - g_settings->setFloat("sound_volume", (float) pos / 100); + s32 pos = ((gui::IGUIScrollBar *)event.GUIEvent.Caller) + ->getPos(); + g_settings->setFloat("sound_volume", (float)pos / 100); gui::IGUIElement *e = getElementFromId(ID_soundText); const wchar_t *text = wgettext("Sound Volume: "); core::stringw volume_text = text; - delete [] text; + delete[] text; volume_text += core::stringw(pos) + core::stringw("%"); e->setText(volume_text.c_str()); return true; } } - } return Parent ? Parent->OnEvent(event) : false; diff --git a/src/gui/guiVolumeChange.h b/src/gui/guiVolumeChange.h index 466e17f9d..f1347a491 100644 --- a/src/gui/guiVolumeChange.h +++ b/src/gui/guiVolumeChange.h @@ -28,8 +28,7 @@ class ISimpleTextureSource; class GUIVolumeChange : public GUIModalMenu { public: - GUIVolumeChange(gui::IGUIEnvironment* env, - gui::IGUIElement* parent, s32 id, + GUIVolumeChange(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, ISimpleTextureSource *tsrc); ~GUIVolumeChange(); @@ -41,7 +40,7 @@ public: void drawMenu(); - bool OnEvent(const SEvent& event); + bool OnEvent(const SEvent &event); bool pausesGame() { return true; } diff --git a/src/gui/intlGUIEditBox.cpp b/src/gui/intlGUIEditBox.cpp index 10395423c..1c8bb64de 100644 --- a/src/gui/intlGUIEditBox.cpp +++ b/src/gui/intlGUIEditBox.cpp @@ -45,9 +45,8 @@ todo: optional scrollbars ctrl+left/right to select word - double click/ctrl click: word select + drag to select whole words, triple click to select line - optional? dragging selected text - numerical + double click/ctrl click: word select + drag to select whole words, triple click to + select line optional? dragging selected text numerical */ namespace irr @@ -56,16 +55,16 @@ namespace gui { //! constructor -intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border, - IGUIEnvironment* environment, IGUIElement* parent, s32 id, - const core::rect<s32>& rectangle, bool writable, bool has_vscrollbar) - : IGUIEditBox(environment, parent, id, rectangle), - Border(border), FrameRect(rectangle), - m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable) +intlGUIEditBox::intlGUIEditBox(const wchar_t *text, bool border, + IGUIEnvironment *environment, IGUIElement *parent, s32 id, + const core::rect<s32> &rectangle, bool writable, bool has_vscrollbar) : + IGUIEditBox(environment, parent, id, rectangle), + Border(border), FrameRect(rectangle), m_scrollbar_width(0), + m_vscrollbar(NULL), m_writable(writable) { - #ifdef _DEBUG +#ifdef _DEBUG setDebugName("intlintlGUIEditBox"); - #endif +#endif Text = text; @@ -82,12 +81,11 @@ intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border, IGUISkin *skin = 0; if (Environment) skin = Environment->getSkin(); - if (Border && skin) - { - FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1; - FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1; - FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1; - FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1; + if (Border && skin) { + FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; + FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; + FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; + FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; } if (skin && has_vscrollbar) { @@ -104,7 +102,6 @@ intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border, setWritable(writable); } - //! destructor intlGUIEditBox::~intlGUIEditBox() { @@ -118,9 +115,8 @@ intlGUIEditBox::~intlGUIEditBox() m_vscrollbar->drop(); } - //! Sets another skin independent font. -void intlGUIEditBox::setOverrideFont(IGUIFont* font) +void intlGUIEditBox::setOverrideFont(IGUIFont *font) { if (OverrideFont == font) return; @@ -136,17 +132,17 @@ void intlGUIEditBox::setOverrideFont(IGUIFont* font) breakText(); } -IGUIFont * intlGUIEditBox::getOverrideFont() const +IGUIFont *intlGUIEditBox::getOverrideFont() const { return OverrideFont; } //! Get the font which is used right now for drawing -IGUIFont* intlGUIEditBox::getActiveFont() const +IGUIFont *intlGUIEditBox::getActiveFont() const { - if ( OverrideFont ) + if (OverrideFont) return OverrideFont; - IGUISkin* skin = Environment->getSkin(); + IGUISkin *skin = Environment->getSkin(); if (skin) return skin->getFont(); return 0; @@ -193,44 +189,37 @@ void intlGUIEditBox::setWordWrap(bool enable) breakText(); } - void intlGUIEditBox::updateAbsolutePosition() { - core::rect<s32> oldAbsoluteRect(AbsoluteRect); + core::rect<s32> oldAbsoluteRect(AbsoluteRect); IGUIElement::updateAbsolutePosition(); - if ( oldAbsoluteRect != AbsoluteRect ) - { - breakText(); + if (oldAbsoluteRect != AbsoluteRect) { + breakText(); } } - //! Checks if word wrap is enabled bool intlGUIEditBox::isWordWrapEnabled() const { return WordWrap; } - //! Enables or disables newlines. void intlGUIEditBox::setMultiLine(bool enable) { MultiLine = enable; } - //! Checks if multi line editing is enabled bool intlGUIEditBox::isMultiLineEnabled() const { return MultiLine; } - void intlGUIEditBox::setPasswordBox(bool passwordBox, wchar_t passwordChar) { PasswordBox = passwordBox; - if (PasswordBox) - { + if (PasswordBox) { PasswordChar = passwordChar; setMultiLine(false); setWordWrap(false); @@ -238,13 +227,11 @@ void intlGUIEditBox::setPasswordBox(bool passwordBox, wchar_t passwordChar) } } - bool intlGUIEditBox::isPasswordBox() const { return PasswordBox; } - //! Sets text justification void intlGUIEditBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) { @@ -252,40 +239,35 @@ void intlGUIEditBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT VAlign = vertical; } - //! called if an event happened. -bool intlGUIEditBox::OnEvent(const SEvent& event) +bool intlGUIEditBox::OnEvent(const SEvent &event) { - if (IsEnabled) - { + if (IsEnabled) { - switch(event.EventType) - { + switch (event.EventType) { case EET_GUI_EVENT: - if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) - { - if (event.GUIEvent.Caller == this) - { + if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) { + if (event.GUIEvent.Caller == this) { MouseMarking = false; - setTextMarkers(0,0); + setTextMarkers(0, 0); } } break; - case EET_KEY_INPUT_EVENT: - { + case EET_KEY_INPUT_EVENT: { #if (defined(__linux__) || defined(__FreeBSD__)) || defined(__DragonFly__) - // ################################################################ + // ################################################################ // ValkaTR: - // This part is the difference from the original intlGUIEditBox - // It converts UTF-8 character into a UCS-2 (wchar_t) - wchar_t wc = L'_'; - mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) ); + // This part is the difference from the original intlGUIEditBox + // It converts UTF-8 character into a UCS-2 (wchar_t) + wchar_t wc = L'_'; + mbtowc(&wc, (char *)&event.KeyInput.Char, + sizeof(event.KeyInput.Char)); - //printf( "char: %lc (%u) \r\n", wc, wc ); + // printf( "char: %lc (%u) \r\n", wc, wc ); - SEvent irrevent(event); - irrevent.KeyInput.Char = wc; - // ################################################################ + SEvent irrevent(event); + irrevent.KeyInput.Char = wc; + // ################################################################ if (processKey(irrevent)) return true; @@ -295,7 +277,7 @@ bool intlGUIEditBox::OnEvent(const SEvent& event) #endif // defined(linux) break; - } + } case EET_MOUSE_INPUT_EVENT: if (processMouse(event)) return true; @@ -308,8 +290,7 @@ bool intlGUIEditBox::OnEvent(const SEvent& event) return IGUIElement::OnEvent(event); } - -bool intlGUIEditBox::processKey(const SEvent& event) +bool intlGUIEditBox::processKey(const SEvent &event) { if (!event.KeyInput.PressedDown) return false; @@ -320,17 +301,14 @@ bool intlGUIEditBox::processKey(const SEvent& event) // control shortcut handling - if (event.KeyInput.Control) - { + if (event.KeyInput.Control) { // german backlash '\' entered with control + '?' - if ( event.KeyInput.Char == '\\' ) - { + if (event.KeyInput.Char == '\\') { inputChar(event.KeyInput.Char); return true; } - switch(event.KeyInput.Key) - { + switch (event.KeyInput.Key) { case KEY_KEY_A: // select all newMarkBegin = 0; @@ -338,10 +316,11 @@ bool intlGUIEditBox::processKey(const SEvent& event) break; case KEY_KEY_C: // copy to clipboard - if (!PasswordBox && Operator && MarkBegin != MarkEnd) - { - const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; - const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + if (!PasswordBox && Operator && MarkBegin != MarkEnd) { + const s32 realmbgn = + MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = + MarkBegin < MarkEnd ? MarkEnd : MarkBegin; core::stringc s; s = Text.subString(realmbgn, realmend - realmbgn).c_str(); @@ -351,19 +330,23 @@ bool intlGUIEditBox::processKey(const SEvent& event) case KEY_KEY_X: // cut to the clipboard if (!PasswordBox && Operator && MarkBegin != MarkEnd) { - const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; - const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + const s32 realmbgn = + MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = + MarkBegin < MarkEnd ? MarkEnd : MarkBegin; // copy core::stringc sc; - sc = Text.subString(realmbgn, realmend - realmbgn).c_str(); + sc = Text.subString(realmbgn, realmend - realmbgn) + .c_str(); Operator->copyToClipboard(sc.c_str()); if (IsEnabled && m_writable) { // delete core::stringw s; s = Text.subString(0, realmbgn); - s.append( Text.subString(realmend, Text.size()-realmend) ); + s.append(Text.subString(realmend, + Text.size() - realmend)); Text = s; CursorPos = realmbgn; @@ -378,38 +361,43 @@ bool intlGUIEditBox::processKey(const SEvent& event) break; // paste from the clipboard - if (Operator) - { - const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; - const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + if (Operator) { + const s32 realmbgn = + MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = + MarkBegin < MarkEnd ? MarkEnd : MarkBegin; // add new character - const c8* p = Operator->getTextFromClipboard(); - if (p) - { - if (MarkBegin == MarkEnd) - { + const c8 *p = Operator->getTextFromClipboard(); + if (p) { + if (MarkBegin == MarkEnd) { // insert text - core::stringw s = Text.subString(0, CursorPos); + core::stringw s = Text.subString( + 0, CursorPos); s.append(p); - s.append( Text.subString(CursorPos, Text.size()-CursorPos) ); + s.append(Text.subString(CursorPos, + Text.size() - CursorPos)); - if (!Max || s.size()<=Max) // thx to Fish FH for fix + if (!Max || s.size() <= Max) // thx to + // Fish FH + // for fix { Text = s; s = p; CursorPos += s.size(); } - } - else - { + } else { // replace text - core::stringw s = Text.subString(0, realmbgn); + core::stringw s = Text.subString( + 0, realmbgn); s.append(p); - s.append( Text.subString(realmend, Text.size()-realmend) ); + s.append(Text.subString(realmend, + Text.size() - realmend)); - if (!Max || s.size()<=Max) // thx to Fish FH for fix + if (!Max || s.size() <= Max) // thx to + // Fish FH + // for fix { Text = s; s = p; @@ -425,14 +413,11 @@ bool intlGUIEditBox::processKey(const SEvent& event) break; case KEY_HOME: // move/highlight to start of text - if (event.KeyInput.Shift) - { + if (event.KeyInput.Shift) { newMarkEnd = CursorPos; newMarkBegin = 0; CursorPos = 0; - } - else - { + } else { CursorPos = 0; newMarkBegin = 0; newMarkEnd = 0; @@ -440,14 +425,11 @@ bool intlGUIEditBox::processKey(const SEvent& event) break; case KEY_END: // move/highlight to end of text - if (event.KeyInput.Shift) - { + if (event.KeyInput.Shift) { newMarkBegin = CursorPos; newMarkEnd = Text.size(); CursorPos = 0; - } - else - { + } else { CursorPos = Text.size(); newMarkBegin = 0; newMarkEnd = 0; @@ -459,293 +441,281 @@ bool intlGUIEditBox::processKey(const SEvent& event) } // default keyboard handling else - switch(event.KeyInput.Key) - { - case KEY_END: - { + switch (event.KeyInput.Key) { + case KEY_END: { s32 p = Text.size(); - if (WordWrap || MultiLine) - { + if (WordWrap || MultiLine) { p = getLineFromPos(CursorPos); p = BrokenTextPositions[p] + (s32)BrokenText[p].size(); - if (p > 0 && (Text[p-1] == L'\r' || Text[p-1] == L'\n' )) - p-=1; + if (p > 0 && (Text[p - 1] == L'\r' || + Text[p - 1] == L'\n')) + p -= 1; } - if (event.KeyInput.Shift) - { + if (event.KeyInput.Shift) { if (MarkBegin == MarkEnd) newMarkBegin = CursorPos; newMarkEnd = p; - } - else - { + } else { newMarkBegin = 0; newMarkEnd = 0; } CursorPos = p; BlinkStartTime = porting::getTimeMs(); - } - break; - case KEY_HOME: - { + } break; + case KEY_HOME: { s32 p = 0; - if (WordWrap || MultiLine) - { + if (WordWrap || MultiLine) { p = getLineFromPos(CursorPos); p = BrokenTextPositions[p]; } - if (event.KeyInput.Shift) - { + if (event.KeyInput.Shift) { if (MarkBegin == MarkEnd) newMarkBegin = CursorPos; newMarkEnd = p; - } - else - { + } else { newMarkBegin = 0; newMarkEnd = 0; } CursorPos = p; BlinkStartTime = porting::getTimeMs(); - } - break; - case KEY_RETURN: - if (MultiLine) - { - inputChar(L'\n'); - return true; - } - else - { - sendGuiEvent( EGET_EDITBOX_ENTER ); - } - break; - case KEY_LEFT: - - if (event.KeyInput.Shift) - { - if (CursorPos > 0) - { - if (MarkBegin == MarkEnd) - newMarkBegin = CursorPos; - - newMarkEnd = CursorPos-1; + } break; + case KEY_RETURN: + if (MultiLine) { + inputChar(L'\n'); + return true; + } else { + sendGuiEvent(EGET_EDITBOX_ENTER); } - } - else - { - newMarkBegin = 0; - newMarkEnd = 0; - } - - if (CursorPos > 0) CursorPos--; - BlinkStartTime = porting::getTimeMs(); - break; + break; + case KEY_LEFT: - case KEY_RIGHT: - if (event.KeyInput.Shift) - { - if (Text.size() > (u32)CursorPos) - { - if (MarkBegin == MarkEnd) - newMarkBegin = CursorPos; + if (event.KeyInput.Shift) { + if (CursorPos > 0) { + if (MarkBegin == MarkEnd) + newMarkBegin = CursorPos; - newMarkEnd = CursorPos+1; + newMarkEnd = CursorPos - 1; + } + } else { + newMarkBegin = 0; + newMarkEnd = 0; } - } - else - { - newMarkBegin = 0; - newMarkEnd = 0; - } - if (Text.size() > (u32)CursorPos) CursorPos++; - BlinkStartTime = porting::getTimeMs(); - break; - case KEY_UP: - if (MultiLine || (WordWrap && BrokenText.size() > 1) ) - { - s32 lineNo = getLineFromPos(CursorPos); - s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin > MarkEnd ? MarkBegin : MarkEnd); - if (lineNo > 0) - { - s32 cp = CursorPos - BrokenTextPositions[lineNo]; - if ((s32)BrokenText[lineNo-1].size() < cp) - CursorPos = BrokenTextPositions[lineNo-1] + (s32)BrokenText[lineNo-1].size()-1; - else - CursorPos = BrokenTextPositions[lineNo-1] + cp; - } + if (CursorPos > 0) + CursorPos--; + BlinkStartTime = porting::getTimeMs(); + break; - if (event.KeyInput.Shift) - { - newMarkBegin = mb; - newMarkEnd = CursorPos; - } - else - { + case KEY_RIGHT: + if (event.KeyInput.Shift) { + if (Text.size() > (u32)CursorPos) { + if (MarkBegin == MarkEnd) + newMarkBegin = CursorPos; + + newMarkEnd = CursorPos + 1; + } + } else { newMarkBegin = 0; newMarkEnd = 0; } - } - else - { - return false; - } - break; - case KEY_DOWN: - if (MultiLine || (WordWrap && BrokenText.size() > 1) ) - { - s32 lineNo = getLineFromPos(CursorPos); - s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin < MarkEnd ? MarkBegin : MarkEnd); - if (lineNo < (s32)BrokenText.size()-1) - { - s32 cp = CursorPos - BrokenTextPositions[lineNo]; - if ((s32)BrokenText[lineNo+1].size() < cp) - CursorPos = BrokenTextPositions[lineNo+1] + BrokenText[lineNo+1].size()-1; - else - CursorPos = BrokenTextPositions[lineNo+1] + cp; - } + if (Text.size() > (u32)CursorPos) + CursorPos++; + BlinkStartTime = porting::getTimeMs(); + break; + case KEY_UP: + if (MultiLine || (WordWrap && BrokenText.size() > 1)) { + s32 lineNo = getLineFromPos(CursorPos); + s32 mb = (MarkBegin == MarkEnd) + ? CursorPos + : (MarkBegin > MarkEnd ? MarkBegin + : MarkEnd); + if (lineNo > 0) { + s32 cp = CursorPos - BrokenTextPositions[lineNo]; + if ((s32)BrokenText[lineNo - 1].size() < cp) + CursorPos = BrokenTextPositions[lineNo - + 1] + + (s32)BrokenText[lineNo - 1] + .size() - + 1; + else + CursorPos = BrokenTextPositions[lineNo - + 1] + + cp; + } - if (event.KeyInput.Shift) - { - newMarkBegin = mb; - newMarkEnd = CursorPos; - } - else - { - newMarkBegin = 0; - newMarkEnd = 0; + if (event.KeyInput.Shift) { + newMarkBegin = mb; + newMarkEnd = CursorPos; + } else { + newMarkBegin = 0; + newMarkEnd = 0; + } + + } else { + return false; } + break; + case KEY_DOWN: + if (MultiLine || (WordWrap && BrokenText.size() > 1)) { + s32 lineNo = getLineFromPos(CursorPos); + s32 mb = (MarkBegin == MarkEnd) + ? CursorPos + : (MarkBegin < MarkEnd ? MarkBegin + : MarkEnd); + if (lineNo < (s32)BrokenText.size() - 1) { + s32 cp = CursorPos - BrokenTextPositions[lineNo]; + if ((s32)BrokenText[lineNo + 1].size() < cp) + CursorPos = BrokenTextPositions[lineNo + + 1] + + BrokenText[lineNo + 1] + .size() - + 1; + else + CursorPos = BrokenTextPositions[lineNo + + 1] + + cp; + } - } - else - { - return false; - } - break; + if (event.KeyInput.Shift) { + newMarkBegin = mb; + newMarkEnd = CursorPos; + } else { + newMarkBegin = 0; + newMarkEnd = 0; + } - case KEY_BACK: - if (!this->IsEnabled || !m_writable) + } else { + return false; + } break; - if (!Text.empty()) { - core::stringw s; + case KEY_BACK: + if (!this->IsEnabled || !m_writable) + break; - if (MarkBegin != MarkEnd) - { - // delete marked text - const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; - const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + if (!Text.empty()) { + core::stringw s; - s = Text.subString(0, realmbgn); - s.append( Text.subString(realmend, Text.size()-realmend) ); - Text = s; + if (MarkBegin != MarkEnd) { + // delete marked text + const s32 realmbgn = MarkBegin < MarkEnd + ? MarkBegin + : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd + ? MarkEnd + : MarkBegin; - CursorPos = realmbgn; - } - else - { - // delete text behind cursor - if (CursorPos>0) - s = Text.subString(0, CursorPos-1); - else - s = L""; - s.append( Text.subString(CursorPos, Text.size()-CursorPos) ); - Text = s; - --CursorPos; - } + s = Text.subString(0, realmbgn); + s.append(Text.subString(realmend, + Text.size() - realmend)); + Text = s; - if (CursorPos < 0) - CursorPos = 0; - BlinkStartTime = porting::getTimeMs(); - newMarkBegin = 0; - newMarkEnd = 0; - textChanged = true; - } - break; - case KEY_DELETE: - if (!this->IsEnabled || !m_writable) + CursorPos = realmbgn; + } else { + // delete text behind cursor + if (CursorPos > 0) + s = Text.subString(0, CursorPos - 1); + else + s = L""; + s.append(Text.subString(CursorPos, + Text.size() - CursorPos)); + Text = s; + --CursorPos; + } + + if (CursorPos < 0) + CursorPos = 0; + BlinkStartTime = porting::getTimeMs(); + newMarkBegin = 0; + newMarkEnd = 0; + textChanged = true; + } break; + case KEY_DELETE: + if (!this->IsEnabled || !m_writable) + break; - if (!Text.empty()) { - core::stringw s; + if (!Text.empty()) { + core::stringw s; - if (MarkBegin != MarkEnd) - { - // delete marked text - const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; - const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + if (MarkBegin != MarkEnd) { + // delete marked text + const s32 realmbgn = MarkBegin < MarkEnd + ? MarkBegin + : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd + ? MarkEnd + : MarkBegin; - s = Text.subString(0, realmbgn); - s.append( Text.subString(realmend, Text.size()-realmend) ); - Text = s; + s = Text.subString(0, realmbgn); + s.append(Text.subString(realmend, + Text.size() - realmend)); + Text = s; - CursorPos = realmbgn; - } - else - { - // delete text before cursor - s = Text.subString(0, CursorPos); - s.append( Text.subString(CursorPos+1, Text.size()-CursorPos-1) ); - Text = s; - } + CursorPos = realmbgn; + } else { + // delete text before cursor + s = Text.subString(0, CursorPos); + s.append(Text.subString(CursorPos + 1, + Text.size() - CursorPos - 1)); + Text = s; + } - if (CursorPos > (s32)Text.size()) - CursorPos = (s32)Text.size(); + if (CursorPos > (s32)Text.size()) + CursorPos = (s32)Text.size(); - BlinkStartTime = porting::getTimeMs(); - newMarkBegin = 0; - newMarkEnd = 0; - textChanged = true; - } - break; + BlinkStartTime = porting::getTimeMs(); + newMarkBegin = 0; + newMarkEnd = 0; + textChanged = true; + } + break; - case KEY_ESCAPE: - case KEY_TAB: - case KEY_SHIFT: - case KEY_F1: - case KEY_F2: - case KEY_F3: - case KEY_F4: - case KEY_F5: - case KEY_F6: - case KEY_F7: - case KEY_F8: - case KEY_F9: - case KEY_F10: - case KEY_F11: - case KEY_F12: - case KEY_F13: - case KEY_F14: - case KEY_F15: - case KEY_F16: - case KEY_F17: - case KEY_F18: - case KEY_F19: - case KEY_F20: - case KEY_F21: - case KEY_F22: - case KEY_F23: - case KEY_F24: - // ignore these keys - return false; + case KEY_ESCAPE: + case KEY_TAB: + case KEY_SHIFT: + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + case KEY_F11: + case KEY_F12: + case KEY_F13: + case KEY_F14: + case KEY_F15: + case KEY_F16: + case KEY_F17: + case KEY_F18: + case KEY_F19: + case KEY_F20: + case KEY_F21: + case KEY_F22: + case KEY_F23: + case KEY_F24: + // ignore these keys + return false; - default: - inputChar(event.KeyInput.Char); - return true; - } + default: + inputChar(event.KeyInput.Char); + return true; + } - // Set new text markers - setTextMarkers( newMarkBegin, newMarkEnd ); + // Set new text markers + setTextMarkers(newMarkBegin, newMarkEnd); // break the text if it has changed - if (textChanged) - { + if (textChanged) { breakText(); sendGuiEvent(EGET_EDITBOX_CHANGED); } @@ -755,7 +725,6 @@ bool intlGUIEditBox::processKey(const SEvent& event) return true; } - //! draws the element and its children void intlGUIEditBox::draw() { @@ -764,7 +733,7 @@ void intlGUIEditBox::draw() const bool focus = Environment->hasFocus(this); - IGUISkin* skin = Environment->getSkin(); + IGUISkin *skin = Environment->getSkin(); if (!skin) return; @@ -772,17 +741,16 @@ void intlGUIEditBox::draw() // draw the border - if (Border) - { + if (Border) { if (m_writable) { - skin->draw3DSunkenPane(this, skin->getColor(EGDC_WINDOW), - false, true, FrameRect, &AbsoluteClippingRect); + skin->draw3DSunkenPane(this, skin->getColor(EGDC_WINDOW), false, + true, FrameRect, &AbsoluteClippingRect); } - FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1; - FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1; - FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1; - FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1; + FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; + FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; + FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; + FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; } updateVScrollBar(); @@ -791,17 +759,15 @@ void intlGUIEditBox::draw() // draw the text - IGUIFont* font = OverrideFont; + IGUIFont *font = OverrideFont; if (!OverrideFont) font = skin->getFont(); s32 cursorLine = 0; s32 charcursorpos = 0; - if (font) - { - if (LastBreakFont != font) - { + if (font) { + if (LastBreakFont != font) { breakText(); } @@ -826,97 +792,107 @@ void intlGUIEditBox::draw() const video::SColor prevColor = OverrideColor; if (!Text.empty()) { - if (!IsEnabled && !OverrideColorEnabled) - { + if (!IsEnabled && !OverrideColorEnabled) { OverrideColorEnabled = true; OverrideColor = skin->getColor(EGDC_GRAY_TEXT); } - for (s32 i=0; i < lineCount; ++i) - { + for (s32 i = 0; i < lineCount; ++i) { setTextRect(i); - // clipping test - don't draw anything outside the visible area + // clipping test - don't draw anything outside the visible + // area core::rect<s32> c = localClipRect; c.clipAgainst(CurrentTextRect); if (!c.isValid()) continue; // get current line - if (PasswordBox) - { - if (BrokenText.size() != 1) - { + if (PasswordBox) { + if (BrokenText.size() != 1) { BrokenText.clear(); BrokenText.push_back(core::stringw()); } - if (BrokenText[0].size() != Text.size()) - { + if (BrokenText[0].size() != Text.size()) { BrokenText[0] = Text; - for (u32 q = 0; q < Text.size(); ++q) - { - BrokenText[0] [q] = PasswordChar; + for (u32 q = 0; q < Text.size(); ++q) { + BrokenText[0][q] = PasswordChar; } } txtLine = &BrokenText[0]; startPos = 0; - } - else - { + } else { txtLine = ml ? &BrokenText[i] : &Text; startPos = ml ? BrokenTextPositions[i] : 0; } - // draw normal text font->draw(txtLine->c_str(), CurrentTextRect, - OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), - false, true, &localClipRect); + OverrideColorEnabled + ? OverrideColor + : skin->getColor(EGDC_BUTTON_TEXT), + false, true, &localClipRect); // draw mark and marked text - if (focus && MarkBegin != MarkEnd && i >= hlineStart && i < hlineStart + hlineCount) - { + if (focus && MarkBegin != MarkEnd && i >= hlineStart && + i < hlineStart + hlineCount) { s32 mbegin = 0, mend = 0; - s32 lineStartPos = 0, lineEndPos = txtLine->size(); + s32 lineStartPos = 0, + lineEndPos = txtLine->size(); - if (i == hlineStart) - { + if (i == hlineStart) { // highlight start is on this line - s = txtLine->subString(0, realmbgn - startPos); - mbegin = font->getDimension(s.c_str()).Width; + s = txtLine->subString( + 0, realmbgn - startPos); + mbegin = font->getDimension(s.c_str()) + .Width; // deal with kerning mbegin += font->getKerningWidth( - &((*txtLine)[realmbgn - startPos]), - realmbgn - startPos > 0 ? &((*txtLine)[realmbgn - startPos - 1]) : 0); + &((*txtLine)[realmbgn - + startPos]), + realmbgn - startPos > 0 + ? &((*txtLine)[realmbgn - + startPos - + 1]) + : 0); lineStartPos = realmbgn - startPos; } - if (i == hlineStart + hlineCount - 1) - { + if (i == hlineStart + hlineCount - 1) { // highlight end is on this line - s2 = txtLine->subString(0, realmend - startPos); - mend = font->getDimension(s2.c_str()).Width; + s2 = txtLine->subString( + 0, realmend - startPos); + mend = font->getDimension(s2.c_str()) + .Width; lineEndPos = (s32)s2.size(); - } - else - mend = font->getDimension(txtLine->c_str()).Width; + } else + mend = font->getDimension(txtLine->c_str()) + .Width; CurrentTextRect.UpperLeftCorner.X += mbegin; - CurrentTextRect.LowerRightCorner.X = CurrentTextRect.UpperLeftCorner.X + mend - mbegin; + CurrentTextRect.LowerRightCorner.X = + CurrentTextRect.UpperLeftCorner + .X + + mend - mbegin; // draw mark - skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), CurrentTextRect, &localClipRect); + skin->draw2DRectangle(this, + skin->getColor(EGDC_HIGH_LIGHT), + CurrentTextRect, &localClipRect); // draw marked text - s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos); + s = txtLine->subString(lineStartPos, + lineEndPos - lineStartPos); if (!s.empty()) font->draw(s.c_str(), CurrentTextRect, - OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT), - false, true, &localClipRect); - + OverrideColorEnabled + ? OverrideColor + : skin->getColor(EGDC_HIGH_LIGHT_TEXT), + false, true, + &localClipRect); } } @@ -927,24 +903,31 @@ void intlGUIEditBox::draw() // draw cursor - if (WordWrap || MultiLine) - { + if (WordWrap || MultiLine) { cursorLine = getLineFromPos(CursorPos); txtLine = &BrokenText[cursorLine]; startPos = BrokenTextPositions[cursorLine]; } - s = txtLine->subString(0,CursorPos-startPos); + s = txtLine->subString(0, CursorPos - startPos); charcursorpos = font->getDimension(s.c_str()).Width + - font->getKerningWidth(L"_", CursorPos-startPos > 0 ? &((*txtLine)[CursorPos-startPos-1]) : 0); + font->getKerningWidth(L"_", + CursorPos - startPos > 0 + ? &((*txtLine)[CursorPos - + startPos - + 1]) + : 0); - if (m_writable) { - if (focus && (porting::getTimeMs() - BlinkStartTime) % 700 < 350) { + if (m_writable) { + if (focus && (porting::getTimeMs() - BlinkStartTime) % 700 < + 350) { setTextRect(cursorLine); CurrentTextRect.UpperLeftCorner.X += charcursorpos; font->draw(L"_", CurrentTextRect, - OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), - false, true, &localClipRect); + OverrideColorEnabled + ? OverrideColor + : skin->getColor(EGDC_BUTTON_TEXT), + false, true, &localClipRect); } } } @@ -953,9 +936,8 @@ void intlGUIEditBox::draw() IGUIElement::draw(); } - //! Sets the new caption of this element. -void intlGUIEditBox::setText(const wchar_t* text) +void intlGUIEditBox::setText(const wchar_t *text) { Text = text; if (u32(CursorPos) > Text.size()) @@ -964,7 +946,6 @@ void intlGUIEditBox::setText(const wchar_t* text) breakText(); } - //! Enables or disables automatic scrolling with cursor position //! \param enable: If set to true, the text will move around with the cursor position void intlGUIEditBox::setAutoScroll(bool enable) @@ -972,7 +953,6 @@ void intlGUIEditBox::setAutoScroll(bool enable) AutoScroll = enable; } - //! Checks to see if automatic scrolling is enabled //! \return true if automatic scrolling is enabled, false if not bool intlGUIEditBox::isAutoScrollEnabled() const @@ -980,7 +960,6 @@ bool intlGUIEditBox::isAutoScrollEnabled() const return AutoScroll; } - //! Gets the area of the text in the edit box //! \return Returns the size in pixels of the text core::dimension2du intlGUIEditBox::getTextDimension() @@ -990,8 +969,7 @@ core::dimension2du intlGUIEditBox::getTextDimension() setTextRect(0); ret = CurrentTextRect; - for (u32 i=1; i < BrokenText.size(); ++i) - { + for (u32 i = 1; i < BrokenText.size(); ++i) { setTextRect(i); ret.addInternalPoint(CurrentTextRect.UpperLeftCorner); ret.addInternalPoint(CurrentTextRect.LowerRightCorner); @@ -1000,7 +978,6 @@ core::dimension2du intlGUIEditBox::getTextDimension() return core::dimension2du(ret.getSize()); } - //! Sets the maximum amount of characters which may be entered in the box. //! \param max: Maximum amount of characters. If 0, the character amount is //! infinity. @@ -1012,60 +989,48 @@ void intlGUIEditBox::setMax(u32 max) Text = Text.subString(0, Max); } - //! Returns maximum amount of characters, previously set by setMax(); u32 intlGUIEditBox::getMax() const { return Max; } - -bool intlGUIEditBox::processMouse(const SEvent& event) +bool intlGUIEditBox::processMouse(const SEvent &event) { - switch(event.MouseInput.Event) - { + switch (event.MouseInput.Event) { case irr::EMIE_LMOUSE_LEFT_UP: - if (Environment->hasFocus(this)) - { + if (Environment->hasFocus(this)) { CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); - if (MouseMarking) - { - setTextMarkers( MarkBegin, CursorPos ); + if (MouseMarking) { + setTextMarkers(MarkBegin, CursorPos); } MouseMarking = false; calculateScrollPos(); return true; } break; - case irr::EMIE_MOUSE_MOVED: - { - if (MouseMarking) - { - CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); - setTextMarkers( MarkBegin, CursorPos ); - calculateScrollPos(); - return true; - } + case irr::EMIE_MOUSE_MOVED: { + if (MouseMarking) { + CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + setTextMarkers(MarkBegin, CursorPos); + calculateScrollPos(); + return true; } - break; + } break; case EMIE_LMOUSE_PRESSED_DOWN: - if (!Environment->hasFocus(this)) - { + if (!Environment->hasFocus(this)) { BlinkStartTime = porting::getTimeMs(); MouseMarking = true; CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); - setTextMarkers(CursorPos, CursorPos ); + setTextMarkers(CursorPos, CursorPos); calculateScrollPos(); return true; - } - else - { - if (!AbsoluteClippingRect.isPointInside( - core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y))) { + } else { + if (!AbsoluteClippingRect.isPointInside(core::position2d<s32>( + event.MouseInput.X, event.MouseInput.Y))) { return false; } - // move cursor CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); @@ -1074,7 +1039,7 @@ bool intlGUIEditBox::processMouse(const SEvent& event) newMarkBegin = CursorPos; MouseMarking = true; - setTextMarkers( newMarkBegin, CursorPos); + setTextMarkers(newMarkBegin, CursorPos); calculateScrollPos(); return true; } @@ -1093,11 +1058,10 @@ bool intlGUIEditBox::processMouse(const SEvent& event) return false; } - s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) { - IGUIFont* font = OverrideFont; - IGUISkin* skin = Environment->getSkin(); + IGUIFont *font = OverrideFont; + IGUISkin *skin = Environment->getSkin(); if (!OverrideFont) font = skin->getFont(); @@ -1112,14 +1076,19 @@ s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) setTextRect(curr_line_idx); if (curr_line_idx == 0 && y < CurrentTextRect.UpperLeftCorner.Y) y = CurrentTextRect.UpperLeftCorner.Y; - if (curr_line_idx == lineCount - 1 && y > CurrentTextRect.LowerRightCorner.Y) + if (curr_line_idx == lineCount - 1 && + y > CurrentTextRect.LowerRightCorner.Y) y = CurrentTextRect.LowerRightCorner.Y; // is it inside this region? - if (y >= CurrentTextRect.UpperLeftCorner.Y && y <= CurrentTextRect.LowerRightCorner.Y) { + if (y >= CurrentTextRect.UpperLeftCorner.Y && + y <= CurrentTextRect.LowerRightCorner.Y) { // we've found the clicked line - txtLine = (WordWrap || MultiLine) ? &BrokenText[curr_line_idx] : &Text; - startPos = (WordWrap || MultiLine) ? BrokenTextPositions[curr_line_idx] : 0; + txtLine = (WordWrap || MultiLine) ? &BrokenText[curr_line_idx] + : &Text; + startPos = (WordWrap || MultiLine) + ? BrokenTextPositions[curr_line_idx] + : 0; break; } } @@ -1129,20 +1098,20 @@ s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) else if (x > CurrentTextRect.LowerRightCorner.X) x = CurrentTextRect.LowerRightCorner.X; - s32 idx = font->getCharacterFromPos(txtLine->c_str(), x - CurrentTextRect.UpperLeftCorner.X); - // Special handling for last line, if we are on limits, add 1 extra shift because idx - // will be the last char, not null char of the wstring + s32 idx = font->getCharacterFromPos( + txtLine->c_str(), x - CurrentTextRect.UpperLeftCorner.X); + // Special handling for last line, if we are on limits, add 1 extra shift because + // idx will be the last char, not null char of the wstring if (curr_line_idx == lineCount - 1 && x == CurrentTextRect.LowerRightCorner.X) idx++; return rangelim(idx + startPos, 0, S32_MAX); } - //! Breaks the single text line. void intlGUIEditBox::breakText() { - IGUISkin* skin = Environment->getSkin(); + IGUISkin *skin = Environment->getSkin(); if ((!WordWrap && !MultiLine) || !skin) return; @@ -1150,7 +1119,7 @@ void intlGUIEditBox::breakText() BrokenText.clear(); // need to reallocate :/ BrokenTextPositions.set_used(0); - IGUIFont* font = OverrideFont; + IGUIFont *font = OverrideFont; if (!OverrideFont) font = skin->getFont(); @@ -1168,8 +1137,7 @@ void intlGUIEditBox::breakText() s32 elWidth = RelativeRect.getWidth() - 6; wchar_t c; - for (s32 i=0; i<size; ++i) - { + for (s32 i = 0; i < size; ++i) { c = Text[i]; bool lineBreak = false; @@ -1177,13 +1145,12 @@ void intlGUIEditBox::breakText() { lineBreak = true; c = ' '; - if (Text[i+1] == L'\n') // Windows breaks + if (Text[i + 1] == L'\n') // Windows breaks { - Text.erase(i+1); + Text.erase(i + 1); --size; } - } - else if (c == L'\n') // Unix breaks + } else if (c == L'\n') // Unix breaks { lineBreak = true; c = ' '; @@ -1193,25 +1160,23 @@ void intlGUIEditBox::breakText() if (!MultiLine) lineBreak = false; - if (c == L' ' || c == 0 || i == (size-1)) - { + if (c == L' ' || c == 0 || i == (size - 1)) { if (!word.empty()) { // here comes the next whitespace, look if // we can break the last word to the next line. - s32 whitelgth = font->getDimension(whitespace.c_str()).Width; + s32 whitelgth = font->getDimension(whitespace.c_str()) + .Width; s32 worldlgth = font->getDimension(word.c_str()).Width; - if (WordWrap && length + worldlgth + whitelgth > elWidth) - { + if (WordWrap && length + worldlgth + whitelgth > + elWidth) { // break to next line length = worldlgth; BrokenText.push_back(line); BrokenTextPositions.push_back(lastLineStart); lastLineStart = i - (s32)word.size(); line = word; - } - else - { + } else { // add word to line line += whitespace; line += word; @@ -1225,21 +1190,18 @@ void intlGUIEditBox::breakText() whitespace += c; // compute line break - if (lineBreak) - { + if (lineBreak) { line += whitespace; line += word; BrokenText.push_back(line); BrokenTextPositions.push_back(lastLineStart); - lastLineStart = i+1; + lastLineStart = i + 1; line = L""; word = L""; whitespace = L""; length = 0; } - } - else - { + } else { // yippee this is a word.. word += c; } @@ -1251,40 +1213,37 @@ void intlGUIEditBox::breakText() BrokenTextPositions.push_back(lastLineStart); } - void intlGUIEditBox::setTextRect(s32 line) { core::dimension2du d; - IGUISkin* skin = Environment->getSkin(); + IGUISkin *skin = Environment->getSkin(); if (!skin) return; - IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont(); + IGUIFont *font = OverrideFont ? OverrideFont : skin->getFont(); if (!font) return; // get text dimension const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1; - if (WordWrap || MultiLine) - { + if (WordWrap || MultiLine) { d = font->getDimension(BrokenText[line].c_str()); - } - else - { + } else { d = font->getDimension(Text.c_str()); d.Height = AbsoluteRect.getHeight(); } d.Height += font->getKerningHeight(); // justification - switch (HAlign) - { + switch (HAlign) { case EGUIA_CENTER: // align to h centre - CurrentTextRect.UpperLeftCorner.X = (FrameRect.getWidth()/2) - (d.Width/2); - CurrentTextRect.LowerRightCorner.X = (FrameRect.getWidth()/2) + (d.Width/2); + CurrentTextRect.UpperLeftCorner.X = + (FrameRect.getWidth() / 2) - (d.Width / 2); + CurrentTextRect.LowerRightCorner.X = + (FrameRect.getWidth() / 2) + (d.Width / 2); break; case EGUIA_LOWERRIGHT: // align to right edge @@ -1295,82 +1254,77 @@ void intlGUIEditBox::setTextRect(s32 line) // align to left edge CurrentTextRect.UpperLeftCorner.X = 0; CurrentTextRect.LowerRightCorner.X = d.Width; - } - switch (VAlign) - { + switch (VAlign) { case EGUIA_CENTER: // align to v centre - CurrentTextRect.UpperLeftCorner.Y = - (FrameRect.getHeight()/2) - (lineCount*d.Height)/2 + d.Height*line; + CurrentTextRect.UpperLeftCorner.Y = (FrameRect.getHeight() / 2) - + (lineCount * d.Height) / 2 + + d.Height * line; break; case EGUIA_LOWERRIGHT: // align to bottom edge - CurrentTextRect.UpperLeftCorner.Y = - FrameRect.getHeight() - lineCount*d.Height + d.Height*line; + CurrentTextRect.UpperLeftCorner.Y = FrameRect.getHeight() - + lineCount * d.Height + + d.Height * line; break; default: // align to top edge - CurrentTextRect.UpperLeftCorner.Y = d.Height*line; + CurrentTextRect.UpperLeftCorner.Y = d.Height * line; break; } - CurrentTextRect.UpperLeftCorner.X -= HScrollPos; + CurrentTextRect.UpperLeftCorner.X -= HScrollPos; CurrentTextRect.LowerRightCorner.X -= HScrollPos; - CurrentTextRect.UpperLeftCorner.Y -= VScrollPos; + CurrentTextRect.UpperLeftCorner.Y -= VScrollPos; CurrentTextRect.LowerRightCorner.Y = CurrentTextRect.UpperLeftCorner.Y + d.Height; CurrentTextRect += FrameRect.UpperLeftCorner; - } - s32 intlGUIEditBox::getLineFromPos(s32 pos) { if (!WordWrap && !MultiLine) return 0; - s32 i=0; - while (i < (s32)BrokenTextPositions.size()) - { + s32 i = 0; + while (i < (s32)BrokenTextPositions.size()) { if (BrokenTextPositions[i] > pos) - return i-1; + return i - 1; ++i; } return (s32)BrokenTextPositions.size() - 1; } - void intlGUIEditBox::inputChar(wchar_t c) { if (!IsEnabled || !m_writable) return; - if (c != 0) - { - if (Text.size() < Max || Max == 0) - { + if (c != 0) { + if (Text.size() < Max || Max == 0) { core::stringw s; - if (MarkBegin != MarkEnd) - { + if (MarkBegin != MarkEnd) { // replace marked text - const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; - const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + const s32 realmbgn = + MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = + MarkBegin < MarkEnd ? MarkEnd : MarkBegin; s = Text.subString(0, realmbgn); s.append(c); - s.append( Text.subString(realmend, Text.size()-realmend) ); + s.append(Text.subString( + realmend, Text.size() - realmend)); Text = s; - CursorPos = realmbgn+1; - } - else - { + CursorPos = realmbgn + 1; + } else { // add new character s = Text.subString(0, CursorPos); s.append(c); - s.append( Text.subString(CursorPos, Text.size()-CursorPos) ); + s.append(Text.subString( + CursorPos, Text.size() - CursorPos)); Text = s; ++CursorPos; } @@ -1384,7 +1338,6 @@ void intlGUIEditBox::inputChar(wchar_t c) calculateScrollPos(); } - void intlGUIEditBox::calculateScrollPos() { if (!AutoScroll) @@ -1395,21 +1348,22 @@ void intlGUIEditBox::calculateScrollPos() setTextRect(cursLine); // don't do horizontal scrolling when wordwrap is enabled. - if (!WordWrap) - { + if (!WordWrap) { // get cursor position - IGUISkin* skin = Environment->getSkin(); + IGUISkin *skin = Environment->getSkin(); if (!skin) return; - IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont(); + IGUIFont *font = OverrideFont ? OverrideFont : skin->getFont(); if (!font) return; core::stringw *txtLine = MultiLine ? &BrokenText[cursLine] : &Text; - s32 cPos = MultiLine ? CursorPos - BrokenTextPositions[cursLine] : CursorPos; + s32 cPos = MultiLine ? CursorPos - BrokenTextPositions[cursLine] + : CursorPos; s32 cStart = CurrentTextRect.UpperLeftCorner.X + HScrollPos + - font->getDimension(txtLine->subString(0, cPos).c_str()).Width; + font->getDimension(txtLine->subString(0, cPos).c_str()) + .Width; s32 cEnd = cStart + font->getDimension(L"_ ").Width; @@ -1428,9 +1382,11 @@ void intlGUIEditBox::calculateScrollPos() // vertical scroll position if (FrameRect.LowerRightCorner.Y < CurrentTextRect.LowerRightCorner.Y) - VScrollPos += CurrentTextRect.LowerRightCorner.Y - FrameRect.LowerRightCorner.Y; // scrolling downwards + VScrollPos += CurrentTextRect.LowerRightCorner.Y - + FrameRect.LowerRightCorner.Y; // scrolling downwards else if (FrameRect.UpperLeftCorner.Y > CurrentTextRect.UpperLeftCorner.Y) - VScrollPos += CurrentTextRect.UpperLeftCorner.Y - FrameRect.UpperLeftCorner.Y; // scrolling upwards + VScrollPos += CurrentTextRect.UpperLeftCorner.Y - + FrameRect.UpperLeftCorner.Y; // scrolling upwards // todo: adjust scrollbar if (m_vscrollbar) @@ -1440,26 +1396,24 @@ void intlGUIEditBox::calculateScrollPos() //! set text markers void intlGUIEditBox::setTextMarkers(s32 begin, s32 end) { - if ( begin != MarkBegin || end != MarkEnd ) - { - MarkBegin = begin; - MarkEnd = end; - sendGuiEvent(EGET_EDITBOX_MARKING_CHANGED); - } + if (begin != MarkBegin || end != MarkEnd) { + MarkBegin = begin; + MarkEnd = end; + sendGuiEvent(EGET_EDITBOX_MARKING_CHANGED); + } } //! send some gui event to parent void intlGUIEditBox::sendGuiEvent(EGUI_EVENT_TYPE type) { - if ( Parent ) - { - SEvent e; - e.EventType = EET_GUI_EVENT; - e.GUIEvent.Caller = this; - e.GUIEvent.Element = 0; - e.GUIEvent.EventType = type; - - Parent->OnEvent(e); + if (Parent) { + SEvent e; + e.EventType = EET_GUI_EVENT; + e.GUIEvent.Caller = this; + e.GUIEvent.Element = 0; + e.GUIEvent.EventType = type; + + Parent->OnEvent(e); } } @@ -1471,8 +1425,8 @@ void intlGUIEditBox::createVScrollBar() if (OverrideFont) { fontHeight = OverrideFont->getDimension(L"").Height; } else { - if (IGUISkin* skin = Environment->getSkin()) { - if (IGUIFont* font = skin->getFont()) { + if (IGUISkin *skin = Environment->getSkin()) { + if (IGUIFont *font = skin->getFont()) { fontHeight = font->getDimension(L"").Height; } } @@ -1482,8 +1436,8 @@ void intlGUIEditBox::createVScrollBar() irr::core::rect<s32> scrollbarrect = FrameRect; scrollbarrect.UpperLeftCorner.X += FrameRect.getWidth() - m_scrollbar_width; - m_vscrollbar = new GUIScrollBar(Environment, getParent(), -1, - scrollbarrect, false, true); + m_vscrollbar = new GUIScrollBar( + Environment, getParent(), -1, scrollbarrect, false, true); m_vscrollbar->setVisible(false); m_vscrollbar->setSmallStep(3 * fontHeight); @@ -1515,7 +1469,7 @@ void intlGUIEditBox::updateVScrollBar() } // check if a vertical scrollbar is needed ? - if (getTextDimension().Height > (u32) FrameRect.getHeight()) { + if (getTextDimension().Height > (u32)FrameRect.getHeight()) { s32 scrollymax = getTextDimension().Height - FrameRect.getHeight(); if (scrollymax != m_vscrollbar->getMax()) { m_vscrollbar->setMax(scrollymax); @@ -1546,33 +1500,34 @@ void intlGUIEditBox::setWritable(bool can_write_text) } //! Writes attributes of the element. -void intlGUIEditBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const +void intlGUIEditBox::serializeAttributes( + io::IAttributes *out, io::SAttributeReadWriteOptions *options = 0) const { // IGUIEditBox::serializeAttributes(out,options); - out->addBool ("OverrideColorEnabled",OverrideColorEnabled ); - out->addColor ("OverrideColor", OverrideColor); + out->addBool("OverrideColorEnabled", OverrideColorEnabled); + out->addColor("OverrideColor", OverrideColor); // out->addFont("OverrideFont",OverrideFont); - out->addInt ("MaxChars", Max); - out->addBool ("WordWrap", WordWrap); - out->addBool ("MultiLine", MultiLine); - out->addBool ("AutoScroll", AutoScroll); - out->addBool ("PasswordBox", PasswordBox); + out->addInt("MaxChars", Max); + out->addBool("WordWrap", WordWrap); + out->addBool("MultiLine", MultiLine); + out->addBool("AutoScroll", AutoScroll); + out->addBool("PasswordBox", PasswordBox); core::stringw ch = L" "; ch[0] = PasswordChar; - out->addString("PasswordChar", ch.c_str()); - out->addEnum ("HTextAlign", HAlign, GUIAlignmentNames); - out->addEnum ("VTextAlign", VAlign, GUIAlignmentNames); - out->addBool ("Writable", m_writable); + out->addString("PasswordChar", ch.c_str()); + out->addEnum("HTextAlign", HAlign, GUIAlignmentNames); + out->addEnum("VTextAlign", VAlign, GUIAlignmentNames); + out->addBool("Writable", m_writable); - IGUIEditBox::serializeAttributes(out,options); + IGUIEditBox::serializeAttributes(out, options); } - //! Reads attributes of the element -void intlGUIEditBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) +void intlGUIEditBox::deserializeAttributes( + io::IAttributes *in, io::SAttributeReadWriteOptions *options = 0) { - IGUIEditBox::deserializeAttributes(in,options); + IGUIEditBox::deserializeAttributes(in, options); setOverrideColor(in->getAttributeAsColor("OverrideColor")); enableOverrideColor(in->getAttributeAsBool("OverrideColorEnabled")); @@ -1587,13 +1542,14 @@ void intlGUIEditBox::deserializeAttributes(io::IAttributes* in, io::SAttributeRe else setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]); - setTextAlignment( (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("HTextAlign", GUIAlignmentNames), - (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("VTextAlign", GUIAlignmentNames)); + setTextAlignment((EGUI_ALIGNMENT)in->getAttributeAsEnumeration( + "HTextAlign", GUIAlignmentNames), + (EGUI_ALIGNMENT)in->getAttributeAsEnumeration( + "VTextAlign", GUIAlignmentNames)); setWritable(in->getAttributeAsBool("Writable")); // setOverrideFont(in->getAttributeAsFont("OverrideFont")); } - } // end namespace gui } // end namespace irr diff --git a/src/gui/intlGUIEditBox.h b/src/gui/intlGUIEditBox.h index 9d643495e..7b5f015fd 100644 --- a/src/gui/intlGUIEditBox.h +++ b/src/gui/intlGUIEditBox.h @@ -16,193 +16,193 @@ namespace irr { namespace gui { - class intlGUIEditBox : public IGUIEditBox - { - public: - - //! constructor - intlGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment, - IGUIElement* parent, s32 id, const core::rect<s32>& rectangle, +class intlGUIEditBox : public IGUIEditBox +{ +public: + //! constructor + intlGUIEditBox(const wchar_t *text, bool border, IGUIEnvironment *environment, + IGUIElement *parent, s32 id, const core::rect<s32> &rectangle, bool writable = true, bool has_vscrollbar = false); - //! destructor - virtual ~intlGUIEditBox(); - - //! Sets another skin independent font. - virtual void setOverrideFont(IGUIFont* font=0); - - //! Gets the override font (if any) - /** \return The override font (may be 0) */ - virtual IGUIFont* getOverrideFont() const; - - //! Get the font which is used right now for drawing - /** Currently this is the override font when one is set and the - font of the active skin otherwise */ - virtual IGUIFont* getActiveFont() const; - - //! Sets another color for the text. - virtual void setOverrideColor(video::SColor color); - - //! Gets the override color - virtual video::SColor getOverrideColor() const; - - //! Sets if the text should use the overide color or the - //! color in the gui skin. - virtual void enableOverrideColor(bool enable); - - //! Checks if an override color is enabled - /** \return true if the override color is enabled, false otherwise */ - virtual bool isOverrideColorEnabled(void) const; - - //! Sets whether to draw the background - virtual void setDrawBackground(bool draw); - - virtual bool isDrawBackgroundEnabled() const { return true; } - - //! Turns the border on or off - virtual void setDrawBorder(bool border); - - virtual bool isDrawBorderEnabled() const { return Border; } - - //! Enables or disables word wrap for using the edit box as multiline text editor. - virtual void setWordWrap(bool enable); - - //! Checks if word wrap is enabled - //! \return true if word wrap is enabled, false otherwise - virtual bool isWordWrapEnabled() const; - - //! Enables or disables newlines. - /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired, - instead a newline character will be inserted. */ - virtual void setMultiLine(bool enable); + //! destructor + virtual ~intlGUIEditBox(); - //! Checks if multi line editing is enabled - //! \return true if mult-line is enabled, false otherwise - virtual bool isMultiLineEnabled() const; + //! Sets another skin independent font. + virtual void setOverrideFont(IGUIFont *font = 0); - //! Enables or disables automatic scrolling with cursor position - //! \param enable: If set to true, the text will move around with the cursor position - virtual void setAutoScroll(bool enable); + //! Gets the override font (if any) + /** \return The override font (may be 0) */ + virtual IGUIFont *getOverrideFont() const; - //! Checks to see if automatic scrolling is enabled - //! \return true if automatic scrolling is enabled, false if not - virtual bool isAutoScrollEnabled() const; + //! Get the font which is used right now for drawing + /** Currently this is the override font when one is set and the + font of the active skin otherwise */ + virtual IGUIFont *getActiveFont() const; - //! Gets the size area of the text in the edit box - //! \return Returns the size in pixels of the text - virtual core::dimension2du getTextDimension(); + //! Sets another color for the text. + virtual void setOverrideColor(video::SColor color); - //! Sets text justification - virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical); + //! Gets the override color + virtual video::SColor getOverrideColor() const; - //! called if an event happened. - virtual bool OnEvent(const SEvent& event); + //! Sets if the text should use the overide color or the + //! color in the gui skin. + virtual void enableOverrideColor(bool enable); - //! draws the element and its children - virtual void draw(); + //! Checks if an override color is enabled + /** \return true if the override color is enabled, false otherwise */ + virtual bool isOverrideColorEnabled(void) const; - //! Sets the new caption of this element. - virtual void setText(const wchar_t* text); + //! Sets whether to draw the background + virtual void setDrawBackground(bool draw); - //! Sets the maximum amount of characters which may be entered in the box. - //! \param max: Maximum amount of characters. If 0, the character amount is - //! infinity. - virtual void setMax(u32 max); + virtual bool isDrawBackgroundEnabled() const { return true; } - //! Returns maximum amount of characters, previously set by setMax(); - virtual u32 getMax() const; + //! Turns the border on or off + virtual void setDrawBorder(bool border); - //! Sets whether the edit box is a password box. Setting this to true will - /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x - \param passwordBox: true to enable password, false to disable - \param passwordChar: the character that is displayed instead of letters */ - virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*'); + virtual bool isDrawBorderEnabled() const { return Border; } - //! Returns true if the edit box is currently a password box. - virtual bool isPasswordBox() const; + //! Enables or disables word wrap for using the edit box as multiline text editor. + virtual void setWordWrap(bool enable); - //! Updates the absolute position, splits text if required - virtual void updateAbsolutePosition(); + //! Checks if word wrap is enabled + //! \return true if word wrap is enabled, false otherwise + virtual bool isWordWrapEnabled() const; - //! set true if this EditBox is writable - virtual void setWritable(bool can_write_text); + //! Enables or disables newlines. + /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired, + instead a newline character will be inserted. */ + virtual void setMultiLine(bool enable); - //! Writes attributes of the element. - virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const; + //! Checks if multi line editing is enabled + //! \return true if mult-line is enabled, false otherwise + virtual bool isMultiLineEnabled() const; - //! Reads attributes of the element - virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options); + //! Enables or disables automatic scrolling with cursor position + //! \param enable: If set to true, the text will move around with the cursor + //! position + virtual void setAutoScroll(bool enable); - virtual void setCursorChar(const wchar_t cursorChar) {} + //! Checks to see if automatic scrolling is enabled + //! \return true if automatic scrolling is enabled, false if not + virtual bool isAutoScrollEnabled() const; - virtual wchar_t getCursorChar() const { return L'|'; } + //! Gets the size area of the text in the edit box + //! \return Returns the size in pixels of the text + virtual core::dimension2du getTextDimension(); - virtual void setCursorBlinkTime(u32 timeMs) {} + //! Sets text justification + virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical); - virtual u32 getCursorBlinkTime() const { return 500; } + //! called if an event happened. + virtual bool OnEvent(const SEvent &event); - protected: - //! Breaks the single text line. - void breakText(); - //! sets the area of the given line - void setTextRect(s32 line); - //! returns the line number that the cursor is on - s32 getLineFromPos(s32 pos); - //! adds a letter to the edit box - void inputChar(wchar_t c); - //! calculates the current scroll position - void calculateScrollPos(); - //! send some gui event to parent - void sendGuiEvent(EGUI_EVENT_TYPE type); - //! set text markers - void setTextMarkers(s32 begin, s32 end); + //! draws the element and its children + virtual void draw(); - bool processKey(const SEvent& event); - bool processMouse(const SEvent& event); - s32 getCursorPos(s32 x, s32 y); + //! Sets the new caption of this element. + virtual void setText(const wchar_t *text); - //! Create a vertical scrollbar - void createVScrollBar(); + //! Sets the maximum amount of characters which may be entered in the box. + //! \param max: Maximum amount of characters. If 0, the character amount is + //! infinity. + virtual void setMax(u32 max); - //! Update the vertical scrollbar (visibilty & scroll position) - void updateVScrollBar(); + //! Returns maximum amount of characters, previously set by setMax(); + virtual u32 getMax() const; - bool MouseMarking = false; - bool Border; - bool OverrideColorEnabled = false; - s32 MarkBegin = 0; - s32 MarkEnd = 0; + //! Sets whether the edit box is a password box. Setting this to true will + /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x + \param passwordBox: true to enable password, false to disable + \param passwordChar: the character that is displayed instead of letters */ + virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*'); - video::SColor OverrideColor = video::SColor(101,255,255,255); - gui::IGUIFont *OverrideFont = nullptr; - gui::IGUIFont *LastBreakFont = nullptr; - IOSOperator *Operator = nullptr; + //! Returns true if the edit box is currently a password box. + virtual bool isPasswordBox() const; - u64 BlinkStartTime = 0; - s32 CursorPos = 0; - s32 HScrollPos = 0; - s32 VScrollPos = 0; // scroll position in characters - u32 Max = 0; + //! Updates the absolute position, splits text if required + virtual void updateAbsolutePosition(); - bool WordWrap = false; - bool MultiLine = false; - bool AutoScroll = true; - bool PasswordBox = false; - wchar_t PasswordChar = L'*'; - EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT; - EGUI_ALIGNMENT VAlign = EGUIA_CENTER; + //! set true if this EditBox is writable + virtual void setWritable(bool can_write_text); - core::array<core::stringw> BrokenText; - core::array<s32> BrokenTextPositions; + //! Writes attributes of the element. + virtual void serializeAttributes(io::IAttributes *out, + io::SAttributeReadWriteOptions *options) const; + + //! Reads attributes of the element + virtual void deserializeAttributes( + io::IAttributes *in, io::SAttributeReadWriteOptions *options); + + virtual void setCursorChar(const wchar_t cursorChar) {} - core::rect<s32> CurrentTextRect = core::rect<s32>(0,0,1,1); - core::rect<s32> FrameRect; // temporary values - u32 m_scrollbar_width; - GUIScrollBar *m_vscrollbar; - bool m_writable; + virtual wchar_t getCursorChar() const { return L'|'; } - }; + virtual void setCursorBlinkTime(u32 timeMs) {} + virtual u32 getCursorBlinkTime() const { return 500; } + +protected: + //! Breaks the single text line. + void breakText(); + //! sets the area of the given line + void setTextRect(s32 line); + //! returns the line number that the cursor is on + s32 getLineFromPos(s32 pos); + //! adds a letter to the edit box + void inputChar(wchar_t c); + //! calculates the current scroll position + void calculateScrollPos(); + //! send some gui event to parent + void sendGuiEvent(EGUI_EVENT_TYPE type); + //! set text markers + void setTextMarkers(s32 begin, s32 end); + + bool processKey(const SEvent &event); + bool processMouse(const SEvent &event); + s32 getCursorPos(s32 x, s32 y); + + //! Create a vertical scrollbar + void createVScrollBar(); + + //! Update the vertical scrollbar (visibilty & scroll position) + void updateVScrollBar(); + + bool MouseMarking = false; + bool Border; + bool OverrideColorEnabled = false; + s32 MarkBegin = 0; + s32 MarkEnd = 0; + + video::SColor OverrideColor = video::SColor(101, 255, 255, 255); + gui::IGUIFont *OverrideFont = nullptr; + gui::IGUIFont *LastBreakFont = nullptr; + IOSOperator *Operator = nullptr; + + u64 BlinkStartTime = 0; + s32 CursorPos = 0; + s32 HScrollPos = 0; + s32 VScrollPos = 0; // scroll position in characters + u32 Max = 0; + + bool WordWrap = false; + bool MultiLine = false; + bool AutoScroll = true; + bool PasswordBox = false; + wchar_t PasswordChar = L'*'; + EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT; + EGUI_ALIGNMENT VAlign = EGUIA_CENTER; + + core::array<core::stringw> BrokenText; + core::array<s32> BrokenTextPositions; + + core::rect<s32> CurrentTextRect = core::rect<s32>(0, 0, 1, 1); + core::rect<s32> FrameRect; // temporary values + u32 m_scrollbar_width; + GUIScrollBar *m_vscrollbar; + bool m_writable; +}; } // end namespace gui } // end namespace irr diff --git a/src/gui/mainmenumanager.h b/src/gui/mainmenumanager.h index 102492255..e2107ab64 100644 --- a/src/gui/mainmenumanager.h +++ b/src/gui/mainmenumanager.h @@ -54,7 +54,7 @@ public: } #endif - if(!m_stack.empty()) + if (!m_stack.empty()) m_stack.back()->setVisible(false); m_stack.push_back(menu); } @@ -68,35 +68,32 @@ public: assert(*i == menu); m_stack.erase(i);*/ - if(!m_stack.empty()) + if (!m_stack.empty()) m_stack.back()->setVisible(true); } // Returns true to prevent further processing - virtual bool preprocessEvent(const SEvent& event) + virtual bool preprocessEvent(const SEvent &event) { if (m_stack.empty()) return false; - GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back()); + GUIModalMenu *mm = dynamic_cast<GUIModalMenu *>(m_stack.back()); return mm && mm->preprocessEvent(event); } - u32 menuCount() - { - return m_stack.size(); - } + u32 menuCount() { return m_stack.size(); } bool pausesGame() { for (gui::IGUIElement *i : m_stack) { - GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(i); + GUIModalMenu *mm = dynamic_cast<GUIModalMenu *>(i); if (mm && mm->pausesGame()) return true; } return false; } - std::list<gui::IGUIElement*> m_stack; + std::list<gui::IGUIElement *> m_stack; }; extern MainMenuManager g_menumgr; @@ -109,36 +106,17 @@ public: MainGameCallback() = default; virtual ~MainGameCallback() = default; - virtual void exitToOS() - { - shutdown_requested = true; - } + virtual void exitToOS() { shutdown_requested = true; } - virtual void disconnect() - { - disconnect_requested = true; - } + virtual void disconnect() { disconnect_requested = true; } - virtual void changePassword() - { - changepassword_requested = true; - } + virtual void changePassword() { changepassword_requested = true; } - virtual void changeVolume() - { - changevolume_requested = true; - } + virtual void changeVolume() { changevolume_requested = true; } - virtual void keyConfig() - { - keyconfig_requested = true; - } - - virtual void signalKeyConfigChange() - { - keyconfig_changed = true; - } + virtual void keyConfig() { keyconfig_requested = true; } + virtual void signalKeyConfigChange() { keyconfig_changed = true; } bool disconnect_requested = false; bool changepassword_requested = false; diff --git a/src/gui/modalMenu.h b/src/gui/modalMenu.h index 1cb687f82..3fc9124ea 100644 --- a/src/gui/modalMenu.h +++ b/src/gui/modalMenu.h @@ -38,8 +38,8 @@ public: class GUIModalMenu : public gui::IGUIElement { public: - GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, - IMenuManager *menumgr, bool remap_dbl_click = true); + GUIModalMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, + IMenuManager *menumgr, bool remap_dbl_click = true); virtual ~GUIModalMenu(); void allowFocusRemoval(bool allow); @@ -70,7 +70,7 @@ protected: bool DoubleClickDetection(const SEvent &event); v2s32 m_pointer; - v2s32 m_old_pointer; // Mouse position after previous mouse event + v2s32 m_old_pointer; // Mouse position after previous mouse event v2u32 m_screensize_old; float m_gui_scale; #ifdef __ANDROID__ @@ -92,7 +92,7 @@ private: IMenuManager *m_menumgr; /* If true, remap a double-click (or double-tap) action to ESC. This is so * that, for example, Android users can double-tap to close a formspec. - * + * * This value can (currently) only be set by the class constructor * and the default value for the setting is true. */ diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 0d64aa618..1f9da71c9 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -36,82 +36,75 @@ with this program; if not, write to the Free Software Foundation, Inc., using namespace irr::core; -const char **button_imagenames = (const char *[]) { - "jump_btn.png", - "down.png", - "zoom.png", - "aux_btn.png" -}; - -const char **joystick_imagenames = (const char *[]) { - "joystick_off.png", - "joystick_bg.png", - "joystick_center.png" -}; +const char **button_imagenames = + (const char *[]){"jump_btn.png", "down.png", "zoom.png", "aux_btn.png"}; + +const char **joystick_imagenames = (const char *[]){ + "joystick_off.png", "joystick_bg.png", "joystick_center.png"}; static irr::EKEY_CODE id2keycode(touch_gui_button_id id) { std::string key = ""; switch (id) { - case forward_id: - key = "forward"; - break; - case left_id: - key = "left"; - break; - case right_id: - key = "right"; - break; - case backward_id: - key = "backward"; - break; - case inventory_id: - key = "inventory"; - break; - case drop_id: - key = "drop"; - break; - case jump_id: - key = "jump"; - break; - case crunch_id: - key = "sneak"; - break; - case zoom_id: - key = "zoom"; - break; - case special1_id: - key = "special1"; - break; - case fly_id: - key = "freemove"; - break; - case noclip_id: - key = "noclip"; - break; - case fast_id: - key = "fastmove"; - break; - case debug_id: - key = "toggle_debug"; - break; - case toggle_chat_id: - key = "toggle_chat"; - break; - case minimap_id: - key = "minimap"; - break; - case chat_id: - key = "chat"; - break; - case camera_id: - key = "camera_mode"; - break; - case range_id: - key = "rangeselect"; - break; - default: - break; + case forward_id: + key = "forward"; + break; + case left_id: + key = "left"; + break; + case right_id: + key = "right"; + break; + case backward_id: + key = "backward"; + break; + case inventory_id: + key = "inventory"; + break; + case drop_id: + key = "drop"; + break; + case jump_id: + key = "jump"; + break; + case crunch_id: + key = "sneak"; + break; + case zoom_id: + key = "zoom"; + break; + case special1_id: + key = "special1"; + break; + case fly_id: + key = "freemove"; + break; + case noclip_id: + key = "noclip"; + break; + case fast_id: + key = "fastmove"; + break; + case debug_id: + key = "toggle_debug"; + break; + case toggle_chat_id: + key = "toggle_chat"; + break; + case minimap_id: + key = "minimap"; + break; + case chat_id: + key = "chat"; + break; + case camera_id: + key = "camera_mode"; + break; + case range_id: + key = "rangeselect"; + break; + default: + break; } assert(!key.empty()); return keyname_to_keycode(g_settings->get("keymap_" + key).c_str()); @@ -120,16 +113,18 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id) TouchScreenGUI *g_touchscreengui; static void load_button_texture(button_info *btn, const char *path, - const rect<s32> &button_rect, ISimpleTextureSource *tsrc, video::IVideoDriver *driver) + const rect<s32> &button_rect, ISimpleTextureSource *tsrc, + video::IVideoDriver *driver) { unsigned int tid; - video::ITexture *texture = guiScalingImageButton(driver, - tsrc->getTexture(path, &tid), button_rect.getWidth(), - button_rect.getHeight()); + video::ITexture *texture = + guiScalingImageButton(driver, tsrc->getTexture(path, &tid), + button_rect.getWidth(), button_rect.getHeight()); if (texture) { btn->guibutton->setUseAlphaChannel(true); if (g_settings->getBool("gui_scaling_filter")) { - rect<s32> txr_rect = rect<s32>(0, 0, button_rect.getWidth(), button_rect.getHeight()); + rect<s32> txr_rect = rect<s32>(0, 0, button_rect.getWidth(), + button_rect.getHeight()); btn->guibutton->setImage(texture, txr_rect); btn->guibutton->setPressedImage(texture, txr_rect); btn->guibutton->setScaleImage(false); @@ -143,17 +138,15 @@ static void load_button_texture(button_info *btn, const char *path, } } -AutoHideButtonBar::AutoHideButtonBar(IrrlichtDevice *device, - IEventReceiver *receiver) : - m_driver(device->getVideoDriver()), - m_guienv(device->getGUIEnvironment()), - m_receiver(receiver) +AutoHideButtonBar::AutoHideButtonBar(IrrlichtDevice *device, IEventReceiver *receiver) : + m_driver(device->getVideoDriver()), m_guienv(device->getGUIEnvironment()), + m_receiver(receiver) { } -void AutoHideButtonBar::init(ISimpleTextureSource *tsrc, - const char *starter_img, int button_id, const v2s32 &UpperLeft, - const v2s32 &LowerRight, autohide_button_bar_dir dir, float timeout) +void AutoHideButtonBar::init(ISimpleTextureSource *tsrc, const char *starter_img, + int button_id, const v2s32 &UpperLeft, const v2s32 &LowerRight, + autohide_button_bar_dir dir, float timeout) { m_texturesource = tsrc; @@ -162,18 +155,19 @@ void AutoHideButtonBar::init(ISimpleTextureSource *tsrc, // init settings bar - irr::core::rect<int> current_button = rect<s32>(UpperLeft.X, UpperLeft.Y, - LowerRight.X, LowerRight.Y); + irr::core::rect<int> current_button = + rect<s32>(UpperLeft.X, UpperLeft.Y, LowerRight.X, LowerRight.Y); - m_starter.guibutton = m_guienv->addButton(current_button, nullptr, button_id, L"", nullptr); + m_starter.guibutton = m_guienv->addButton( + current_button, nullptr, button_id, L"", nullptr); m_starter.guibutton->grab(); - m_starter.repeatcounter = -1; - m_starter.keycode = KEY_OEM_8; // use invalid keycode as it's not relevant + m_starter.repeatcounter = -1; + m_starter.keycode = KEY_OEM_8; // use invalid keycode as it's not relevant m_starter.immediate_release = true; m_starter.ids.clear(); - load_button_texture(&m_starter, starter_img, current_button, - m_texturesource, m_driver); + load_button_texture(&m_starter, starter_img, current_button, m_texturesource, + m_driver); m_dir = dir; m_timeout_value = timeout; @@ -189,13 +183,13 @@ AutoHideButtonBar::~AutoHideButtonBar() } } -void AutoHideButtonBar::addButton(touch_gui_button_id button_id, - const wchar_t *caption, const char *btn_image) +void AutoHideButtonBar::addButton(touch_gui_button_id button_id, const wchar_t *caption, + const char *btn_image) { if (!m_initialized) { errorstream << "AutoHideButtonBar::addButton not yet initialized!" - << std::endl; + << std::endl; return; } int button_size = 0; @@ -212,55 +206,55 @@ void AutoHideButtonBar::addButton(touch_gui_button_id button_id, int x_end = 0; if (m_dir == AHBB_Dir_Left_Right) { - x_start = m_lower_right.X + (button_size * 1.25 * m_buttons.size()) - + (button_size * 0.25); + x_start = m_lower_right.X + + (button_size * 1.25 * m_buttons.size()) + + (button_size * 0.25); x_end = x_start + button_size; } else { - x_end = m_upper_left.X - (button_size * 1.25 * m_buttons.size()) - - (button_size * 0.25); + x_end = m_upper_left.X - (button_size * 1.25 * m_buttons.size()) - + (button_size * 0.25); x_start = x_end - button_size; } - current_button = rect<s32>(x_start, m_upper_left.Y, x_end, - m_lower_right.Y); + current_button = rect<s32>( + x_start, m_upper_left.Y, x_end, m_lower_right.Y); } else { double y_start = 0; double y_end = 0; if (m_dir == AHBB_Dir_Top_Bottom) { - y_start = m_lower_right.X + (button_size * 1.25 * m_buttons.size()) - + (button_size * 0.25); + y_start = m_lower_right.X + + (button_size * 1.25 * m_buttons.size()) + + (button_size * 0.25); y_end = y_start + button_size; } else { - y_end = m_upper_left.X - (button_size * 1.25 * m_buttons.size()) - - (button_size * 0.25); + y_end = m_upper_left.X - (button_size * 1.25 * m_buttons.size()) - + (button_size * 0.25); y_start = y_end - button_size; } - current_button = rect<s32>(m_upper_left.X, y_start, - m_lower_right.Y, y_end); + current_button = rect<s32>( + m_upper_left.X, y_start, m_lower_right.Y, y_end); } - auto *btn = new button_info(); - btn->guibutton = m_guienv->addButton(current_button, - nullptr, button_id, caption, nullptr); + auto *btn = new button_info(); + btn->guibutton = m_guienv->addButton( + current_button, nullptr, button_id, caption, nullptr); btn->guibutton->grab(); btn->guibutton->setVisible(false); btn->guibutton->setEnabled(false); - btn->repeatcounter = -1; - btn->keycode = id2keycode(button_id); + btn->repeatcounter = -1; + btn->keycode = id2keycode(button_id); btn->immediate_release = true; btn->ids.clear(); - load_button_texture(btn, btn_image, current_button, m_texturesource, - m_driver); + load_button_texture(btn, btn_image, current_button, m_texturesource, m_driver); m_buttons.push_back(btn); } void AutoHideButtonBar::addToggleButton(touch_gui_button_id button_id, - const wchar_t *caption, const char *btn_image_1, - const char *btn_image_2) + const wchar_t *caption, const char *btn_image_1, const char *btn_image_2) { addButton(button_id, caption, btn_image_1); button_info *btn = m_buttons.back(); @@ -291,11 +285,11 @@ bool AutoHideButtonBar::isButton(const SEvent &event) auto *translated = new SEvent(); memset(translated, 0, sizeof(SEvent)); - translated->EventType = irr::EET_KEY_INPUT_EVENT; - translated->KeyInput.Key = (*iter)->keycode; - translated->KeyInput.Control = false; - translated->KeyInput.Shift = false; - translated->KeyInput.Char = 0; + translated->EventType = irr::EET_KEY_INPUT_EVENT; + translated->KeyInput.Key = (*iter)->keycode; + translated->KeyInput.Control = false; + translated->KeyInput.Shift = false; + translated->KeyInput.Char = 0; // add this event translated->KeyInput.PressedDown = true; @@ -314,12 +308,14 @@ bool AutoHideButtonBar::isButton(const SEvent &event) if ((*iter)->togglable == 1) { (*iter)->togglable = 2; load_button_texture(*iter, (*iter)->textures[1], - (*iter)->guibutton->getRelativePosition(), + (*iter)->guibutton + ->getRelativePosition(), m_texturesource, m_driver); } else if ((*iter)->togglable == 2) { (*iter)->togglable = 1; load_button_texture(*iter, (*iter)->textures[0], - (*iter)->guibutton->getRelativePosition(), + (*iter)->guibutton + ->getRelativePosition(), m_texturesource, m_driver); } @@ -410,42 +406,41 @@ void AutoHideButtonBar::show() } } -TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver): - m_device(device), - m_guienv(device->getGUIEnvironment()), - m_receiver(receiver), - m_settingsbar(device, receiver), - m_rarecontrolsbar(device, receiver) +TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver) : + m_device(device), m_guienv(device->getGUIEnvironment()), + m_receiver(receiver), m_settingsbar(device, receiver), + m_rarecontrolsbar(device, receiver) { for (auto &button : m_buttons) { - button.guibutton = nullptr; + button.guibutton = nullptr; button.repeatcounter = -1; - button.repeatdelay = BUTTON_REPEAT_DELAY; + button.repeatdelay = BUTTON_REPEAT_DELAY; } m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold"); m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick"); - m_joystick_triggers_special1 = g_settings->getBool("virtual_joystick_triggers_aux"); + m_joystick_triggers_special1 = + g_settings->getBool("virtual_joystick_triggers_aux"); m_screensize = m_device->getVideoDriver()->getScreenSize(); button_size = MYMIN(m_screensize.Y / 4.5f, porting::getDisplayDensity() * - g_settings->getFloat("hud_scaling") * 65.0f); + g_settings->getFloat("hud_scaling") * 65.0f); } void TouchScreenGUI::initButton(touch_gui_button_id id, const rect<s32> &button_rect, const std::wstring &caption, bool immediate_release, float repeat_delay) { - button_info *btn = &m_buttons[id]; - btn->guibutton = m_guienv->addButton(button_rect, nullptr, id, caption.c_str()); + button_info *btn = &m_buttons[id]; + btn->guibutton = m_guienv->addButton(button_rect, nullptr, id, caption.c_str()); btn->guibutton->grab(); - btn->repeatcounter = -1; - btn->repeatdelay = repeat_delay; - btn->keycode = id2keycode(id); + btn->repeatcounter = -1; + btn->repeatdelay = repeat_delay; + btn->keycode = id2keycode(id); btn->immediate_release = immediate_release; btn->ids.clear(); - load_button_texture(btn, button_imagenames[id], button_rect, - m_texturesource, m_device->getVideoDriver()); + load_button_texture(btn, button_imagenames[id], button_rect, m_texturesource, + m_device->getVideoDriver()); } button_info *TouchScreenGUI::initJoystickButton(touch_gui_button_id id, @@ -457,8 +452,8 @@ button_info *TouchScreenGUI::initJoystickButton(touch_gui_button_id id, btn->guibutton->grab(); btn->ids.clear(); - load_button_texture(btn, joystick_imagenames[texture_id], - button_rect, m_texturesource, m_device->getVideoDriver()); + load_button_texture(btn, joystick_imagenames[texture_id], button_rect, + m_texturesource, m_device->getVideoDriver()); return btn; } @@ -467,7 +462,7 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc) { assert(tsrc); - m_visible = true; + m_visible = true; m_texturesource = tsrc; /* Init joystick display "button" @@ -475,23 +470,21 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc) */ if (m_fixed_joystick) { m_joystick_btn_off = initJoystickButton(joystick_off_id, - rect<s32>(button_size, - m_screensize.Y - button_size * 4, + rect<s32>(button_size, m_screensize.Y - button_size * 4, button_size * 4, - m_screensize.Y - button_size), 0); + m_screensize.Y - button_size), + 0); } else { m_joystick_btn_off = initJoystickButton(joystick_off_id, - rect<s32>(button_size, - m_screensize.Y - button_size * 3, + rect<s32>(button_size, m_screensize.Y - button_size * 3, button_size * 3, - m_screensize.Y - button_size), 0); + m_screensize.Y - button_size), + 0); } m_joystick_btn_bg = initJoystickButton(joystick_bg_id, - rect<s32>(button_size, - m_screensize.Y - button_size * 4, - button_size * 4, - m_screensize.Y - button_size), + rect<s32>(button_size, m_screensize.Y - button_size * 4, + button_size * 4, m_screensize.Y - button_size), 1, false); m_joystick_btn_center = initJoystickButton(joystick_center_id, @@ -531,39 +524,48 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc) L"spc1", false); m_settingsbar.init(m_texturesource, "gear_icon.png", settings_starter_id, - v2s32(m_screensize.X - (1.25 * button_size), - m_screensize.Y - ((SETTINGS_BAR_Y_OFFSET + 1.0) * button_size) - + (0.5 * button_size)), - v2s32(m_screensize.X - (0.25 * button_size), - m_screensize.Y - (SETTINGS_BAR_Y_OFFSET * button_size) - + (0.5 * button_size)), - AHBB_Dir_Right_Left, 3.0); - - m_settingsbar.addButton(fly_id, L"fly", "fly_btn.png"); - m_settingsbar.addButton(noclip_id, L"noclip", "noclip_btn.png"); - m_settingsbar.addButton(fast_id, L"fast", "fast_btn.png"); - m_settingsbar.addButton(debug_id, L"debug", "debug_btn.png"); - m_settingsbar.addButton(camera_id, L"camera", "camera_btn.png"); - m_settingsbar.addButton(range_id, L"rangeview", "rangeview_btn.png"); - m_settingsbar.addButton(minimap_id, L"minimap", "minimap_btn.png"); + v2s32(m_screensize.X - (1.25 * button_size), + m_screensize.Y - + ((SETTINGS_BAR_Y_OFFSET + 1.0) * + button_size) + + (0.5 * button_size)), + v2s32(m_screensize.X - (0.25 * button_size), + m_screensize.Y - + (SETTINGS_BAR_Y_OFFSET * + button_size) + + (0.5 * button_size)), + AHBB_Dir_Right_Left, 3.0); + + m_settingsbar.addButton(fly_id, L"fly", "fly_btn.png"); + m_settingsbar.addButton(noclip_id, L"noclip", "noclip_btn.png"); + m_settingsbar.addButton(fast_id, L"fast", "fast_btn.png"); + m_settingsbar.addButton(debug_id, L"debug", "debug_btn.png"); + m_settingsbar.addButton(camera_id, L"camera", "camera_btn.png"); + m_settingsbar.addButton(range_id, L"rangeview", "rangeview_btn.png"); + m_settingsbar.addButton(minimap_id, L"minimap", "minimap_btn.png"); // Chat is shown by default, so chat_hide_btn.png is shown first. - m_settingsbar.addToggleButton(toggle_chat_id, L"togglechat", - "chat_hide_btn.png", "chat_show_btn.png"); + m_settingsbar.addToggleButton(toggle_chat_id, L"togglechat", "chat_hide_btn.png", + "chat_show_btn.png"); m_rarecontrolsbar.init(m_texturesource, "rare_controls.png", - rare_controls_starter_id, - v2s32(0.25 * button_size, - m_screensize.Y - ((RARE_CONTROLS_BAR_Y_OFFSET + 1.0) * button_size) - + (0.5 * button_size)), - v2s32(0.75 * button_size, - m_screensize.Y - (RARE_CONTROLS_BAR_Y_OFFSET * button_size) - + (0.5 * button_size)), - AHBB_Dir_Left_Right, 2.0); - - m_rarecontrolsbar.addButton(chat_id, L"Chat", "chat_btn.png"); - m_rarecontrolsbar.addButton(inventory_id, L"inv", "inventory_btn.png"); - m_rarecontrolsbar.addButton(drop_id, L"drop", "drop_btn.png"); + rare_controls_starter_id, + v2s32(0.25 * button_size, + m_screensize.Y - + ((RARE_CONTROLS_BAR_Y_OFFSET + + 1.0) * + button_size) + + (0.5 * button_size)), + v2s32(0.75 * button_size, + m_screensize.Y - + (RARE_CONTROLS_BAR_Y_OFFSET * + button_size) + + (0.5 * button_size)), + AHBB_Dir_Left_Right, 2.0); + + m_rarecontrolsbar.addButton(chat_id, L"Chat", "chat_btn.png"); + m_rarecontrolsbar.addButton(inventory_id, L"inv", "inventory_btn.png"); + m_rarecontrolsbar.addButton(drop_id, L"drop", "drop_btn.png"); } touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y) @@ -571,13 +573,13 @@ touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y) IGUIElement *rootguielement = m_guienv->getRootGUIElement(); if (rootguielement != nullptr) { - gui::IGUIElement *element = - rootguielement->getElementFromPoint(core::position2d<s32>(x, y)); + gui::IGUIElement *element = rootguielement->getElementFromPoint( + core::position2d<s32>(x, y)); if (element) for (unsigned int i = 0; i < after_last_element_id; i++) if (element == m_buttons[i].guibutton) - return (touch_gui_button_id) i; + return (touch_gui_button_id)i; } return after_last_element_id; @@ -591,7 +593,7 @@ touch_gui_button_id TouchScreenGUI::getButtonID(size_t eventID) auto id = std::find(btn->ids.begin(), btn->ids.end(), eventID); if (id != btn->ids.end()) - return (touch_gui_button_id) i; + return (touch_gui_button_id)i; } return after_last_element_id; @@ -601,17 +603,18 @@ bool TouchScreenGUI::isHUDButton(const SEvent &event) { // check if hud item is pressed for (auto &hud_rect : m_hud_rects) { - if (hud_rect.second.isPointInside(v2s32(event.TouchInput.X, - event.TouchInput.Y))) { + if (hud_rect.second.isPointInside( + v2s32(event.TouchInput.X, event.TouchInput.Y))) { auto *translated = new SEvent(); memset(translated, 0, sizeof(SEvent)); translated->EventType = irr::EET_KEY_INPUT_EVENT; - translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + hud_rect.first); - translated->KeyInput.Control = false; - translated->KeyInput.Shift = false; + translated->KeyInput.Key = + (irr::EKEY_CODE)(KEY_KEY_1 + hud_rect.first); + translated->KeyInput.Control = false; + translated->KeyInput.Shift = false; translated->KeyInput.PressedDown = true; m_receiver->OnEvent(*translated); - m_hud_ids[event.TouchInput.ID] = translated->KeyInput.Key; + m_hud_ids[event.TouchInput.ID] = translated->KeyInput.Key; delete translated; return true; } @@ -619,25 +622,27 @@ bool TouchScreenGUI::isHUDButton(const SEvent &event) return false; } -void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button, - size_t eventID, bool action) +void TouchScreenGUI::handleButtonEvent( + touch_gui_button_id button, size_t eventID, bool action) { button_info *btn = &m_buttons[button]; auto *translated = new SEvent(); memset(translated, 0, sizeof(SEvent)); - translated->EventType = irr::EET_KEY_INPUT_EVENT; - translated->KeyInput.Key = btn->keycode; - translated->KeyInput.Control = false; - translated->KeyInput.Shift = false; - translated->KeyInput.Char = 0; + translated->EventType = irr::EET_KEY_INPUT_EVENT; + translated->KeyInput.Key = btn->keycode; + translated->KeyInput.Control = false; + translated->KeyInput.Shift = false; + translated->KeyInput.Char = 0; // add this event if (action) { - assert(std::find(btn->ids.begin(), btn->ids.end(), eventID) == btn->ids.end()); + assert(std::find(btn->ids.begin(), btn->ids.end(), eventID) == + btn->ids.end()); btn->ids.push_back(eventID); - if (btn->ids.size() > 1) return; + if (btn->ids.size() > 1) + return; btn->repeatcounter = 0; translated->KeyInput.PressedDown = true; @@ -656,7 +661,7 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button, return; translated->KeyInput.PressedDown = false; - btn->repeatcounter = -1; + btn->repeatcounter = -1; m_receiver->OnEvent(*translated); } delete translated; @@ -666,7 +671,6 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) { touch_gui_button_id button = getButtonID(evt_id); - if (button != after_last_element_id) { // handle button events handleButtonEvent(button, evt_id, false); @@ -678,13 +682,13 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) if (m_move_sent_as_mouse_event) { auto *translated = new SEvent; memset(translated, 0, sizeof(SEvent)); - translated->EventType = EET_MOUSE_INPUT_EVENT; - translated->MouseInput.X = m_move_downlocation.X; - translated->MouseInput.Y = m_move_downlocation.Y; - translated->MouseInput.Shift = false; - translated->MouseInput.Control = false; + translated->EventType = EET_MOUSE_INPUT_EVENT; + translated->MouseInput.X = m_move_downlocation.X; + translated->MouseInput.Y = m_move_downlocation.Y; + translated->MouseInput.Shift = false; + translated->MouseInput.Control = false; translated->MouseInput.ButtonStates = 0; - translated->MouseInput.Event = EMIE_LMOUSE_LEFT_UP; + translated->MouseInput.Event = EMIE_LMOUSE_LEFT_UP; m_receiver->OnEvent(*translated); delete translated; } else { @@ -706,13 +710,11 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) m_joystick_btn_bg->guibutton->setVisible(false); m_joystick_btn_center->guibutton->setVisible(false); } else { - infostream - << "TouchScreenGUI::translateEvent released unknown button: " - << evt_id << std::endl; + infostream << "TouchScreenGUI::translateEvent released unknown button: " + << evt_id << std::endl; } - for (auto iter = m_known_ids.begin(); - iter != m_known_ids.end(); ++iter) { + for (auto iter = m_known_ids.begin(); iter != m_known_ids.end(); ++iter) { if (iter->id == evt_id) { m_known_ids.erase(iter); break; @@ -723,9 +725,8 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) void TouchScreenGUI::translateEvent(const SEvent &event) { if (!m_visible) { - infostream - << "TouchScreenGUI::translateEvent got event but not visible!" - << std::endl; + infostream << "TouchScreenGUI::translateEvent got event but not visible!" + << std::endl; return; } @@ -740,8 +741,8 @@ void TouchScreenGUI::translateEvent(const SEvent &event) */ id_status toadd{}; toadd.id = event.TouchInput.ID; - toadd.X = event.TouchInput.X; - toadd.Y = event.TouchInput.Y; + toadd.X = event.TouchInput.X; + toadd.Y = event.TouchInput.Y; m_known_ids.push_back(toadd); size_t eventID = event.TouchInput.ID; @@ -770,49 +771,67 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_rarecontrolsbar.deactivate(); s32 dxj = event.TouchInput.X - button_size * 5.0f / 2.0f; - s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5.0f / 2.0f; + s32 dyj = event.TouchInput.Y - m_screensize.Y + + button_size * 5.0f / 2.0f; /* Select joystick when left 1/3 of screen dragged or * when joystick tapped (fixed joystick position) */ - if ((m_fixed_joystick && dxj * dxj + dyj * dyj <= button_size * button_size * 1.5 * 1.5) || - (!m_fixed_joystick && event.TouchInput.X < m_screensize.X / 3.0f)) { - // If we don't already have a starting point for joystick make this the one. + if ((m_fixed_joystick && + dxj * dxj + dyj * dyj <= + button_size * button_size * + 1.5 * 1.5) || + (!m_fixed_joystick && + event.TouchInput.X < + m_screensize.X / + 3.0f)) { + // If we don't already have a starting point for joystick + // make this the one. if (m_joystick_id == -1) { - m_joystick_id = event.TouchInput.ID; + m_joystick_id = event.TouchInput.ID; m_joystick_has_really_moved = false; m_joystick_btn_off->guibutton->setVisible(false); m_joystick_btn_bg->guibutton->setVisible(true); - m_joystick_btn_center->guibutton->setVisible(true); + m_joystick_btn_center->guibutton->setVisible( + true); - // If it's a fixed joystick, don't move the joystick "button". + // If it's a fixed joystick, don't move the + // joystick "button". if (!m_fixed_joystick) m_joystick_btn_bg->guibutton->setRelativePosition(v2s32( - event.TouchInput.X - button_size * 3.0f / 2.0f, - event.TouchInput.Y - button_size * 3.0f / 2.0f)); + event.TouchInput.X - + button_size * 3.0f / + 2.0f, + event.TouchInput.Y - + button_size * 3.0f / + 2.0f)); m_joystick_btn_center->guibutton->setRelativePosition(v2s32( - event.TouchInput.X - button_size / 2.0f, - event.TouchInput.Y - button_size / 2.0f)); + event.TouchInput.X - + button_size / 2.0f, + event.TouchInput.Y - + button_size / 2.0f)); } } else { - // If we don't already have a moving point make this the moving one. + // If we don't already have a moving point make this the + // moving one. if (m_move_id == -1) { - m_move_id = event.TouchInput.ID; - m_move_has_really_moved = false; - m_move_downtime = porting::getTimeMs(); - m_move_downlocation = v2s32(event.TouchInput.X, event.TouchInput.Y); + m_move_id = event.TouchInput.ID; + m_move_has_really_moved = false; + m_move_downtime = porting::getTimeMs(); + m_move_downlocation = v2s32(event.TouchInput.X, + event.TouchInput.Y); m_move_sent_as_mouse_event = false; } } } - m_pointerpos[event.TouchInput.ID] = v2s32(event.TouchInput.X, event.TouchInput.Y); - } - else if (event.TouchInput.Event == ETIE_LEFT_UP) { - verbosestream - << "Up event for pointerid: " << event.TouchInput.ID << std::endl; + m_pointerpos[event.TouchInput.ID] = + v2s32(event.TouchInput.X, event.TouchInput.Y); + } else if (event.TouchInput.Event == ETIE_LEFT_UP) { + verbosestream << "Up event for pointerid: " << event.TouchInput.ID + << std::endl; handleReleaseEvent(event.TouchInput.ID); } else { assert(event.TouchInput.Event == ETIE_MOVED); @@ -823,13 +842,19 @@ void TouchScreenGUI::translateEvent(const SEvent &event) if (m_move_id != -1) { if ((event.TouchInput.ID == m_move_id) && - (!m_move_sent_as_mouse_event)) { + (!m_move_sent_as_mouse_event)) { double distance = sqrt( - (m_pointerpos[event.TouchInput.ID].X - event.TouchInput.X) * - (m_pointerpos[event.TouchInput.ID].X - event.TouchInput.X) + - (m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y) * - (m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y)); + (m_pointerpos[event.TouchInput.ID].X - + event.TouchInput.X) * + (m_pointerpos[event.TouchInput.ID] + .X - + event.TouchInput.X) + + (m_pointerpos[event.TouchInput.ID].Y - + event.TouchInput.Y) * + (m_pointerpos[event.TouchInput.ID] + .Y - + event.TouchInput.Y)); if ((distance > m_touchscreen_threshold) || (m_move_has_really_moved)) { @@ -842,25 +867,31 @@ void TouchScreenGUI::translateEvent(const SEvent &event) s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y; // adapt to similar behaviour as pc screen - double d = g_settings->getFloat("mouse_sensitivity") * 3.0f; + double d = g_settings->getFloat( + "mouse_sensitivity") * + 3.0f; m_camera_yaw_change -= dx * d; - m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * d), -180), 180); + m_camera_pitch = MYMIN( + MYMAX(m_camera_pitch + (dy * d), + -180), + 180); // update shootline - m_shootline = m_device - ->getSceneManager() - ->getSceneCollisionManager() - ->getRayFromScreenCoordinates(v2s32(X, Y)); + m_shootline = m_device->getSceneManager() + ->getSceneCollisionManager() + ->getRayFromScreenCoordinates(v2s32( + X, + Y)); m_pointerpos[event.TouchInput.ID] = v2s32(X, Y); } } else if ((event.TouchInput.ID == m_move_id) && (m_move_sent_as_mouse_event)) { - m_shootline = m_device - ->getSceneManager() - ->getSceneCollisionManager() - ->getRayFromScreenCoordinates( - v2s32(event.TouchInput.X, event.TouchInput.Y)); + m_shootline = m_device->getSceneManager() + ->getSceneCollisionManager() + ->getRayFromScreenCoordinates(v2s32( + event.TouchInput.X, + event.TouchInput.Y)); } } @@ -878,13 +909,17 @@ void TouchScreenGUI::translateEvent(const SEvent &event) double distance_sq = dx * dx + dy * dy; s32 dxj = event.TouchInput.X - button_size * 5.0f / 2.0f; - s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5.0f / 2.0f; - bool inside_joystick = (dxj * dxj + dyj * dyj <= button_size * button_size * 1.5 * 1.5); + s32 dyj = event.TouchInput.Y - m_screensize.Y + + button_size * 5.0f / 2.0f; + bool inside_joystick = (dxj * dxj + dyj * dyj <= + button_size * button_size * 1.5 * 1.5); if (m_joystick_has_really_moved || - (!m_joystick_has_really_moved && inside_joystick) || + (!m_joystick_has_really_moved && + inside_joystick) || (!m_fixed_joystick && - distance_sq > m_touchscreen_threshold * m_touchscreen_threshold)) { + distance_sq > m_touchscreen_threshold * + m_touchscreen_threshold)) { m_joystick_has_really_moved = true; double distance = sqrt(distance_sq); @@ -896,7 +931,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) angle = fmod(angle + 180 + 22.5, 360); // reset state before applying - for (bool & joystick_status : m_joystick_status) + for (bool &joystick_status : m_joystick_status) joystick_status = false; if (distance <= m_touchscreen_threshold) { @@ -926,20 +961,31 @@ void TouchScreenGUI::translateEvent(const SEvent &event) if (distance > button_size) { m_joystick_status[j_special1] = true; // move joystick "button" - s32 ndx = button_size * dx / distance - button_size / 2.0f; - s32 ndy = button_size * dy / distance - button_size / 2.0f; + s32 ndx = button_size * dx / distance - + button_size / 2.0f; + s32 ndy = button_size * dy / distance - + button_size / 2.0f; if (m_fixed_joystick) { m_joystick_btn_center->guibutton->setRelativePosition(v2s32( - button_size * 5 / 2 + ndx, - m_screensize.Y - button_size * 5 / 2 + ndy)); + button_size * 5 / 2 + ndx, + m_screensize.Y - + button_size * 5 / + 2 + + ndy)); } else { m_joystick_btn_center->guibutton->setRelativePosition(v2s32( - m_pointerpos[event.TouchInput.ID].X + ndx, - m_pointerpos[event.TouchInput.ID].Y + ndy)); + m_pointerpos[event.TouchInput.ID] + .X + + ndx, + m_pointerpos[event.TouchInput.ID] + .Y + + ndy)); } } else { - m_joystick_btn_center->guibutton->setRelativePosition( - v2s32(X - button_size / 2, Y - button_size / 2)); + m_joystick_btn_center->guibutton + ->setRelativePosition(v2s32( + X - button_size / 2, + Y - button_size / 2)); } } } @@ -955,22 +1001,23 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event) if (m_buttons[i].ids.empty()) continue; - for (auto iter = m_buttons[i].ids.begin(); - iter != m_buttons[i].ids.end(); ++iter) { + for (auto iter = m_buttons[i].ids.begin(); iter != m_buttons[i].ids.end(); + ++iter) { if (event.TouchInput.ID == *iter) { - int current_button_id = - getButtonID(event.TouchInput.X, event.TouchInput.Y); + int current_button_id = getButtonID( + event.TouchInput.X, event.TouchInput.Y); if (current_button_id == i) continue; // remove old button - handleButtonEvent((touch_gui_button_id) i, *iter, false); + handleButtonEvent((touch_gui_button_id)i, *iter, false); if (current_button_id == after_last_element_id) return; - handleButtonEvent((touch_gui_button_id) current_button_id, *iter, true); + handleButtonEvent((touch_gui_button_id)current_button_id, + *iter, true); return; } } @@ -982,48 +1029,48 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event) return; button_info *btn = &m_buttons[current_button_id]; - if (std::find(btn->ids.begin(), btn->ids.end(), event.TouchInput.ID) - == btn->ids.end()) - handleButtonEvent((touch_gui_button_id) current_button_id, + if (std::find(btn->ids.begin(), btn->ids.end(), event.TouchInput.ID) == + btn->ids.end()) + handleButtonEvent((touch_gui_button_id)current_button_id, event.TouchInput.ID, true); } bool TouchScreenGUI::doubleTapDetection() { m_key_events[0].down_time = m_key_events[1].down_time; - m_key_events[0].x = m_key_events[1].x; - m_key_events[0].y = m_key_events[1].y; + m_key_events[0].x = m_key_events[1].x; + m_key_events[0].y = m_key_events[1].y; m_key_events[1].down_time = m_move_downtime; - m_key_events[1].x = m_move_downlocation.X; - m_key_events[1].y = m_move_downlocation.Y; + m_key_events[1].x = m_move_downlocation.X; + m_key_events[1].y = m_move_downlocation.Y; u64 delta = porting::getDeltaMs(m_key_events[0].down_time, porting::getTimeMs()); if (delta > 400) return false; - double distance = sqrt( - (m_key_events[0].x - m_key_events[1].x) * - (m_key_events[0].x - m_key_events[1].x) + - (m_key_events[0].y - m_key_events[1].y) * - (m_key_events[0].y - m_key_events[1].y)); + double distance = sqrt((m_key_events[0].x - m_key_events[1].x) * + (m_key_events[0].x - m_key_events[1].x) + + (m_key_events[0].y - m_key_events[1].y) * + (m_key_events[0].y - m_key_events[1].y)); if (distance > (20 + m_touchscreen_threshold)) return false; auto *translated = new SEvent(); memset(translated, 0, sizeof(SEvent)); - translated->EventType = EET_MOUSE_INPUT_EVENT; - translated->MouseInput.X = m_key_events[0].x; - translated->MouseInput.Y = m_key_events[0].y; - translated->MouseInput.Shift = false; - translated->MouseInput.Control = false; + translated->EventType = EET_MOUSE_INPUT_EVENT; + translated->MouseInput.X = m_key_events[0].x; + translated->MouseInput.Y = m_key_events[0].y; + translated->MouseInput.Shift = false; + translated->MouseInput.Control = false; translated->MouseInput.ButtonStates = EMBSM_RIGHT; // update shootline - m_shootline = m_device - ->getSceneManager() - ->getSceneCollisionManager() - ->getRayFromScreenCoordinates(v2s32(m_key_events[0].x, m_key_events[0].y)); + m_shootline = m_device->getSceneManager() + ->getSceneCollisionManager() + ->getRayFromScreenCoordinates( + v2s32(m_key_events[0].x, + m_key_events[0].y)); translated->MouseInput.Event = EMIE_RMOUSE_PRESSED_DOWN; verbosestream << "TouchScreenGUI::translateEvent right click press" << std::endl; @@ -1031,7 +1078,8 @@ bool TouchScreenGUI::doubleTapDetection() translated->MouseInput.ButtonStates = 0; translated->MouseInput.Event = EMIE_RMOUSE_LEFT_UP; - verbosestream << "TouchScreenGUI::translateEvent right click release" << std::endl; + verbosestream << "TouchScreenGUI::translateEvent right click release" + << std::endl; m_receiver->OnEvent(*translated); delete translated; return true; @@ -1044,8 +1092,8 @@ void TouchScreenGUI::applyJoystickStatus() continue; SEvent translated{}; - translated.EventType = irr::EET_KEY_INPUT_EVENT; - translated.KeyInput.Key = id2keycode(m_joystick_names[i]); + translated.EventType = irr::EET_KEY_INPUT_EVENT; + translated.KeyInput.Key = id2keycode(m_joystick_names[i]); translated.KeyInput.PressedDown = false; m_receiver->OnEvent(translated); @@ -1095,11 +1143,11 @@ void TouchScreenGUI::step(float dtime) if (button.repeatcounter < button.repeatdelay) continue; - button.repeatcounter = 0; + button.repeatcounter = 0; SEvent translated; memset(&translated, 0, sizeof(SEvent)); - translated.EventType = irr::EET_KEY_INPUT_EVENT; - translated.KeyInput.Key = button.keycode; + translated.EventType = irr::EET_KEY_INPUT_EVENT; + translated.KeyInput.Key = button.keycode; translated.KeyInput.PressedDown = false; m_receiver->OnEvent(translated); @@ -1117,31 +1165,33 @@ void TouchScreenGUI::step(float dtime) } // if a new placed pointer isn't moved for some time start digging - if ((m_move_id != -1) && - (!m_move_has_really_moved) && + if ((m_move_id != -1) && (!m_move_has_really_moved) && (!m_move_sent_as_mouse_event)) { u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs()); if (delta > MIN_DIG_TIME_MS) { - m_shootline = m_device - ->getSceneManager() - ->getSceneCollisionManager() - ->getRayFromScreenCoordinates( - v2s32(m_move_downlocation.X,m_move_downlocation.Y)); + m_shootline = m_device->getSceneManager() + ->getSceneCollisionManager() + ->getRayFromScreenCoordinates(v2s32( + m_move_downlocation + .X, + m_move_downlocation + .Y)); SEvent translated; memset(&translated, 0, sizeof(SEvent)); - translated.EventType = EET_MOUSE_INPUT_EVENT; - translated.MouseInput.X = m_move_downlocation.X; - translated.MouseInput.Y = m_move_downlocation.Y; - translated.MouseInput.Shift = false; - translated.MouseInput.Control = false; + translated.EventType = EET_MOUSE_INPUT_EVENT; + translated.MouseInput.X = m_move_downlocation.X; + translated.MouseInput.Y = m_move_downlocation.Y; + translated.MouseInput.Shift = false; + translated.MouseInput.Control = false; translated.MouseInput.ButtonStates = EMBSM_LEFT; - translated.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN; - verbosestream << "TouchScreenGUI::step left click press" << std::endl; + translated.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN; + verbosestream << "TouchScreenGUI::step left click press" + << std::endl; m_receiver->OnEvent(translated); - m_move_sent_as_mouse_event = true; + m_move_sent_as_mouse_event = true; } } |