This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
The-Powder-Toy/src/gui/interface/Textbox.h
jacob1 e5230b5b9f upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work

... and maybe others

Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-05-25 21:19:44 -04:00

85 lines
2.2 KiB
C++

#ifndef TEXTBOX_H
#define TEXTBOX_H
#include "common/String.h"
#include "Label.h"
#include "PowderToy.h"
namespace ui
{
class Textbox;
class TextboxAction
{
public:
virtual void TextChangedCallback(ui::Textbox * sender) {}
virtual ~TextboxAction() {}
};
class Textbox : public Label
{
friend class TextboxAction;
void AfterTextChange(bool changed);
public:
bool ReadOnly;
enum ValidInput { All, Multiline, Numeric, Number }; // Numeric doesn't delete trailing 0's
Textbox(Point position, Point size, String textboxText = String(), String textboxPlaceholder = String());
virtual ~Textbox();
virtual void SetText(String text);
virtual String GetText();
virtual void SetPlaceholder(String text);
void SetBorder(bool border) { this->border = border; }
void SetHidden(bool hidden);
bool GetHidden() { return masked; }
void SetActionCallback(TextboxAction * action) { actionCallback = action; }
void SetLimit(size_t limit);
size_t GetLimit();
ValidInput GetInputType();
void SetInputType(ValidInput input);
void resetCursorPosition();
void TabFocus();
//Determines if the given character is valid given the input type
bool CharacterValid(int character);
bool StringValid(String text);
virtual void Tick(float dt);
virtual void OnContextMenuAction(int item);
virtual void OnMouseClick(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 OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt);
virtual void OnVKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt);
virtual void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt);
void OnTextInput(String text) override;
virtual void Draw(const Point& screenPos);
protected:
ValidInput inputType;
size_t limit;
unsigned long repeatTime;
int keyDown;
Uint16 characterDown;
bool mouseDown;
bool masked, border;
int cursor, cursorPositionX, cursorPositionY;
TextboxAction *actionCallback;
String backingText;
String placeHolder;
virtual void cutSelection();
virtual void pasteIntoSelection();
};
}
#endif // TEXTBOX_H