import functions from the private prototype: goPage(), goHome(), goEnd(), goPageMouse()
--- a/OHP3D.cpp Wed Dec 27 12:50:47 2023 +0100
+++ b/OHP3D.cpp Wed Dec 27 23:25:06 2023 +0100
@@ -309,6 +309,36 @@
runShaders();
glXSwapBuffers(dpy, win);
+ auto goPage = [&](int count) {
+ // TODO: support pages with different ratios
+ ctx.moveRight(count * 1.8 * textures[0]->getRatio());
+ };
+
+ auto goHome = [&]() {
+ ctx.cameraFront = initialCtx.cameraFront;
+ ctx.cameraPos = initialCtx.cameraPos;
+ ctx.cameraUp = initialCtx.cameraUp;
+ };
+
+ auto goEnd = [&]() {
+ goHome();
+ goPage(textures.size() - 1);
+ };
+
+ auto goPageMouse = [&](XButtonEvent ev) {
+ XWindowAttributes gwa;
+ XGetWindowAttributes(dpy, win, &gwa);
+
+ bool top = ev.y < gwa.height / 2, bottom = !top;
+ bool left = ev.x < gwa.width / 2, right = !left;
+
+ if (top && left) goHome();
+ else if (top && right) goEnd();
+ else if (bottom && left) goPage(-1);
+ else if (bottom && right) goPage(+1);
+ };
+
+
for (XEvent xev; keepRunningX11;) {
int epollEventCount = epoll.wait();
//std::cout << "trace: epoll.wait() = " << epollEventCount << std::endl;
@@ -338,9 +368,6 @@
const float cSp = 0.05f; // camera speed
const float aSp = 5.f; // angle speed
- const float pSp = 1.8 * textures[0]->getRatio(); // page
- // TODO: support pages with different ratios
- // TODO: import original controls from the private prototype
if (key.matches(XK_q, XK_Escape)) keepRunningX11 = false;
else if (key.matches(XK_Left, XK_s)) ctx.turnLeft(aSp);
@@ -355,10 +382,10 @@
else if (key.matches(XK_comma)) ctx.moveRight(cSp);
else if (key.matches(XK_l)) ctx.moveUp(cSp);
else if (key.matches(XK_period)) ctx.moveDown(cSp);
- else if (key.matches(XK_j)) ctx.moveLeft(pSp);
- else if (key.matches(XK_k)) ctx.moveRight(pSp);
- else if (key.matches(XK_u)) ctx.moveLeft(cSp * 10);
- else if (key.matches(XK_i)) ctx.moveRight(cSp * 10);
+ else if (key.matches(XK_j, XK_Page_Up)) goPage(-1);
+ else if (key.matches(XK_k, XK_Page_Down)) goPage(+1);
+ else if (key.matches(XK_u, XK_Home)) goHome();
+ else if (key.matches(XK_i, XK_End)) goEnd();
else if (key.matches(XK_x)) resetView();
else if (key.matches(XK_F11, XK_y)) toggleFullscreen();
redraw = true;
@@ -366,7 +393,7 @@
std::cout << "XEvent: ButtonPress:"
<< " button=" << xev.xbutton.button
<< std::endl;
- if (xev.xbutton.button == 1);
+ if (xev.xbutton.button == 1) goPageMouse(xev.xbutton);
else if (xev.xbutton.button == 4) ctx.adjustFov(-1.0);
else if (xev.xbutton.button == 5) ctx.adjustFov(+1.0);
else if (xev.xbutton.button == 8) resetView();