mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-17 20:45:23 +00:00
Work on TextField
This commit is contained in:
@@ -60,7 +60,13 @@ public:
|
||||
void mouseMove(const boo::SWindowCoord&);
|
||||
void mouseEnter(const boo::SWindowCoord&);
|
||||
void mouseLeave(const boo::SWindowCoord&);
|
||||
void scroll(const boo::SWindowCoord&, const boo::SScrollDelta&);
|
||||
void touchDown(const boo::STouchCoord&, uintptr_t);
|
||||
void touchUp(const boo::STouchCoord&, uintptr_t);
|
||||
void touchMove(const boo::STouchCoord&, uintptr_t);
|
||||
|
||||
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
|
||||
void think();
|
||||
void draw(boo::IGraphicsCommandQueue* gfxQ);
|
||||
};
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ class ModalWindow : public View
|
||||
|
||||
int m_width = 0;
|
||||
int m_height = 0;
|
||||
int m_widthConstrain;
|
||||
int m_heightConstrain;
|
||||
RectangleConstraint m_constraint;
|
||||
|
||||
Zeus::CColor m_windowBg;
|
||||
Zeus::CColor m_windowBgClear;
|
||||
@@ -57,7 +56,7 @@ protected:
|
||||
virtual void updateContentOpacity(float opacity) {}
|
||||
|
||||
public:
|
||||
ModalWindow(ViewResources& res, View& parentView, int widthConstrain=-1, int heightConstrain=-1);
|
||||
ModalWindow(ViewResources& res, View& parentView, const RectangleConstraint& constraint);
|
||||
void think();
|
||||
bool skipBuildInAnimation();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "View.hpp"
|
||||
#include "ViewResources.hpp"
|
||||
#include "MultiLineTextView.hpp"
|
||||
#include "TextField.hpp"
|
||||
#include "SplitView.hpp"
|
||||
#include "Tooltip.hpp"
|
||||
#include "FontCache.hpp"
|
||||
@@ -26,6 +27,7 @@ class RootView : public View
|
||||
bool m_destroyed = false;
|
||||
IViewManager& m_viewMan;
|
||||
ViewResources* m_viewRes;
|
||||
View* m_activeTextView = nullptr;
|
||||
|
||||
DeferredWindowEvents<RootView> m_events;
|
||||
|
||||
@@ -64,6 +66,13 @@ public:
|
||||
const ThemeData& themeData() const {return m_viewRes->m_theme;}
|
||||
|
||||
View* setContentView(View* view);
|
||||
void setActiveTextView(View* textView)
|
||||
{
|
||||
if (m_activeTextView)
|
||||
m_activeTextView->setActive(false);
|
||||
m_activeTextView = textView;
|
||||
textView->setActive(true);
|
||||
}
|
||||
|
||||
void resetTooltip(ViewResources& res);
|
||||
void displayTooltip(const std::string& name, const std::string& help);
|
||||
|
||||
@@ -12,7 +12,7 @@ class TextField : public Control
|
||||
std::string m_textStr;
|
||||
std::unique_ptr<TextView> m_text;
|
||||
|
||||
SolidShaderVert m_verts[28];
|
||||
SolidShaderVert m_verts[32];
|
||||
boo::IGraphicsBufferD* m_bVertsBuf = nullptr;
|
||||
boo::IVertexFormat* m_bVtxFmt = nullptr; /* OpenGL only */
|
||||
boo::IShaderDataBinding* m_bShaderBinding = nullptr;
|
||||
@@ -20,6 +20,13 @@ class TextField : public Control
|
||||
int m_nomWidth = 0;
|
||||
int m_nomHeight = 0;
|
||||
|
||||
size_t m_selectionStart = 0;
|
||||
size_t m_selectionCount = 0;
|
||||
size_t m_cursorPos = 0;
|
||||
size_t m_cursorFrames = 0;
|
||||
|
||||
bool m_active = false;
|
||||
|
||||
void setInactive();
|
||||
void setHover();
|
||||
void setDisabled();
|
||||
@@ -27,19 +34,29 @@ class TextField : public Control
|
||||
public:
|
||||
TextField(ViewResources& res, View& parentView, IStringBinding* strBind);
|
||||
|
||||
const std::string& getText() const {return m_textStr;}
|
||||
void setText(const std::string& str);
|
||||
|
||||
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&);
|
||||
void mouseLeave(const boo::SWindowCoord&coord);
|
||||
void mouseLeave(const boo::SWindowCoord&);
|
||||
void charKeyDown(unsigned long, boo::EModifierKey, bool);
|
||||
void specialKeyDown(boo::ESpecialKey, boo::EModifierKey, bool);
|
||||
void think();
|
||||
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;}
|
||||
|
||||
void setActive(bool active);
|
||||
void setCursorPos(size_t pos);
|
||||
|
||||
void setSelectionRange(size_t start, size_t count);
|
||||
void clearSelectionRange();
|
||||
|
||||
void setMultiplyColor(const Zeus::CColor& color)
|
||||
{
|
||||
View::setMultiplyColor(color);
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
RenderGlyph(int& adv, const FontAtlas::Glyph& glyph, const Zeus::CColor& defaultColor);
|
||||
};
|
||||
std::vector<RenderGlyph>& accessGlyphs() {return m_glyphs;}
|
||||
const std::vector<RenderGlyph>& accessGlyphs() const {return m_glyphs;}
|
||||
void updateGlyphs() {m_valid = false;}
|
||||
|
||||
void typesetGlyphs(const std::string& str,
|
||||
@@ -85,10 +86,13 @@ public:
|
||||
int nominalHeight() const {return m_fontAtlas.FT_LineHeight() >> 6;}
|
||||
|
||||
std::pair<int,int> queryGlyphDimensions(size_t pos) const;
|
||||
size_t reverseSelectGlyph(int x) const;
|
||||
int queryReverseAdvance(size_t idx) const;
|
||||
|
||||
private:
|
||||
std::vector<RenderGlyph> m_glyphs;
|
||||
std::vector<std::pair<int,int>> m_glyphDims;
|
||||
std::vector<int> m_glyphAdvs;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,65 @@ class ThemeData;
|
||||
class ViewResources;
|
||||
class RootView;
|
||||
|
||||
class RectangleConstraint
|
||||
{
|
||||
public:
|
||||
enum class Test
|
||||
{
|
||||
Fixed,
|
||||
Minimum,
|
||||
Maximum
|
||||
};
|
||||
private:
|
||||
int m_x, m_y;
|
||||
Test m_xtest, m_ytest;
|
||||
public:
|
||||
RectangleConstraint(int x=-1, int y=-1, Test xtest=Test::Fixed, Test ytest=Test::Fixed)
|
||||
: m_x(x), m_y(y), m_xtest(xtest), m_ytest(ytest) {}
|
||||
std::pair<int,int> solve(int x, int y) const
|
||||
{
|
||||
std::pair<int,int> ret;
|
||||
|
||||
if (m_x < 0)
|
||||
ret.first = x;
|
||||
else
|
||||
{
|
||||
switch (m_xtest)
|
||||
{
|
||||
case Test::Fixed:
|
||||
ret.first = m_x;
|
||||
break;
|
||||
case Test::Minimum:
|
||||
ret.first = std::max(m_x, x);
|
||||
break;
|
||||
case Test::Maximum:
|
||||
ret.first = std::min(m_x, x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_y < 0)
|
||||
ret.second = y;
|
||||
else
|
||||
{
|
||||
switch (m_ytest)
|
||||
{
|
||||
case Test::Fixed:
|
||||
ret.second = m_y;
|
||||
break;
|
||||
case Test::Minimum:
|
||||
ret.second = std::max(m_y, y);
|
||||
break;
|
||||
case Test::Maximum:
|
||||
ret.second = std::min(m_y, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
class View
|
||||
{
|
||||
public:
|
||||
@@ -127,13 +186,26 @@ public:
|
||||
virtual int nominalWidth() const {return 0;}
|
||||
virtual int nominalHeight() const {return 0;}
|
||||
|
||||
virtual void updateCVar(HECL::CVar* cvar) {}
|
||||
virtual void setActive(bool) {}
|
||||
|
||||
virtual void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey) {}
|
||||
virtual void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey) {}
|
||||
virtual void mouseMove(const boo::SWindowCoord&) {}
|
||||
virtual void mouseEnter(const boo::SWindowCoord&) {}
|
||||
virtual void mouseLeave(const boo::SWindowCoord&) {}
|
||||
virtual void scroll(const boo::SWindowCoord&, const boo::SScrollDelta&) {}
|
||||
virtual void touchDown(const boo::STouchCoord&, uintptr_t) {}
|
||||
virtual void touchUp(const boo::STouchCoord&, uintptr_t) {}
|
||||
virtual void touchMove(const boo::STouchCoord&, uintptr_t) {}
|
||||
virtual void charKeyDown(unsigned long, boo::EModifierKey, bool) {}
|
||||
virtual void charKeyUp(unsigned long, boo::EModifierKey) {}
|
||||
virtual void specialKeyDown(boo::ESpecialKey, boo::EModifierKey, bool) {}
|
||||
virtual void specialKeyUp(boo::ESpecialKey, boo::EModifierKey) {}
|
||||
virtual void modKeyDown(boo::EModifierKey, bool) {}
|
||||
virtual void modKeyUp(boo::EModifierKey) {}
|
||||
|
||||
virtual void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
|
||||
virtual void think() {}
|
||||
virtual void draw(boo::IGraphicsCommandQueue* gfxQ);
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class ThemeData
|
||||
{
|
||||
Zeus::CColor m_uiText = Zeus::CColor::skWhite;
|
||||
Zeus::CColor m_fieldText = Zeus::CColor::skBlack;
|
||||
Zeus::CColor m_selectedFieldText = Zeus::CColor::skWhite;
|
||||
|
||||
Zeus::CColor m_vpBg = {0.2, 0.2, 0.2, 1.0};
|
||||
Zeus::CColor m_tbBg = {0.4, 0.4, 0.4, 1.0};
|
||||
@@ -38,10 +39,12 @@ class ThemeData
|
||||
Zeus::CColor m_textfield1Hover = {0.6425, 0.6425, 0.6425, 1.0};
|
||||
Zeus::CColor m_textfield2Disabled = {0.7823, 0.7823, 0.7823, 0.5};
|
||||
Zeus::CColor m_textfield1Disabled = {0.5725, 0.5725, 0.5725, 0.5};
|
||||
Zeus::CColor m_textfieldSelection = {0.2725, 0.2725, 0.2725, 1.0};
|
||||
|
||||
public:
|
||||
virtual const Zeus::CColor& uiText() const {return m_uiText;}
|
||||
virtual const Zeus::CColor& fieldText() const {return m_fieldText;}
|
||||
virtual const Zeus::CColor& selectedFieldText() const {return m_selectedFieldText;}
|
||||
|
||||
virtual const Zeus::CColor& viewportBackground() const {return m_vpBg;}
|
||||
virtual const Zeus::CColor& toolbarBackground() const {return m_tbBg;}
|
||||
@@ -66,6 +69,7 @@ public:
|
||||
virtual const Zeus::CColor& textfield2Hover() const {return m_textfield2Hover;}
|
||||
virtual const Zeus::CColor& textfield1Disabled() const {return m_textfield1Disabled;}
|
||||
virtual const Zeus::CColor& textfield2Disabled() const {return m_textfield2Disabled;}
|
||||
virtual const Zeus::CColor& textfieldSelection() const {return m_textfieldSelection;}
|
||||
};
|
||||
|
||||
class ViewResources
|
||||
|
||||
Reference in New Issue
Block a user