source: projects/visualisator/gtkpapertapecolor.h @ 19

Last change on this file since 19 was 19, checked in by sven, 16 years ago

The Gtk::PaperTape gtkmm implementation of the GtkPaperTape widget. Now
quite more object oriented, using a MVC approach. There's much still to
do.

I commit these files now because I won't be able to work at the project
in the next week(s). Afterwards I plan to make more use of the
versioning features, commiting on a more regular basis.

-- Sven @ workstation

File size: 5.6 KB
Line 
1#ifndef __GTK_PAPER_TAPE_COLOR__
2#define __GTK_PAPER_TAPE_COLOR__
3
4#include <gtkmm/drawingarea.h>
5#include <gtkmm/checkmenuitem.h>
6#include <gtkmm/menuitem.h>
7#include <gtkmm/sizegroup.h>
8#include <gtkmm/actiongroup.h>
9#include <gtkmm/toggleaction.h>
10#include <gtkmm/colorbutton.h>
11#include <gtkmm/action.h>
12#include <vector>
13#include <iostream>
14
15#include <cairomm/pattern.h>
16
17namespace Gtk
18{ class PaperTapeColor; }
19#include "gtkpapertape.h"
20#include "gtkpapertapeview.h"
21#include "lochstreifen.h"
22
23namespace Gtk {
24
25
26/**
27 * The PaperTapeColor class represents a color which will be used
28 * to paint some component on the PAPERTAPE. It also implements
29 * an Action -- that is: This class is an Action. It serves a
30 * nice Menuitem for color selection, as well as an auxillary
31 * toggle Menuitem to switch the display of that LOCHSTREIFEN
32 * component on or off.
33 * This is mainly intended to be used with PaperTapeView. That
34 * class automatically initializes such a PaperTapeColor class
35 * for every LOCHSTREIFEN cairo_pattern_t object. These Color
36 * Objects are stored in a map.
37 * @see PaperTapeView::colors
38 **/
39class PaperTapeColor : public Action {
40private:
41        /// The toggle action as a "nested action", somewhat quick&dirty
42        Glib::RefPtr<ToggleAction> toggle_action;
43        /// Much more Quick and Dirty: The menuitem which will be
44        /// generated at run time by create_menu_item_vfunc.
45        /// Stored here for enable/disable access from toggled()
46        MenuItem* menu_item;
47
48        /// The View for which this color is allocated.
49        /// Deprecated -- not used at all!
50        PaperTapeView* view;
51
52        /// can this element be disabled with
53        /// display_toggle?
54        bool switchable;
55        /// Title for color dialog
56        Glib::ustring dialog_title;
57        /// Label for menu color item
58        Glib::ustring menu_label;
59        /// Label for toggle menu item
60        Glib::ustring toggle_label;
61        /// Action name (base name for toggle and color action)
62        Glib::ustring action_name;
63        /// Target pattern which will be affected
64        cairo_pattern_t **target;
65
66        /// The current value of the color
67        cairo_pattern_t *value;
68
69        /// The constructor is private, too. USe construct(...)
70        /// to get a RefPtr instance.
71        PaperTapeColor(const Glib::ustring& name);
72
73        /// see signal_color_changed() for an explanation.
74        sigc::signal<void,PaperTapeColor*> color_changed;
75protected:
76        /// This method creates the ColorMenuItem thing
77        /// at runtime.
78        virtual Widget* create_menu_item_vfunc();
79        /// This is used to keep the Gtk Action mechanism from
80        /// overwriting my own MenuItem with a stupid GtkLabel.
81        virtual void connect_proxy_vfunc (Widget* proxy) {
82                std::cout << "They'll want to proxy some widget!\n";
83        }
84
85        /// This is currently not used (Static initialisation issue --
86        /// GLIB not initialized!), but is intended to make the
87        /// menu_items over many PaperTapeColors look equal.
88        static const Glib::RefPtr<SizeGroup> label_group;
89
90        /// An internal signal for the color_button
91        void color_set(); // CB
92        /// An internal signal for the toggle_action
93        void toggled(); // CB
94
95        /// The color button, quick and dirty stored here for
96        /// access e.g. at color_set() or set().
97        ColorButton color_button;
98       
99public:
100        /**
101         * The official constuctor, it will return a RefPtr reference,
102         * like all the Gtk::Action classes have.
103         * @param view The View which called this
104         * @param target The address of the LOCHSTREIFEN target pattern link
105         * @param action_base_name The base name, "_color" and "_toggle" will be appended
106         * @param dialog_title The title of the Color selection dialog
107         * @param menu_label The pango markuped label of the ColorMenuItem
108         * @param toggle_label THe label of the ToggleMenuItem. Leave empty if not toggled.
109         * @returns A smart pointer to a PaperTapeColor.
110         **/
111        static Glib::RefPtr<PaperTapeColor> create(
112                PaperTapeView* view,
113                cairo_pattern_t** target,
114                const Glib::ustring& action_base_name,
115                const Glib::ustring& dialog_title,
116                const Glib::ustring& menu_label,
117                const Glib::ustring& toggle_label
118        );
119
120        /// Well, use this to find out if you need to export the
121        /// toggle_action Action. It won't be useful if the element that
122        /// this color represents is not intented to be turned off.
123        bool is_switchable() { return switchable; }
124       
125        /// Give out if the element that this color represents is currently
126        /// displayed.
127        bool is_displayed() { return toggle_action->get_active(); }
128       
129        /// Get the toggle action. Don't use it if is_switchable()
130        /// returns false.
131        Glib::RefPtr<ToggleAction> get_toggle_action() { return toggle_action; }
132       
133        /**
134         * This is a user function (for you!) to set the Color directly.
135         * It will send all signals and update all buttons automatically.
136         * Note: This won't turn on the color, if turned off currently.
137         * Use get_toggle_action()->set_active(true); for that purpose.
138         *
139         * @param red Percentual red, from 0.0 to 1.0
140         * @param green These fields are just the same...
141         * @param blue ...than cairo_pattern_create_from_rgba...
142         * @param alpha ...wants them.
143         **/
144        void set(double red, double green, double blue, double alpha);
145        /// This makes the same, it just copies your pattern.
146        void set(cairo_pattern_t* pattern);
147       
148        /**
149         * This signal is emitted whenever the color is changed (by used input or
150         * exiplit set() call) or the visibility of the element which is controlled
151         * by this Color object has been toggled.
152         * Therefore you can use this signal quite well to perform exposure events,
153         * etc.
154         * You'll recieve a pointer to this object with this signal. Don't free it.
155         **/
156        sigc::signal<void,PaperTapeColor*> signal_color_changed() { return color_changed; }
157       
158        /// Don't know if anybody needs this function.
159        MenuItem* create_menu_item() {
160                return (MenuItem*)create_menu_item_vfunc();
161        }
162};
163
164
165} // namespace
166#endif // TAPE_COLOR
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License