Added a color well to the histogram example.
This commit is contained in:
parent
bf411e787e
commit
a038923060
|
@ -1,6 +1,8 @@
|
||||||
// 15 may 2016
|
// 15 may 2016
|
||||||
#import "uipriv_darwin.h"
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
|
// TODO no intrinsic height?
|
||||||
|
|
||||||
@interface colorButton : NSColorWell {
|
@interface colorButton : NSColorWell {
|
||||||
uiColorButton *libui_b;
|
uiColorButton *libui_b;
|
||||||
BOOL libui_changing;
|
BOOL libui_changing;
|
||||||
|
|
|
@ -9,6 +9,7 @@ uiWindow *mainwin;
|
||||||
uiArea *histogram;
|
uiArea *histogram;
|
||||||
uiAreaHandler handler;
|
uiAreaHandler handler;
|
||||||
uiSpinbox *datapoints[10];
|
uiSpinbox *datapoints[10];
|
||||||
|
uiColorButton *colorButton;
|
||||||
int currentPoint = -1;
|
int currentPoint = -1;
|
||||||
|
|
||||||
// some metrics
|
// some metrics
|
||||||
|
@ -94,6 +95,7 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
|
||||||
uiDrawStrokeParams sp;
|
uiDrawStrokeParams sp;
|
||||||
uiDrawMatrix m;
|
uiDrawMatrix m;
|
||||||
double graphWidth, graphHeight;
|
double graphWidth, graphHeight;
|
||||||
|
double graphR, graphG, graphB, graphA;
|
||||||
|
|
||||||
// fill the area with white
|
// fill the area with white
|
||||||
setSolidBrush(&brush, colorWhite, 1.0);
|
setSolidBrush(&brush, colorWhite, 1.0);
|
||||||
|
@ -134,15 +136,23 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
|
||||||
uiDrawMatrixTranslate(&m, xoffLeft, yoffTop);
|
uiDrawMatrixTranslate(&m, xoffLeft, yoffTop);
|
||||||
uiDrawTransform(p->Context, &m);
|
uiDrawTransform(p->Context, &m);
|
||||||
|
|
||||||
|
// now get the color for the graph itself and set up the brush
|
||||||
|
uiColorButtonColor(colorButton, &graphR, &graphG, &graphB, &graphA);
|
||||||
|
brush.Type = uiDrawBrushTypeSolid;
|
||||||
|
brush.R = graphR;
|
||||||
|
brush.G = graphG;
|
||||||
|
brush.B = graphB;
|
||||||
|
// we set brush->A below to different values for the fill and stroke
|
||||||
|
|
||||||
// now create the fill for the graph below the graph line
|
// now create the fill for the graph below the graph line
|
||||||
path = constructGraph(graphWidth, graphHeight, 1);
|
path = constructGraph(graphWidth, graphHeight, 1);
|
||||||
setSolidBrush(&brush, colorDodgerBlue, 0.5);
|
brush.A = graphA / 2;
|
||||||
uiDrawFill(p->Context, path, &brush);
|
uiDrawFill(p->Context, path, &brush);
|
||||||
uiDrawFreePath(path);
|
uiDrawFreePath(path);
|
||||||
|
|
||||||
// now draw the histogram line
|
// now draw the histogram line
|
||||||
path = constructGraph(graphWidth, graphHeight, 0);
|
path = constructGraph(graphWidth, graphHeight, 0);
|
||||||
setSolidBrush(&brush, colorDodgerBlue, 1.0);
|
brush.A = graphA;
|
||||||
uiDrawStroke(p->Context, path, &brush, &sp);
|
uiDrawStroke(p->Context, path, &brush, &sp);
|
||||||
uiDrawFreePath(path);
|
uiDrawFreePath(path);
|
||||||
|
|
||||||
|
@ -216,6 +226,11 @@ static void onDatapointChanged(uiSpinbox *s, void *data)
|
||||||
uiAreaQueueRedrawAll(histogram);
|
uiAreaQueueRedrawAll(histogram);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void onColorChanged(uiColorButton *b, void *data)
|
||||||
|
{
|
||||||
|
uiAreaQueueRedrawAll(histogram);
|
||||||
|
}
|
||||||
|
|
||||||
static int onClosing(uiWindow *w, void *data)
|
static int onClosing(uiWindow *w, void *data)
|
||||||
{
|
{
|
||||||
uiControlDestroy(uiControl(mainwin));
|
uiControlDestroy(uiControl(mainwin));
|
||||||
|
@ -235,6 +250,7 @@ int main(void)
|
||||||
const char *err;
|
const char *err;
|
||||||
uiBox *hbox, *vbox;
|
uiBox *hbox, *vbox;
|
||||||
int i;
|
int i;
|
||||||
|
uiDrawBrush brush;
|
||||||
|
|
||||||
handler.Draw = handlerDraw;
|
handler.Draw = handlerDraw;
|
||||||
handler.MouseEvent = handlerMouseEvent;
|
handler.MouseEvent = handlerMouseEvent;
|
||||||
|
@ -272,6 +288,17 @@ int main(void)
|
||||||
uiBoxAppend(vbox, uiControl(datapoints[i]), 0);
|
uiBoxAppend(vbox, uiControl(datapoints[i]), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
colorButton = uiNewColorButton();
|
||||||
|
// TODO inline these
|
||||||
|
setSolidBrush(&brush, colorDodgerBlue, 1.0);
|
||||||
|
uiColorButtonSetColor(colorButton,
|
||||||
|
brush.R,
|
||||||
|
brush.G,
|
||||||
|
brush.B,
|
||||||
|
brush.A);
|
||||||
|
uiColorButtonOnChanged(colorButton, onColorChanged, NULL);
|
||||||
|
uiBoxAppend(vbox, uiControl(colorButton), 0);
|
||||||
|
|
||||||
histogram = uiNewArea(&handler);
|
histogram = uiNewArea(&handler);
|
||||||
uiBoxAppend(hbox, uiControl(histogram), 1);
|
uiBoxAppend(hbox, uiControl(histogram), 1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue