Browse Source

Continue blendish work

pull/1/head
falkTX 10 years ago
parent
commit
e5bd3dfa09
1 changed files with 188 additions and 59 deletions
  1. +188
    -59
      examples/blendish.cpp

+ 188
- 59
examples/blendish.cpp View File

@@ -35,26 +35,39 @@ USE_NAMESPACE_DGL;
// ------------------------------------------------------
// Test

class BlenderOption : public NanoWidget
class BlendishCommon : public NanoWidget
{
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),
state(BND_DEFAULT),
area(10, 10, 200, BND_WIDGET_HEIGHT) {}
fState(kStateDefault)
{
setSize(250, BND_WIDGET_HEIGHT);
}

State getCurrentState() const noexcept
{
return fState;
}

protected:
bool onMouse(const MouseEvent& e)
{
if (! e.press)
return false;
if (! area.contains(e.pos))
if (! contains(e.pos))
return false;

if (state == BND_ACTIVE)
state = BND_HOVER;
if (fState == kStateActive)
fState = kStateHover;
else
state = BND_ACTIVE;
fState = kStateActive;

repaint();
return true;
@@ -62,11 +75,11 @@ protected:

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();
return true;
}
@@ -74,83 +87,172 @@ protected:
return false;
}

if (state == BND_DEFAULT)
if (fState == kStateDefault)
{
state = BND_HOVER;
fState = kStateHover;
repaint();
}

return true;
}

private:
State fState;
};

// ------------------------------------------------------
// Test

class BlendishLabel : public BlendishCommon
{
public:
BlendishLabel(NanoWidget* groupWidget)
: BlendishCommon(groupWidget) {}

protected:
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:
BlenderRadioBox(NanoWidget* groupWidget)
: NanoWidget(groupWidget),
state(BND_DEFAULT),
area(10, 40, 200, BND_WIDGET_HEIGHT) {}
BlendishToolButton(NanoWidget* groupWidget)
: BlendishCommon(groupWidget) {}

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
{
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

@@ -159,13 +261,33 @@ class TestWidget : public NanoWidget
public:
TestWidget(Window& parent)
: 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());

bndSetFont(nvgCreateFont(context, "system", "./blendish_res/DejaVuSans.ttf"));
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:
@@ -176,8 +298,15 @@ protected:
}

private:
BlenderOption opt;
BlenderRadioBox rb;
BlendishLabel w0;
BlendishToolButton w1;
BlendishPushButton w2;
BlendishCheckbox w3;
BlendishComboBox w4;
BlendishColorButton w5;
BlendishSlider w6;
BlendishScrollBar w7;
BlendishScrollBar w7b;
};

// ------------------------------------------------------


Loading…
Cancel
Save