1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14// Code by: Jeremy Moles (cubicool) 2007-2008
16#ifndef OSGWIDGET_INPUT
17#define OSGWIDGET_INPUT
19#include <osgWidget/Label>
23// This is a string of values we use to try and determine the best Y
24// descent value (yoffset); you're welcome to use what works best for
26const std::string DESCENT_STRING("qpl");
28class OSGWIDGET_EXPORT Input: public Label
32 Input(const std::string& = "", const std::string& = "", unsigned int = 20);
34 virtual void parented (Window*);
35 virtual void positioned ();
37 virtual bool focus (const WindowManager*);
38 virtual bool unfocus (const WindowManager*);
39 virtual bool keyUp (int, int, const WindowManager*);
40 virtual bool keyDown (int, int, const WindowManager*);
41 virtual bool mouseDrag (double, double, const WindowManager*);
42 virtual bool mousePush (double x, double y, const WindowManager*);
43 virtual bool mouseRelease (double, double, const WindowManager*);
45 void setCursor (Widget*);
46 unsigned int calculateBestYOffset (const std::string& = "qgl");
49 void setXOffset(point_type xo) {
53 void setYOffset(point_type yo) {
57 void setXYOffset(point_type xo, point_type yo) {
62 osg::Drawable* getCursor() {
66 const osg::Drawable* getCursor() const {
70 point_type getXOffset() const {
74 point_type getYOffset() const {
78 XYCoord getXYOffset() const {
79 return XYCoord(_xoff, _yoff);
83 virtual void _calculateSize(const XYCoord&);
85 void _calculateCursorOffsets();
92 unsigned int _cursorIndex;
93 unsigned int _maxSize;
95 std::vector<point_type> _offsets;
96 std::vector<unsigned int> _wordsOffsets;
97 std::vector<point_type> _widths;
98 osg::ref_ptr<Widget> _cursor;
100 bool _insertMode; // Insert was pressed --> true --> typing will overwrite existing text
102 osg::ref_ptr<Widget> _selection;
103 unsigned int _selectionStartIndex;
104 unsigned int _selectionEndIndex;
105 unsigned int _selectionIndex;
107 point_type _mouseClickX;