osgWidget/Input
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library 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
* OpenSceneGraph Public License for more details.
*/
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_INPUT
#define OSGWIDGET_INPUT
#include <osgWidget/Label>
namespace osgWidget {
// This is a string of values we use to try and determine the best Y
// descent value (yoffset); you're welcome to use what works best for
// your font.
const std::string DESCENT_STRING("qpl");
class OSGWIDGET_EXPORT Input: public Label
{
public:
Input(const std::string& = "", const std::string& = "", unsigned int = 20);
virtual void parented (Window*);
virtual void positioned ();
virtual bool focus (const WindowManager*);
virtual bool unfocus (const WindowManager*);
virtual bool keyUp (int, int, const WindowManager*);
virtual bool keyDown (int, int, const WindowManager*);
virtual bool mouseDrag (double, double, const WindowManager*);
virtual bool mousePush (double x, double y, const WindowManager*);
virtual bool mouseRelease (double, double, const WindowManager*);
void setCursor (Widget*);
unsigned int calculateBestYOffset (const std::string& = "qgl");
void clear();
void setXOffset(point_type xo) {
_xoff = xo;
}
void setYOffset(point_type yo) {
_yoff = yo;
}
void setXYOffset(point_type xo, point_type yo) {
_xoff = xo;
_yoff = yo;
}
osg::Drawable* getCursor() {
return _cursor.get();
}
const osg::Drawable* getCursor() const {
return _cursor.get();
}
point_type getXOffset() const {
return _xoff;
}
point_type getYOffset() const {
return _yoff;
}
XYCoord getXYOffset() const {
return XYCoord(_xoff, _yoff);
}
protected:
virtual void _calculateSize(const XYCoord&);
void _calculateCursorOffsets();
point_type _xoff;
point_type _yoff;
unsigned int _index;
unsigned int _size;
unsigned int _cursorIndex;
unsigned int _maxSize;
std::vector<point_type> _offsets;
std::vector<unsigned int> _wordsOffsets;
std::vector<point_type> _widths;
osg::ref_ptr<Widget> _cursor;
bool _insertMode; // Insert was pressed --> true --> typing will overwrite existing text
osg::ref_ptr<Widget> _selection;
unsigned int _selectionStartIndex;
unsigned int _selectionEndIndex;
unsigned int _selectionIndex;
point_type _mouseClickX;
};
}
#endif
osgWidget::Input::_widths
std::vector< point_type > _widths
Definition osgWidget/Input:97
osgWidget::Input::setXOffset
void setXOffset(point_type xo)
Definition osgWidget/Input:49
osgWidget::Input::calculateBestYOffset
unsigned int calculateBestYOffset(const std::string &="qgl")
osgWidget::Input::keyDown
virtual bool keyDown(int, int, const WindowManager *)
osgWidget::Input::_index
unsigned int _index
Definition osgWidget/Input:90
osgWidget::Input::_offsets
std::vector< point_type > _offsets
Definition osgWidget/Input:95
osgWidget::Input::unfocus
virtual bool unfocus(const WindowManager *)
osgWidget::Input::parented
virtual void parented(Window *)
osgWidget::Input::positioned
virtual void positioned()
osgWidget::Input::_calculateSize
virtual void _calculateSize(const XYCoord &)
osgWidget::Input::_selectionEndIndex
unsigned int _selectionEndIndex
Definition osgWidget/Input:104
osgWidget::Input::getXYOffset
XYCoord getXYOffset() const
Definition osgWidget/Input:78
osgWidget::Input::getCursor
const osg::Drawable * getCursor() const
Definition osgWidget/Input:66
osgWidget::Input::getXOffset
point_type getXOffset() const
Definition osgWidget/Input:70
osgWidget::Input::mouseRelease
virtual bool mouseRelease(double, double, const WindowManager *)
osgWidget::Input::_mouseClickX
point_type _mouseClickX
Definition osgWidget/Input:107
osgWidget::Input::_wordsOffsets
std::vector< unsigned int > _wordsOffsets
Definition osgWidget/Input:96
osgWidget::Input::_selection
osg::ref_ptr< Widget > _selection
Definition osgWidget/Input:102
osgWidget::Input::_selectionStartIndex
unsigned int _selectionStartIndex
Definition osgWidget/Input:103
osgWidget::Input::setYOffset
void setYOffset(point_type yo)
Definition osgWidget/Input:53
osgWidget::Input::_cursor
osg::ref_ptr< Widget > _cursor
Definition osgWidget/Input:98
osgWidget::Input::keyUp
virtual bool keyUp(int, int, const WindowManager *)
osgWidget::Input::mouseDrag
virtual bool mouseDrag(double, double, const WindowManager *)
osgWidget::Input::_selectionIndex
unsigned int _selectionIndex
Definition osgWidget/Input:105
osgWidget::Input::_size
unsigned int _size
Definition osgWidget/Input:91
osgWidget::Input::getYOffset
point_type getYOffset() const
Definition osgWidget/Input:74
osgWidget::Input::setXYOffset
void setXYOffset(point_type xo, point_type yo)
Definition osgWidget/Input:57
osgWidget::Input::_cursorIndex
unsigned int _cursorIndex
Definition osgWidget/Input:92
osgWidget::Input::_maxSize
unsigned int _maxSize
Definition osgWidget/Input:93
osgWidget::Input::focus
virtual bool focus(const WindowManager *)
osgWidget::Input::_xoff
point_type _xoff
Definition osgWidget/Input:87
osgWidget::Input::setCursor
void setCursor(Widget *)
osgWidget::Input::clear
void clear()
osgWidget::Input::Input
Input(const std::string &="", const std::string &="", unsigned int=20)
osgWidget::Input::getCursor
osg::Drawable * getCursor()
Definition osgWidget/Input:62
osgWidget::Input::mousePush
virtual bool mousePush(double x, double y, const WindowManager *)
osgWidget::Input::_calculateCursorOffsets
void _calculateCursorOffsets()
osgWidget::Input::_insertMode
bool _insertMode
Definition osgWidget/Input:100
osgWidget::Input::_yoff
point_type _yoff
Definition osgWidget/Input:88
osgWidget::Label::Label
Label(const std::string &="", const std::string &="")
osgWidget::Widget
Definition osgWidget/Widget:35
osgWidget::WindowManager
Definition WindowManager:39
osgWidget::Window
Definition Window:44
osg::Drawable
Definition Drawable:89
osg::ref_ptr
Definition ref_ptr:32
osgWidget
Definition Box:21
osgWidget::point_type
Point::value_type point_type
Definition osgWidget/Types:33
osgWidget::XYCoord
osg::Vec2 XYCoord
Definition osgWidget/Types:36
osgWidget::DESCENT_STRING
const std::string DESCENT_STRING("qpl")
OSGWIDGET_EXPORT
#define OSGWIDGET_EXPORT
Definition osgWidget/Export:42
Label