307 |
307 |
308 // rended the 3D scene even before the first event: |
308 // rended the 3D scene even before the first event: |
309 runShaders(); |
309 runShaders(); |
310 glXSwapBuffers(dpy, win); |
310 glXSwapBuffers(dpy, win); |
311 |
311 |
|
312 auto goPage = [&](int count) { |
|
313 // TODO: support pages with different ratios |
|
314 ctx.moveRight(count * 1.8 * textures[0]->getRatio()); |
|
315 }; |
|
316 |
|
317 auto goHome = [&]() { |
|
318 ctx.cameraFront = initialCtx.cameraFront; |
|
319 ctx.cameraPos = initialCtx.cameraPos; |
|
320 ctx.cameraUp = initialCtx.cameraUp; |
|
321 }; |
|
322 |
|
323 auto goEnd = [&]() { |
|
324 goHome(); |
|
325 goPage(textures.size() - 1); |
|
326 }; |
|
327 |
|
328 auto goPageMouse = [&](XButtonEvent ev) { |
|
329 XWindowAttributes gwa; |
|
330 XGetWindowAttributes(dpy, win, &gwa); |
|
331 |
|
332 bool top = ev.y < gwa.height / 2, bottom = !top; |
|
333 bool left = ev.x < gwa.width / 2, right = !left; |
|
334 |
|
335 if (top && left) goHome(); |
|
336 else if (top && right) goEnd(); |
|
337 else if (bottom && left) goPage(-1); |
|
338 else if (bottom && right) goPage(+1); |
|
339 }; |
|
340 |
|
341 |
312 for (XEvent xev; keepRunningX11;) { |
342 for (XEvent xev; keepRunningX11;) { |
313 int epollEventCount = epoll.wait(); |
343 int epollEventCount = epoll.wait(); |
314 //std::cout << "trace: epoll.wait() = " << epollEventCount << std::endl; |
344 //std::cout << "trace: epoll.wait() = " << epollEventCount << std::endl; |
315 for (int epollEvent = 0; epollEvent < epollEventCount; epollEvent++) { |
345 for (int epollEvent = 0; epollEvent < epollEventCount; epollEvent++) { |
316 bool redraw = false; |
346 bool redraw = false; |
336 << " key=" << key.name |
366 << " key=" << key.name |
337 << std::endl; |
367 << std::endl; |
338 |
368 |
339 const float cSp = 0.05f; // camera speed |
369 const float cSp = 0.05f; // camera speed |
340 const float aSp = 5.f; // angle speed |
370 const float aSp = 5.f; // angle speed |
341 const float pSp = 1.8 * textures[0]->getRatio(); // page |
|
342 // TODO: support pages with different ratios |
|
343 // TODO: import original controls from the private prototype |
|
344 |
371 |
345 if (key.matches(XK_q, XK_Escape)) keepRunningX11 = false; |
372 if (key.matches(XK_q, XK_Escape)) keepRunningX11 = false; |
346 else if (key.matches(XK_Left, XK_s)) ctx.turnLeft(aSp); |
373 else if (key.matches(XK_Left, XK_s)) ctx.turnLeft(aSp); |
347 else if (key.matches(XK_Right, XK_f)) ctx.turnRight(aSp); |
374 else if (key.matches(XK_Right, XK_f)) ctx.turnRight(aSp); |
348 else if (key.matches(XK_Up, XK_e)) ctx.moveForward(cSp); |
375 else if (key.matches(XK_Up, XK_e)) ctx.moveForward(cSp); |
353 else if (key.matches(XK_g)) ctx.turnDown(aSp); |
380 else if (key.matches(XK_g)) ctx.turnDown(aSp); |
354 else if (key.matches(XK_m)) ctx.moveLeft(cSp); |
381 else if (key.matches(XK_m)) ctx.moveLeft(cSp); |
355 else if (key.matches(XK_comma)) ctx.moveRight(cSp); |
382 else if (key.matches(XK_comma)) ctx.moveRight(cSp); |
356 else if (key.matches(XK_l)) ctx.moveUp(cSp); |
383 else if (key.matches(XK_l)) ctx.moveUp(cSp); |
357 else if (key.matches(XK_period)) ctx.moveDown(cSp); |
384 else if (key.matches(XK_period)) ctx.moveDown(cSp); |
358 else if (key.matches(XK_j)) ctx.moveLeft(pSp); |
385 else if (key.matches(XK_j, XK_Page_Up)) goPage(-1); |
359 else if (key.matches(XK_k)) ctx.moveRight(pSp); |
386 else if (key.matches(XK_k, XK_Page_Down)) goPage(+1); |
360 else if (key.matches(XK_u)) ctx.moveLeft(cSp * 10); |
387 else if (key.matches(XK_u, XK_Home)) goHome(); |
361 else if (key.matches(XK_i)) ctx.moveRight(cSp * 10); |
388 else if (key.matches(XK_i, XK_End)) goEnd(); |
362 else if (key.matches(XK_x)) resetView(); |
389 else if (key.matches(XK_x)) resetView(); |
363 else if (key.matches(XK_F11, XK_y)) toggleFullscreen(); |
390 else if (key.matches(XK_F11, XK_y)) toggleFullscreen(); |
364 redraw = true; |
391 redraw = true; |
365 } else if (xev.type == ButtonPress) { |
392 } else if (xev.type == ButtonPress) { |
366 std::cout << "XEvent: ButtonPress:" |
393 std::cout << "XEvent: ButtonPress:" |
367 << " button=" << xev.xbutton.button |
394 << " button=" << xev.xbutton.button |
368 << std::endl; |
395 << std::endl; |
369 if (xev.xbutton.button == 1); |
396 if (xev.xbutton.button == 1) goPageMouse(xev.xbutton); |
370 else if (xev.xbutton.button == 4) ctx.adjustFov(-1.0); |
397 else if (xev.xbutton.button == 4) ctx.adjustFov(-1.0); |
371 else if (xev.xbutton.button == 5) ctx.adjustFov(+1.0); |
398 else if (xev.xbutton.button == 5) ctx.adjustFov(+1.0); |
372 else if (xev.xbutton.button == 8) resetView(); |
399 else if (xev.xbutton.button == 8) resetView(); |
373 else if (xev.xbutton.button == 9) keepRunningX11 = false; |
400 else if (xev.xbutton.button == 9) keepRunningX11 = false; |
374 redraw = true; |
401 redraw = true; |