From 5ae77ee4ac57ae427e77f707e004a29d7ff26bcc Mon Sep 17 00:00:00 2001 From: omigamedev Date: Wed, 25 Jan 2017 21:02:26 +0000 Subject: [PATCH] added partial mouse events for Windows, implemented clipping rect intersection, added auto value to width and height attributes --- data/layout.xml | 78 ++++++++++++++++++++++++------------------------- engine/app.cpp | 68 ++++++++++++++++++++++++++++++------------ engine/main.cpp | 6 ++-- 3 files changed, 90 insertions(+), 62 deletions(-) diff --git a/data/layout.xml b/data/layout.xml index 34bb991..4d088c5 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -1,45 +1,43 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + - - - - + + + + + + + + + diff --git a/engine/app.cpp b/engine/app.cpp index b1cdb7e..03e8a8b 100644 --- a/engine/app.cpp +++ b/engine/app.cpp @@ -9,6 +9,16 @@ void App::create() height = 500; } +glm::vec4 rect_intersection(glm::vec4 a, glm::vec4 b) +{ + // convert from [x,y,w,h] to [x1,y1,x2,y1] + a = glm::vec4(a.xy(), a.xy() + a.zw()); + b = glm::vec4(b.xy(), b.xy() + b.zw()); + auto o = glm::vec4(glm::max(a.xy(), b.xy()), glm::min(a.zw(), b.zw())); + o = glm::vec4(o.xy(), glm::max({ 0, 0 }, o.zw() - o.xy())); + return o; +} + void App::update_layout() { YGNodeCalculateLayout(y_root, YGUndefined, YGUndefined, YGDirectionLTR); @@ -21,14 +31,18 @@ void App::update_layout() auto ctx = reinterpret_cast(YGNodeGetContext(y_current)); if (!ctx) { - float x = YGNodeLayoutGetLeft(y_current); - float y = YGNodeLayoutGetTop(y_current); - float w = YGNodeLayoutGetWidth(y_current); - float h = YGNodeLayoutGetHeight(y_current); - ctx = new glm::vec4(x, y, w, h); + ctx = new glm::vec4(); YGNodeSetContext(y_current, ctx); } + if (y_current == y_root) + { + ctx->x = YGNodeLayoutGetLeft(y_current); + ctx->y = YGNodeLayoutGetTop(y_current); + ctx->z = YGNodeLayoutGetWidth(y_current); + ctx->w = YGNodeLayoutGetHeight(y_current); + } + int n = YGNodeGetChildCount(y_current); for (int i = 0; i < n; i++) { @@ -39,14 +53,11 @@ void App::update_layout() float y = YGNodeLayoutGetTop(y_child); float w = YGNodeLayoutGetWidth(y_child); float h = YGNodeLayoutGetHeight(y_child); - float pt = 0;//YGNodeLayoutGetPadding(y_current, YGEdgeTop); - float pr = 0;//YGNodeLayoutGetPadding(y_current, YGEdgeRight); - float pb = 0;//YGNodeLayoutGetPadding(y_current, YGEdgeBottom); - float pl = 0;//YGNodeLayoutGetPadding(y_current, YGEdgeLeft); - ctx_child->x = ctx->x + x + pl; - ctx_child->y = ctx->y + y + pt; - ctx_child->z = w - (pl + pr); - ctx_child->w = h - (pt + pb); + ctx_child->x = ctx->x + x; + ctx_child->y = ctx->y + y; + ctx_child->z = w; + ctx_child->w = h; + *ctx_child = rect_intersection(*ctx_child, *ctx); YGNodeSetContext(y_child, ctx_child); y_stack.emplace(y_child); } @@ -126,6 +137,9 @@ void App::load_layout() YGNodeStyleSetPosition(y_node, YGEdgeRight, 0); YGNodeStyleSetPosition(y_node, YGEdgeBottom, 0); YGNodeStyleSetPosition(y_node, YGEdgeLeft, 0); + + YGNodeStyleSetOverflow(y_node, YGOverflowHidden); + while (attr) { const auto ka = att::value(attr->Name()); @@ -133,10 +147,18 @@ void App::load_layout() switch (ka) { case att::kAttribute::Width: - if (strchr(attr->Value(), '%')) - YGNodeStyleSetWidthPercent(y_node, attr->FloatValue()); + if (strcmp(attr->Value(), "auto") == 0) + { + YGNodeStyleSetWidth(y_node, YGUndefined); + YGNodeStyleSetWidthPercent(y_node, YGUndefined); + } else - YGNodeStyleSetWidth(y_node, attr->FloatValue()); + { + if (strchr(attr->Value(), '%')) + YGNodeStyleSetWidthPercent(y_node, attr->FloatValue()); + else + YGNodeStyleSetWidth(y_node, attr->FloatValue()); + } break; case att::kAttribute::MinWidth: if (strchr(attr->Value(), '%')) @@ -148,10 +170,18 @@ void App::load_layout() YGNodeStyleSetMaxWidth(y_node, attr->FloatValue()); break; case att::kAttribute::Height: - if (strchr(attr->Value(), '%')) - YGNodeStyleSetHeightPercent(y_node, attr->FloatValue()); + if (strcmp(attr->Value(), "auto") == 0) + { + YGNodeStyleSetHeight(y_node, YGUndefined); + YGNodeStyleSetHeightPercent(y_node, YGUndefined); + } else - YGNodeStyleSetHeight(y_node, attr->FloatValue()); + { + if (strchr(attr->Value(), '%')) + YGNodeStyleSetHeightPercent(y_node, attr->FloatValue()); + else + YGNodeStyleSetHeight(y_node, attr->FloatValue()); + } break; case att::kAttribute::MinHeight: YGNodeStyleSetMinHeight(y_node, attr->FloatValue()); diff --git a/engine/main.cpp b/engine/main.cpp index eb85af2..fa7258a 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -460,13 +460,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) keys[wp] = false; break; case WM_MOUSEMOVE: - //current->pointerMove(LOWORD(lp), HIWORD(lp)); + App::I.mouse_move(LOWORD(lp), HIWORD(lp)); break; case WM_LBUTTONDOWN: - //current->pointerDown(LOWORD(lp), HIWORD(lp)); + App::I.mouse_down(0, LOWORD(lp), HIWORD(lp)); break; case WM_LBUTTONUP: - //current->pointerUp(LOWORD(lp), HIWORD(lp)); + App::I.mouse_up(0, LOWORD(lp), HIWORD(lp)); break; } return DefWindowProc(hWnd, msg, wp, lp);