root/trunk/FRII/gui/ColorPatch.hh

Revision 10, 2.2 kB (checked in by t, 3 years ago)

Tailorization
Import of the upstream sources from

Repository: :pserver:anonymous@cvs.sf.net:/cvsroot/familyjewels

Kind: cvs

Module: FRII

Revision: 2005-12-09 09:00:54 by titus

Original author: tailor@vallista.idyll.org
Date: 2005-12-09 09:00:54

  • Property svn:executable set to *
Line 
1 /*
2  * This file is part of the FamilyRelations II source distribution.
3  *
4  * FamilyRelations II is part of the FamilyJewels package for comparative
5  * sequence analysis: http://family.caltech.edu/.
6  *
7  * Contact author: C. Titus Brown, titus@caltech.edu.
8  *
9  * This program and all associated source code files are Copyright (C) 2003,
10  * 2004 the California Institute of Technology, Pasadena, CA, 91125 USA.  It
11  * is under the Lesser GNU Public License; please see the included
12  * LICENSE.txt file for more information, or contact Titus directly.
13  *
14  */
15
16 // Interface and implementation for a color display/chooser.
17
18 #ifndef COLOR_PATCH_HH
19 #define COLOR_PATCH_HH
20
21 #include <FL/Fl.H>
22 #include <FL/fl_draw.H>
23 #include <FL/Fl_Box.H>
24 #include <FL/fl_show_colormap.H>
25
26 #include <vector>
27
28 namespace gui {
29
30   //
31   // ColorChangeListener_
32   //
33
34   class ColorChangeListener_ {
35   protected:
36     ColorChangeListener_() { };
37   public:
38                               virtual ~ColorChangeListener_() { };
39     virtual void notify(Fl_Color c) = 0;
40   };
41
42   //
43   // class ColorPatch
44   //
45
46   class ColorPatch : public Fl_Box {
47   protected:
48     std::vector<ColorChangeListener_*> _to_notify_list;
49     Fl_Color _color;
50
51     // Just draw a box of color.
52     void draw() { fl_color(color()); fl_rectf(x(), y(), w(), h()); }
53
54     // When clicked on, bring up a window with a color chooser.
55     int handle(int e) {
56       if (e == FL_PUSH) {
57         // CTB -- I don't know how to make the colormap stay up.  Hmm.
58         Fl_Color old_color = color();
59         Fl_Color new_color = fl_show_colormap(old_color);
60         if (new_color != old_color) {
61           color(new_color);
62           redraw();
63           notify_changed();
64         }
65
66         return 1;
67       } else {
68         return Fl_Widget::handle(e);
69       }
70     }
71
72     void notify_changed() {
73       Fl_Color c = color();
74       for (unsigned int i = 0; i < _to_notify_list.size(); i++) {
75         _to_notify_list[i]->notify(c);
76       }
77     }
78   public:
79     // Constructor: take normal Fl_Box parameters + a color.
80     ColorPatch(int x, int y, int w, int h, Fl_Color c) :
81       Fl_Box(x, y, w, h), _color(c) {
82       color(_color);
83     };
84
85     virtual ~ColorPatch() { };
86
87     void add_change_listener(ColorChangeListener_* l) {
88       _to_notify_list.push_back(l);
89     }
90   };
91 }
92
93 #endif // COLOR_PATCH_HH
94
Note: See TracBrowser for help on using the browser.