From 1abc40e2394e69ac227e91720ccffe935a4b8c11 Mon Sep 17 00:00:00 2001 From: EvanR Date: Sun, 4 Jan 2009 23:17:59 -0600 Subject: [PATCH] Initial refactoring of the scroll stuff. The good news is that the graphical gliches are gone and the layout kludge is obliterated. The bad news is that you cannot scroll in the song editor. The point of this branch is to replace both the song_scroll and pattern_scroll fltk::ScrollGroups with two scroll bars which simply control the widgets using their callback. The resulting sanity will make the graphical problems trivially evaporate. --- src/arranger.cpp | 101 +++++++++++-------------------------------------------- src/arranger.h | 11 ++++-- src/ui.cpp | 12 ++++--- src/ui.fl | 23 +++++++------ src/ui.h | 8 +++-- 5 files changed, 53 insertions(+), 102 deletions(-) diff --git a/src/arranger.cpp b/src/arranger.cpp index 8442ecb..d2a6c5d 100644 --- a/src/arranger.cpp +++ b/src/arranger.cpp @@ -56,9 +56,6 @@ Arranger::Arranger(int x, int y, int w, int h, const char* label = 0) : fltk::Wi q_tick = 128*4; - xp_last = 0; - yp_last = 0; - insert_flag = 0; box_flag = 0; rresize_flag = 0; @@ -70,6 +67,10 @@ Arranger::Arranger(int x, int y, int w, int h, const char* label = 0) : fltk::Wi maxt = 0; + + int fakew = 1000; + int fakeh = 16*30; + } int Arranger::handle(int event){ @@ -394,6 +395,8 @@ int Arranger::handle(int event){ void Arranger::draw(){ + fltk::push_clip(0,0,w(),h()); + fltk::setfont(fltk::HELVETICA,8); fltk::setcolor(fltk::GRAY05); @@ -597,81 +600,19 @@ void Arranger::draw(){ s=s->next; } } -} - -static int kludge = 4;//see the same kludge in pianoroll.cpp -void Arranger::layout(){ - if(kludge > 0){ - kludge--; - return; - } - -/* this function has given some trouble so i will -document what it is supposed to do - -it is called, ideally, when the scroller is dragged, -when zoom changes, the window is resized or when -something changes in the arranger that means it needs -to be resized. -this function is supposed to tell the timeline and -track info widgets to update their scroll state and -redraw to simulate being controlled by the scroller. + fltk::pop_clip(); -the arranger widget itself needs to resize itself -so that it covers - -vertically, all track modules and scroll area, whichever is bigger -horizontally, all blocks (plus some) and scroll area, whichever is bigger - -*/ - - - - maxt = 0; - for(int i=0; ihead->next; - while(s){ - if(s->tick+s->dur > maxt){maxt=s->tick+s->dur;} - s=s->next; - } - } - - - - - int wp1 = ui->song_scroll->w(); - int wp2 = tick2xpix(maxt)+500; - int hp1 = ui->song_scroll->h(); - int hp2 = tracks.size() * 30; - int xp = ui->song_scroll->xposition(); - int yp = ui->song_scroll->yposition(); - - - ui->song_timeline->scroll = xp; - ui->track_info->scroll = yp; - - int hp = hp1>hp2 ? hp1 : hp2; - if(h() < hp){ - h(hp); - } - - ui->track_info->scroll = yp; - ui->track_info->redraw(); - - int wp = wp1>wp2 ? wp1 : wp2; - if(w() < wp){ - w(wp); - } - -//printf("relayout arranger %d %d\n",w(),h()); +} - ui->song_timeline->scroll = xp; +void Arranger::scrollTo(int X, int Y){ + scrollx = X; + scrolly = Y; + redraw(); + ui->song_timeline->scroll = X; ui->song_timeline->redraw(); - -// yp_last = yp; -// xp_last = xp; - + ui->track_info->scroll = Y; + ui->track_info->redraw(); } @@ -738,19 +679,17 @@ void Arranger::update(int pos){ if(!is_backend_playing()){ return; } - int wp = ui->song_scroll->w(); - int xp = ui->song_scroll->xposition(); - int yp = ui->song_scroll->yposition(); + //int wp = ui->song_scroll->w(); int X1 = tick2xpix(pos); - int X2 = X1 - xp; + int X2 = X1 - scrollx; if(X1 > w()-40){ return; } if(X2 < 0){ - ui->song_scroll->scrollTo(X1-50<0?0:X1-50,yp); + scrollTo(X1-50<0?0:X1-50,scrolly); } - if(X2 > wp-30){ - ui->song_scroll->scrollTo(X1-50,yp); + if(X2 > w()-30){ + scrollTo(X1-50,scrolly); } } diff --git a/src/arranger.h b/src/arranger.h index c870733..653cd81 100644 --- a/src/arranger.h +++ b/src/arranger.h @@ -27,8 +27,8 @@ class Arranger : public fltk::Widget { int maxt; - int xp_last; - int yp_last; + int fakeh; + int fakew; int insert_flag; int insert_torig; @@ -110,6 +110,9 @@ class Arranger : public fltk::Widget { int check_resize_safety(); int check_paste_safety(); + int scrollx; + int scrolly; + public: int zoom; @@ -125,10 +128,12 @@ class Arranger : public fltk::Widget { void update(int pos); - void layout(); + //void layout(); void reset_handle(){last_handle==NULL;} + void scrollTo(int X, int Y); + }; #endif diff --git a/src/ui.cpp b/src/ui.cpp index e569ce9..d861696 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -486,15 +486,19 @@ UI::UI() { } o->end(); } - {CustomScroll* o = song_scroll = new CustomScroll(255, 15, 385, 430); + {fltk::Group* o = song_scrollgroup = new fltk::Group(255, 15, 385, 430); o->set_vertical(); o->begin(); - {Arranger* o = arranger = new Arranger(0, 0, 245, 220, "arranger"); + {Arranger* o = arranger = new Arranger(0, 0, 370, 415, "arranger"); + o->set_vertical(); o->box(fltk::FLAT_BOX); - o->resize(1000,30*16); + fltk::Group::current()->resizable(o); + } + {fltk::Scrollbar* o = song_vscroll = new fltk::Scrollbar(370, 0, 15, 415); + o->set_vertical(); } + song_hscroll = new fltk::Scrollbar(0, 415, 370, 15); o->end(); - o->type(fltk::ScrollGroup::BOTH_ALWAYS); fltk::Group::current()->resizable(o); } o->end(); diff --git a/src/ui.fl b/src/ui.fl index 14d349d..c3d1a4e 100644 --- a/src/ui.fl +++ b/src/ui.fl @@ -69,7 +69,7 @@ o->resize(640,455);} visible {fltk::Group} {} {open xywh {0 0 640 445} resizable } { - {fltk::Group} song_edit { + {fltk::Group} song_edit {open xywh {0 0 640 445} } { {fltk::Group} {} { @@ -98,21 +98,22 @@ o->label_scale=4;} class Timeline } } - {fltk::ScrollGroup} song_scroll { + {fltk::Group} song_scrollgroup {open xywh {255 15 385 430} resizable - extra_code {\#include -\#include "customscroll.h" -o->type(fltk::ScrollGroup::BOTH_ALWAYS);} - class CustomScroll } { {fltk::Widget} arranger { - label arranger - xywh {0 0 245 220} box FLAT_BOX + label arranger selected + xywh {0 0 370 415} resizable box FLAT_BOX extra_code {\#include "seq.h" -\#include "arranger.h" -o->resize(1000,30*16);} +\#include "arranger.h"} class Arranger } + {fltk::Scrollbar} song_vscroll { + xywh {370 0 15 415} + } + {fltk::Scrollbar} song_hscroll { + xywh {0 415 370 15} + } } } {fltk::Group} pattern_edit {open @@ -148,7 +149,7 @@ o->resize(960,900);} xywh {0 370 595 75} } { {fltk::Widget} event_edit { - label {event editor} selected + label {event editor} xywh {0 0 580 75} resizable box FLAT_BOX extra_code {\#include "eventedit.h"} class EventEdit diff --git a/src/ui.h b/src/ui.h index d69091b..0626c80 100644 --- a/src/ui.h +++ b/src/ui.h @@ -10,10 +10,10 @@ #include #include "trackinfo.h" #include -#include -#include "customscroll.h" #include "arranger.h" +#include #include "timeline.h" +#include #include "pianoroll.h" #include "eventedit.h" #include "eventmenu.h" @@ -49,8 +49,10 @@ private: static void cb_line(fltk::Button*, void*); public: Timeline *song_timeline; - CustomScroll *song_scroll; + fltk::Group *song_scrollgroup; Arranger *arranger; + fltk::Scrollbar *song_vscroll; + fltk::Scrollbar *song_hscroll; fltk::Group *pattern_edit; Timeline *pattern_timeline; fltk::ScrollGroup *pattern_scroll; -- 2.11.4.GIT