From c3e7ff8e43d3caf35a42714b87b399ee87d5238e Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 12 Feb 2018 13:31:52 +0300 Subject: [PATCH] mouse scroll works --- include/tic80.h | 5 ++++- src/code.c | 24 ++++++++++++++---------- src/console.c | 19 ++++++++++++------- src/main.c | 11 ++++++++++- src/music.c | 39 ++++++++++++++++++++++++--------------- src/sprite.c | 32 ++++++++++++++++++-------------- 6 files changed, 82 insertions(+), 48 deletions(-) diff --git a/include/tic80.h b/include/tic80.h index 383e1f9..4b746a5 100644 --- a/include/tic80.h +++ b/include/tic80.h @@ -98,7 +98,10 @@ typedef struct u16 middle:1; u16 right:1; - u16 scroll:13; + s16 scrollx:6; + s16 scrolly:6; + + u16 temp:1; }; u16 btns; diff --git a/src/code.c b/src/code.c index 9337c8e..37e3732 100644 --- a/src/code.c +++ b/src/code.c @@ -1057,21 +1057,25 @@ static void processMouse(Code* code) static void textEditTick(Code* code) { + // process scroll + { + tic80_input* input = &code->tic->ram.input; + + if(input->mouse.scrolly) + { + enum{Scroll = 3}; + s32 delta = input->mouse.scrolly > 0 ? -Scroll : Scroll; + code->scroll.y += delta; + + normalizeScroll(code); + } + } + // SDL_Event* event = NULL; // while ((event = pollEvent())) // { // switch(event->type) // { -// case SDL_MOUSEWHEEL: -// { -// enum{Scroll = 3}; -// s32 delta = event->wheel.y > 0 ? -Scroll : Scroll; - -// code->scroll.y += delta; - -// normalizeScroll(code); -// } -// break; // case SDL_KEYDOWN: // processKeydown(code, event->key.keysym.sym); // break; diff --git a/src/console.c b/src/console.c index cfff713..f01f05b 100644 --- a/src/console.c +++ b/src/console.c @@ -2556,18 +2556,23 @@ static void checkNewVersion(Console* console) static void tick(Console* console) { + // process scroll + { + tic80_input* input = &console->tic->ram.input; + + if(input->mouse.scrolly) + { + enum{Scroll = 3}; + s32 delta = input->mouse.scrolly > 0 ? -Scroll : Scroll; + setScroll(console, console->scroll.pos + delta); + } + } + // SDL_Event* event = NULL; // while ((event = pollEvent())) // { // switch(event->type) // { - // case SDL_MOUSEWHEEL: - // { - // enum{Scroll = 3}; - // s32 delta = event->wheel.y > 0 ? -Scroll : Scroll; - // setScroll(console, console->scroll.pos + delta); - // } - // break; // case SDL_KEYDOWN: // { // switch(event->key.keysym.sym) diff --git a/src/main.c b/src/main.c index ee8fef2..09e34c9 100644 --- a/src/main.c +++ b/src/main.c @@ -512,15 +512,24 @@ static void processGamepad() static void pollEvent() { + tic80_input* input = &platform.studio->tic->ram.input; + input->mouse.btns = 0; + SDL_Event event; - if(SDL_PollEvent(&event)) + while(SDL_PollEvent(&event)) { switch(event.type) { // case SDL_KEYDOWN: // if(processShortcuts(&event.key)) return NULL; // break; + case SDL_MOUSEWHEEL: + { + input->mouse.scrollx = event.wheel.x; + input->mouse.scrolly = event.wheel.y; + } + break; case SDL_JOYDEVICEADDED: { s32 id = event.jdevice.which; diff --git a/src/music.c b/src/music.c index 8ce7d2f..307edf1 100644 --- a/src/music.c +++ b/src/music.c @@ -1571,26 +1571,35 @@ static void scrollNotes(Music* music, s32 delta) static void drawTrackerLayout(Music* music) { + tic_mem* tic = music->tic; + + // process scroll + { + tic80_input* input = &tic->ram.input; + + if(input->mouse.scrolly) + { + if(tic->api.key(tic, tic_key_ctrl)) + { + scrollNotes(music, input->mouse.scrolly > 0 ? 1 : -1); + } + else + { + enum{Scroll = NOTES_PER_BEET}; + s32 delta = input->mouse.scrolly > 0 ? -Scroll : Scroll; + + music->tracker.scroll += delta; + + updateScroll(music); + } + } + } + // SDL_Event* event = NULL; // while ((event = pollEvent())) // { // switch (event->type) // { - // case SDL_MOUSEWHEEL: - // if(SDL_GetModState() & TIC_MOD_CTRL) - // { - // scrollNotes(music, event->wheel.y > 0 ? 1 : -1); - // } - // else - // { - // enum{Scroll = NOTES_PER_BEET}; - // s32 delta = event->wheel.y > 0 ? -Scroll : Scroll; - - // music->tracker.scroll += delta; - - // updateScroll(music); - // } - // break; // case SDL_KEYDOWN: // processKeydown(music, &event->key.keysym); // break; diff --git a/src/sprite.c b/src/sprite.c index 65e3fb0..566baf0 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -1588,6 +1588,24 @@ static void drawSpriteToolbar(Sprite* sprite) static void tick(Sprite* sprite) { + // process scroll + { + tic80_input* input = &sprite->tic->ram.input; + + if(input->mouse.scrolly) + { + s32 size = sprite->size; + s32 delta = input->mouse.scrolly; + + if(delta > 0) + { + if(size < (TIC_SPRITESIZE * TIC_SPRITESIZE)) size <<= 1; + } + else if(size > TIC_SPRITESIZE) size >>= 1; + + updateSpriteSize(sprite, size); + } + } // SDL_Event* event = NULL; // while ((event = pollEvent())) @@ -1597,20 +1615,6 @@ static void tick(Sprite* sprite) // case SDL_KEYDOWN: // processKeydown(sprite, event->key.keysym.sym); // break; - // case SDL_MOUSEWHEEL: - // { - // s32 size = sprite->size; - // s32 delta = event->wheel.y; - - // if(delta > 0) - // { - // if(size < (TIC_SPRITESIZE * TIC_SPRITESIZE)) size <<= 1; - // } - // else if(size > TIC_SPRITESIZE) size >>= 1; - - // updateSpriteSize(sprite, size); - // } - // break; // } // }