Skip to content

Commit

Permalink
area advancement WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
parro-it committed Jun 21, 2016
1 parent 3c4099b commit 5d3d754
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 91 deletions.
2 changes: 2 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"auto.gypi"
],
"sources": [
"src/UiArea/DrawStrokeParams.cc",
"src/UiArea/UiDrawContext.cc",
"src/UiArea/UiDrawPath.cc",
"src/UiArea/DrawBrush.cc",
"src/SizeDouble.cc",
Expand Down
143 changes: 90 additions & 53 deletions src/UiArea/DrawStrokeParams.cc
Original file line number Diff line number Diff line change
@@ -1,61 +1,98 @@
#include "../libui/ui.h"
#include "ui-node.h"
#include "../../libui/ui.h"
#include "../ui-node.h"
#include "nbind/nbind.h"


struct uiDrawStrokeParams {
int Cap;
int Join;
// TODO what if this is 0? on windows there will be a crash with dashing
double Thickness;
double MiterLimit;
double *Dashes;
// TOOD what if this is 1 on Direct2D?
// TODO what if a dash is 0 on Cairo or Quartz?
int NumDashes;
double DashPhase;
};

class DrawStrokeParams {
private:
int Cap;
int Join;
double Thickness;
double MiterLimit;
std::vector<double> Dashes;
int NumDashes;
double DashPhase;
public:
DrawStrokeParams(int cap, int join, double thickness, double miterLimit,std::vector<double> dashes,int numDashes,double DashPhase);
int getCap();
int getJoin();
double getThickness();
double getMiterLimit();
std::vector<double> getDashes();
int getNumDashes();
double getDashPhase();

void setCap(int value);
void setJoin(int value);
void setThickness(double value);
void setMiterLimit(double value);
void setDashes(std::vector<double> value);
void setNumDashes(int value);
void setDashPhase(double value);

uiDrawStrokeParams *toStruct();

void toJS(nbind::cbOutput output);

DrawStrokeParams::DrawStrokeParams(int cap, int join, double thickness, double miterLimit,std::vector<double> dashes,int numDashes,double DashPhase) {

}

int DrawStrokeParams::getCap() {
return Cap;
}

int DrawStrokeParams::getJoin() {
return Join;
}

double DrawStrokeParams::getThickness() {
return Thickness;
}

double DrawStrokeParams::getMiterLimit() {
return MiterLimit;

}

std::vector<double> DrawStrokeParams::getDashes() {
return Dashes;
}

int DrawStrokeParams::getNumDashes() {
return NumDashes;

}

double DrawStrokeParams::getDashPhase() {
return DashPhase;

}

void DrawStrokeParams::setCap(int value) {

}

void DrawStrokeParams::setJoin(int value) {

}

void DrawStrokeParams::setThickness(double value) {

}

void DrawStrokeParams::setMiterLimit(double value) {

}

void DrawStrokeParams::setDashes(std::vector<double> value) {

}

void DrawStrokeParams::setNumDashes(int value) {

}

void DrawStrokeParams::setDashPhase(double value) {

}


uiDrawStrokeParams * DrawStrokeParams::toStruct() {
return NULL;
}


void DrawStrokeParams::toJS(nbind::cbOutput output) {

}


NBIND_CLASS(DrawStrokeParams) {
construct<double, Color>();
method(getColor);
method(setColor);
method(getPos);
method(setPos);
method(toJS);
getset(getColor, setColor);
getset(getPos, setPos);
method(getCap);
method(getJoin);
method(getThickness);
method(getMiterLimit);
method(getDashes);
method(getNumDashes);
method(getDashPhase);
method(setCap);
method(setJoin);
method(setThickness);
method(setMiterLimit);
method(setDashes);
method(setNumDashes);
method(setDashPhase);
method(toStruct);
method(toJS);
}
4 changes: 0 additions & 4 deletions src/UiArea/UiArea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include "nbind/api.h"

INHERITS_CONTROL_METHODS(UiArea)
_UI_EXTERN void uiAreaSetSize(uiArea *a, int width, int height);
// TODO uiAreaQueueRedraw()
_UI_EXTERN void uiAreaQueueRedrawAll(uiArea *a);
_UI_EXTERN void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height);

void UiArea::setSize(int width, int height) {
uiAreaSetSize(
Expand Down
68 changes: 51 additions & 17 deletions src/UiArea/UiDrawContext.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
#include "../../libui/ui.h"
#include "../ui-node.h"
#include "nbind/nbind.h"

_UI_EXTERN void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStrokeParams *p);
_UI_EXTERN void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b);

_UI_EXTERN void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m);

// TODO add a uiDrawPathStrokeToFill() or something like that
_UI_EXTERN void uiDrawClip(uiDrawContext *c, uiDrawPath *path);

_UI_EXTERN void uiDrawSave(uiDrawContext *c);
_UI_EXTERN void uiDrawRestore(uiDrawContext *c);

_UI_EXTERN void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout);


class UiDrawContext {
Expand All @@ -19,12 +10,55 @@ class UiDrawContext {

public:
UiDrawContext(uiDrawContext *ctx);
void stroke(UiDrawPath *path, UiDrawBrush *b, uiDrawStrokeParams *p);
void fill(uiDrawPath *path, uiDrawBrush *b);
void transform(uiDrawMatrix *m);
void clip(uiDrawPath *path);
void stroke(UiDrawPath *path, DrawBrush *b, DrawStrokeParams *p);
void fill(UiDrawPath *path, DrawBrush *b);
void transform(UiDrawMatrix *m);
void clip(UiDrawPath *path);
void save();
void restore();
void text(double x, double y, uiDrawTextLayout *layout);
void text(double x, double y, void *layout);

};

UiDrawContext::UiDrawContext(uiDrawContext *ctx) {
c = ctx;
}

void UiDrawContext::stroke(UiDrawPath *path, DrawBrush *b, DrawStrokeParams *p) {
uiDrawStroke(c, path->getHandle(), b->toStruct(), p->toStruct());
}

void UiDrawContext::fill(UiDrawPath *path, DrawBrush *b) {
uiDrawFill(c, path->getHandle(), b->toStruct());
}

void UiDrawContext::transform(UiDrawMatrix *m) {
uiDrawTransform(c, m->getStruct());
}

void UiDrawContext::clip(UiDrawPath *path) {
uiDrawClip(c, path->getHandle());
}

void UiDrawContext::save() {
uiDrawSave(c);
}

void UiDrawContext::restore() {
uiDrawRestore(c);
}

void UiDrawContext::text(double x, double y, void *layout) {
// uiDrawText(c, x, y, layout);
}


NBIND_CLASS(UiDrawContext) {
method(stroke);
method(fill);
method(transform);
method(clip);
method(save);
method(restore);
method(text);
}
20 changes: 3 additions & 17 deletions src/UiArea/UiDrawPath.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
#include "nbind/nbind.h"


class UiDrawPath {
private:
uiDrawPath *handle;

public:
UiDrawPath(int fillMode);
void freePath();
void newFigure(double x, double y);
void newFigureWithArc(double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative);
void lineTo(double x, double y);
void arcTo(double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative);
void bezierTo(double c1x, double c1y, double c2x, double c2y, double endX, double endY);
void closeFigure();
void addRectangle(double x, double y, double width, double height);
void end();
};

UiDrawPath::UiDrawPath(int fillMode) {
handle = uiDrawNewPath(fillMode);
}
Expand Down Expand Up @@ -62,6 +45,9 @@ void UiDrawPath::end() {
uiDrawPathEnd(handle);
}

uiDrawPath *UiDrawPath::getHandle() {
return handle;
}

NBIND_CLASS(UiDrawPath) {
construct<int>();
Expand Down
49 changes: 49 additions & 0 deletions src/ui-node.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,35 @@ class UiColorButton : public UiControl {
// UIArea



class DrawStrokeParams {
private:
int Cap;
int Join;
double Thickness;
double MiterLimit;
std::vector<double> Dashes;
int NumDashes;
double DashPhase;
public:
DrawStrokeParams(int cap, int join, double thickness, double miterLimit,std::vector<double> dashes,int numDashes,double DashPhase);
int getCap();
int getJoin();
double getThickness();
double getMiterLimit();
std::vector<double> getDashes();
int getNumDashes();
double getDashPhase();
void setCap(int value);
void setJoin(int value);
void setThickness(double value);
void setMiterLimit(double value);
void setDashes(std::vector<double> value);
void setNumDashes(int value);
void setDashPhase(double value);
uiDrawStrokeParams *toStruct();
void toJS(nbind::cbOutput output);
};
class UiDrawMatrix {
private:
uiDrawMatrix *m;
Expand Down Expand Up @@ -614,6 +643,26 @@ class UiAreaDrawParams {
};


class UiDrawPath {
private:
uiDrawPath *handle;

public:
uiDrawPath *getHandle();
UiDrawPath(int fillMode);
void freePath();
void newFigure(double x, double y);
void newFigureWithArc(double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative);
void lineTo(double x, double y);
void arcTo(double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative);
void bezierTo(double c1x, double c1y, double c2x, double c2y, double endX, double endY);
void closeFigure();
void addRectangle(double x, double y, double width, double height);
void end();

};


class UiArea : public UiControl {
public:
UiArea(
Expand Down

0 comments on commit 5d3d754

Please sign in to comment.