| @@ -35,26 +35,39 @@ USE_NAMESPACE_DGL; | |||||
| // ------------------------------------------------------ | // ------------------------------------------------------ | ||||
| // Test | // Test | ||||
| class BlenderOption : public NanoWidget | |||||
| class BlendishCommon : public NanoWidget | |||||
| { | { | ||||
| public: | public: | ||||
| BlenderOption(NanoWidget* groupWidget) | |||||
| enum State { | |||||
| kStateDefault = 0, // not interacting | |||||
| kStateHover = 1, // the mouse is hovering over the control | |||||
| kStateActive = 2 // the widget is activated (pressed) or in an active state (toggled) | |||||
| }; | |||||
| BlendishCommon(NanoWidget* groupWidget) | |||||
| : NanoWidget(groupWidget), | : NanoWidget(groupWidget), | ||||
| state(BND_DEFAULT), | |||||
| area(10, 10, 200, BND_WIDGET_HEIGHT) {} | |||||
| fState(kStateDefault) | |||||
| { | |||||
| setSize(250, BND_WIDGET_HEIGHT); | |||||
| } | |||||
| State getCurrentState() const noexcept | |||||
| { | |||||
| return fState; | |||||
| } | |||||
| protected: | protected: | ||||
| bool onMouse(const MouseEvent& e) | bool onMouse(const MouseEvent& e) | ||||
| { | { | ||||
| if (! e.press) | if (! e.press) | ||||
| return false; | return false; | ||||
| if (! area.contains(e.pos)) | |||||
| if (! contains(e.pos)) | |||||
| return false; | return false; | ||||
| if (state == BND_ACTIVE) | |||||
| state = BND_HOVER; | |||||
| if (fState == kStateActive) | |||||
| fState = kStateHover; | |||||
| else | else | ||||
| state = BND_ACTIVE; | |||||
| fState = kStateActive; | |||||
| repaint(); | repaint(); | ||||
| return true; | return true; | ||||
| @@ -62,11 +75,11 @@ protected: | |||||
| bool onMotion(const MotionEvent& e) | bool onMotion(const MotionEvent& e) | ||||
| { | { | ||||
| if (! area.contains(e.pos)) | |||||
| if (! contains(e.pos)) | |||||
| { | { | ||||
| if (state == BND_HOVER) | |||||
| if (fState == kStateHover) | |||||
| { | { | ||||
| state = BND_DEFAULT; | |||||
| fState = kStateDefault; | |||||
| repaint(); | repaint(); | ||||
| return true; | return true; | ||||
| } | } | ||||
| @@ -74,83 +87,172 @@ protected: | |||||
| return false; | return false; | ||||
| } | } | ||||
| if (state == BND_DEFAULT) | |||||
| if (fState == kStateDefault) | |||||
| { | { | ||||
| state = BND_HOVER; | |||||
| fState = kStateHover; | |||||
| repaint(); | repaint(); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| private: | |||||
| State fState; | |||||
| }; | |||||
| // ------------------------------------------------------ | |||||
| // Test | |||||
| class BlendishLabel : public BlendishCommon | |||||
| { | |||||
| public: | |||||
| BlendishLabel(NanoWidget* groupWidget) | |||||
| : BlendishCommon(groupWidget) {} | |||||
| protected: | |||||
| void onNanoDisplay() override | void onNanoDisplay() override | ||||
| { | { | ||||
| bndOptionButton(getContext(), 10, 10, 200, BND_WIDGET_HEIGHT, state, "checkbox whoohoo!"); | |||||
| bndLabel(getContext(), | |||||
| getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(), | |||||
| BND_ICON_HELP, | |||||
| "this is a label [help]"); | |||||
| } | } | ||||
| private: | |||||
| BNDwidgetState state; | |||||
| Rectangle<int> area; | |||||
| }; | }; | ||||
| class BlenderRadioBox : public NanoWidget | |||||
| class BlendishToolButton : public BlendishCommon | |||||
| { | { | ||||
| public: | public: | ||||
| BlenderRadioBox(NanoWidget* groupWidget) | |||||
| : NanoWidget(groupWidget), | |||||
| state(BND_DEFAULT), | |||||
| area(10, 40, 200, BND_WIDGET_HEIGHT) {} | |||||
| BlendishToolButton(NanoWidget* groupWidget) | |||||
| : BlendishCommon(groupWidget) {} | |||||
| protected: | protected: | ||||
| bool onMouse(const MouseEvent& e) | |||||
| void onNanoDisplay() override | |||||
| { | { | ||||
| if (! e.press) | |||||
| return false; | |||||
| if (! area.contains(e.pos)) | |||||
| return false; | |||||
| bndToolButton(getContext(), | |||||
| getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(), | |||||
| 0, static_cast<BNDwidgetState>(getCurrentState()), BND_ICON_SOUND, | |||||
| "this is a tool-button [sound]"); | |||||
| } | |||||
| }; | |||||
| if (state == BND_ACTIVE) | |||||
| state = BND_HOVER; | |||||
| else | |||||
| state = BND_ACTIVE; | |||||
| class BlendishPushButton: public BlendishCommon | |||||
| { | |||||
| public: | |||||
| BlendishPushButton(NanoWidget* groupWidget) | |||||
| : BlendishCommon(groupWidget) {} | |||||
| repaint(); | |||||
| return true; | |||||
| protected: | |||||
| void onNanoDisplay() override | |||||
| { | |||||
| bndRadioButton(getContext(), | |||||
| getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(), | |||||
| 0, static_cast<BNDwidgetState>(getCurrentState()), BND_ICON_NEW, | |||||
| "this is a push-button [file->new]"); | |||||
| } | } | ||||
| }; | |||||
| bool onMotion(const MotionEvent& e) | |||||
| // text field here | |||||
| class BlendishCheckbox : public BlendishCommon | |||||
| { | |||||
| public: | |||||
| BlendishCheckbox(NanoWidget* groupWidget) | |||||
| : BlendishCommon(groupWidget) {} | |||||
| protected: | |||||
| void onNanoDisplay() override | |||||
| { | { | ||||
| if (! area.contains(e.pos)) | |||||
| { | |||||
| if (state == BND_HOVER) | |||||
| { | |||||
| state = BND_DEFAULT; | |||||
| repaint(); | |||||
| return true; | |||||
| } | |||||
| bndOptionButton(getContext(), | |||||
| getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(), | |||||
| static_cast<BNDwidgetState>(getCurrentState()), | |||||
| "this is a checkbox"); | |||||
| } | |||||
| }; | |||||
| return false; | |||||
| } | |||||
| class BlendishComboBox : public BlendishCommon | |||||
| { | |||||
| public: | |||||
| BlendishComboBox(NanoWidget* groupWidget) | |||||
| : BlendishCommon(groupWidget) {} | |||||
| if (state == BND_DEFAULT) | |||||
| { | |||||
| state = BND_HOVER; | |||||
| repaint(); | |||||
| } | |||||
| protected: | |||||
| void onNanoDisplay() override | |||||
| { | |||||
| bndChoiceButton(getContext(), | |||||
| getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(), | |||||
| 0, static_cast<BNDwidgetState>(getCurrentState()), BND_ICON_NEW, | |||||
| "this is a combobox"); | |||||
| // bndMenuBackground | |||||
| // bndMenuLabel | |||||
| // bndMenuItem | |||||
| } | |||||
| }; | |||||
| return true; | |||||
| class BlendishColorButton : public BlendishCommon | |||||
| { | |||||
| public: | |||||
| BlendishColorButton(NanoWidget* groupWidget) | |||||
| : BlendishCommon(groupWidget) {} | |||||
| protected: | |||||
| void onNanoDisplay() override | |||||
| { | |||||
| bndColorButton(getContext(), | |||||
| getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(), | |||||
| BND_DEFAULT, | |||||
| Color::fromHTML("#132487")); | |||||
| } | } | ||||
| }; | |||||
| // bndNumberField | |||||
| class BlendishSlider : public BlendishCommon | |||||
| { | |||||
| public: | |||||
| BlendishSlider(NanoWidget* groupWidget) | |||||
| : BlendishCommon(groupWidget) {} | |||||
| protected: | |||||
| void onNanoDisplay() override | void onNanoDisplay() override | ||||
| { | { | ||||
| bndRadioButton(getContext(), 10, 40, 200, BND_WIDGET_HEIGHT, 0, state, BND_ICON_NONE, "radio blender style yeah"); | |||||
| bndSlider(getContext(), | |||||
| getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(), | |||||
| 0, static_cast<BNDwidgetState>(getCurrentState()), | |||||
| 0.25f, "this is a slider", "and value"); | |||||
| } | } | ||||
| }; | |||||
| private: | |||||
| BNDwidgetState state; | |||||
| Rectangle<int> area; | |||||
| class BlendishScrollBar : public BlendishCommon | |||||
| { | |||||
| public: | |||||
| BlendishScrollBar(NanoWidget* groupWidget, bool horizontal) | |||||
| : BlendishCommon(groupWidget) | |||||
| { | |||||
| if (horizontal) | |||||
| setSize(250, BND_SCROLLBAR_HEIGHT); | |||||
| else | |||||
| setSize(BND_SCROLLBAR_WIDTH, 200); | |||||
| } | |||||
| protected: | |||||
| void onNanoDisplay() override | |||||
| { | |||||
| bndScrollBar(getContext(), | |||||
| getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(), | |||||
| static_cast<BNDwidgetState>(getCurrentState()), | |||||
| 0.25f, 0.5f); | |||||
| } | |||||
| }; | }; | ||||
| // bndTooltipBackground | |||||
| // bndNodePort | |||||
| // bndNodeWire | |||||
| // bndColoredNodeWire | |||||
| // bndNodeBackground | |||||
| // bndSplitterWidgets | |||||
| // bndJoinAreaOverlay | |||||
| // ------------------------------------------------------ | // ------------------------------------------------------ | ||||
| // Test | // Test | ||||
| @@ -159,13 +261,33 @@ class TestWidget : public NanoWidget | |||||
| public: | public: | ||||
| TestWidget(Window& parent) | TestWidget(Window& parent) | ||||
| : NanoWidget(parent, NanoVG::CREATE_ANTIALIAS|NanoVG::CREATE_STENCIL_STROKES), | : NanoWidget(parent, NanoVG::CREATE_ANTIALIAS|NanoVG::CREATE_STENCIL_STROKES), | ||||
| opt(this), | |||||
| rb(this) | |||||
| w0(this), | |||||
| w1(this), | |||||
| w2(this), | |||||
| w3(this), | |||||
| w4(this), | |||||
| w5(this), | |||||
| w6(this), | |||||
| w7(this, true), | |||||
| w7b(this, false) | |||||
| { | { | ||||
| NVGcontext* const context(getContext()); | NVGcontext* const context(getContext()); | ||||
| bndSetFont(nvgCreateFont(context, "system", "./blendish_res/DejaVuSans.ttf")); | bndSetFont(nvgCreateFont(context, "system", "./blendish_res/DejaVuSans.ttf")); | ||||
| bndSetIconImage(nvgCreateImage(context, "./blendish_res/blender_icons16.png", 0)); | bndSetIconImage(nvgCreateImage(context, "./blendish_res/blender_icons16.png", 0)); | ||||
| w0.setAbsolutePos(10, 10+25*0); | |||||
| w1.setAbsolutePos(10, 10+25*1); | |||||
| w2.setAbsolutePos(10, 10+25*2); | |||||
| w3.setAbsolutePos(10, 10+25*3); | |||||
| w4.setAbsolutePos(10, 10+25*4); | |||||
| w5.setAbsolutePos(10, 10+25*5); | |||||
| w6.setAbsolutePos(10, 10+25*6); | |||||
| w7.setAbsolutePos(10, 10+25*7); | |||||
| //w8.setAbsolutePos(10, 10+25*8); | |||||
| //w9.setAbsolutePos(10, 10+25*9); | |||||
| w7b.setAbsolutePos(470, 10); | |||||
| } | } | ||||
| protected: | protected: | ||||
| @@ -176,8 +298,15 @@ protected: | |||||
| } | } | ||||
| private: | private: | ||||
| BlenderOption opt; | |||||
| BlenderRadioBox rb; | |||||
| BlendishLabel w0; | |||||
| BlendishToolButton w1; | |||||
| BlendishPushButton w2; | |||||
| BlendishCheckbox w3; | |||||
| BlendishComboBox w4; | |||||
| BlendishColorButton w5; | |||||
| BlendishSlider w6; | |||||
| BlendishScrollBar w7; | |||||
| BlendishScrollBar w7b; | |||||
| }; | }; | ||||
| // ------------------------------------------------------ | // ------------------------------------------------------ | ||||