From 9b485d89995ac9f6776c67384e1cf9a460631ebd Mon Sep 17 00:00:00 2001 From: otya128 Date: Wed, 14 Dec 2016 20:06:10 +0900 Subject: [PATCH] Add scroll support --- SMILEBASIC/petitcomputer.d | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index 3ca0c66..c5e06ad 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -172,6 +172,7 @@ struct Display { SDL_Rect[] rect; Size windowSize; + int yoffset; } class RingBuffer(T) { @@ -384,7 +385,7 @@ class PetitComputer } void chScreen2(int x, int y, int w, int h) { - glViewport2(x, currentDisplay.windowSize.height - h - y, w, h); + glViewport2(x, currentDisplay.yoffset - h - y, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, w, h, 0, 1024, -2048); @@ -395,7 +396,7 @@ class PetitComputer } void chRenderingDisplay(int i, int x, int y, int w, int h) { - glViewport2(x + currentDisplay.rect[i].x, currentDisplay.windowSize.height - h - y - currentDisplay.rect[i].y, w, h); + glViewport2(x + currentDisplay.rect[i].x, currentDisplay.yoffset - h - y - currentDisplay.rect[i].y, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(x, x + w, y + h, y, 1024, -2048); @@ -456,6 +457,7 @@ class PetitComputer currentDisplay = Display([display0, display1], Size(std.algorithm.max(resolutionTable[gamepad].width, resolutionTable[tv].width), resolutionTable[gamepad].height + resolutionTable[tv].height)); xscreenmode = 4; } + currentDisplay.yoffset = currentDisplay.windowSize.height; int grpw, grph; graphic.getSize(grpw, grph); //1024*1024? @@ -747,8 +749,10 @@ class PetitComputer int mousex, mousey; if (SDL_GetMouseState(&mousex, &mousey) & SDL_BUTTON_LMASK) { + int ww, wh; + SDL_GetWindowSize(window, &ww, &wh); mousex = cast(int)(mousex / scaleX); - mousey = cast(int)(mousey / scaleY); + mousey = cast(int)(mousey / scaleY) - (wh - currentDisplay.yoffset); import std.algorithm.comparison : clamp; auto old = touchPosition; if (x.mode != XMode.WIIU) @@ -859,6 +863,12 @@ class PetitComputer } keybuffermutex.unlock(); break; + case SDL_MOUSEWHEEL: + synchronized (renderSync) + { + currentDisplay.yoffset -= event.wheel.y * 10; + } + break; default: break; }