mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Finally do some drawing.
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
#include "globals.h"
|
||||
#include "ui.h"
|
||||
#include "uipp.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
static uiWindow* mainwin;
|
||||
static uiArea* area;
|
||||
|
||||
static uiDrawStrokeParams STROKE = {
|
||||
uiDrawLineCapFlat,
|
||||
uiDrawLineJoinMiter,
|
||||
0.5,
|
||||
1.0,
|
||||
nullptr,
|
||||
0,
|
||||
0.0
|
||||
};
|
||||
|
||||
static uiDrawBrush WHITE = { uiDrawBrushTypeSolid, 1.0, 0.0, 1.0, 1.0 };
|
||||
static uiDrawBrush BLACK = { uiDrawBrushTypeSolid, 0.0, 0.0, 0.0, 1.0 };
|
||||
|
||||
static int close_cb(uiWindow* window, void* data)
|
||||
{
|
||||
uiQuit();
|
||||
@@ -17,6 +32,8 @@ static int quit_cb(void* data)
|
||||
|
||||
static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
|
||||
{
|
||||
UIPath(p).rectangle(0, 0, p->AreaWidth, p->AreaHeight).fill(WHITE);
|
||||
UIPath(p).begin(0, 0).lineTo(p->AreaWidth, p->AreaHeight).end().stroke(BLACK, STROKE);
|
||||
}
|
||||
|
||||
static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *
|
||||
|
||||
78
src/gui/uipp.h
Normal file
78
src/gui/uipp.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef UIPP_H
|
||||
#define UIPP_H
|
||||
|
||||
class UIPath
|
||||
{
|
||||
class Figure
|
||||
{
|
||||
public:
|
||||
Figure(UIPath& path, double x, double y):
|
||||
_path(path)
|
||||
{
|
||||
uiDrawPathNewFigure(path._path, x, y);
|
||||
}
|
||||
|
||||
Figure& lineTo(double x, double y)
|
||||
{
|
||||
uiDrawPathLineTo(_path._path, x, y);
|
||||
return *this;
|
||||
}
|
||||
|
||||
UIPath& end()
|
||||
{
|
||||
uiDrawPathCloseFigure(_path._path);
|
||||
return _path;
|
||||
}
|
||||
|
||||
private:
|
||||
UIPath& _path;
|
||||
};
|
||||
|
||||
public:
|
||||
UIPath(uiAreaDrawParams* params):
|
||||
_params(params),
|
||||
_path(uiDrawNewPath(uiDrawFillModeWinding))
|
||||
{}
|
||||
|
||||
UIPath& rectangle(double x, double y, double w, double h)
|
||||
{
|
||||
uiDrawPathAddRectangle(_path, x, y, w, h);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Figure begin(double x, double y)
|
||||
{
|
||||
return Figure(*this, x, y);
|
||||
}
|
||||
|
||||
void fill(uiDrawBrush& fillBrush)
|
||||
{
|
||||
uiDrawPathEnd(_path);
|
||||
uiDrawFill(_params->Context, _path, &fillBrush);
|
||||
}
|
||||
|
||||
void stroke(uiDrawBrush& strokeBrush, uiDrawStrokeParams& strokeParams)
|
||||
{
|
||||
uiDrawPathEnd(_path);
|
||||
uiDrawStroke(_params->Context, _path, &strokeBrush, &strokeParams);
|
||||
}
|
||||
|
||||
void fill(uiDrawBrush& strokeBrush, uiDrawStrokeParams& strokeParams, uiDrawBrush& fillBrush)
|
||||
{
|
||||
uiDrawPathEnd(_path);
|
||||
uiDrawFill(_params->Context, _path, &fillBrush);
|
||||
uiDrawStroke(_params->Context, _path, &strokeBrush, &strokeParams);
|
||||
}
|
||||
|
||||
~UIPath()
|
||||
{
|
||||
uiDrawFreePath(_path);
|
||||
}
|
||||
|
||||
private:
|
||||
uiAreaDrawParams* _params;
|
||||
uiDrawPath* _path;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user