Components
Overview
A component denotes any object which is displayed on a
component scene
.
These include 2D and 3D components as well as
widgets and windows.
Components
Everything you can place on a component or widget scene is a component. Thus
the following applies also to all widgets and windows.
Placement
Components are placed on an EM_COMPONENT_SCENE with add_component. To specify the position and dimension of the component use set_position and set_dimension on the component.
Drawing
Each component on the current scene will be drawn each frame by a call to redraw which itself calls prepare_drawing, draw and finish_drawing. These features are deferred and part of their implementation depends on the type of component (2D or 3D). Unless you subclass EM_COMPONENT directly you don't have to worry about these features.
Events
All components have an event notification mechanism which publishes mouse, keyboard and other events. A detailed description is found in the events section.
Tooltips
Each component can have a tooltip. Set it with set_tooltip and
clear it by setting the tooltip to Void.
To control tooltips see the options section.
2D Component
The class EM_2D_COMPONENT is the base class for all components which are drawn in 2D using any drawing commands from EM_SURFACE.
To create a custom 2D component, create a subclass and implement the deferred feature draw. This feature will be called every frame. When you implement draw use the component's surface to drawn on. The rectangle part of surface from (0, 0) to (width, height) will be drawn on the screen at the component's position.
3D Component
If you want to draw 3D with OpenGL use an EM_3D_COMPONENT. Create a subclass and put your OpenGL code in the feature draw.
The preparation for drawing is done in prepare_drawing: Setting the viewport and loading projection and model view matrix. If you need custom initialisation like activating fog either do it in draw or redefine prepare_drawing. When redefining prepare_drawing make sure to call the original version or set all settings yourself.
In the feature draw you can start right away with OpenGL commands.
The class SIERPINSKY_DISPLAY in the example is an implementation of an EM_3D_COMPONENT.