metaforce/specter/include/Specter/TextField.hpp

140 lines
4.1 KiB
C++
Raw Normal View History

2015-11-21 01:14:49 +00:00
#ifndef SPECTER_TEXTFIELD_HPP
#define SPECTER_TEXTFIELD_HPP
2015-12-18 03:26:10 +00:00
#include "Control.hpp"
2015-12-17 21:28:37 +00:00
#include "TextView.hpp"
2015-12-27 22:42:45 +00:00
#include <boo/IWindow.hpp>
namespace Specter
{
2015-12-27 22:42:45 +00:00
class TextField : public ITextInputView
{
2015-12-27 22:42:45 +00:00
bool m_hasTextSet = false;
bool m_hasMarkSet = false;
2015-12-17 21:28:37 +00:00
std::string m_textStr;
2015-12-27 22:42:45 +00:00
std::string m_deferredTextStr;
std::string m_deferredMarkStr;
2015-12-17 21:28:37 +00:00
std::unique_ptr<TextView> m_text;
std::unique_ptr<TextView> m_errText;
2015-12-17 21:28:37 +00:00
SolidShaderVert m_verts[41];
VertexBufferBinding m_vertsBinding;
2015-12-17 21:28:37 +00:00
int m_nomWidth = 0;
int m_nomHeight = 0;
2015-12-27 22:42:45 +00:00
bool m_hasSelectionClear = false;
bool m_hasSelectionSet = false;
bool m_hasCursorSet = false;
2015-12-20 04:39:09 +00:00
size_t m_selectionStart = 0;
2015-12-27 22:42:45 +00:00
size_t m_deferredSelectionStart = 0;
2015-12-20 04:39:09 +00:00
size_t m_selectionCount = 0;
2015-12-27 22:42:45 +00:00
size_t m_deferredSelectionCount = 0;
size_t m_markReplStart = 0;
size_t m_deferredMarkReplStart = 0;
size_t m_markReplCount = 0;
size_t m_deferredMarkReplCount = 0;
size_t m_markSelStart = 0;
size_t m_deferredMarkSelStart = 0;
size_t m_markSelCount = 0;
size_t m_deferredMarkSelCount = 0;
2015-12-20 04:39:09 +00:00
size_t m_cursorPos = 0;
2015-12-27 22:42:45 +00:00
size_t m_deferredCursorPos = SIZE_MAX;
2015-12-20 04:39:09 +00:00
size_t m_cursorFrames = 0;
2015-12-20 21:59:23 +00:00
size_t m_clickFrames = 15;
size_t m_clickFrames2 = 15;
size_t m_errorFrames = 360;
2015-12-20 21:59:23 +00:00
size_t m_dragStart = 0;
size_t m_dragging = 0;
2015-12-20 04:39:09 +00:00
bool m_active = false;
bool m_error = false;
2015-12-20 04:39:09 +00:00
enum class BGState
{
Inactive,
Hover,
Disabled
} m_bgState = BGState::Inactive;
2015-12-17 21:28:37 +00:00
void setInactive();
void setHover();
void setDisabled();
void refreshBg();
2015-12-17 21:28:37 +00:00
public:
2015-12-18 03:26:10 +00:00
TextField(ViewResources& res, View& parentView, IStringBinding* strBind);
2015-12-17 21:28:37 +00:00
2015-12-20 04:39:09 +00:00
const std::string& getText() const {return m_textStr;}
2015-12-17 21:28:37 +00:00
void setText(const std::string& str);
2015-12-24 03:32:00 +00:00
void clipboardCopy();
2015-12-28 00:24:29 +00:00
void clipboardCut();
2015-12-24 03:32:00 +00:00
void clipboardPaste();
2015-12-17 21:28:37 +00:00
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseMove(const boo::SWindowCoord&);
void mouseEnter(const boo::SWindowCoord&);
2015-12-20 04:39:09 +00:00
void mouseLeave(const boo::SWindowCoord&);
void specialKeyDown(boo::ESpecialKey, boo::EModifierKey, bool);
2015-12-27 22:42:45 +00:00
bool hasMarkedText() const;
std::pair<int,int> markedRange() const;
std::pair<int,int> selectedRange() const;
void setMarkedText(const std::string& str,
const std::pair<int,int>& selectedRange,
const std::pair<int,int>& replacementRange);
void unmarkText();
std::string substringForRange(const std::pair<int,int>& range,
std::pair<int,int>& actualRange) const;
void insertText(const std::string& str, const std::pair<int,int>& range);
int characterIndexAtPoint(const boo::SWindowCoord& point) const;
boo::SWindowRect rectForCharacterRange(const std::pair<int,int>& range,
std::pair<int,int>& actualRange) const;
2015-12-20 04:39:09 +00:00
void think();
2015-12-17 21:28:37 +00:00
void resized(const boo::SWindowRect& rootView, const boo::SWindowRect& sub);
void draw(boo::IGraphicsCommandQueue* gfxQ);
int nominalWidth() const {return m_nomWidth;}
int nominalHeight() const {return m_nomHeight;}
2015-12-20 04:39:09 +00:00
void setActive(bool active);
void setCursorPos(size_t pos);
void setErrorState(const std::string& message);
void clearErrorState();
2015-12-20 04:39:09 +00:00
void setSelectionRange(size_t start, size_t count);
void clearSelectionRange();
2015-12-17 21:28:37 +00:00
void setMultiplyColor(const Zeus::CColor& color)
{
View::setMultiplyColor(color);
m_viewVertBlock.m_color = color;
m_viewVertBlockBuf->load(&m_viewVertBlock, sizeof(ViewBlock));
m_text->setMultiplyColor(color);
if (m_errText)
m_errText->setMultiplyColor(color);
2015-12-17 21:28:37 +00:00
}
2015-12-27 22:42:45 +00:00
private:
void _setCursorPos();
void _reallySetCursorPos(size_t pos);
void _setSelectionRange();
void _reallySetSelectionRange(size_t start, size_t len);
void _reallySetMarkRange(size_t start, size_t len);
void _clearSelectionRange();
void _setText();
void _setMarkedText();
};
}
2015-11-21 01:14:49 +00:00
#endif // SPECTER_TEXTFIELD_HPP