Browse Source

blendish: support for "join area" arrow overlay

pull/1/head
Leonard Ritter 10 years ago
parent
commit
6801ceea4b
2 changed files with 74 additions and 0 deletions
  1. +63
    -0
      blendish.h
  2. +11
    -0
      example.cpp

+ 63
- 0
blendish.h View File

@@ -406,6 +406,13 @@ void bndNodeBackground(NVGcontext *ctx, float x, float y, float w, float h,
// the rectangle at origin (x,y) and size (w, h)
void bndSplitterWidgets(NVGcontext *ctx, float x, float y, float w, float h);

// Draw the join area overlay stencil into the rectangle
// at origin (x,y) and size (w,h)
// vertical is 0 or 1 and designates the arrow orientation,
// mirror is 0 or 1 and flips the arrow side
void bndJoinAreaOverlay(NVGcontext *ctx, float x, float y, float w, float h,
int vertical, int mirror);

////////////////////////////////////////////////////////////////////////////////
// Estimator Functions
@@ -1239,6 +1246,62 @@ void bndSplitterWidgets(NVGcontext *ctx, float x, float y, float w, float h) {
nvgStroke(ctx);
}

void bndJoinAreaOverlay(NVGcontext *ctx, float x, float y, float w, float h,
int vertical, int mirror) {
if (vertical) {
float u = w;
w = h; h = u;
}
float s = (w<h)?w:h;
float x0,y0,x1,y1;
if (mirror) {
x0 = x+w;
y0 = y+h;
x1 = x;
y1 = y;
s = -s;
} else {
x0 = x;
y0 = y;
x1 = x+w;
y1 = y+h;
}
float yc = (y0+y1)*0.5f;
float s2 = s/2.0f;
float s4 = s/4.0f;
float s8 = s/8.0f;
float x4 = x0+s4;
float points[][2] = {
{ x0,y0 },
{ x1,y0 },
{ x1,y1 },
{ x0,y1 },
{ x0,yc+s8 },
{ x4,yc+s8 },
{ x4,yc+s4 },
{ x0+s2,yc },
{ x4,yc-s4 },
{ x4,yc-s8 },
{ x0,yc-s8 }
};
nvgBeginPath(ctx);
int count = sizeof(points) / (sizeof(float)*2);
nvgMoveTo(ctx,points[0][vertical&1],points[0][(vertical&1)^1]);
for (int i = 1; i < count; ++i) {
nvgLineTo(ctx,points[i][vertical&1],points[i][(vertical&1)^1]);
}
//nvgClosePath(ctx);
nvgFillColor(ctx, nvgRGBAf(0,0,0,0.3));
nvgFill(ctx);
}

////////////////////////////////////////////////////////////////////////////////

float bndLabelWidth(NVGcontext *ctx, int iconid, const char *label) {


+ 11
- 0
example.cpp View File

@@ -485,6 +485,7 @@ void draw_noodles(NVGcontext *vg, int x, int y) {

void draw(NVGcontext *vg, float w, float h) {
bndBackground(vg, 0, 0, w, h);
bndSplitterWidgets(vg, 0, 0, w, h);
int x = 10;
@@ -732,6 +733,16 @@ void draw(NVGcontext *vg, float w, float h) {
uiLayout();
drawUI(vg, 0, 0, 0);
UIvec2 cursor = uiGetCursor();
cursor.x -= w/2;
cursor.y -= h/2;
if (abs(cursor.x) > (w/4)) {
bndJoinAreaOverlay(vg, 0, 0, w, h, 0, (cursor.x > 0));
} else if (abs(cursor.y) > (h/4)) {
bndJoinAreaOverlay(vg, 0, 0, w, h, 1, (cursor.y > 0));
}
uiProcess();
}



Loading…
Cancel
Save