Fixed bug in DragBar.
[epichord.git] / src / dragbar.cpp
blob0bf10435af48397cc05f39e2980dffe08538e526
1 /*
2 Epichord - a midi sequencer
3 Copyright (C) 2008 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
23 #include <stdlib.h>
24 #include <stdio.h>
26 #include <fltk/Widget.h>
27 #include <fltk/Group.h>
28 #include <fltk/draw.h>
29 #include <fltk/events.h>
31 #include "dragbar.h"
34 DragBar::DragBar(int x, int y, int w, int h, const char* label) :
35 fltk::Widget(x, y, w, h, label) {
37 cached_flag;
41 int DragBar::handle(int event){
42 int X = fltk::event_x();
43 switch(event){
44 case fltk::PUSH:
45 orig_x = X;
46 orig_val = val;
47 return 1;
48 case fltk::DRAG:
49 val = orig_val - (X - orig_x);
50 if(val < 0){val=0;}
51 if(val != last_val){
52 redraw();
53 do_callback();
54 last_val = val;
56 return 1;
58 return 0;
61 void DragBar::draw(){
62 draw_box();
64 fltk::push_clip(2,2,w()-4,h()-4);
66 fltk::setcolor(fltk::GRAY60);
67 fltk::fillrect(2,2,w()-4,h()-4);
69 if(!cached_flag){//draw first time
70 for(int i=-val; i<w(); i+=6){
71 if(i+10 > 0){
72 fltk::setcolor(fltk::GRAY80);
73 fltk::fillrect(i+5,4,3,1);
74 fltk::fillrect(i+5,4,1,2);
76 fltk::setcolor(fltk::GRAY30);
77 fltk::fillrect(i+5,6,3,1);
78 fltk::fillrect(i+7,5,1,2);
80 fltk::setcolor(fltk::GRAY80);
81 fltk::fillrect(i+5,4+5,3,1);
82 fltk::fillrect(i+5,4+5,1,2);
84 fltk::setcolor(fltk::GRAY30);
85 fltk::fillrect(i+5,6+5,3,1);
86 fltk::fillrect(i+7,5+5,1,2);
90 int GX=x();
91 int GY=y();
92 fltk::Widget* p = parent();
93 while(p){
94 if(p->parent() != NULL){//the window
95 GX+=p->x();
96 GY+=p->y();
98 p = p->parent();
100 readimage(gfxbuf,fltk::RGB,fltk::Rectangle(GX+2,GY+2,102,h()-4));
101 cached_flag=1;
103 else{
104 for(int i=-val; i<w(); i+=102){
105 if(i+200 > 0){
106 drawimage(gfxbuf,fltk::RGB,fltk::Rectangle(2+i,2,102,h()-4));
111 fltk::pop_clip();