Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

component.h

Go to the documentation of this file.
00001 /*
00002         ClanGUI, copyrights by various people. Have a look in the CREDITS file.
00003         
00004         This sourcecode is distributed using the Library GNU Public Licence,
00005         version 2 or (at your option) any later version. Please read LICENSE
00006         for details.
00007 */
00008 
00010 
00011 #ifndef header_component
00012 #define header_component
00013 
00014 #include <string>
00015 
00016 #include "../signals.h"
00017 #include "../Core/Math/rect.h"
00018 #include "../Core/Math/point.h"
00019 #include "../Display/Input/key.h"
00020 
00021 class CL_GUIManager;
00022 class CL_ComponentStyle;
00023 class CL_InputDevice;
00024 class CL_ComponentOptions;
00025 class CL_StyleManager;
00026 class CL_Component_Generic;
00027 
00028 class CL_Component
00029 //: Generic component interface
00030 {
00032 public:
00033         CL_Component(
00034                 CL_Component *parent,
00035                 CL_StyleManager *style = NULL);
00036 
00037         CL_Component(
00038                 const CL_Rect &pos,
00039                 CL_Component *parent,
00040                 CL_StyleManager *style = NULL);
00041 
00042         CL_Component(
00043                 const CL_ComponentOptions &options,
00044                 CL_Component *parent,
00045                 CL_StyleManager *style = NULL);
00046         
00047         virtual ~CL_Component();
00048 
00050 public:
00051         CL_Component *get_parent() const;
00052         // Returns the parent component, or NULL if none.
00053 
00054         CL_Component *get_root_parent();
00055         // Returns the root parent.
00056 
00057         CL_GUIManager *get_gui_manager() const;
00058         // Returns the GUI manager that this component is attached to, or NULL if none.
00059 
00060         CL_StyleManager *get_style_manager() const;
00061         // Returns the style manager used by this component.
00062 
00063         int get_width() const;
00064         // Returns the width of the component.
00065 
00066         int get_height() const;
00067         // Returns the height of the component.
00068 
00069         CL_Rect get_screen_rect() const;
00070         // Returns the components position in screen coordinates.
00071 
00072         const CL_Rect &get_position() const;
00073         // Returns the position of this component.
00074 
00075         bool has_child(CL_Component *component) const;
00076         // Returns true if the passed component is a child of this component.
00077 
00078         std::list<CL_Component *> &get_children();
00079         // Returns the list of child components.
00080 
00081         const std::list<CL_Component *> &get_children() const;
00082         // Returns the list of child components.
00083 
00084         CL_Rect get_children_rect();
00085         // Returns the bounding rectangle of the component's children.
00086 
00087         CL_Component *get_component_at(int pos_x, int pos_y);
00088         // Returns the component at (pos_x, pos_y).
00089         // NULL is returned if the point is outside the component.
00090         // The component itself is returned if the component has no child at the specified point.
00091 
00092         bool is_visible() const;
00093         // Returns true if component is visible.
00094 
00095         bool is_enabled() const;
00096         // Returns true if component accepts user input.
00097 
00098         bool is_popup() const;
00099         // Returns true if component is a popup window.
00100 
00101         bool has_focus() const;
00102         // Returns true if component has the focus.
00103 
00104         bool is_mouse_captured() const;
00105         // Returns true if component has mouse captured.
00106 
00107         bool is_removeflag_set() const;
00108         // I have no idea what this does... -- mbn 3. okt 2000.
00109 
00111 public:
00112         void update();
00113         // Calls sig_begin_paint(), then sig_paint(), and finally sig_end_paint().
00114 
00115         void set_position(const CL_Rect &new_pos);
00116         // Sets the position (relative to its parent) and size of this component.
00117 
00118         void set_position(int new_x, int new_y);
00119         // Sets the position of this component (relative to its parent).
00120 
00121         void set_size(int new_width, int new_height);
00122         // Sets the size of this component.
00123 
00124         void set_parent(CL_Component *parent);
00125         // Sets the parent of this component.
00126 
00127         void set_gui_manager(CL_GUIManager *gui);
00128         // Sets the GUI manager this component is attached to.
00129 
00130         void set_width(int width);
00131         // Changes the width of the component.
00132 
00133         void set_height(int height);
00134         // Changes the height of the component.
00135 
00136         void show(bool show = true);
00137         // Changes the visibility flag.
00138 
00139         void enable(bool enable = true);
00140         // Enable/Disable user input.
00141 
00142         void popup(bool popup);
00143         // Change popup flag.
00144 
00145         void set_focus();
00146         // Give focus to this component.
00147 
00148         void capture_mouse();
00149         // Capture the mouse on the currently attached GUI manager. All mouse input
00150         // will be directed to this component until release_mouse() is called.
00151 
00152         void release_mouse();
00153         // Releases the mouse capture.
00154 
00155         void close();
00156         // Closes this component. What does that mean?? -- mbn 3. okt. 2000
00157 
00158         void run(CL_GUIManager *parent = NULL);
00159         // Run the component as a modal component until it returns
00160 
00161         void quit();
00162         // Quit the modal loop of the component
00163 
00164         void clear_removeflag();
00165         // Clears the remove flag... dunno what the remove flag means. -- mbn 3. okt 2000
00166 
00167         void add_child(CL_Component *child, bool delete_child = false);
00168         // Adds the specified component as a children to this component.
00169         // If 'delete_child' is true, the child will be deleted when the component is deleted.
00170 
00171         void remove_child(CL_Component *child);
00172         // Removes the specified child from the component.
00173 
00174         void add_components(class CL_ComponentManager *component_manager);
00175         // Add all components in a component manager.
00176 
00177         void attach_style(CL_ComponentStyle *style);
00178         // Attaches a component style to the component.
00179 
00180         void detach_style(CL_ComponentStyle *style);
00181         // Removes a component style to the component.
00182 
00184 public:
00185         CL_Signal_v0 &sig_paint();
00186         // Draws the component. Must be called in a
00187         // begin_paint() / end_paint() session.
00188 
00189         CL_Signal_v0 &sig_begin_paint();
00190         // Called prior to component drawing. Sets up a cliprect and translocates
00191         // coordinates accordingly to this component.
00192 
00193         CL_Signal_v0 &sig_end_paint();
00194         // Cleans up when component drawing is finished (cleans up cliprects and
00195         // translocation stuff).
00196 
00197         CL_Signal_v3<CL_Component *, CL_InputDevice *, CL_Key> &sig_key_down();
00198         // Called when a key is pressed.
00199 
00200         CL_Signal_v3<CL_Component *, CL_InputDevice *, CL_Key> &sig_key_up();
00201         // Called when a key is released.
00202 
00203         CL_Signal_v4<CL_Component *, CL_InputDevice *, int, int> &sig_mouse_moved();
00204         // Called when the mouse is moved.
00205 
00206         CL_Signal_v0 &sig_got_focus();
00207         // Called when component gains focus.
00208 
00209         CL_Signal_v0 &sig_lost_focus();
00210         // Called when component lose focus.
00211 
00212         CL_Signal_v2<int, int> &sig_resized();
00213         // Called when component is resized.
00214 
00215         CL_Signal_v0 &sig_mouse_entered();
00216         // Called when mouse enters the component area.
00217 
00218         CL_Signal_v0 &sig_mouse_left();
00219         // Called when mouse leaves the component area.
00220 
00221         CL_Signal_v1<CL_Component *> &sig_child_add();
00222         // Called when a child component is added to the component.
00223 
00224         CL_Signal_v1<CL_Component *> &sig_child_remove();
00225         // Called when a child component is removed from the component.
00226 
00227         CL_Signal_v2<int &, int &> &sig_transform_coords();
00228         // Called when needing to convert parent coordinates into coordinates used by this component.
00229         // This is used in 3D guis to convert from screen coordinates to gui coordinates.
00230         // (project the screen cordinates down on the plane that the gui is laying on)
00231         
00233 private:
00234         class CL_Component_Generic *impl;
00235 };
00236 
00237 #endif

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001