Commit 96c8824a authored by Jack Andersen's avatar Jack Andersen

New code style refactor

parent b8da816d
......@@ -4,130 +4,117 @@
#include "specter/Control.hpp"
#include "specter/Icon.hpp"
namespace specter
{
namespace specter {
class Button : public Control
{
class Button : public Control {
public:
enum class Style
{
Block,
Text,
};
enum class Style {
Block,
Text,
};
private:
Style m_style;
IButtonBinding::MenuStyle m_menuStyle = IButtonBinding::MenuStyle::None;
zeus::CColor m_textColor;
zeus::CColor m_bgColor;
std::string m_textStr;
std::unique_ptr<TextView> m_text;
std::unique_ptr<IconView> m_icon;
SolidShaderVert m_verts[40];
VertexBufferBindingSolid m_vertsBinding;
void _loadVerts()
{
m_vertsBinding.load<decltype(m_verts)>(m_verts);
}
RectangleConstraint m_constraint;
int m_nomWidth, m_nomHeight;
int m_textWidth, m_textIconWidth;
struct ButtonTarget : View
{
Button& m_button;
bool m_pressed = false;
bool m_hovered = false;
void setInactive();
void setHover();
void setPressed();
void setDisabled();
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseEnter(const boo::SWindowCoord&);
void mouseLeave(const boo::SWindowCoord&);
ButtonTarget(ViewResources& res, Button& button) : View(res, button), m_button(button) {}
};
ViewChild<std::unique_ptr<ButtonTarget>> m_buttonTarget;
struct MenuTarget : View
{
Button& m_button;
bool m_pressed = false;
bool m_hovered = false;
void setInactive();
void setHover();
void setPressed();
void setDisabled();
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseEnter(const boo::SWindowCoord&);
void mouseLeave(const boo::SWindowCoord&);
MenuTarget(ViewResources& res, Button& button) : View(res, button), m_button(button) {}
};
ViewChild<std::unique_ptr<MenuTarget>> m_menuTarget;
ViewChild<std::unique_ptr<View>> m_modalMenu;
Style m_style;
IButtonBinding::MenuStyle m_menuStyle = IButtonBinding::MenuStyle::None;
zeus::CColor m_textColor;
zeus::CColor m_bgColor;
std::string m_textStr;
std::unique_ptr<TextView> m_text;
std::unique_ptr<IconView> m_icon;
SolidShaderVert m_verts[40];
VertexBufferBindingSolid m_vertsBinding;
void _loadVerts() { m_vertsBinding.load<decltype(m_verts)>(m_verts); }
RectangleConstraint m_constraint;
int m_nomWidth, m_nomHeight;
int m_textWidth, m_textIconWidth;
struct ButtonTarget : View {
Button& m_button;
bool m_pressed = false;
bool m_hovered = false;
void setInactive();
void setHover();
void setPressed();
void setDisabled();
public:
class Resources
{
friend class ViewResources;
friend class Button;
void init(boo::IGraphicsDataFactory::Context& ctx, const IThemeData& theme);
void destroy() {}
};
~Button() {closeMenu({});}
Button(ViewResources& res, View& parentView,
IButtonBinding* controlBinding, std::string_view text, Icon* icon=nullptr,
Style style=Style::Block, const zeus::CColor& bgColor=zeus::CColor::skWhite,
RectangleConstraint constraint=RectangleConstraint());
Button(ViewResources& res, View& parentView,
IButtonBinding* controlBinding, std::string_view text, const zeus::CColor& textColor,
Icon* icon=nullptr, Style style=Style::Block, const zeus::CColor& bgColor=zeus::CColor::skWhite,
RectangleConstraint constraint=RectangleConstraint());
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&);
void think();
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
void draw(boo::IGraphicsCommandQueue* gfxQ);
void setText(std::string_view text, const zeus::CColor& textColor);
void setText(std::string_view text);
void setIcon(Icon* icon=nullptr);
std::string_view getText() const {return m_textStr;}
void colorGlyphs(const zeus::CColor& newColor);
int nominalWidth() const {return m_nomWidth;}
int nominalHeight() const {return m_nomHeight;}
void closeMenu(const boo::SWindowCoord& coord);
ViewChild<std::unique_ptr<View>>& getMenu() {return m_modalMenu;}
void setMultiplyColor(const zeus::CColor& color)
{
View::setMultiplyColor(color);
m_viewVertBlock.m_color = color;
if (m_viewVertBlockBuf)
m_viewVertBlockBuf.access().finalAssign(m_viewVertBlock);
m_text->setMultiplyColor(color);
if (m_icon)
m_icon->setMultiplyColor(color);
}
};
ButtonTarget(ViewResources& res, Button& button) : View(res, button), m_button(button) {}
};
ViewChild<std::unique_ptr<ButtonTarget>> m_buttonTarget;
struct MenuTarget : View {
Button& m_button;
}
bool m_pressed = false;
bool m_hovered = false;
void setInactive();
void setHover();
void setPressed();
void setDisabled();
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseEnter(const boo::SWindowCoord&);
void mouseLeave(const boo::SWindowCoord&);
MenuTarget(ViewResources& res, Button& button) : View(res, button), m_button(button) {}
};
ViewChild<std::unique_ptr<MenuTarget>> m_menuTarget;
ViewChild<std::unique_ptr<View>> m_modalMenu;
public:
class Resources {
friend class ViewResources;
friend class Button;
void init(boo::IGraphicsDataFactory::Context& ctx, const IThemeData& theme);
void destroy() {}
};
~Button() { closeMenu({}); }
Button(ViewResources& res, View& parentView, IButtonBinding* controlBinding, std::string_view text,
Icon* icon = nullptr, Style style = Style::Block, const zeus::CColor& bgColor = zeus::CColor::skWhite,
RectangleConstraint constraint = RectangleConstraint());
Button(ViewResources& res, View& parentView, IButtonBinding* controlBinding, std::string_view text,
const zeus::CColor& textColor, Icon* icon = nullptr, Style style = Style::Block,
const zeus::CColor& bgColor = zeus::CColor::skWhite, RectangleConstraint constraint = RectangleConstraint());
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseMove(const boo::SWindowCoord&);
void mouseLeave(const boo::SWindowCoord&);
void think();
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
void draw(boo::IGraphicsCommandQueue* gfxQ);
void setText(std::string_view text, const zeus::CColor& textColor);
void setText(std::string_view text);
void setIcon(Icon* icon = nullptr);
std::string_view getText() const { return m_textStr; }
void colorGlyphs(const zeus::CColor& newColor);
int nominalWidth() const { return m_nomWidth; }
int nominalHeight() const { return m_nomHeight; }
void closeMenu(const boo::SWindowCoord& coord);
ViewChild<std::unique_ptr<View>>& getMenu() { return m_modalMenu; }
void setMultiplyColor(const zeus::CColor& color) {
View::setMultiplyColor(color);
m_viewVertBlock.m_color = color;
if (m_viewVertBlockBuf)
m_viewVertBlockBuf.access().finalAssign(m_viewVertBlock);
m_text->setMultiplyColor(color);
if (m_icon)
m_icon->setMultiplyColor(color);
}
};
} // namespace specter
......@@ -2,119 +2,106 @@
#include "View.hpp"
namespace specter
{
namespace specter {
class Control;
class Button;
enum class ControlType
{
Button,
Float,
Int,
String,
CVar
};
enum class ControlType { Button, Float, Int, String, CVar };
struct IControlBinding
{
virtual ControlType type() const = 0;
virtual std::string_view name(const Control* control) const=0;
virtual std::string_view help(const Control* control) const {return {};}
struct IControlBinding {
virtual ControlType type() const = 0;
virtual std::string_view name(const Control* control) const = 0;
virtual std::string_view help(const Control* control) const { return {}; }
};
struct IButtonBinding : IControlBinding
{
ControlType type() const { return ControlType::Button; }
static IButtonBinding* castTo(IControlBinding* bind)
{ return bind->type() == ControlType::Button ? static_cast<IButtonBinding*>(bind) : nullptr; }
struct IButtonBinding : IControlBinding {
ControlType type() const { return ControlType::Button; }
static IButtonBinding* castTo(IControlBinding* bind) {
return bind->type() == ControlType::Button ? static_cast<IButtonBinding*>(bind) : nullptr;
}
/** Pressed/Released while Hovering action,
* cancellable by holding the button and releasing outside */
virtual void activated(const Button* button, const boo::SWindowCoord& coord) {}
/** Pressed/Released while Hovering action,
* cancellable by holding the button and releasing outside */
virtual void activated(const Button* button, const boo::SWindowCoord& coord) {}
/** Pass-through down action */
virtual void down(const Button* button, const boo::SWindowCoord& coord) {}
/** Pass-through down action */
virtual void down(const Button* button, const boo::SWindowCoord& coord) {}
/** Pass-through up action */
virtual void up(const Button* button, const boo::SWindowCoord& coord) {}
/** Pass-through up action */
virtual void up(const Button* button, const boo::SWindowCoord& coord) {}
/** Optional style of menu to bind to button */
enum class MenuStyle
{
None, /**< No menu; normal button */
Primary, /**< Menu button replaces normal button */
Auxiliary /**< Menu button placed alongside normal button */
};
/** Optional style of menu to bind to button */
enum class MenuStyle {
None, /**< No menu; normal button */
Primary, /**< Menu button replaces normal button */
Auxiliary /**< Menu button placed alongside normal button */
};
/** Informs button which MenuStyle to present to user */
virtual MenuStyle menuStyle(const specter::Button* button) const {return MenuStyle::None;}
/** Informs button which MenuStyle to present to user */
virtual MenuStyle menuStyle(const specter::Button* button) const { return MenuStyle::None; }
/** Called when user requests menu, Button assumes modal ownership */
virtual std::unique_ptr<View> buildMenu(const specter::Button* button) {return std::unique_ptr<View>();}
/** Called when user requests menu, Button assumes modal ownership */
virtual std::unique_ptr<View> buildMenu(const specter::Button* button) { return std::unique_ptr<View>(); }
};
struct IFloatBinding : IControlBinding
{
ControlType type() const { return ControlType::Float; }
static IFloatBinding* castTo(IControlBinding* bind)
{ return bind->type() == ControlType::Float ? static_cast<IFloatBinding*>(bind) : nullptr; }
virtual float getDefault(const Control* control) const {return 0.0;}
virtual std::pair<float,float> getBounds(const Control* control) const {return std::make_pair(FLT_MIN, FLT_MAX);}
virtual void changed(const Control* control, float val)=0;
struct IFloatBinding : IControlBinding {
ControlType type() const { return ControlType::Float; }
static IFloatBinding* castTo(IControlBinding* bind) {
return bind->type() == ControlType::Float ? static_cast<IFloatBinding*>(bind) : nullptr;
}
virtual float getDefault(const Control* control) const { return 0.0; }
virtual std::pair<float, float> getBounds(const Control* control) const { return std::make_pair(FLT_MIN, FLT_MAX); }
virtual void changed(const Control* control, float val) = 0;
};
struct IIntBinding : IControlBinding
{
ControlType type() const { return ControlType::Int; }
static IIntBinding* castTo(IControlBinding* bind)
{ return bind->type() == ControlType::Int ? static_cast<IIntBinding*>(bind) : nullptr; }
virtual int getDefault(const Control* control) const {return 0;}
virtual std::pair<int,int> getBounds(const Control* control) const {return std::make_pair(INT_MIN, INT_MAX);}
virtual void changed(const Control* control, int val)=0;
struct IIntBinding : IControlBinding {
ControlType type() const { return ControlType::Int; }
static IIntBinding* castTo(IControlBinding* bind) {
return bind->type() == ControlType::Int ? static_cast<IIntBinding*>(bind) : nullptr;
}
virtual int getDefault(const Control* control) const { return 0; }
virtual std::pair<int, int> getBounds(const Control* control) const { return std::make_pair(INT_MIN, INT_MAX); }
virtual void changed(const Control* control, int val) = 0;
};
struct IStringBinding : IControlBinding
{
ControlType type() const { return ControlType::String; }
static IStringBinding* castTo(IControlBinding* bind)
{ return bind->type() == ControlType::String ? static_cast<IStringBinding*>(bind) : nullptr; }
virtual std::string getDefault(const Control* control) const {return "";}
virtual void changed(const Control* control, std::string_view val)=0;
struct IStringBinding : IControlBinding {
ControlType type() const { return ControlType::String; }
static IStringBinding* castTo(IControlBinding* bind) {
return bind->type() == ControlType::String ? static_cast<IStringBinding*>(bind) : nullptr;
}
virtual std::string getDefault(const Control* control) const { return ""; }
virtual void changed(const Control* control, std::string_view val) = 0;
};
struct CVarControlBinding : IControlBinding
{
hecl::CVar* m_cvar;
CVarControlBinding(hecl::CVar* cvar)
: m_cvar(cvar) {}
ControlType type() const { return ControlType::CVar; }
static CVarControlBinding* castTo(IControlBinding* bind)
{ return bind->type() == ControlType::CVar ? static_cast<CVarControlBinding*>(bind) : nullptr; }
std::string_view name(const Control* control) const {return m_cvar->name();}
std::string_view help(const Control* control) const {return m_cvar->rawHelp();}
struct CVarControlBinding : IControlBinding {
hecl::CVar* m_cvar;
CVarControlBinding(hecl::CVar* cvar) : m_cvar(cvar) {}
ControlType type() const { return ControlType::CVar; }
static CVarControlBinding* castTo(IControlBinding* bind) {
return bind->type() == ControlType::CVar ? static_cast<CVarControlBinding*>(bind) : nullptr;
}
std::string_view name(const Control* control) const { return m_cvar->name(); }
std::string_view help(const Control* control) const { return m_cvar->rawHelp(); }
};
class Control : public View
{
class Control : public View {
protected:
IControlBinding* m_controlBinding = nullptr;
IControlBinding* m_controlBinding = nullptr;
public:
Control(ViewResources& res, View& parentView, IControlBinding* controlBinding);
Control(ViewResources& res, View& parentView, IControlBinding* controlBinding);
};
class ITextInputView : public Control, public boo::ITextInputCallback
{
class ITextInputView : public Control, public boo::ITextInputCallback {
protected:
static std::recursive_mutex m_textInputLk;
ITextInputView(ViewResources& res, View& parentView,
IControlBinding* controlBinding)
: Control(res, parentView, controlBinding) {}
static std::recursive_mutex m_textInputLk;
ITextInputView(ViewResources& res, View& parentView, IControlBinding* controlBinding)
: Control(res, parentView, controlBinding) {}
public:
virtual void clipboardCopy() {}
virtual void clipboardCut() {}
virtual void clipboardPaste() {}
virtual void clipboardCopy() {}
virtual void clipboardCut() {}
virtual void clipboardPaste() {}
};
}
} // namespace specter
This diff is collapsed.
This diff is collapsed.
......@@ -2,17 +2,14 @@
#include "View.hpp"
namespace specter
{
struct IMenuNode
{
virtual boo::ITexture* icon() const {return nullptr;}
virtual const std::string* text() const {return nullptr;}
virtual size_t subNodeCount() const {return 0;}
virtual IMenuNode* subNode(size_t idx) {return nullptr;}
virtual void activated(const boo::SWindowCoord& coord) {}
namespace specter {
struct IMenuNode {
virtual boo::ITexture* icon() const { return nullptr; }
virtual const std::string* text() const { return nullptr; }
virtual size_t subNodeCount() const { return 0; }
virtual IMenuNode* subNode(size_t idx) { return nullptr; }
virtual void activated(const boo::SWindowCoord& coord) {}
};
}
} // namespace specter
......@@ -4,31 +4,27 @@
#include "SplitView.hpp"
#include <hecl/hecl.hpp>
namespace specter
{
namespace specter {
struct ISpaceController;
struct IViewManager
{
struct IViewManager {
public:
virtual const Translator* getTranslator() const {return nullptr;}
virtual std::string_view translateOr(std::string_view key, std::string_view vor) const
{
const Translator* trans = getTranslator();
if (trans)
return trans->translateOr(key, vor);
return vor;
}
virtual void deferSpaceSplit(ISpaceController* split, SplitView::Axis axis, int thisSlot,
const boo::SWindowCoord& coord) {}
virtual const std::vector<hecl::SystemString>* recentProjects() const {return nullptr;}
virtual void pushRecentProject(hecl::SystemStringView path) {}
virtual const std::vector<hecl::SystemString>* recentFiles() const {return nullptr;}
virtual void pushRecentFile(hecl::SystemStringView path) {}
virtual const Translator* getTranslator() const { return nullptr; }
virtual std::string_view translateOr(std::string_view key, std::string_view vor) const {
const Translator* trans = getTranslator();
if (trans)
return trans->translateOr(key, vor);
return vor;
}
virtual void deferSpaceSplit(ISpaceController* split, SplitView::Axis axis, int thisSlot,
const boo::SWindowCoord& coord) {}
virtual const std::vector<hecl::SystemString>* recentProjects() const { return nullptr; }
virtual void pushRecentProject(hecl::SystemStringView path) {}
virtual const std::vector<hecl::SystemString>* recentFiles() const { return nullptr; }
virtual void pushRecentFile(hecl::SystemStringView path) {}
};
}
} // namespace specter
......@@ -2,71 +2,63 @@
#include "View.hpp"
namespace specter
{
namespace specter {
struct Icon
{
boo::ObjToken<boo::ITexture> m_tex;
zeus::CVector2f m_uvCoords[4];
Icon() = default;
Icon(const boo::ObjToken<boo::ITexture>& tex, float rect[4])
: m_tex(tex)
{
m_uvCoords[0][0] = rect[0];
m_uvCoords[0][1] = -rect[3];
struct Icon {
boo::ObjToken<boo::ITexture> m_tex;
zeus::CVector2f m_uvCoords[4];
Icon() = default;
Icon(const boo::ObjToken<boo::ITexture>& tex, float rect[4]) : m_tex(tex) {
m_uvCoords[0][0] = rect[0];
m_uvCoords[0][1] = -rect[3];
m_uvCoords[1][0] = rect[0];
m_uvCoords[1][1] = -rect[1];
m_uvCoords[1][0] = rect[0];
m_uvCoords[1][1] = -rect[1];
m_uvCoords[2][0] = rect[2];
m_uvCoords[2][1] = -rect[3];
m_uvCoords[2][0] = rect[2];
m_uvCoords[2][1] = -rect[3];
m_uvCoords[3][0] = rect[2];
m_uvCoords[3][1] = -rect[1];
}
m_uvCoords[3][0] = rect[2];
m_uvCoords[3][1] = -rect[1];
}
};
template <size_t COLS, size_t ROWS>
class IconAtlas
{
boo::ObjToken<boo::ITextureS> m_tex;
Icon m_icons[COLS][ROWS];
class IconAtlas {
boo::ObjToken<boo::ITextureS> m_tex;
Icon m_icons[COLS][ROWS];
Icon MakeIcon(float x, float y) {
float rect[] = {x / float(COLS), y / float(ROWS), x / float(COLS) + 1.f / float(COLS),
y / float(ROWS) + 1.f / float(ROWS)};
return Icon(m_tex.get(), rect);
}
Icon MakeIcon(float x, float y)
{
float rect[] = {x / float(COLS), y / float(ROWS),
x / float(COLS) + 1.f / float(COLS), y / float(ROWS) + 1.f / float(ROWS)};
return Icon(m_tex.get(), rect);
}
public:
IconAtlas() = default;
operator bool() const {return m_tex;}
void initializeAtlas(const boo::ObjToken<boo::ITextureS>& tex)
{
m_tex = tex;
for (int c=0 ; c<COLS ; ++c)
for (int r=0 ; r<ROWS ; ++r)
m_icons[c][r] = MakeIcon(c, r);
}
void destroyAtlas()
{
for (int c=0 ; c<COLS ; ++c)
for (int r=0 ; r<ROWS ; ++r)
m_icons[c][r].m_tex.reset();
m_tex.reset();
}
Icon& getIcon(size_t c, size_t r) {return m_icons[c][r];}
IconAtlas() = default;
operator bool() const { return m_tex; }
void initializeAtlas(const boo::ObjToken<boo::ITextureS>& tex) {
m_tex = tex;
for (int c = 0; c < COLS; ++c)
for (int r = 0; r < ROWS; ++r)
m_icons[c][r] = MakeIcon(c, r);
}
void destroyAtlas() {
for (int c = 0; c < COLS; ++c)
for (int r = 0; r < ROWS; ++r)
m_icons[c][r].m_tex.reset();
m_tex.reset();
}
Icon& getIcon(size_t c, size_t r) { return m_icons[c][r]; }
};
class IconView : public View
{
VertexBufferBindingTex m_vertexBinding;
class IconView : public View {
VertexBufferBindingTex m_vertexBinding;
public:
IconView(ViewResources& res, View& parentView, Icon& icon);
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
void draw(boo::IGraphicsCommandQueue* gfxQ);
IconView(ViewResources& res, View& parentView, Icon& icon);
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
void draw(boo::IGraphicsCommandQueue* gfxQ);
};
}
} // namespace specter
......@@ -5,89 +5,82 @@
#include "ScrollView.hpp"
#include "IMenuNode.hpp"
namespace specter
{
class Menu : public View
{
IMenuNode* m_rootNode;
IMenuNode* m_thisNode;
std::unique_ptr<Menu> m_subMenu;
std::unique_ptr<TextView> m_headText;
int m_cWidth, m_cHeight, m_cTop;
SolidShaderVert m_verts[8];
VertexBufferBindingSolid m_vertsBinding;
void setVerts(int width, int height, float pf);
struct ContentView : View
{
Menu& m_menu;
ContentView(ViewResources& res, Menu& menu);
boo::SWindowRect m_scissorRect;
SolidShaderVert m_hlVerts[4];
VertexBufferBindingSolid m_hlVertsBinding;
size_t m_highlightedItem = -1;
void setHighlightedItem(size_t idx);
void unsetHighlightedItem(size_t idx)
{
if (m_highlightedItem == idx)