Update NTK.
[nondaw.git] / sequencer / src / gui / draw.C
blob5d94fb0f710d037eed606459f83c96277721cd4e
2 /*******************************************************************************/
3 /* Copyright (C) 2007-2008 Jonathan Moore Liles                                */
4 /*                                                                             */
5 /* This program is free software; you can redistribute it and/or modify it     */
6 /* under the terms of the GNU General Public License as published by the       */
7 /* Free Software Foundation; either version 2 of the License, or (at your      */
8 /* option) any later version.                                                  */
9 /*                                                                             */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       */
12 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   */
13 /* more details.                                                               */
14 /*                                                                             */
15 /* You should have received a copy of the GNU General Public License along     */
16 /* with This program; see the file COPYING.  If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 /*******************************************************************************/
20 /* This file contains ALL platform specific drawing code required by the canvas */
22 #include "ui.H"
23 #include "draw.H"
25 #include "../common.h"
26 #include <stdlib.h>
27 #include <math.h>
29 #include "../canvas.H"
31 struct color_table {
32     int state;
33     unsigned char r, g, b;
36 struct color_table color_defs[] = {
37     { EMPTY,     18,  18,  18  },
38     { FULL,      255, 69,  0   },
39     { PARTIAL,   0,   0,   0   },
40     { CONTINUED, 80,  80,  80  },
41     { LINE,      10,  10,  10  },
42     { HIT,       255, 255, 255 },
43     { PLAYHEAD,  10,  69,  10  },
44     { SELECTED,  255, 10,  255 },
47 Fl_Color *state_colors;
49 Fl_Color velocity_colors[128];
50 Fl_Color velocity2_colors[128];
52 bool draw_borders = 1;
54 void
55 init_colors ( void )
57     unsigned int i;
58     /* velocity colors */
60     for ( i = 128; i--; )
61     {
62         velocity_colors[i] = fl_color_average( FL_GRAY, fl_rgb_color( i * 2, 255 - i * 2, 32 ), 0.4 );
63         velocity2_colors[i] = fl_color_average( FL_WHITE, velocity_colors[i], 0.5 );
64     }
66     state_colors = (Fl_Color*)malloc(sizeof( Fl_Color ) * MAX_STATE );
68     for ( i = elementsof( color_defs ); i--; )
69     {
70         state_colors[ color_defs[i].state ] = fl_rgb_color( color_defs[i].r,
71                                                             color_defs[i].g,
72                                                             color_defs[i].b );
73     }
76 int
77 gui_draw_ruler ( int x, int y, int w, int div_w, int div, int ofs, int p1, int p2 )
79     /* Across the top */
81     fl_font( FL_TIMES, ruler_height );
83     int h = ruler_height;
85     fl_color( canvas_background_color );
87     //  fl_rectf( x, y, x + (div_w * w), y + h );
88     fl_rectf( x, y, (div_w * w), h );
90     fl_color( FL_RED );
92     fl_line( x + div_w / 2, y, x + div_w * w, y );
94     char pat[40];
95     int z = div;
96     int i;
97     for ( i = 0; i < w; i++ )
98         if ( 0 == i % z )
99         {
100             int nx = x + (i * div_w) + (div_w / 2);
102             fl_color( FL_RED );
104             fl_line( nx, y, nx, y + h );
106             int k = ofs + i;
107             sprintf( pat, "%i", 1 + (k / z ));
109             fl_color( FL_WHITE );
110             fl_draw( pat, nx + div_w / 2, y + h + 1 / 2 );
111         }
113     if ( p1 != p2 )
114     {
115         if ( p1 >= 0 )
116         {
117             if ( p1 < p2 )
118                 fl_color( FL_GREEN );
119             else
120                 fl_color( FL_RED );
122             fl_rectf( x + (div_w * p1), y + h / 2, div_w, h / 2 );
124         }
125         if ( p2 >= 0 )
126         {
127             if ( p2 < p1 )
128                 fl_color( FL_GREEN );
129             else
130                 fl_color( FL_RED );
131             fl_rectf( x + (div_w * p2), y + h / 2, div_w, h / 2 );
133         }
134     }
136     return h;
139 void
140 gui_clear_area ( int x, int y, int w, int h )
142     fl_color( canvas_background_color );
144     fl_rectf( x, y, w, h );
148 gui_draw_string ( int x, int y, int w, int h, int color, const char *s, bool draw )
150     int rw;
152     if ( ! s )
153         return 0;
155     fl_font( FL_COURIER, min( h, 18 ) );
157     rw = fl_width( s );
159     if ( fl_not_clipped( x, y, rw, h ) && draw )
160     {
161         gui_clear_area( x, y, w, h );
163         if ( color )
164             fl_color( velocity_colors[ color ] );
165         else
166             fl_color( FL_DARK_CYAN );
168         fl_draw( s, x, y + h / 2 + fl_descent() );
169     }
171     return rw;
174 void
175 gui_draw_shape ( int x, int y, int w, int h, int shape, int state, int flags, int color  )
177     /* take advantage of FLTK's clipping */
178     if ( ! fl_not_clipped( x, y, w, h ) )
179         return;
181     if ( flags & F_PLAYHEAD )
182     {
183         state = state == FULL ? HIT : PLAYHEAD;
184         flags &= ~ F_SELECTION;
185     }
187     Fl_Color c1, c2;
189     if ( state == FULL && color  )
190     {
191         c1 = velocity_colors[ color ];
192         c2 = velocity2_colors[ color ];
193     }
194     else
195     {
196         c1 = state_colors[ state ];
197         c2 = fl_color_average( FL_WHITE, c1, 0.1 );
198     }
199         
200     if ( flags & F_SELECTION )
201         fl_color( fl_darker( fl_color() ) );
203     int bw = 1;
205     switch ( shape )
206     {
207         case SQUARE:
208 //            fl_rectf( x, y, w, h, FL_BLACK );
210             fl_color( c1 );
211             fl_rectf( x + bw, y + bw, w - bw * 2, h - bw * 2 );
212             if ( draw_borders )
213             {
214                 fl_color( c2 );
215                 fl_line_style( FL_SOLID, 2 );
216                 fl_rect( x + bw + 1, y + bw + 1, w - (bw+1) * 2, h - (bw+1) * 2 );
217                 fl_line_style( FL_SOLID, 0 );
218             }
219             break;
220         case BOX:
221             fl_draw_box( FL_THIN_UP_BOX, x + bw, y + bw, w - bw * 2, h - bw * 2, c1 );
222             break;
223         default:
224             ASSERTION( "unknown shape" );
225             break;
226     }
228     if ( flags & F_P1 || flags & F_P2 )
229     {
230         if ( flags & F_P1 )
231             fl_color( FL_GREEN );
232         else
233             fl_color( FL_RED );
235         int rw = w / 4;
236         int rh = h / 4;
238         fl_rectf( x + (w / 2) - (rw / 2), y + (h / 2) - (rh / 2), rw, rh );
239     }
242 extern UI *ui;
244 static
245 void
246 clear_status ( void * )
248     ui->status->label( NULL );
251 /** inform the user of something via a status bar */
252 void
253 gui_status ( const char *fmt, ... )
255     va_list args;
257     static char pat[256];
259     if ( fmt )
260     {
261         va_start( args, fmt );
262         vsnprintf( pat, 256, fmt, args );
263         va_end( args );
264     }
266     ui->status->label( pat );
268     Fl::add_timeout( 5.0f, clear_status );