From 56c04b6e308789e44be192bb212b80302ae3bf33 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 12 Mar 2008 12:59:59 -0500 Subject: [PATCH] Add new Fl_Scalepack class. --- DPM.C | 2 +- Fl_Scalepack.C | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ Fl_Scalepack.H | 41 ++++++++++++++++++++++ Makefile | 4 +-- Mixer_Strip.fl | 32 ++++++++++++++--- 5 files changed, 167 insertions(+), 7 deletions(-) create mode 100644 Fl_Scalepack.C create mode 100644 Fl_Scalepack.H diff --git a/DPM.C b/DPM.C index 54cffc3..d05ee9d 100644 --- a/DPM.C +++ b/DPM.C @@ -30,7 +30,7 @@ DPM::DPM ( int X, int Y, int W, int H, const char *L ) : Meter( X, Y, W, H, L ) { - divisions( 32 ); + divisions( 64 ); type( FL_VERTICAL ); dim( 0.80f ); diff --git a/Fl_Scalepack.C b/Fl_Scalepack.C new file mode 100644 index 0000000..e8564cd --- /dev/null +++ b/Fl_Scalepack.C @@ -0,0 +1,95 @@ + +/*******************************************************************************/ +/* Copyright (C) 2008 Jonathan Moore Liles */ +/* */ +/* This program is free software; you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, but WITHOUT */ +/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ +/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ +/* more details. */ +/* */ +/* You should have received a copy of the GNU General Public License along */ +/* with This program; see the file COPYING. If not,write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*******************************************************************************/ + + +/* Fl_Scalepack + + This is similar to an Fl_Pack, but instead of the pack resizing + itself to enclose its children, this pack resizes its children to + fit itself. Of course, this only works well with highly flexible + widgets, but the task comes up often enough to warrent this class. + + If any child happens to be the resizable() widget, it is given half + of the available area, with the other widgets packed around it in + the remaining space. + +*/ + +#include "Fl_Scalepack.H" + +#include + +#include + +Fl_Scalepack::Fl_Scalepack ( int X, int Y, int W, int H, const char *L ) : + Fl_Group( X, Y, W, H, L ) +{ + resizable( 0 ); + _spacing = 0; +} + +void +Fl_Scalepack::draw ( void ) +{ + int tx = x() + Fl::box_dx( box() ); + int ty = y() + Fl::box_dy( box() ); + int tw = w() - Fl::box_dw( box() ); + int th = h() - Fl::box_dh( box() ); + + if ( damage() & FL_DAMAGE_ALL ) + { + draw_box(); + draw_label(); + } + + int v = 0; + + for ( int i = children(); i--; ) + if ( child( i )->visible() ) + ++v; + + int sz, pos; + + if ( type() == HORIZONTAL ) + { + sz = tw / v; + pos = tw - ( tw % sz ); + } + else + { + sz = th / v; + pos = th - ( th % sz ); + } + + for ( int i = children(); i--; ) + if ( child( i )->visible() ) + { + pos -= sz; + + if ( type() == HORIZONTAL ) + child( i )->resize( tx + pos, ty, sz, th ); + else + child( i )->resize( tx, ty + pos, tw, sz ); + + if ( damage() & FL_DAMAGE_CHILD ) + update_child( *child( i ) ); + else + draw_child( *child( i ) ); + } +} diff --git a/Fl_Scalepack.H b/Fl_Scalepack.H new file mode 100644 index 0000000..935b578 --- /dev/null +++ b/Fl_Scalepack.H @@ -0,0 +1,41 @@ + +/*******************************************************************************/ +/* Copyright (C) 2008 Jonathan Moore Liles */ +/* */ +/* This program is free software; you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, but WITHOUT */ +/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ +/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ +/* more details. */ +/* */ +/* You should have received a copy of the GNU General Public License along */ +/* with This program; see the file COPYING. If not,write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*******************************************************************************/ + +#pragma once + +#include + +class Fl_Scalepack : public Fl_Group +{ + + int _spacing; + +public: + + enum { VERTICAL, HORIZONTAL }; + + Fl_Scalepack ( int X, int Y, int W, int H, const char *L = 0 ); + virtual ~Fl_Scalepack ( ) { } + + int spacing ( void ) const { return _spacing; } + void spacing ( int v ) { _spacing = v; redraw(); } + + virtual void draw ( void ); + +}; diff --git a/Makefile b/Makefile index fdf58a6..482e326 100644 --- a/Makefile +++ b/Makefile @@ -26,8 +26,8 @@ $(OBJS): Makefile test: $(OBJS) $(CXX) $(CXXFLAGS) $(LIBS) $(OBJS) -o $@ -mixer: Mixer_Strip.o Mixer.o DPM.o - $(CXX) $(CXXFLAGS) $(LIBS) Mixer_Strip.o Mixer.o DPM.o -o $@ +mixer: Mixer_Strip.o Mixer.o DPM.o Fl_Scalepack.o + $(CXX) $(CXXFLAGS) $(LIBS) Mixer_Strip.o Mixer.o DPM.o Fl_Scalepack.o -o $@ ESRCS=Audio_File.C Audio_File_SF.C Loggable.C diff --git a/Mixer_Strip.fl b/Mixer_Strip.fl index 2f89d59..77ab719 100644 --- a/Mixer_Strip.fl +++ b/Mixer_Strip.fl @@ -5,6 +5,9 @@ code_name {.C} decl {\#include "DPM.H"} {public global } +decl {\#include "Fl_Scalepack.H"} {public global +} + widget_class Mixer_Strip {open xywh {1051 42 124 816} type Double box UP_FRAME color 32 selection_color 63 resizable code0 {size( 120, h() );} visible @@ -41,10 +44,31 @@ widget_class Mixer_Strip {open callback {// parent()->parent()->damage( FL_DAMAGE_ALL, x(), y(), w(), h() );} xywh {14 195 33 471} type {Vert Knob} color 32 selection_color 1 minimum 1.5 maximum 0 step 0.01 value 1 textsize 14 } - Fl_Box meter { - label DPM selected - xywh {57 193 55 484} box ROUNDED_BOX selection_color 88 - class DPM + Fl_Pack meters_pack { + label meters open selected + xywh {57 189 59 490} type HORIZONTAL + class Fl_Scalepack + } { + Fl_Box meter { + label DPM + xywh {57 193 28 484} box ROUNDED_BOX selection_color 88 + class DPM + } + Fl_Box {} { + label DPM + xywh {86 193 30 484} box ROUNDED_BOX selection_color 88 + class DPM + } + Fl_Box {} { + label DPM + xywh {96 203 20 476} box ROUNDED_BOX selection_color 88 + class DPM + } + Fl_Box {} { + label DPM + xywh {106 213 20 476} box ROUNDED_BOX selection_color 88 + class DPM + } } } Fl_Box {} {