From Jean-Sebastien Guay, "osgWidget::WindowManager did nothing in its keyUp event, and in particular didn't call any callbacks. Since I wanted to have callbacks on keyUp, I copied what it does on keyDown, which works for me. I could have just used keyDown and saved myself the trouble, but you know me... :-)
osgWidget::Input:
[Functional changes]
- Previously, the field would be filled with spaces up to its max length, and typing would just replace the spaces. Also, there was a _textLength variable that kept track of the real length of text in the field, since the osgText::Text's length just reflected the length of spaces+text entered. This was not great, as you could still select the spaces with the mouse and it just feels hacky. So I changed it to only contain the text entered, no spaces, and _textLength was removed since it's now redundant (the osgText::Text's length is used instead).
- Fixed the selection size which (visually only) showed one more character selected than what was really selected.
- Fixed selection by dragging the mouse, it would sometimes not select the last character of the string.
- Cursor will now accurately reflect whether insert mode is activated (block cursor) or we're in normal mode (line cursor) like in most editors.
- Implemented Ctrl-X (cut)
- Added a new clear() method that allows the field to be emptied correctly. Useful for a command line interface, for example (hint, hint).
- Mouse and keyboard event handler methods would always return false, which meant selecting with the mouse would also rotate the trackball, and typing an 's' would turn on stats.
[Code cleanup]
- Renamed the (local) _selectionMin and _selectionMax variables which are used in a lot of places, as the underscores would lead to think they were members. Either I called them selection{Min|Max} or delete{Min|Max} where it made more sense.
- Fixed some indenting which was at 3 spaces (inconsistently), I'm sure I didn't catch all the lines where this was the case though.
- Put spaces between variable, operator and value where missing, especially in for()s. Again I only did this where I made changes, there are probably others left.
The result is that delete, backspace, Ctrl-X, Ctrl-C, Ctrl-V, and typing behaviour should now be consistent with text editor conventions, whether insert mode is enabled or not. I hope. :-)
Note, there's a nasty const_cast in there. Why isn't osgText::Font::getGlyph() declared const?
Also, as a note, the current implementation of cut, copy and paste (in addition to being Windows only, yuck) gets and puts the data into an std::string, thus if the osgText::String in the field contains unicode characters I think it won't work correctly. Perhaps someone could implement a proper clipboard class that would be cross-platform and support osgText::String (more precisely other languages like Chinese) correctly? Cut, copy and paste are not critical to what I'm doing so I won't invest the time to do that, but I just thought I'd mention it.
"
This commit is contained in:
@@ -25,53 +25,53 @@ namespace osgDB
|
||||
#define OSG_HEADER_HIGH 0x1AFB4545
|
||||
|
||||
// Reader/writer plugin version
|
||||
#define PLUGIN_VERSION 2
|
||||
const unsigned int PLUGIN_VERSION = 2;
|
||||
|
||||
#define BOOL_SIZE 1
|
||||
#define CHAR_SIZE 1
|
||||
#define SHORT_SIZE 2
|
||||
#define INT_SIZE 4
|
||||
#define LONG_SIZE 4
|
||||
#define FLOAT_SIZE 4
|
||||
#define DOUBLE_SIZE 8
|
||||
#define GLENUM_SIZE 4
|
||||
const int BOOL_SIZE = 1;
|
||||
const int CHAR_SIZE = 1;
|
||||
const int SHORT_SIZE = 2;
|
||||
const int INT_SIZE = 4;
|
||||
const int LONG_SIZE = 4;
|
||||
const int FLOAT_SIZE = 4;
|
||||
const int DOUBLE_SIZE = 8;
|
||||
const int GLENUM_SIZE = 4;
|
||||
|
||||
#define ID_BYTE_ARRAY 0
|
||||
#define ID_UBYTE_ARRAY 1
|
||||
#define ID_SHORT_ARRAY 2
|
||||
#define ID_USHORT_ARRAY 3
|
||||
#define ID_INT_ARRAY 4
|
||||
#define ID_UINT_ARRAY 5
|
||||
#define ID_FLOAT_ARRAY 6
|
||||
#define ID_DOUBLE_ARRAY 7
|
||||
#define ID_VEC2B_ARRAY 8
|
||||
#define ID_VEC3B_ARRAY 9
|
||||
#define ID_VEC4B_ARRAY 10
|
||||
#define ID_VEC4UB_ARRAY 11
|
||||
#define ID_VEC2S_ARRAY 12
|
||||
#define ID_VEC3S_ARRAY 13
|
||||
#define ID_VEC4S_ARRAY 14
|
||||
#define ID_VEC2_ARRAY 15
|
||||
#define ID_VEC3_ARRAY 16
|
||||
#define ID_VEC4_ARRAY 17
|
||||
#define ID_VEC2D_ARRAY 18
|
||||
#define ID_VEC3D_ARRAY 19
|
||||
#define ID_VEC4D_ARRAY 20
|
||||
const int ID_BYTE_ARRAY = 0;
|
||||
const int ID_UBYTE_ARRAY = 1;
|
||||
const int ID_SHORT_ARRAY = 2;
|
||||
const int ID_USHORT_ARRAY = 3;
|
||||
const int ID_INT_ARRAY = 4;
|
||||
const int ID_UINT_ARRAY = 5;
|
||||
const int ID_FLOAT_ARRAY = 6;
|
||||
const int ID_DOUBLE_ARRAY = 7;
|
||||
const int ID_VEC2B_ARRAY = 8;
|
||||
const int ID_VEC3B_ARRAY = 9;
|
||||
const int ID_VEC4B_ARRAY = 10;
|
||||
const int ID_VEC4UB_ARRAY = 11;
|
||||
const int ID_VEC2S_ARRAY = 12;
|
||||
const int ID_VEC3S_ARRAY = 13;
|
||||
const int ID_VEC4S_ARRAY = 14;
|
||||
const int ID_VEC2_ARRAY = 15;
|
||||
const int ID_VEC3_ARRAY = 16;
|
||||
const int ID_VEC4_ARRAY = 17;
|
||||
const int ID_VEC2D_ARRAY = 18;
|
||||
const int ID_VEC3D_ARRAY = 19;
|
||||
const int ID_VEC4D_ARRAY = 20;
|
||||
|
||||
#define ID_DRAWARRAYS 50
|
||||
#define ID_DRAWARRAY_LENGTH 51
|
||||
#define ID_DRAWELEMENTS_UBYTE 52
|
||||
#define ID_DRAWELEMENTS_USHORT 53
|
||||
#define ID_DRAWELEMENTS_UINT 54
|
||||
const int ID_DRAWARRAYS = 50;
|
||||
const int ID_DRAWARRAY_LENGTH = 51;
|
||||
const int ID_DRAWELEMENTS_UBYTE = 52;
|
||||
const int ID_DRAWELEMENTS_USHORT = 53;
|
||||
const int ID_DRAWELEMENTS_UINT = 54;
|
||||
|
||||
// Used by BEGIN_BRACKET and END_BRACKET
|
||||
#define INDENT_VALUE 2
|
||||
const int INDENT_VALUE = 2;
|
||||
|
||||
// Used by the writeImage/readImage parameter
|
||||
#define IMAGE_INLINE_DATA 0
|
||||
#define IMAGE_INLINE_FILE 1
|
||||
#define IMAGE_EXTERNAL 2
|
||||
#define IMAGE_WRITE_OUT 3
|
||||
const int IMAGE_INLINE_DATA = 0;
|
||||
const int IMAGE_INLINE_FILE = 1;
|
||||
const int IMAGE_EXTERNAL = 2;
|
||||
const int IMAGE_WRITE_OUT = 3;
|
||||
|
||||
struct ObjectGLenum
|
||||
{
|
||||
|
||||
@@ -27,83 +27,84 @@ const std::string DESCENT_STRING("qpl");
|
||||
|
||||
class OSGWIDGET_EXPORT Input: public Label
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
Input(const std::string& = "", const std::string& = "", unsigned int = 20);
|
||||
Input(const std::string& = "", const std::string& = "", unsigned int = 20);
|
||||
|
||||
virtual void parented (Window*);
|
||||
virtual void positioned ();
|
||||
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 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 setCursor (Widget*);
|
||||
unsigned int calculateBestYOffset (const std::string& = "qgl");
|
||||
void clear();
|
||||
|
||||
void setXOffset(point_type xo) {
|
||||
_xoff = xo;
|
||||
}
|
||||
void setXOffset(point_type xo) {
|
||||
_xoff = xo;
|
||||
}
|
||||
|
||||
void setYOffset(point_type yo) {
|
||||
_yoff = yo;
|
||||
}
|
||||
void setYOffset(point_type yo) {
|
||||
_yoff = yo;
|
||||
}
|
||||
|
||||
void setXYOffset(point_type xo, point_type yo) {
|
||||
_xoff = xo;
|
||||
_yoff = yo;
|
||||
}
|
||||
void setXYOffset(point_type xo, point_type yo) {
|
||||
_xoff = xo;
|
||||
_yoff = yo;
|
||||
}
|
||||
|
||||
osg::Drawable* getCursor() {
|
||||
return _cursor.get();
|
||||
}
|
||||
osg::Drawable* getCursor() {
|
||||
return _cursor.get();
|
||||
}
|
||||
|
||||
const osg::Drawable* getCursor() const {
|
||||
return _cursor.get();
|
||||
}
|
||||
const osg::Drawable* getCursor() const {
|
||||
return _cursor.get();
|
||||
}
|
||||
|
||||
point_type getXOffset() const {
|
||||
return _xoff;
|
||||
}
|
||||
point_type getXOffset() const {
|
||||
return _xoff;
|
||||
}
|
||||
|
||||
point_type getYOffset() const {
|
||||
return _yoff;
|
||||
}
|
||||
point_type getYOffset() const {
|
||||
return _yoff;
|
||||
}
|
||||
|
||||
XYCoord getXYOffset() const {
|
||||
return XYCoord(_xoff, _yoff);
|
||||
}
|
||||
XYCoord getXYOffset() const {
|
||||
return XYCoord(_xoff, _yoff);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _calculateSize(const XYCoord&);
|
||||
protected:
|
||||
virtual void _calculateSize(const XYCoord&);
|
||||
|
||||
void _calculateCursorOffsets();
|
||||
void _calculateCursorOffsets();
|
||||
|
||||
point_type _xoff;
|
||||
point_type _yoff;
|
||||
point_type _xoff;
|
||||
point_type _yoff;
|
||||
|
||||
unsigned int _index;
|
||||
unsigned int _size;
|
||||
unsigned int _cursorIndex;
|
||||
unsigned int _maxSize;
|
||||
unsigned int _textLength;
|
||||
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;
|
||||
std::vector<point_type> _offsets;
|
||||
std::vector<unsigned int> _wordsOffsets;
|
||||
std::vector<point_type> _widths;
|
||||
osg::ref_ptr<Widget> _cursor;
|
||||
|
||||
bool _insertMode;
|
||||
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;
|
||||
osg::ref_ptr<Widget> _selection;
|
||||
unsigned int _selectionStartIndex;
|
||||
unsigned int _selectionEndIndex;
|
||||
unsigned int _selectionIndex;
|
||||
|
||||
point_type _mouseClickX;
|
||||
point_type _mouseClickX;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user