Skip to content

Commit

Permalink
Area move and resize
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed May 4, 2018
1 parent 210ef6a commit 1988294
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
20 changes: 19 additions & 1 deletion examples/area-adv.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,30 @@ function handlerDraw(area, p) {

// ------

// Circle
path = new libui.UiDrawPath(libui.fillMode.winding);
path.newFigure(0, 0);
path.arcTo(250, 300, 50, 0, 2 * Math.PI, false);
path.end();
p.getContext().fill(path, radialBrush);
path.freePath();

// Dashed line
path = new libui.UiDrawPath(libui.fillMode.winding);
path.newFigure(250, 20);
path.lineTo(300, 150);
path.end();
p.getContext().stroke(path, solidBrush, dashedStroke);
path.freePath();

// Move handle
path = new libui.UiDrawPath(libui.fillMode.winding);
path.addRectangle(330, 0, 20, 20);
path.end();
p.getContext().fill(path, solidBrush);
path.freePath();

// Rotated square
path = new libui.UiDrawPath(libui.fillMode.winding);
p.getContext().transform(matrix);
path.addRectangle(20, 230, 100, 100);
Expand All @@ -60,6 +70,14 @@ function handlerDraw(area, p) {
path.freePath();
}

function mouseEvent(area, evt) {
const x = evt.getX(), y = evt.getY();

if (330 <= x && x <= 350 && 0 <= y && y <= 20) {
area.beginWindowMove();
}
}

function noop() {}

function main() {
Expand All @@ -70,7 +88,7 @@ function main() {
libui.stopLoop();
});

const textDrawArea = new libui.UiArea(handlerDraw, noop, noop, noop, noop);
const textDrawArea = new libui.UiArea(handlerDraw, mouseEvent, noop, noop, noop);
const wrapper = new libui.UiVerticalBox();
wrapper.append(textDrawArea, true);
mainwin.setChild(wrapper);
Expand Down
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,17 @@ const extKeys = {
nDivide: 39
};

const resizeEdge = {
left: 0,
top: 1,
right: 2,
bottom: 3,
topLeft: 4,
topRight: 5,
bottomLeft: 6,
bottomRight: 7
};

module.exports.textStretch = textStretch;
module.exports.textItalic = textItalic;
module.exports.textWeight = textWeight;
Expand All @@ -439,6 +450,7 @@ module.exports.lineJoin = lineJoin;
module.exports.fillMode = fillMode;
module.exports.modifierKeys = modifierKeys;
module.exports.extKeys = extKeys;
module.exports.resizeEdge = resizeEdge;
module.exports.startLoop = startLoop;
module.exports.stopLoop = stopLoop;
module.exports.onShouldQuit = binding.lib.Ui.onShouldQuit;
34 changes: 22 additions & 12 deletions src/UiArea/UiArea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@
#include "control.h"
#include "ui.h"

void UiArea::setSize(int width, int height) {
uiAreaSetSize((uiArea *)getHandle(), width, height);
}

void UiArea::queueRedrawAll() {
uiAreaQueueRedrawAll((uiArea *)getHandle());
}

void UiArea::scrollTo(double x, double y, double width, double height) {
uiAreaScrollTo((uiArea *)getHandle(), x, y, width, height);
}

UiArea::UiArea(nbind::cbFunction &drawCb, nbind::cbFunction &mouseEventCb,
nbind::cbFunction &mouseCrossedCb,
nbind::cbFunction &dragBrokenCb, nbind::cbFunction &keyEventCb)
Expand All @@ -31,6 +19,26 @@ UiArea::UiArea(nbind::cbFunction &drawCb, nbind::cbFunction &mouseEventCb,
drawCb, mouseEventCb, mouseCrossedCb, dragBrokenCb, keyEventCb),
width, height)) {}

void UiArea::setSize(int width, int height) {
uiAreaSetSize((uiArea *)getHandle(), width, height);
}

void UiArea::queueRedrawAll() {
uiAreaQueueRedrawAll((uiArea *)getHandle());
}

void UiArea::scrollTo(double x, double y, double width, double height) {
uiAreaScrollTo((uiArea *)getHandle(), x, y, width, height);
}

void UiArea::beginWindowMove() {
uiAreaBeginUserWindowMove((uiArea *)getHandle());
}

void UiArea::beginWindowResize(int resizeEdge) {
uiAreaBeginUserWindowResize((uiArea *)getHandle(), resizeEdge);
}

#include "nbind/api.h"

NBIND_CLASS(UiArea) {
Expand All @@ -42,4 +50,6 @@ NBIND_CLASS(UiArea) {
method(setSize);
method(queueRedrawAll);
method(scrollTo);
method(beginWindowMove);
method(beginWindowResize);
}
2 changes: 2 additions & 0 deletions src/includes/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class UiArea : public UiControl {
void setSize(int width, int height);
void queueRedrawAll();
void scrollTo(double x, double y, double width, double height);
void beginWindowMove();
void beginWindowResize(int resizeEdge);
};

class DrawStrokeParams {
Expand Down

0 comments on commit 1988294

Please sign in to comment.