Browse Source

blendish: fixed bndJoinAreaOverlay

oui: added uiContains()
pull/1/head
Leonard Ritter 10 years ago
parent
commit
f79ab2da03
2 changed files with 41 additions and 16 deletions
  1. +15
    -16
      blendish.h
  2. +26
    -0
      oui.h

+ 15
- 16
blendish.h View File

@@ -1248,26 +1248,26 @@ void bndSplitterWidgets(NVGcontext *ctx, float x, float y, float w, float h) {

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;
x0 = w;
y0 = h;
x1 = 0;
y1 = 0;
s = -s;
} else {
x0 = x;
y0 = y;
x1 = x+w;
y1 = y+h;
x0 = 0;
y0 = 0;
x1 = w;
y1 = h;
}
float yc = (y0+y1)*0.5f;
@@ -1275,7 +1275,7 @@ void bndJoinAreaOverlay(NVGcontext *ctx, float x, float y, float w, float h,
float s4 = s/4.0f;
float s8 = s/8.0f;
float x4 = x0+s4;
float points[][2] = {
{ x0,y0 },
{ x1,y0 },
@@ -1289,14 +1289,13 @@ void bndJoinAreaOverlay(NVGcontext *ctx, float x, float y, float w, float h,
{ 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]);
nvgMoveTo(ctx,x+points[0][vertical&1],y+points[0][(vertical&1)^1]);
for (int i = 1; i < count; ++i) {
nvgLineTo(ctx,points[i][vertical&1],points[i][(vertical&1)^1]);
nvgLineTo(ctx,x+points[i][vertical&1],y+points[i][(vertical&1)^1]);
}
//nvgClosePath(ctx);
nvgFillColor(ctx, nvgRGBAf(0,0,0,0.3));
nvgFill(ctx);


+ 26
- 0
oui.h View File

@@ -522,6 +522,10 @@ int uiGetChildId(int item);
// undefined.
UIrect uiGetRect(int item);

// returns 1 if an items absolute rectangle contains a given coordinate
// otherwise 0
int uiContains(int item, int x, int y);

// when called from an input event handler, returns the active items absolute
// layout rectangle. If uiGetActiveRect() is called outside of a handler,
// the values of the returned rectangle are undefined.
@@ -1288,6 +1292,28 @@ int uiGetChildCount(int item) {
return uiItemPtr(item)->numkids;
}

UIrect uiGetAbsoluteRect(int item) {
UIrect rect = uiGetRect(item);
item = uiParent(item);
while (item >= 0) {
rect.x += uiItemPtr(item)->rect.x;
rect.y += uiItemPtr(item)->rect.y;
item = uiParent(item);
}
return rect;
}

int uiContains(int item, int x, int y) {
UIrect rect = uiGetAbsoluteRect(item);
x -= rect.x;
y -= rect.y;
if ((x>=0)
&& (y>=0)
&& (x<rect.w)
&& (y<rect.h)) return 1;
return 0;
}

int uiFindItem(int item, int x, int y, int ox, int oy) {
UIitem *pitem = uiItemPtr(item);
if (pitem->frozen) return -1;


Loading…
Cancel
Save