Skip to content

Commit

Permalink
Work-around strange codegen problem with x0 in Bargraph.onDraw
Browse files Browse the repository at this point in the history
One less problem in #35
  • Loading branch information
p0nce committed Jun 19, 2015
1 parent 26963ca commit 07f8c7a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
48 changes: 48 additions & 0 deletions gui/dplug/gui/drawex.d
Expand Up @@ -157,4 +157,52 @@ if (isWritableView!V && isNumeric!T && is(COLOR : ViewColor!V))
}
}
}
}

void aaFillRectFloat(bool CHECKED=true, V, COLOR)(auto ref V v, float x1, float y1, float x2, float y2, COLOR color)
if (isWritableView!V && is(COLOR : ViewColor!V))
{
import ae.utils.math;
sort2(x1, x2);
sort2(y1, y2);

int ix1 = cast(int)(floor(x1));
int iy1 = cast(int)(floor(y1));
int ix2 = cast(int)(floor(x2));
int iy2 = cast(int)(floor(y2));
float fx1 = x1 - ix1;
float fy1 = y1 - iy1;
float fx2 = x2 - ix2;
float fy2 = y2 - iy2;

static ubyte toAlpha(float fraction) pure nothrow @nogc
{
return cast(ubyte)(cast(int)(0.5f + 255.0f * fraction));
}

v.aaPutPixelFloat!CHECKED(ix1, iy1, color, toAlpha( (1-fx1) * (1-fy1) ));
v.hline!CHECKED(ix1+1, ix2, iy1, color, toAlpha(1 - fy1));
v.aaPutPixelFloat!CHECKED(ix2, iy1, color, toAlpha( fx2 * (1-fy1) ));

v.vline!CHECKED(ix1, iy1+1, iy2, color, toAlpha(1 - fx1));
v.vline!CHECKED(ix2, iy1+1, iy2, color, toAlpha(fx2));

v.aaPutPixelFloat!CHECKED(ix1, iy2, color, toAlpha( (1-fx1) * fy2 ));
v.hline!CHECKED(ix1+1, ix2, iy2, color, toAlpha(fy2));
v.aaPutPixelFloat!CHECKED(ix2, iy2, color, toAlpha( fx2 * fy2 ));

v.fillRect!CHECKED(ix1+1, iy1+1, ix2, iy2, color);
}

template aaPutPixelFloat(bool CHECKED=true)
{
void aaPutPixelFloat(V, COLOR)(auto ref V v, int x, int y, COLOR color, ubyte alpha)
{
static if (CHECKED)
if (x<0 || x>=v.w || y<0 || y>=v.h)
return;

COLOR* p = v.pixelPtr(x, y);
*p = COLOR.op!q{.blend(a, b, c)}(color, *p, alpha);
}
}
16 changes: 8 additions & 8 deletions gui/dplug/gui/toolkit/bargraph.d
Expand Up @@ -68,34 +68,34 @@ public:

box2f available = box2f(border, border, width - border, height - border);

float heightPerLed = available.height / cast(float)numLeds;
float widthPerLed = available.width / cast(float)numChannels;
float heightPerLed = cast(float)(available.height) / cast(float)numLeds;
float widthPerLed = cast(float)(available.width) / cast(float)numChannels;

float tolerance = 1.0f / numLeds;

foreach(channel; 0..numChannels)
{
float value = getValue(channel);
float x0 = border + widthPerLed * (channel + 0.15f);
float x1 = x0 + widthPerLed * 0.7f;

foreach(i; 0..numLeds)
{
float x0 = available.min.x + widthPerLed * (channel + 0.15f);
float x1 = x0 + widthPerLed * 0.7f;
float y0 = available.min.y + heightPerLed * (i + 0.1f);
float y0 = border + heightPerLed * (i + 0.1f);
float y1 = y0 + heightPerLed * 0.8f;

depthMap.aaFillRect(x0, y0, x1, y1, RGBA(60, 255, 0, 0));
depthMap.aaFillRectFloat!true(x0, y0, x1, y1, RGBA(60, 255, 0, 0));

float ratio = 1 - i / cast(float)(numLeds - 1);


ubyte shininess = cast(ubyte)(0.5f + 255.0f * (1 - smoothStep(value - tolerance, value, ratio)));

RGBA color = _leds[i].diffuse;
color.r = (color.r * (255 + shininess) + 255) / 510;
color.g = (color.g * (255 + shininess) + 255) / 510;
color.b = (color.b * (255 + shininess) + 255) / 510;
color.a = shininess;
diffuseMap.aaFillRect(x0, y0, x1, y1, color);
diffuseMap.aaFillRectFloat!true(x0, y0, x1, y1, color);

}
}
Expand Down

0 comments on commit 07f8c7a

Please sign in to comment.