Key repeat for text boxes
This commit is contained in:
parent
4ce22e4e77
commit
17e7ace364
@ -1,6 +1,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <time.h>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "interface/Point.h"
|
#include "interface/Point.h"
|
||||||
#include "interface/Textbox.h"
|
#include "interface/Textbox.h"
|
||||||
@ -16,7 +17,8 @@ Textbox::Textbox(Point position, Point size, std::string textboxText, std::strin
|
|||||||
border(true),
|
border(true),
|
||||||
mouseDown(false),
|
mouseDown(false),
|
||||||
limit(std::string::npos),
|
limit(std::string::npos),
|
||||||
inputType(All)
|
inputType(All),
|
||||||
|
keyDown(0)
|
||||||
{
|
{
|
||||||
placeHolder = textboxPlaceholder;
|
placeHolder = textboxPlaceholder;
|
||||||
|
|
||||||
@ -231,7 +233,31 @@ bool Textbox::CharacterValid(Uint16 character)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Textbox::Tick(float dt)
|
||||||
|
{
|
||||||
|
Label::Tick(dt);
|
||||||
|
if((keyDown || characterDown) && repeatTime <= clock())
|
||||||
|
{
|
||||||
|
OnVKeyPress(keyDown, characterDown, false, false, false);
|
||||||
|
repeatTime = clock()+(0.03 * CLOCKS_PER_SEC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Textbox::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
|
{
|
||||||
|
keyDown = 0;
|
||||||
|
characterDown = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
|
{
|
||||||
|
characterDown = character;
|
||||||
|
keyDown = key;
|
||||||
|
repeatTime = clock()+(0.3 * CLOCKS_PER_SEC);
|
||||||
|
OnVKeyPress(key, character, shift, ctrl, alt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
if(ctrl && key == 'c' && !masked)
|
if(ctrl && key == 'c' && !masked)
|
||||||
|
@ -44,16 +44,22 @@ public:
|
|||||||
//Determines if the given character is valid given the input type
|
//Determines if the given character is valid given the input type
|
||||||
bool CharacterValid(Uint16 character);
|
bool CharacterValid(Uint16 character);
|
||||||
|
|
||||||
|
virtual void Tick(float dt);
|
||||||
virtual void OnContextMenuAction(int item);
|
virtual void OnContextMenuAction(int item);
|
||||||
virtual void OnMouseClick(int x, int y, unsigned button);
|
virtual void OnMouseClick(int x, int y, unsigned button);
|
||||||
virtual void OnMouseUp(int x, int y, unsigned button);
|
virtual void OnMouseUp(int x, int y, unsigned button);
|
||||||
virtual void OnMouseMoved(int localx, int localy, int dx, int dy);
|
virtual void OnMouseMoved(int localx, int localy, int dx, int dy);
|
||||||
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
virtual void OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
virtual void Draw(const Point& screenPos);
|
virtual void Draw(const Point& screenPos);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ValidInput inputType;
|
ValidInput inputType;
|
||||||
size_t limit;
|
size_t limit;
|
||||||
|
int repeatTime;
|
||||||
|
int keyDown;
|
||||||
|
Uint16 characterDown;
|
||||||
bool mouseDown;
|
bool mouseDown;
|
||||||
bool masked, border;
|
bool masked, border;
|
||||||
int cursor, cursorPositionX, cursorPositionY;
|
int cursor, cursorPositionX, cursorPositionY;
|
||||||
|
Reference in New Issue
Block a user