forked from Mirrorlandia_minetest/minetest
refacto: factorize multiple code parts from guiEditbox childs (#10782)
This commit is contained in:
parent
e663aecbae
commit
58a709096e
@ -7,6 +7,7 @@ set(gui_SRCS
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiButtonItemImage.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiButtonItemImage.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiChatConsole.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiChatConsole.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiConfirmRegistration.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiConfirmRegistration.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/guiEditBox.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiEditBoxWithScrollbar.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiEditBoxWithScrollbar.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiEngine.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiEngine.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/guiFormSpecMenu.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/guiFormSpecMenu.cpp
|
||||||
|
95
src/gui/guiEditBox.cpp
Normal file
95
src/gui/guiEditBox.cpp
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
Minetest
|
||||||
|
Copyright (C) 2021 Minetest
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "guiEditBox.h"
|
||||||
|
|
||||||
|
#include "IGUISkin.h"
|
||||||
|
#include "IGUIEnvironment.h"
|
||||||
|
#include "IGUIFont.h"
|
||||||
|
|
||||||
|
GUIEditBox::~GUIEditBox()
|
||||||
|
{
|
||||||
|
if (m_override_font)
|
||||||
|
m_override_font->drop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUIEditBox::setOverrideFont(IGUIFont *font)
|
||||||
|
{
|
||||||
|
if (m_override_font == font)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_override_font)
|
||||||
|
m_override_font->drop();
|
||||||
|
|
||||||
|
m_override_font = font;
|
||||||
|
|
||||||
|
if (m_override_font)
|
||||||
|
m_override_font->grab();
|
||||||
|
|
||||||
|
breakText();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Get the font which is used right now for drawing
|
||||||
|
IGUIFont *GUIEditBox::getActiveFont() const
|
||||||
|
{
|
||||||
|
if (m_override_font)
|
||||||
|
return m_override_font;
|
||||||
|
IGUISkin *skin = Environment->getSkin();
|
||||||
|
if (skin)
|
||||||
|
return skin->getFont();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Sets another color for the text.
|
||||||
|
void GUIEditBox::setOverrideColor(video::SColor color)
|
||||||
|
{
|
||||||
|
m_override_color = color;
|
||||||
|
m_override_color_enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
video::SColor GUIEditBox::getOverrideColor() const
|
||||||
|
{
|
||||||
|
return m_override_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Sets if the text should use the overide color or the color in the gui skin.
|
||||||
|
void GUIEditBox::enableOverrideColor(bool enable)
|
||||||
|
{
|
||||||
|
m_override_color_enabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Enables or disables word wrap
|
||||||
|
void GUIEditBox::setWordWrap(bool enable)
|
||||||
|
{
|
||||||
|
m_word_wrap = enable;
|
||||||
|
breakText();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Enables or disables newlines.
|
||||||
|
void GUIEditBox::setMultiLine(bool enable)
|
||||||
|
{
|
||||||
|
m_multiline = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Enables or disables automatic scrolling with cursor position
|
||||||
|
//! \param enable: If set to true, the text will move around with the cursor position
|
||||||
|
void GUIEditBox::setAutoScroll(bool enable)
|
||||||
|
{
|
||||||
|
m_autoscroll = enable;
|
||||||
|
}
|
103
src/gui/guiEditBox.h
Normal file
103
src/gui/guiEditBox.h
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
Minetest
|
||||||
|
Copyright (C) 2021 Minetest
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "IGUIEditBox.h"
|
||||||
|
#include "IOSOperator.h"
|
||||||
|
#include "guiScrollBar.h"
|
||||||
|
|
||||||
|
using namespace irr;
|
||||||
|
using namespace irr::gui;
|
||||||
|
|
||||||
|
class GUIEditBox : public IGUIEditBox
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GUIEditBox(IGUIEnvironment *environment, IGUIElement *parent, s32 id,
|
||||||
|
core::rect<s32> rectangle) :
|
||||||
|
IGUIEditBox(environment, parent, id, rectangle)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~GUIEditBox();
|
||||||
|
|
||||||
|
//! Sets another skin independent font.
|
||||||
|
virtual void setOverrideFont(IGUIFont *font = 0);
|
||||||
|
|
||||||
|
virtual IGUIFont *getOverrideFont() const { return m_override_font; }
|
||||||
|
|
||||||
|
//! 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
|
||||||
|
{
|
||||||
|
return m_override_color_enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! 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 { return m_word_wrap; }
|
||||||
|
|
||||||
|
//! 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);
|
||||||
|
|
||||||
|
//! Checks if multi line editing is enabled
|
||||||
|
//! \return true if mult-line is enabled, false otherwise
|
||||||
|
virtual bool isMultiLineEnabled() const { return m_multiline; }
|
||||||
|
|
||||||
|
//! 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);
|
||||||
|
|
||||||
|
//! Checks to see if automatic scrolling is enabled
|
||||||
|
//! \return true if automatic scrolling is enabled, false if not
|
||||||
|
virtual bool isAutoScrollEnabled() const { return m_autoscroll; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void breakText() = 0;
|
||||||
|
|
||||||
|
gui::IGUIFont *m_override_font = nullptr;
|
||||||
|
|
||||||
|
bool m_override_color_enabled = false;
|
||||||
|
bool m_word_wrap = false;
|
||||||
|
bool m_multiline = false;
|
||||||
|
bool m_autoscroll = true;
|
||||||
|
|
||||||
|
video::SColor m_override_color = video::SColor(101, 255, 255, 255);
|
||||||
|
};
|
@ -22,16 +22,14 @@ optional? dragging selected text
|
|||||||
numerical
|
numerical
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
//! constructor
|
//! constructor
|
||||||
GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool border,
|
GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool border,
|
||||||
IGUIEnvironment* environment, IGUIElement* parent, s32 id,
|
IGUIEnvironment* environment, IGUIElement* parent, s32 id,
|
||||||
const core::rect<s32>& rectangle, bool writable, bool has_vscrollbar)
|
const core::rect<s32>& rectangle, bool writable, bool has_vscrollbar)
|
||||||
: IGUIEditBox(environment, parent, id, rectangle), m_mouse_marking(false),
|
: GUIEditBox(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_border(border), m_background(true), m_mark_begin(0), m_mark_end(0), m_last_break_font(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_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_passwordbox(false),
|
||||||
m_passwordchar(L'*'), m_halign(EGUIA_UPPERLEFT), m_valign(EGUIA_CENTER),
|
m_passwordchar(L'*'), m_halign(EGUIA_UPPERLEFT), m_valign(EGUIA_CENTER),
|
||||||
m_current_text_rect(0, 0, 1, 1), m_frame_rect(rectangle),
|
m_current_text_rect(0, 0, 1, 1), m_frame_rect(rectangle),
|
||||||
m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable),
|
m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable),
|
||||||
@ -69,9 +67,6 @@ GUIEditBoxWithScrollBar::GUIEditBoxWithScrollBar(const wchar_t* text, bool borde
|
|||||||
//! destructor
|
//! destructor
|
||||||
GUIEditBoxWithScrollBar::~GUIEditBoxWithScrollBar()
|
GUIEditBoxWithScrollBar::~GUIEditBoxWithScrollBar()
|
||||||
{
|
{
|
||||||
if (m_override_font)
|
|
||||||
m_override_font->drop();
|
|
||||||
|
|
||||||
if (m_operator)
|
if (m_operator)
|
||||||
m_operator->drop();
|
m_operator->drop();
|
||||||
|
|
||||||
@ -80,54 +75,6 @@ GUIEditBoxWithScrollBar::~GUIEditBoxWithScrollBar()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Sets another skin independent font.
|
|
||||||
void GUIEditBoxWithScrollBar::setOverrideFont(IGUIFont* font)
|
|
||||||
{
|
|
||||||
if (m_override_font == font)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (m_override_font)
|
|
||||||
m_override_font->drop();
|
|
||||||
|
|
||||||
m_override_font = font;
|
|
||||||
|
|
||||||
if (m_override_font)
|
|
||||||
m_override_font->grab();
|
|
||||||
|
|
||||||
breakText();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Gets the override font (if any)
|
|
||||||
IGUIFont * GUIEditBoxWithScrollBar::getOverrideFont() const
|
|
||||||
{
|
|
||||||
return m_override_font;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Get the font which is used right now for drawing
|
|
||||||
IGUIFont* GUIEditBoxWithScrollBar::getActiveFont() const
|
|
||||||
{
|
|
||||||
if (m_override_font)
|
|
||||||
return m_override_font;
|
|
||||||
IGUISkin* skin = Environment->getSkin();
|
|
||||||
if (skin)
|
|
||||||
return skin->getFont();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Sets another color for the text.
|
|
||||||
void GUIEditBoxWithScrollBar::setOverrideColor(video::SColor color)
|
|
||||||
{
|
|
||||||
m_override_color = color;
|
|
||||||
m_override_color_enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
video::SColor GUIEditBoxWithScrollBar::getOverrideColor() const
|
|
||||||
{
|
|
||||||
return m_override_color;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//! Turns the border on or off
|
//! Turns the border on or off
|
||||||
void GUIEditBoxWithScrollBar::setDrawBorder(bool border)
|
void GUIEditBoxWithScrollBar::setDrawBorder(bool border)
|
||||||
{
|
{
|
||||||
@ -140,24 +87,6 @@ void GUIEditBoxWithScrollBar::setDrawBackground(bool draw)
|
|||||||
m_background = draw;
|
m_background = draw;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Sets if the text should use the overide color or the color in the gui skin.
|
|
||||||
void GUIEditBoxWithScrollBar::enableOverrideColor(bool enable)
|
|
||||||
{
|
|
||||||
m_override_color_enabled = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GUIEditBoxWithScrollBar::isOverrideColorEnabled() const
|
|
||||||
{
|
|
||||||
return m_override_color_enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Enables or disables word wrap
|
|
||||||
void GUIEditBoxWithScrollBar::setWordWrap(bool enable)
|
|
||||||
{
|
|
||||||
m_word_wrap = enable;
|
|
||||||
breakText();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GUIEditBoxWithScrollBar::updateAbsolutePosition()
|
void GUIEditBoxWithScrollBar::updateAbsolutePosition()
|
||||||
{
|
{
|
||||||
@ -170,26 +99,6 @@ void GUIEditBoxWithScrollBar::updateAbsolutePosition()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Checks if word wrap is enabled
|
|
||||||
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)
|
void GUIEditBoxWithScrollBar::setPasswordBox(bool password_box, wchar_t password_char)
|
||||||
{
|
{
|
||||||
@ -850,22 +759,6 @@ void GUIEditBoxWithScrollBar::setText(const wchar_t* text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! 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)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
|
||||||
return m_autoscroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//! Gets the area of the text in the edit box
|
//! Gets the area of the text in the edit box
|
||||||
//! \return Returns the size in pixels of the text
|
//! \return Returns the size in pixels of the text
|
||||||
core::dimension2du GUIEditBoxWithScrollBar::getTextDimension()
|
core::dimension2du GUIEditBoxWithScrollBar::getTextDimension()
|
||||||
|
@ -5,15 +5,10 @@
|
|||||||
#ifndef GUIEDITBOXWITHSCROLLBAR_HEADER
|
#ifndef GUIEDITBOXWITHSCROLLBAR_HEADER
|
||||||
#define GUIEDITBOXWITHSCROLLBAR_HEADER
|
#define GUIEDITBOXWITHSCROLLBAR_HEADER
|
||||||
|
|
||||||
#include "IGUIEditBox.h"
|
#include "guiEditBox.h"
|
||||||
#include "IOSOperator.h"
|
|
||||||
#include "guiScrollBar.h"
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace irr;
|
class GUIEditBoxWithScrollBar : public GUIEditBox
|
||||||
using namespace irr::gui;
|
|
||||||
|
|
||||||
class GUIEditBoxWithScrollBar : public IGUIEditBox
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -25,61 +20,13 @@ public:
|
|||||||
//! destructor
|
//! destructor
|
||||||
virtual ~GUIEditBoxWithScrollBar();
|
virtual ~GUIEditBoxWithScrollBar();
|
||||||
|
|
||||||
//! 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
|
//! Sets whether to draw the background
|
||||||
virtual void setDrawBackground(bool draw);
|
virtual void setDrawBackground(bool draw);
|
||||||
|
|
||||||
//! Turns the border on or off
|
//! Turns the border on or off
|
||||||
virtual void setDrawBorder(bool border);
|
virtual void setDrawBorder(bool 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);
|
|
||||||
|
|
||||||
//! Checks if multi line editing is enabled
|
|
||||||
//! \return true if mult-line is enabled, false otherwise
|
|
||||||
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
|
|
||||||
virtual void setAutoScroll(bool enable);
|
|
||||||
|
|
||||||
//! Checks to see if automatic scrolling is enabled
|
|
||||||
//! \return true if automatic scrolling is enabled, false if not
|
|
||||||
virtual bool isAutoScrollEnabled() const;
|
|
||||||
|
|
||||||
//! Gets the size area of the text in the edit box
|
//! Gets the size area of the text in the edit box
|
||||||
//! \return Returns the size in pixels of the text
|
//! \return Returns the size in pixels of the text
|
||||||
@ -137,7 +84,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Breaks the single text line.
|
//! Breaks the single text line.
|
||||||
void breakText();
|
virtual void breakText();
|
||||||
//! sets the area of the given line
|
//! sets the area of the given line
|
||||||
void setTextRect(s32 line);
|
void setTextRect(s32 line);
|
||||||
//! returns the line number that the cursor is on
|
//! returns the line number that the cursor is on
|
||||||
@ -164,12 +111,11 @@ protected:
|
|||||||
bool m_mouse_marking;
|
bool m_mouse_marking;
|
||||||
bool m_border;
|
bool m_border;
|
||||||
bool m_background;
|
bool m_background;
|
||||||
bool m_override_color_enabled;
|
|
||||||
s32 m_mark_begin;
|
s32 m_mark_begin;
|
||||||
s32 m_mark_end;
|
s32 m_mark_end;
|
||||||
|
|
||||||
video::SColor m_override_color;
|
gui::IGUIFont *m_last_break_font;
|
||||||
gui::IGUIFont *m_override_font, *m_last_break_font;
|
|
||||||
IOSOperator* m_operator;
|
IOSOperator* m_operator;
|
||||||
|
|
||||||
u32 m_blink_start_time;
|
u32 m_blink_start_time;
|
||||||
@ -177,7 +123,7 @@ protected:
|
|||||||
s32 m_hscroll_pos, m_vscroll_pos; // scroll position in characters
|
s32 m_hscroll_pos, m_vscroll_pos; // scroll position in characters
|
||||||
u32 m_max;
|
u32 m_max;
|
||||||
|
|
||||||
bool m_word_wrap, m_multiline, m_autoscroll, m_passwordbox;
|
bool m_passwordbox;
|
||||||
wchar_t m_passwordchar;
|
wchar_t m_passwordchar;
|
||||||
EGUI_ALIGNMENT m_halign, m_valign;
|
EGUI_ALIGNMENT m_halign, m_valign;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ namespace gui
|
|||||||
intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border,
|
intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border,
|
||||||
IGUIEnvironment* environment, IGUIElement* parent, s32 id,
|
IGUIEnvironment* environment, IGUIElement* parent, s32 id,
|
||||||
const core::rect<s32>& rectangle, bool writable, bool has_vscrollbar)
|
const core::rect<s32>& rectangle, bool writable, bool has_vscrollbar)
|
||||||
: IGUIEditBox(environment, parent, id, rectangle),
|
: GUIEditBox(environment, parent, id, rectangle),
|
||||||
Border(border), FrameRect(rectangle),
|
Border(border), FrameRect(rectangle),
|
||||||
m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable)
|
m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable)
|
||||||
{
|
{
|
||||||
@ -108,9 +108,6 @@ intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border,
|
|||||||
//! destructor
|
//! destructor
|
||||||
intlGUIEditBox::~intlGUIEditBox()
|
intlGUIEditBox::~intlGUIEditBox()
|
||||||
{
|
{
|
||||||
if (OverrideFont)
|
|
||||||
OverrideFont->drop();
|
|
||||||
|
|
||||||
if (Operator)
|
if (Operator)
|
||||||
Operator->drop();
|
Operator->drop();
|
||||||
|
|
||||||
@ -118,52 +115,6 @@ intlGUIEditBox::~intlGUIEditBox()
|
|||||||
m_vscrollbar->drop();
|
m_vscrollbar->drop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Sets another skin independent font.
|
|
||||||
void intlGUIEditBox::setOverrideFont(IGUIFont* font)
|
|
||||||
{
|
|
||||||
if (OverrideFont == font)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (OverrideFont)
|
|
||||||
OverrideFont->drop();
|
|
||||||
|
|
||||||
OverrideFont = font;
|
|
||||||
|
|
||||||
if (OverrideFont)
|
|
||||||
OverrideFont->grab();
|
|
||||||
|
|
||||||
breakText();
|
|
||||||
}
|
|
||||||
|
|
||||||
IGUIFont * intlGUIEditBox::getOverrideFont() const
|
|
||||||
{
|
|
||||||
return OverrideFont;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Get the font which is used right now for drawing
|
|
||||||
IGUIFont* intlGUIEditBox::getActiveFont() const
|
|
||||||
{
|
|
||||||
if ( OverrideFont )
|
|
||||||
return OverrideFont;
|
|
||||||
IGUISkin* skin = Environment->getSkin();
|
|
||||||
if (skin)
|
|
||||||
return skin->getFont();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Sets another color for the text.
|
|
||||||
void intlGUIEditBox::setOverrideColor(video::SColor color)
|
|
||||||
{
|
|
||||||
OverrideColor = color;
|
|
||||||
OverrideColorEnabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
video::SColor intlGUIEditBox::getOverrideColor() const
|
|
||||||
{
|
|
||||||
return OverrideColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Turns the border on or off
|
//! Turns the border on or off
|
||||||
void intlGUIEditBox::setDrawBorder(bool border)
|
void intlGUIEditBox::setDrawBorder(bool border)
|
||||||
{
|
{
|
||||||
@ -175,25 +126,6 @@ void intlGUIEditBox::setDrawBackground(bool draw)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Sets if the text should use the overide color or the color in the gui skin.
|
|
||||||
void intlGUIEditBox::enableOverrideColor(bool enable)
|
|
||||||
{
|
|
||||||
OverrideColorEnabled = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool intlGUIEditBox::isOverrideColorEnabled() const
|
|
||||||
{
|
|
||||||
return OverrideColorEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Enables or disables word wrap
|
|
||||||
void intlGUIEditBox::setWordWrap(bool enable)
|
|
||||||
{
|
|
||||||
WordWrap = enable;
|
|
||||||
breakText();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void intlGUIEditBox::updateAbsolutePosition()
|
void intlGUIEditBox::updateAbsolutePosition()
|
||||||
{
|
{
|
||||||
core::rect<s32> oldAbsoluteRect(AbsoluteRect);
|
core::rect<s32> oldAbsoluteRect(AbsoluteRect);
|
||||||
@ -204,28 +136,6 @@ void intlGUIEditBox::updateAbsolutePosition()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! 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)
|
void intlGUIEditBox::setPasswordBox(bool passwordBox, wchar_t passwordChar)
|
||||||
{
|
{
|
||||||
PasswordBox = passwordBox;
|
PasswordBox = passwordBox;
|
||||||
@ -464,7 +374,7 @@ bool intlGUIEditBox::processKey(const SEvent& event)
|
|||||||
case KEY_END:
|
case KEY_END:
|
||||||
{
|
{
|
||||||
s32 p = Text.size();
|
s32 p = Text.size();
|
||||||
if (WordWrap || MultiLine)
|
if (m_word_wrap || m_multiline)
|
||||||
{
|
{
|
||||||
p = getLineFromPos(CursorPos);
|
p = getLineFromPos(CursorPos);
|
||||||
p = BrokenTextPositions[p] + (s32)BrokenText[p].size();
|
p = BrokenTextPositions[p] + (s32)BrokenText[p].size();
|
||||||
@ -492,7 +402,7 @@ bool intlGUIEditBox::processKey(const SEvent& event)
|
|||||||
{
|
{
|
||||||
|
|
||||||
s32 p = 0;
|
s32 p = 0;
|
||||||
if (WordWrap || MultiLine)
|
if (m_word_wrap || m_multiline)
|
||||||
{
|
{
|
||||||
p = getLineFromPos(CursorPos);
|
p = getLineFromPos(CursorPos);
|
||||||
p = BrokenTextPositions[p];
|
p = BrokenTextPositions[p];
|
||||||
@ -514,7 +424,7 @@ bool intlGUIEditBox::processKey(const SEvent& event)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KEY_RETURN:
|
case KEY_RETURN:
|
||||||
if (MultiLine)
|
if (m_multiline)
|
||||||
{
|
{
|
||||||
inputChar(L'\n');
|
inputChar(L'\n');
|
||||||
return true;
|
return true;
|
||||||
@ -567,7 +477,7 @@ bool intlGUIEditBox::processKey(const SEvent& event)
|
|||||||
BlinkStartTime = porting::getTimeMs();
|
BlinkStartTime = porting::getTimeMs();
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
if (MultiLine || (WordWrap && BrokenText.size() > 1) )
|
if (m_multiline || (m_word_wrap && BrokenText.size() > 1) )
|
||||||
{
|
{
|
||||||
s32 lineNo = getLineFromPos(CursorPos);
|
s32 lineNo = getLineFromPos(CursorPos);
|
||||||
s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin > MarkEnd ? MarkBegin : MarkEnd);
|
s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin > MarkEnd ? MarkBegin : MarkEnd);
|
||||||
@ -598,7 +508,7 @@ bool intlGUIEditBox::processKey(const SEvent& event)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
if (MultiLine || (WordWrap && BrokenText.size() > 1) )
|
if (m_multiline || (m_word_wrap && BrokenText.size() > 1) )
|
||||||
{
|
{
|
||||||
s32 lineNo = getLineFromPos(CursorPos);
|
s32 lineNo = getLineFromPos(CursorPos);
|
||||||
s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin < MarkEnd ? MarkBegin : MarkEnd);
|
s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin < MarkEnd ? MarkBegin : MarkEnd);
|
||||||
@ -791,8 +701,8 @@ void intlGUIEditBox::draw()
|
|||||||
|
|
||||||
// draw the text
|
// draw the text
|
||||||
|
|
||||||
IGUIFont* font = OverrideFont;
|
IGUIFont* font = m_override_font;
|
||||||
if (!OverrideFont)
|
if (!m_override_font)
|
||||||
font = skin->getFont();
|
font = skin->getFont();
|
||||||
|
|
||||||
s32 cursorLine = 0;
|
s32 cursorLine = 0;
|
||||||
@ -813,7 +723,7 @@ void intlGUIEditBox::draw()
|
|||||||
core::stringw s, s2;
|
core::stringw s, s2;
|
||||||
|
|
||||||
// get mark position
|
// get mark position
|
||||||
const bool ml = (!PasswordBox && (WordWrap || MultiLine));
|
const bool ml = (!PasswordBox && (m_word_wrap || m_multiline));
|
||||||
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
|
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
|
||||||
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
|
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
|
||||||
const s32 hlineStart = ml ? getLineFromPos(realmbgn) : 0;
|
const s32 hlineStart = ml ? getLineFromPos(realmbgn) : 0;
|
||||||
@ -822,14 +732,14 @@ void intlGUIEditBox::draw()
|
|||||||
|
|
||||||
// Save the override color information.
|
// Save the override color information.
|
||||||
// Then, alter it if the edit box is disabled.
|
// Then, alter it if the edit box is disabled.
|
||||||
const bool prevOver = OverrideColorEnabled;
|
const bool prevOver = m_override_color_enabled;
|
||||||
const video::SColor prevColor = OverrideColor;
|
const video::SColor prevColor = m_override_color;
|
||||||
|
|
||||||
if (!Text.empty()) {
|
if (!Text.empty()) {
|
||||||
if (!IsEnabled && !OverrideColorEnabled)
|
if (!IsEnabled && !m_override_color_enabled)
|
||||||
{
|
{
|
||||||
OverrideColorEnabled = true;
|
m_override_color_enabled = true;
|
||||||
OverrideColor = skin->getColor(EGDC_GRAY_TEXT);
|
m_override_color = skin->getColor(EGDC_GRAY_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (s32 i=0; i < lineCount; ++i)
|
for (s32 i=0; i < lineCount; ++i)
|
||||||
@ -870,7 +780,7 @@ void intlGUIEditBox::draw()
|
|||||||
|
|
||||||
// draw normal text
|
// draw normal text
|
||||||
font->draw(txtLine->c_str(), CurrentTextRect,
|
font->draw(txtLine->c_str(), CurrentTextRect,
|
||||||
OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
|
m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT),
|
||||||
false, true, &localClipRect);
|
false, true, &localClipRect);
|
||||||
|
|
||||||
// draw mark and marked text
|
// draw mark and marked text
|
||||||
@ -914,20 +824,20 @@ void intlGUIEditBox::draw()
|
|||||||
|
|
||||||
if (!s.empty())
|
if (!s.empty())
|
||||||
font->draw(s.c_str(), CurrentTextRect,
|
font->draw(s.c_str(), CurrentTextRect,
|
||||||
OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
|
m_override_color_enabled ? m_override_color : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
|
||||||
false, true, &localClipRect);
|
false, true, &localClipRect);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the override color information to its previous settings.
|
// Return the override color information to its previous settings.
|
||||||
OverrideColorEnabled = prevOver;
|
m_override_color_enabled = prevOver;
|
||||||
OverrideColor = prevColor;
|
m_override_color = prevColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw cursor
|
// draw cursor
|
||||||
|
|
||||||
if (WordWrap || MultiLine)
|
if (m_word_wrap || m_multiline)
|
||||||
{
|
{
|
||||||
cursorLine = getLineFromPos(CursorPos);
|
cursorLine = getLineFromPos(CursorPos);
|
||||||
txtLine = &BrokenText[cursorLine];
|
txtLine = &BrokenText[cursorLine];
|
||||||
@ -943,7 +853,7 @@ void intlGUIEditBox::draw()
|
|||||||
CurrentTextRect.UpperLeftCorner.X += charcursorpos;
|
CurrentTextRect.UpperLeftCorner.X += charcursorpos;
|
||||||
|
|
||||||
font->draw(L"_", CurrentTextRect,
|
font->draw(L"_", CurrentTextRect,
|
||||||
OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
|
m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT),
|
||||||
false, true, &localClipRect);
|
false, true, &localClipRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -965,22 +875,6 @@ void intlGUIEditBox::setText(const wchar_t* text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! 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)
|
|
||||||
{
|
|
||||||
AutoScroll = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//! Checks to see if automatic scrolling is enabled
|
|
||||||
//! \return true if automatic scrolling is enabled, false if not
|
|
||||||
bool intlGUIEditBox::isAutoScrollEnabled() const
|
|
||||||
{
|
|
||||||
return AutoScroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//! Gets the area of the text in the edit box
|
//! Gets the area of the text in the edit box
|
||||||
//! \return Returns the size in pixels of the text
|
//! \return Returns the size in pixels of the text
|
||||||
core::dimension2du intlGUIEditBox::getTextDimension()
|
core::dimension2du intlGUIEditBox::getTextDimension()
|
||||||
@ -1096,12 +990,12 @@ bool intlGUIEditBox::processMouse(const SEvent& event)
|
|||||||
|
|
||||||
s32 intlGUIEditBox::getCursorPos(s32 x, s32 y)
|
s32 intlGUIEditBox::getCursorPos(s32 x, s32 y)
|
||||||
{
|
{
|
||||||
IGUIFont* font = OverrideFont;
|
IGUIFont* font = m_override_font;
|
||||||
IGUISkin* skin = Environment->getSkin();
|
IGUISkin* skin = Environment->getSkin();
|
||||||
if (!OverrideFont)
|
if (!m_override_font)
|
||||||
font = skin->getFont();
|
font = skin->getFont();
|
||||||
|
|
||||||
const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1;
|
const u32 lineCount = (m_word_wrap || m_multiline) ? BrokenText.size() : 1;
|
||||||
|
|
||||||
core::stringw *txtLine = NULL;
|
core::stringw *txtLine = NULL;
|
||||||
s32 startPos = 0;
|
s32 startPos = 0;
|
||||||
@ -1118,8 +1012,8 @@ s32 intlGUIEditBox::getCursorPos(s32 x, s32 y)
|
|||||||
// is it inside this region?
|
// 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
|
// we've found the clicked line
|
||||||
txtLine = (WordWrap || MultiLine) ? &BrokenText[curr_line_idx] : &Text;
|
txtLine = (m_word_wrap || m_multiline) ? &BrokenText[curr_line_idx] : &Text;
|
||||||
startPos = (WordWrap || MultiLine) ? BrokenTextPositions[curr_line_idx] : 0;
|
startPos = (m_word_wrap || m_multiline) ? BrokenTextPositions[curr_line_idx] : 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1144,14 +1038,14 @@ void intlGUIEditBox::breakText()
|
|||||||
{
|
{
|
||||||
IGUISkin* skin = Environment->getSkin();
|
IGUISkin* skin = Environment->getSkin();
|
||||||
|
|
||||||
if ((!WordWrap && !MultiLine) || !skin)
|
if ((!m_word_wrap && !m_multiline) || !skin)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BrokenText.clear(); // need to reallocate :/
|
BrokenText.clear(); // need to reallocate :/
|
||||||
BrokenTextPositions.set_used(0);
|
BrokenTextPositions.set_used(0);
|
||||||
|
|
||||||
IGUIFont* font = OverrideFont;
|
IGUIFont* font = m_override_font;
|
||||||
if (!OverrideFont)
|
if (!m_override_font)
|
||||||
font = skin->getFont();
|
font = skin->getFont();
|
||||||
|
|
||||||
if (!font)
|
if (!font)
|
||||||
@ -1190,7 +1084,7 @@ void intlGUIEditBox::breakText()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// don't break if we're not a multi-line edit box
|
// don't break if we're not a multi-line edit box
|
||||||
if (!MultiLine)
|
if (!m_multiline)
|
||||||
lineBreak = false;
|
lineBreak = false;
|
||||||
|
|
||||||
if (c == L' ' || c == 0 || i == (size-1))
|
if (c == L' ' || c == 0 || i == (size-1))
|
||||||
@ -1201,7 +1095,7 @@ void intlGUIEditBox::breakText()
|
|||||||
s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
|
s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
|
||||||
s32 worldlgth = font->getDimension(word.c_str()).Width;
|
s32 worldlgth = font->getDimension(word.c_str()).Width;
|
||||||
|
|
||||||
if (WordWrap && length + worldlgth + whitelgth > elWidth)
|
if (m_word_wrap && length + worldlgth + whitelgth > elWidth)
|
||||||
{
|
{
|
||||||
// break to next line
|
// break to next line
|
||||||
length = worldlgth;
|
length = worldlgth;
|
||||||
@ -1260,14 +1154,14 @@ void intlGUIEditBox::setTextRect(s32 line)
|
|||||||
if (!skin)
|
if (!skin)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont();
|
IGUIFont* font = m_override_font ? m_override_font : skin->getFont();
|
||||||
|
|
||||||
if (!font)
|
if (!font)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// get text dimension
|
// get text dimension
|
||||||
const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1;
|
const u32 lineCount = (m_word_wrap || m_multiline) ? BrokenText.size() : 1;
|
||||||
if (WordWrap || MultiLine)
|
if (m_word_wrap || m_multiline)
|
||||||
{
|
{
|
||||||
d = font->getDimension(BrokenText[line].c_str());
|
d = font->getDimension(BrokenText[line].c_str());
|
||||||
}
|
}
|
||||||
@ -1328,7 +1222,7 @@ void intlGUIEditBox::setTextRect(s32 line)
|
|||||||
|
|
||||||
s32 intlGUIEditBox::getLineFromPos(s32 pos)
|
s32 intlGUIEditBox::getLineFromPos(s32 pos)
|
||||||
{
|
{
|
||||||
if (!WordWrap && !MultiLine)
|
if (!m_word_wrap && !m_multiline)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
s32 i=0;
|
s32 i=0;
|
||||||
@ -1387,7 +1281,7 @@ void intlGUIEditBox::inputChar(wchar_t c)
|
|||||||
|
|
||||||
void intlGUIEditBox::calculateScrollPos()
|
void intlGUIEditBox::calculateScrollPos()
|
||||||
{
|
{
|
||||||
if (!AutoScroll)
|
if (!m_autoscroll)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// calculate horizontal scroll position
|
// calculate horizontal scroll position
|
||||||
@ -1395,18 +1289,18 @@ void intlGUIEditBox::calculateScrollPos()
|
|||||||
setTextRect(cursLine);
|
setTextRect(cursLine);
|
||||||
|
|
||||||
// don't do horizontal scrolling when wordwrap is enabled.
|
// don't do horizontal scrolling when wordwrap is enabled.
|
||||||
if (!WordWrap)
|
if (!m_word_wrap)
|
||||||
{
|
{
|
||||||
// get cursor position
|
// get cursor position
|
||||||
IGUISkin* skin = Environment->getSkin();
|
IGUISkin* skin = Environment->getSkin();
|
||||||
if (!skin)
|
if (!skin)
|
||||||
return;
|
return;
|
||||||
IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont();
|
IGUIFont* font = m_override_font ? m_override_font : skin->getFont();
|
||||||
if (!font)
|
if (!font)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
core::stringw *txtLine = MultiLine ? &BrokenText[cursLine] : &Text;
|
core::stringw *txtLine = m_multiline ? &BrokenText[cursLine] : &Text;
|
||||||
s32 cPos = MultiLine ? CursorPos - BrokenTextPositions[cursLine] : CursorPos;
|
s32 cPos = m_multiline ? CursorPos - BrokenTextPositions[cursLine] : CursorPos;
|
||||||
|
|
||||||
s32 cStart = CurrentTextRect.UpperLeftCorner.X + HScrollPos +
|
s32 cStart = CurrentTextRect.UpperLeftCorner.X + HScrollPos +
|
||||||
font->getDimension(txtLine->subString(0, cPos).c_str()).Width;
|
font->getDimension(txtLine->subString(0, cPos).c_str()).Width;
|
||||||
@ -1423,7 +1317,7 @@ void intlGUIEditBox::calculateScrollPos()
|
|||||||
// todo: adjust scrollbar
|
// todo: adjust scrollbar
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!WordWrap && !MultiLine)
|
if (!m_word_wrap && !m_multiline)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// vertical scroll position
|
// vertical scroll position
|
||||||
@ -1468,8 +1362,8 @@ void intlGUIEditBox::createVScrollBar()
|
|||||||
{
|
{
|
||||||
s32 fontHeight = 1;
|
s32 fontHeight = 1;
|
||||||
|
|
||||||
if (OverrideFont) {
|
if (m_override_font) {
|
||||||
fontHeight = OverrideFont->getDimension(L"").Height;
|
fontHeight = m_override_font->getDimension(L"").Height;
|
||||||
} else {
|
} else {
|
||||||
if (IGUISkin* skin = Environment->getSkin()) {
|
if (IGUISkin* skin = Environment->getSkin()) {
|
||||||
if (IGUIFont* font = skin->getFont()) {
|
if (IGUIFont* font = skin->getFont()) {
|
||||||
@ -1520,7 +1414,7 @@ void intlGUIEditBox::updateVScrollBar()
|
|||||||
m_vscrollbar->setPageSize(s32(getTextDimension().Height));
|
m_vscrollbar->setPageSize(s32(getTextDimension().Height));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_vscrollbar->isVisible() && MultiLine) {
|
if (!m_vscrollbar->isVisible() && m_multiline) {
|
||||||
AbsoluteRect.LowerRightCorner.X -= m_scrollbar_width;
|
AbsoluteRect.LowerRightCorner.X -= m_scrollbar_width;
|
||||||
|
|
||||||
m_vscrollbar->setVisible(true);
|
m_vscrollbar->setVisible(true);
|
||||||
@ -1548,13 +1442,13 @@ void intlGUIEditBox::serializeAttributes(io::IAttributes* out, io::SAttributeRea
|
|||||||
{
|
{
|
||||||
// IGUIEditBox::serializeAttributes(out,options);
|
// IGUIEditBox::serializeAttributes(out,options);
|
||||||
|
|
||||||
out->addBool ("OverrideColorEnabled",OverrideColorEnabled );
|
out->addBool ("OverrideColorEnabled", m_override_color_enabled );
|
||||||
out->addColor ("OverrideColor", OverrideColor);
|
out->addColor ("OverrideColor", m_override_color);
|
||||||
// out->addFont("OverrideFont",OverrideFont);
|
// out->addFont("OverrideFont",m_override_font);
|
||||||
out->addInt ("MaxChars", Max);
|
out->addInt ("MaxChars", Max);
|
||||||
out->addBool ("WordWrap", WordWrap);
|
out->addBool ("WordWrap", m_word_wrap);
|
||||||
out->addBool ("MultiLine", MultiLine);
|
out->addBool ("MultiLine", m_multiline);
|
||||||
out->addBool ("AutoScroll", AutoScroll);
|
out->addBool ("AutoScroll", m_autoscroll);
|
||||||
out->addBool ("PasswordBox", PasswordBox);
|
out->addBool ("PasswordBox", PasswordBox);
|
||||||
core::stringw ch = L" ";
|
core::stringw ch = L" ";
|
||||||
ch[0] = PasswordChar;
|
ch[0] = PasswordChar;
|
||||||
|
@ -7,16 +7,15 @@
|
|||||||
#include "IrrCompileConfig.h"
|
#include "IrrCompileConfig.h"
|
||||||
//#ifdef _IRR_COMPILE_WITH_GUI_
|
//#ifdef _IRR_COMPILE_WITH_GUI_
|
||||||
|
|
||||||
#include <IGUIEditBox.h>
|
#include "guiEditBox.h"
|
||||||
#include "irrArray.h"
|
#include "irrArray.h"
|
||||||
#include "IOSOperator.h"
|
#include "IOSOperator.h"
|
||||||
#include "guiScrollBar.h"
|
|
||||||
|
|
||||||
namespace irr
|
namespace irr
|
||||||
{
|
{
|
||||||
namespace gui
|
namespace gui
|
||||||
{
|
{
|
||||||
class intlGUIEditBox : public IGUIEditBox
|
class intlGUIEditBox : public GUIEditBox
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -28,32 +27,6 @@ namespace gui
|
|||||||
//! destructor
|
//! destructor
|
||||||
virtual ~intlGUIEditBox();
|
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
|
//! Sets whether to draw the background
|
||||||
virtual void setDrawBackground(bool draw);
|
virtual void setDrawBackground(bool draw);
|
||||||
|
|
||||||
@ -64,30 +37,6 @@ namespace gui
|
|||||||
|
|
||||||
virtual bool isDrawBorderEnabled() const { return 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);
|
|
||||||
|
|
||||||
//! Checks if multi line editing is enabled
|
|
||||||
//! \return true if mult-line is enabled, false otherwise
|
|
||||||
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
|
|
||||||
virtual void setAutoScroll(bool enable);
|
|
||||||
|
|
||||||
//! Checks to see if automatic scrolling is enabled
|
|
||||||
//! \return true if automatic scrolling is enabled, false if not
|
|
||||||
virtual bool isAutoScrollEnabled() const;
|
|
||||||
|
|
||||||
//! Gets the size area of the text in the edit box
|
//! Gets the size area of the text in the edit box
|
||||||
//! \return Returns the size in pixels of the text
|
//! \return Returns the size in pixels of the text
|
||||||
virtual core::dimension2du getTextDimension();
|
virtual core::dimension2du getTextDimension();
|
||||||
@ -143,7 +92,7 @@ namespace gui
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Breaks the single text line.
|
//! Breaks the single text line.
|
||||||
void breakText();
|
virtual void breakText();
|
||||||
//! sets the area of the given line
|
//! sets the area of the given line
|
||||||
void setTextRect(s32 line);
|
void setTextRect(s32 line);
|
||||||
//! returns the line number that the cursor is on
|
//! returns the line number that the cursor is on
|
||||||
@ -169,12 +118,9 @@ namespace gui
|
|||||||
|
|
||||||
bool MouseMarking = false;
|
bool MouseMarking = false;
|
||||||
bool Border;
|
bool Border;
|
||||||
bool OverrideColorEnabled = false;
|
|
||||||
s32 MarkBegin = 0;
|
s32 MarkBegin = 0;
|
||||||
s32 MarkEnd = 0;
|
s32 MarkEnd = 0;
|
||||||
|
|
||||||
video::SColor OverrideColor = video::SColor(101,255,255,255);
|
|
||||||
gui::IGUIFont *OverrideFont = nullptr;
|
|
||||||
gui::IGUIFont *LastBreakFont = nullptr;
|
gui::IGUIFont *LastBreakFont = nullptr;
|
||||||
IOSOperator *Operator = nullptr;
|
IOSOperator *Operator = nullptr;
|
||||||
|
|
||||||
@ -184,9 +130,6 @@ namespace gui
|
|||||||
s32 VScrollPos = 0; // scroll position in characters
|
s32 VScrollPos = 0; // scroll position in characters
|
||||||
u32 Max = 0;
|
u32 Max = 0;
|
||||||
|
|
||||||
bool WordWrap = false;
|
|
||||||
bool MultiLine = false;
|
|
||||||
bool AutoScroll = true;
|
|
||||||
bool PasswordBox = false;
|
bool PasswordBox = false;
|
||||||
wchar_t PasswordChar = L'*';
|
wchar_t PasswordChar = L'*';
|
||||||
EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT;
|
EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT;
|
||||||
|
Loading…
Reference in New Issue
Block a user