Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Area beginWindowMove beginWindowResize #105

Open
wants to merge 5 commits into
base: 0_3_0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
11 changes: 6 additions & 5 deletions src/UiArea/UiAreaHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@

void Draw(UiAreaHandler *self, uiArea *area, uiAreaDrawParams *params) {
UiAreaDrawParams *pp = new UiAreaDrawParams(params);
(*self->draw)(controlsMap[uiControl(area)], pp);
(*self->draw)((UiArea *)controlsMap[uiControl(area)], pp);
}

void MouseEvent(UiAreaHandler *self, uiArea *area, uiAreaMouseEvent *event) {
UiAreaMouseEvent *ev = new UiAreaMouseEvent(event);
(*(self->mouseEvent))(controlsMap[uiControl(area)], ev);
(*(self->mouseEvent))((UiArea *)controlsMap[uiControl(area)], ev);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the event callbacks got a UiControl object (not UiArea)

}

void MouseCrossed(UiAreaHandler *self, uiArea *area, int left) {
(*(self->mouseCrossed))(controlsMap[uiControl(area)], left);
(*(self->mouseCrossed))((UiArea *)controlsMap[uiControl(area)], left);
}

void DragBroken(UiAreaHandler *self, uiArea *area) {
(*(self->dragBroken))(controlsMap[uiControl(area)]);
(*(self->dragBroken))((UiArea *)controlsMap[uiControl(area)]);
}

int KeyEvent(UiAreaHandler *self, uiArea *area, uiAreaKeyEvent *event) {
UiAreaKeyEvent *ev = new UiAreaKeyEvent(event);
return (self->keyEvent)->call<int>(controlsMap[uiControl(area)], ev);
return (self->keyEvent)
->call<int>((UiArea *)controlsMap[uiControl(area)], ev);
}

UiAreaHandler *UiAreaHandlerFactory::build(nbind::cbFunction &drawCb,
Expand Down
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