Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
Friends | List of all members
CWidget Class Reference

Description

Base class for all widgets.

This class is not abstract, but by itself allows to display arbitrary SDL surfaces.

Definition at line 94 of file ui_screen.H.

#include "ui_screen.H"

Inheritance diagram for CWidget:
Inheritance graph
[legend]

Public Member Functions

Setup ...
void Set (SDL_Surface *_surf, int x0, int y0)
 
void SetArea (SDL_Rect _area)
 
SDL_Rect * GetArea ()
 
class CScreenGetScreen ()
 
bool IsOnScreen (class CScreen *_screen)
 
class CCanvasGetCanvas ()
 
Coordinate transformations (screen <-> render <-> local) ...
void LocalToScreenCoords (int *x, int *y)
 
void ScreenToLocalCoords (int *x, int *y)
 
void GetMouseEventPos (SDL_Event *ev, int *x, int *y)
 
Surface-oriented drawing ...

This class itself is able to display a non-interactive surface.

void SetSurface (SDL_Surface *_surface)
 Set the static surface to display. The caller stays owner of surface, must not delete it as long as it is set here. The surface dimensions must match 'area'.
 
virtual SDL_Surface * GetSurface ()
 Get an up-to-date surface or 'NULL' if none is available.
 
Texture-oriented drawing...
void GetRenderArea (SDL_Rect *ra)
 Transpose 'area' to the current screen coordinates to be passed to all SDL rendering functions.
 
virtual SDL_Texture * GetTexture ()
 Return an up-to-date texture. More...
 
void SetTextureBlendMode (SDL_BlendMode _sdlBlendMode)
 Set the blend mode for the texture created by the default implementation of GetTexture(). The default is SDL_BLENDMODE_NONE.
 
virtual void Render (SDL_Renderer *ren)
 Render this widget. More...
 
void ClearTexture ()
 Clear the internally cached texture object to save memory.
 
Event handling ...
virtual bool HandleEvent (SDL_Event *ev)
 Handle an event and return 'true' if the event was consumed and is to be ignored by later widgets.
 

Protected Member Functions

Change management...

The following methods trigger a redrawing at next occasion. The following conventions must be satisfied by this and all derived classes:

  1. On a change, the most specialized 'Change*()' function is called, which may in turn call other 'Change*()' methods.
  2. All public methods call their change methods => no need to make these public.
  3. The 'Change*()' methods must be very fast (i.e. O(1)) in execution, at least if invoked repeatedly.
void ChangedSurface ()
 Mark (only) the surface as changed to trigger a redrawing at next occasion.
 
void Changed ()
 Anything may have changed: Trigger a redrawing at next occasion.
 

Friends

class CScreen
 
class CCanvas
 

Member Function Documentation

◆ GetTexture()

virtual SDL_Texture * CWidget::GetTexture ( )
virtual

Return an up-to-date texture.

The default implementation maintains an internal texture that is updated based on the surface set by SetSurface(). Widgets that generate SDL texture objects directly may override this method.

◆ Render()

virtual void CWidget::Render ( SDL_Renderer *  ren)
virtual

Render this widget.

The default implementation uses the 'GetTexture()' method above. By overriding this method it is possible to define widgets with a custom SDL rendering procedure, which may be more efficient than preparing a single texture containing the complete widget.

It is allowed to pass 'ren == NULL', in which case all textures and internal data structures are (re-)calculated, but nothing is actually rendered.

Reimplemented in CCanvas, CCursorWidget, CListbox, CMenu, and CInputLine.


The documentation for this class was generated from the following file: