mouse scroll works

This commit is contained in:
BADIM-PC\Vadim 2018-02-12 13:31:52 +03:00
parent e377fa9987
commit c3e7ff8e43
6 changed files with 82 additions and 48 deletions

View File

@ -98,7 +98,10 @@ typedef struct
u16 middle:1; u16 middle:1;
u16 right:1; u16 right:1;
u16 scroll:13; s16 scrollx:6;
s16 scrolly:6;
u16 temp:1;
}; };
u16 btns; u16 btns;

View File

@ -1057,21 +1057,25 @@ static void processMouse(Code* code)
static void textEditTick(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; // SDL_Event* event = NULL;
// while ((event = pollEvent())) // while ((event = pollEvent()))
// { // {
// switch(event->type) // 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: // case SDL_KEYDOWN:
// processKeydown(code, event->key.keysym.sym); // processKeydown(code, event->key.keysym.sym);
// break; // break;

View File

@ -2556,18 +2556,23 @@ static void checkNewVersion(Console* console)
static void tick(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; // SDL_Event* event = NULL;
// while ((event = pollEvent())) // while ((event = pollEvent()))
// { // {
// switch(event->type) // 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: // case SDL_KEYDOWN:
// { // {
// switch(event->key.keysym.sym) // switch(event->key.keysym.sym)

View File

@ -512,15 +512,24 @@ static void processGamepad()
static void pollEvent() static void pollEvent()
{ {
tic80_input* input = &platform.studio->tic->ram.input;
input->mouse.btns = 0;
SDL_Event event; SDL_Event event;
if(SDL_PollEvent(&event)) while(SDL_PollEvent(&event))
{ {
switch(event.type) switch(event.type)
{ {
// case SDL_KEYDOWN: // case SDL_KEYDOWN:
// if(processShortcuts(&event.key)) return NULL; // if(processShortcuts(&event.key)) return NULL;
// break; // break;
case SDL_MOUSEWHEEL:
{
input->mouse.scrollx = event.wheel.x;
input->mouse.scrolly = event.wheel.y;
}
break;
case SDL_JOYDEVICEADDED: case SDL_JOYDEVICEADDED:
{ {
s32 id = event.jdevice.which; s32 id = event.jdevice.which;

View File

@ -1571,26 +1571,35 @@ static void scrollNotes(Music* music, s32 delta)
static void drawTrackerLayout(Music* music) 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; // SDL_Event* event = NULL;
// while ((event = pollEvent())) // while ((event = pollEvent()))
// { // {
// switch (event->type) // 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: // case SDL_KEYDOWN:
// processKeydown(music, &event->key.keysym); // processKeydown(music, &event->key.keysym);
// break; // break;

View File

@ -1588,6 +1588,24 @@ static void drawSpriteToolbar(Sprite* sprite)
static void tick(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; // SDL_Event* event = NULL;
// while ((event = pollEvent())) // while ((event = pollEvent()))
@ -1597,20 +1615,6 @@ static void tick(Sprite* sprite)
// case SDL_KEYDOWN: // case SDL_KEYDOWN:
// processKeydown(sprite, event->key.keysym.sym); // processKeydown(sprite, event->key.keysym.sym);
// break; // 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;
// } // }
// } // }