// Copyright (C) 2002-2012 Nikolaus Gebhardt
// Modified by Mustapha T.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "guiEditBoxWithScrollbar.h"
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IGUIFont.h"
#include "IVideoDriver.h"
#include "rect.h"
#include "porting.h"
#include "Keycodes.h"
/*
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
*/
//! 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)
{
#ifdef _DEBUG
setDebugName("GUIEditBoxWithScrollBar");
#endif
Text = text;
if (Environment)
m_operator = Environment->getOSOperator();
if (m_operator)
m_operator->grab();
// this element can be tabbed to
setTabStop(true);
setTabOrder(-1);
if (has_vscrollbar) {
createVScrollBar();
}
calculateFrameRect();
breakText();
calculateScrollPos();
setWritable(writable);
}
//! destructor
GUIEditBoxWithScrollBar::~GUIEditBoxWithScrollBar()
{
if (m_override_font)
m_override_font->drop();
if (m_operator)
m_operator->drop();
m_vscrollbar->remove();
}
//! 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
void GUIEditBoxWithScrollBar::setDrawBorder(bool border)
{
m_border = border;
}
//! Sets whether to draw the background
void GUIEditBoxWithScrollBar::setDrawBackground(bool draw)
{
m_background = draw;
}
//! Sets if the text should use the overide color or the color in the gui skin.
|