From 1165a45ce73febf7a4daa2279db2a37c2bbc306d Mon Sep 17 00:00:00 2001 From: ketmar Date: Mon, 29 Nov 2021 11:27:46 +0000 Subject: [PATCH] erga: added agg mini hittest API FossilOrigin-Name: 733b6b52a983af11fcb407b17fba6ad7dd711efc077dd847fc524e2058733702 --- egra/gfx/aggmini/core.d | 4 ++++ egra/gfx/aggmini/render.d | 24 +++++++++++++----------- egra/test.d | 21 ++++++++++++++++++--- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/egra/gfx/aggmini/core.d b/egra/gfx/aggmini/core.d index a2b6b8c..b235801 100644 --- a/egra/gfx/aggmini/core.d +++ b/egra/gfx/aggmini/core.d @@ -309,6 +309,10 @@ public: return this; } + // input coords are unaffected by transform + // returns alpha (0 means "no hit") + ubyte hitTest (in int x, in int y) { pragma(inline, true); return rast.hitTest(x, y); } + // doesn't reset pathes ref AGGDrawer render (in GxColor c, in bool doReset=true) { if (!gxIsTransparent(c)) { diff --git a/egra/gfx/aggmini/render.d b/egra/gfx/aggmini/render.d index 5fcc931..29a3354 100644 --- a/egra/gfx/aggmini/render.d +++ b/egra/gfx/aggmini/render.d @@ -961,7 +961,7 @@ public: Renderer.render(mScanline, c, clipRect); mScanline.resetSpans(); } - mScanline.addCell(x, y, mGamma[alpha]); + mScanline.addCell(x, y, mGamma.ptr[alpha]); } ++x; } @@ -975,7 +975,7 @@ public: Renderer.render(mScanline, c, clipRect); mScanline.resetSpans(); } - mScanline.addSpan(x, y, curCell.x-x, mGamma[alpha]); + mScanline.addSpan(x, y, curCell.x-x, mGamma.ptr[alpha]); } } } @@ -983,9 +983,10 @@ public: if (mScanline.spanCount) Renderer.render(mScanline, c, clipRect); } - bool hitTest (int tx, int ty) { + // returns "gamma alpha" (0 means "no hit") + ubyte hitTest (int tx, int ty) { const(Cell)** cells = mOutline.cells(); - if (mOutline.numCells == 0) return false; + if (mOutline.numCells == 0) return 0; int cover = 0; const(Cell)* curCell = *cells++; @@ -1009,9 +1010,9 @@ public: } if (area) { - int alpha = calculateAlpha((cover<<(PolyBaseShift+1))-area); - if (alpha) { - if (tx == x && ty == y) return true; + immutable int alpha = calculateAlpha((cover<<(PolyBaseShift+1))-area); + if (alpha && mGamma.ptr[alpha]) { + if (tx == x && ty == y) return mGamma.ptr[alpha]; } ++x; } @@ -1019,13 +1020,14 @@ public: if (curCell is null) break; if (curCell.x > x) { - int alpha = calculateAlpha(cover<<(PolyBaseShift+1)); - if (alpha) { - if (ty == y && tx >= x && tx <= curCell.x) return true; + immutable int alpha = calculateAlpha(cover<<(PolyBaseShift+1)); + if (alpha && mGamma.ptr[alpha]) { + if (ty == y && tx >= x && tx <= curCell.x) return mGamma.ptr[alpha]; } } } - return false; + + return 0; } private: diff --git a/egra/test.d b/egra/test.d index aaf1e6c..dab3490 100644 --- a/egra/test.d +++ b/egra/test.d @@ -302,6 +302,7 @@ final class MainPaneWindow : SubWindow { int tessType = -1; AGGTesselation deftess; bool timetest; + int lastMX = -10000, lastMY = -10000; this () { super(null, GxPoint(0, 0), GxSize(screenWidth, screenHeight)); @@ -351,6 +352,7 @@ final class MainPaneWindow : SubWindow { import iv.pxclock; ulong estt; + ubyte hit = 0; if (timetest) { timetest = false; estt = 0; @@ -392,12 +394,18 @@ final class MainPaneWindow : SubWindow { .width = 1.0f; gxagg.contour(); } + + hit = gxagg.hitTest(lastMX, lastMY); gxagg.endFrame(gxrgba(255, 0, 0, (tessType >= 0 ? 255 : 66))); { import std.format : format; string s = "tess: %s level: %d; mcsecs: %s".format(gxagg.tesselator, gxagg.bezierLimit, estt); gxDrawTextUtf(200, 20, s, GxColors.k8orange); + if (hit) { + s = "hit: %3s".format(hit); + gxDrawTextUtf(200, 40, s, GxColors.k8orange); + } } } @@ -514,10 +522,17 @@ final class MainPaneWindow : SubWindow { // returning `false` to avoid screen rebuilding by dispatcher override bool onMouseBubble (MouseEvent event) { if (event.type == MouseEventType.buttonPressed || event.type == MouseEventType.buttonReleased) { - postScreenRebuild(); - } else { + if (lastMX != event.x || lastMY != event.y) { + lastMX = event.x; + lastMY = event.y; + //widgetChanged(); + } + widgetChanged(); + } else if (event.modifierState) { // for OpenGL, this rebuilds the whole screen anyway - postScreenRepaint(); + lastMX = event.x; + lastMY = event.y; + widgetChanged(); } return false; } -- 2.11.4.GIT