SDL Graphic User Interface
This unit contains an "engine" for all the controls and base classes for them.
Declared types
- TSDLCursor = record Image : TSDLImage; HotSpotX : Byte; HotSpotY : Byte; end;
- Use this to assign image to a cursor.
- TSDLBarKind = (sbHorizontal, sbVertical);
- Used for ScrollBar and Gauge.
- TStateImage = (siFocused,siDown,siDisabled,siNone);
- Elements of TStateImages.
- TStateImages = set of TStateImage;
- Shows what items are contained in control image in form of patterns.
See TSDLStdControl.
- TDrawOption = (doNormal,doCenter,doTile,doStretch);
- Shows how to draw a control. See TSDLImageObject.DrawOption for more info.
- TSDLDragMode = (sdmManual,sdmAutomatic);
- Shows if you can drag a control.
- Event types:
TSDLNotifyEvent = procedure(Sender: TSDLComponent) of object;
TSDLMouseEvent = procedure(Sender: TSDLComponent;Button: Integer;
Modifier: TSDLMod;AX,AY: Word) of object;
TSDLMouseClickEvent = procedure(Sender: TSDLComponent;
AX,AY: Integer) of object;
TSDLMouseMoveEvent = procedure(Sender: TSDLComponent;
Modifier: TSDLMod; AX,AY : Integer) of object;
TSDLMouseWheelEvent = procedure(Sender: TSDLComponent;Dir: Integer;
Modifier: TSDLMod;AX,AY : Word) of object;
TSDLKeyEvent = procedure(Sender: TSDLControl; var Key: Word;
Modifier: TSDLMod) of object;
TSDLKeyPressEvent = procedure (Sender: TSDLControl; var Key: Char) of object;
TSDLDrawItemEvent = procedure(Sender: TSDLControl;const ItemNo: Integer;
Rect: TSDL_Rect; State: Integer) of object;
TSDLObject
TSDLObject is a base class controls, GUI and SDLMouse. It provides what is common for all of them. Properties are:
- property Count: Integer read GetCount;
- How many child objects does it own.
- property ControlCount: Integer read GetControlCount;
- How many child controls does it own. This is less or equal to Count.
- property GUI: TSDLGui read FGui;
- Pointer to gui instance. This is nil for TSDLGui.
- property Objects[Index: Integer]: TSDLImageObject read GetObject;
- Returns indexed object.
- property Controls[Index: Integer]: TSDLControl read GetControl;
- Returns indexed control.
- property ActiveControl: TSDLControl read FActiveControl write FActiveControl;
- Child control that has focus.
- property Parent: TSDLObject read FParent;
- Poiter to parent object.
- property ControlParent: TSDLControl read FControlParent;
- Pointer to first parent that is TSDLControl.
- property Z: Integer read FZ write SetZ;
- Used for Z ordering.
- property Height: Integer read FHeight write SetHeight;
- Height of the object.
- property Width: Integer read FWidth write SetWidth;
- Width of the object.
Methods are:
- constructor Create(AParent: TSDLObject); virtual;
- Creates a new instance of the object. AParent can be TSDLGui or other component.
- procedure Clear;
- Frees all child controls.
- function IndexOfObject(AObject: TSDLImageObject): Integer;
- Returns index of the specified object.
- function IndexOfControl(Control: TSDLControl): Integer;
- Returns index of the specified control.
TSDLImageObject
Next class in the hierarhy is TSDLImageObject. It is a base class for TSDLComponent and TSDLMouse.
Although TSDLComponent and its descendatns: TSDLControl and TSDLStdControl are part of SDLGui.pas
you can find their description in SDLCtrls. Properties of TSDLImageObject are:
- property WorldX: Integer read GetWorldX;
- Returns absolute X coordinate
- property WorldY: Integer read GetWorldY;
- Returns absolute Y coordinate
- property BoundsRect: TSDL_Rect read GetBoundsRect;
- Returns absolute bounds rect.
- property Image: TSDLImage read FImage write SetImage;
- Represents control's Image.
- property Dead: Boolean read FDead;
- True if you killed the control using Kill method.
- property AnimCount: Integer read FAnimCount write FAnimCount;
- Represents count of patterns to animate for this control.
- property AnimLooped: Boolean read FAnimLooped write FAnimLooped;
- If false animation will stop after AnimCount frames, else it will be looped.
- property AnimPos: Double read FAnimPos write FAnimPos;
- Current position of animation.
- property AnimSpeed: Double read FAnimSpeed write FAnimSpeed;
- Speed of animation. Set this as 1/(number of ms between two frames). Default 3/1000.
- property AnimStart: Integer read FAnimStart write FAnimStart;
- From witch pattern to start the animation.
- property X: Integer read FX write SetX;
- Coordinate X relative to parent position.
- property Y: Integer read FY write SetY;
- Coordinate Y relative to parent position.
- property Visible: Boolean read GetVisible write SetVisible default True;
- Indicates whether the control is visible.
- property DrawOption: TDrawOption read FDrawOption write FDrawOption default doStretch;
- Indicates how the control's image will be drawn. Possible options are:
- doNormal
- Draws the image in its actual size, no matter of control's width and height.
- doCenter
- Draws the image in its actual size but centers it in BoundsRect of control.
- doTile
- Tiles the image to fill control's bounds rect.
- doStretch
- Stretches the image to fit in control's bounds rect.
- property ImageIndex: Integer read FImageIndex write SetImageIndex default -1;
- If any of the parents have RImages: TSDLImages property it will set an indexed image from that list to this control.
Method is:
- procedure Kill;
- Prepares control for destruction. It will be destroyed at the end of Gui.Update method. Generally you can
destroy a control using its Free method. You have to use this method when you want to destroy a form, from
its own method. For example, Form1.Button1Click(...) can't contain Form1.Free so you have to call Form1.Kill.
TSDLMouse
This class is used to preprocess mouse events, send them to proper controls and provide a system for adding
an image to the cursor. You do not need to create this, since TSDLGui will create one instance and place it in
its SDLMouse property. Properties are:
- property ConstCursor: Boolean read FConstCursor write SetConstCursor;
- If True cursor image can not change if it gets over the control which has Cursor property set.
- property HotSpotX: Byte read FHotSpotX write FHotSpotX;
- X coord of hot spot. Hot spot determines what point in cursor image to consider as cursor's peak.
- property HotSpotY: Byte read FHotSpotY write FHotSpotY;
- Y coord of hot spot.
- property DefaultCursor: TSDLCursor read FDefaultCursor write FDefaultCursor;
- Deafult image for the cursor. Image of the cursor will be this unless it gets over control which
has Cursor property set and ConstCursor is false.
- property DownControl: TSDLComponent read FDownControl;
- Control that mouse button was pressed on.
- property OverControl: TSDLComponent read FOverControl;
- Control over which the cursor is.
Method is:
- procedure SetCursor(const Value: TSDLCursor);
- Sets the Value as cursor's image. Image will return to DefaultImage if one is present if you move the
mouse over the control that does'n have Cursor property assigned.
TSDLGui
This class is like an engine for the entire gui system. In every cycle of you application you should
call ProcessEvent for all events and Update method for drawing. Properties are:
- HintColor: Cardinal;
- Background of hint text box.
- ShowHintAfter: Cardinal;
- Number of miliseconds mouse needs to stay still over the control to popup the hint. Default 500.
- ShowHintFor: Cardinal;
- Number of miliseconds till hint disappears.
- HintFont: TSDLFont;
- Font for hints.
- DesignForm: TObject;
- Used only by SDL Form Designer application.
- SetSelControl: TSDLNotifyEvent;
- Used only by SDL Form Designer application.
- DragEnabled: Boolean;
- Shows if draging of controls is enabled. Used by SDL Form Designer application.
- ShowHints: Boolean;
- Popup hints only if this is True.
- property AllCount: Integer read FAllCount;
- Count of all created objects.
- property SDLMouse: TSDLMouse read FSDLMouse;
- Pointer to TSDLMouse instance.
- property PopupMenu: TSDLComponent read FPopupMenu write FPopupMenu;
- Pointer to currently poped up TSDLPopupMenu.
Methods are:
- procedure ProcessEvent(const Event: TSDL_Event);
- Process the specified event sending it to the appropriate controls.
- procedure Update;
- Animates and draws all controls, draws the hint if one is present and frees the killed controls.
- procedure SendQuitSignal;
- Sends the SDL_QUITEV signal so application can terminate properly.