OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Protected Member Functions | List of all members
OpenXcom::InteractiveSurface Class Reference

Surface that the user can interact with. More...

#include <InteractiveSurface.h>

Inheritance diagram for OpenXcom::InteractiveSurface:
OpenXcom::Surface OpenXcom::ActionMenuItem OpenXcom::BaseView OpenXcom::ComboBox OpenXcom::Globe OpenXcom::ImageButton OpenXcom::Inventory OpenXcom::Map OpenXcom::MedikitButton OpenXcom::MedikitView OpenXcom::MiniBaseView OpenXcom::MiniMapView OpenXcom::ScannerView OpenXcom::ScrollBar OpenXcom::Slider OpenXcom::TextButton OpenXcom::TextEdit OpenXcom::TextList

Public Member Functions

 InteractiveSurface (int width, int height, int x=0, int y=0)
 Creates a new interactive surface with the specified size and position. More...
 
virtual ~InteractiveSurface ()
 Cleans up the interactive surface.
 
void setVisible (bool visible)
 Sets the surface's visibility. More...
 
virtual void handle (Action *action, State *state)
 Processes any pending events. More...
 
virtual void setFocus (bool focus)
 Sets the focus of this surface. More...
 
bool isFocused () const
 Gets the focus of this surface. More...
 
virtual void unpress (State *state)
 Unpresses the surface. More...
 
void onMouseClick (ActionHandler handler, Uint8 button=SDL_BUTTON_LEFT)
 Hooks an action handler to a mouse click on the surface. More...
 
void onMousePress (ActionHandler handler, Uint8 button=0)
 Hooks an action handler to a mouse press over the surface. More...
 
void onMouseRelease (ActionHandler handler, Uint8 button=0)
 Hooks an action handler to a mouse release over the surface. More...
 
void onMouseIn (ActionHandler handler)
 Hooks an action handler to moving the mouse into the surface. More...
 
void onMouseOver (ActionHandler handler)
 Hooks an action handler to moving the mouse over the surface. More...
 
void onMouseOut (ActionHandler handler)
 Hooks an action handler to moving the mouse out of the surface. More...
 
void onKeyboardPress (ActionHandler handler, SDLKey key=SDLK_ANY)
 Hooks an action handler to pressing a key when the surface is focused. More...
 
void onKeyboardRelease (ActionHandler handler, SDLKey key=SDLK_ANY)
 Hooks an action handler to releasing a key when the surface is focused. More...
 
virtual void mousePress (Action *action, State *state)
 Processes a mouse button press event. More...
 
virtual void mouseRelease (Action *action, State *state)
 Processes a mouse button release event. More...
 
virtual void mouseClick (Action *action, State *state)
 Processes a mouse click event. More...
 
virtual void mouseIn (Action *action, State *state)
 Processes a mouse hover in event. More...
 
virtual void mouseOver (Action *action, State *state)
 Processes a mouse hover event. More...
 
virtual void mouseOut (Action *action, State *state)
 Processes a mouse hover out event. More...
 
virtual void keyboardPress (Action *action, State *state)
 Processes a keyboard key press event. More...
 
virtual void keyboardRelease (Action *action, State *state)
 Processes a keyboard key release event. More...
 
void setListButton ()
 Check this surface to see if it's a textlist button. More...
 
- Public Member Functions inherited from OpenXcom::Surface
 Surface (int width, int height, int x=0, int y=0, int bpp=8)
 Creates a new surface with the specified size and position. More...
 
 Surface (const Surface &other)
 Creates a new surface from an existing one. More...
 
virtual ~Surface ()
 Cleans up the surface. More...
 
void loadScr (const std::string &filename)
 Loads an X-Com SCR graphic. More...
 
void loadSpk (const std::string &filename)
 Loads an X-Com SPK graphic. More...
 
void loadBdy (const std::string &filename)
 Loads a TFTD BDY graphic. More...
 
void loadImage (const std::string &filename)
 Loads a general image file. More...
 
void clear ()
 Clears the surface's contents. More...
 
void offset (int off, int min=-1, int max=-1, int mul=1)
 Offsets the surface's colors by a set amount. More...
 
void invert (Uint8 mid)
 Inverts the surface's colors. More...
 
virtual void think ()
 Runs surface functionality every cycle. More...
 
virtual void draw ()
 Draws the surface's graphic. More...
 
virtual void blit (Surface *surface)
 Blits this surface onto another one. More...
 
virtual void initText (Font *, Font *, Language *)
 Initializes the surface's various text resources.
 
void copy (Surface *surface)
 Copies a portion of another surface into this one. More...
 
void drawRect (SDL_Rect *rect, Uint8 color)
 Draws a filled rectangle on the surface. More...
 
void drawRect (Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 color)
 Draws a filled rectangle on the surface. More...
 
void drawLine (Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 color)
 Draws a line on the surface. More...
 
void drawCircle (Sint16 x, Sint16 y, Sint16 r, Uint8 color)
 Draws a filled circle on the surface. More...
 
void drawPolygon (Sint16 *x, Sint16 *y, int n, Uint8 color)
 Draws a filled polygon on the surface. More...
 
void drawTexturedPolygon (Sint16 *x, Sint16 *y, int n, Surface *texture, int dx, int dy)
 Draws a textured polygon on the surface. More...
 
void drawString (Sint16 x, Sint16 y, const char *s, Uint8 color)
 Draws a string on the surface. More...
 
virtual void setPalette (SDL_Color *colors, int firstcolor=0, int ncolors=256)
 Sets the surface's palette. More...
 
SDL_Color * getPalette () const
 Returns the surface's 8bpp palette. More...
 
virtual void setX (int x)
 Sets the X position of the surface. More...
 
int getX () const
 Returns the position of the surface in the X axis. More...
 
virtual void setY (int y)
 Sets the Y position of the surface. More...
 
int getY () const
 Returns the position of the surface in the Y axis. More...
 
void setVisible (bool visible)
 Sets the surface's visibility. More...
 
bool getVisible () const
 Gets the surface's visibility. More...
 
void resetCrop ()
 Resets the cropping rectangle for the surface. More...
 
SDL_Rect * getCrop ()
 Gets the cropping rectangle for the surface. More...
 
void setPixel (int x, int y, Uint8 pixel)
 Changes the color of a pixel in the surface, relative to the top-left corner of the surface. More...
 
void setPixelIterative (int *x, int *y, Uint8 pixel)
 Changes the color of a pixel in the surface and returns the next pixel position. More...
 
Uint8 getPixel (int x, int y) const
 Returns the color of a specified pixel in the surface. More...
 
SDL_Surface * getSurface () const
 Returns the internal SDL_Surface for SDL calls. More...
 
int getWidth () const
 Returns the width of the surface. More...
 
virtual void setWidth (int width)
 Sets the width of the surface. More...
 
int getHeight () const
 Returns the height of the surface. More...
 
virtual void setHeight (int height)
 Sets the height of the surface. More...
 
void setHidden (bool hidden)
 Sets the surface's special hidden flag. More...
 
void lock ()
 Locks the surface. More...
 
void unlock ()
 Unlocks the surface. More...
 
void blitNShade (Surface *surface, int x, int y, int off, bool half=false, int newBaseColor=0)
 Specific blit function to blit battlescape terrain data in different shades in a fast way. More...
 
void invalidate ()
 Invalidate the surface: force it to be redrawn. More...
 
std::string getTooltip () const
 Gets the tooltip of the surface. More...
 
void setTooltip (const std::string &tooltip)
 Sets the tooltip of the surface. More...
 

Protected Member Functions

bool isButtonPressed (Uint8 button=0)
 Is this mouse button pressed?
 
virtual bool isButtonHandled (Uint8 button=0)
 Is this mouse button event handled?
 
void setButtonPressed (Uint8 button, bool pressed)
 Set a mouse button's internal state.
 
- Protected Member Functions inherited from OpenXcom::Surface
void resize (int width, int height)
 Recreates the surface with a new size. More...
 

Detailed Description

Surface that the user can interact with.

Specialized version of the standard Surface that processes all the various SDL events and turns them into useful interactions with the Surface, so specialized subclasses don't need to worry about it.

Constructor & Destructor Documentation

OpenXcom::InteractiveSurface::InteractiveSurface ( int  width,
int  height,
int  x = 0,
int  y = 0 
)

Creates a new interactive surface with the specified size and position.

Sets up a blank interactive surface with the specified size and position.

Parameters
widthWidth in pixels.
heightHeight in pixels.
xX position in pixels.
yY position in pixels.

Member Function Documentation

void OpenXcom::InteractiveSurface::handle ( Action action,
State state 
)
virtual

Processes any pending events.

Called whenever an action occurs, and processes it to check if it's relevant to the surface and convert it into a meaningful interaction like a "click", calling the respective handlers.

Parameters
actionPointer to an action.
stateState that the action handlers belong to.

Reimplemented in OpenXcom::TextList, OpenXcom::ComboBox, OpenXcom::Slider, OpenXcom::ScrollBar, and OpenXcom::TextEdit.

bool OpenXcom::InteractiveSurface::isFocused ( ) const

Gets the focus of this surface.

Returns the surface's focus.

Surfaces will only receive keyboard events if focused.

Returns
Is it focused?
void OpenXcom::InteractiveSurface::keyboardPress ( Action action,
State state 
)
virtual

Processes a keyboard key press event.

Called every time there's a keyboard press when the surface is focused.

Allows the surface to have custom functionality for this action, and can be called externally to simulate the action.

Parameters
actionPointer to an action.
stateState that the action handlers belong to.

Reimplemented in OpenXcom::Globe, OpenXcom::TextEdit, and OpenXcom::Map.

void OpenXcom::InteractiveSurface::keyboardRelease ( Action action,
State state 
)
virtual

Processes a keyboard key release event.

Called every time there's a keyboard release over the surface.

Allows the surface to have custom functionality for this action, and can be called externally to simulate the action.

Parameters
actionPointer to an action.
stateState that the action handlers belong to.

Reimplemented in OpenXcom::Map.

void OpenXcom::InteractiveSurface::mouseClick ( Action action,
State state 
)
virtual

Processes a mouse click event.

Called every time there's a mouse click on the surface.

Allows the surface to have custom functionality for this action, and can be called externally to simulate the action.

Parameters
actionPointer to an action.
stateState that the action handlers belong to.

Reimplemented in OpenXcom::Globe, OpenXcom::TextList, OpenXcom::Inventory, and OpenXcom::ArrowButton.

void OpenXcom::InteractiveSurface::mouseIn ( Action action,
State state 
)
virtual

Processes a mouse hover in event.

Called every time the mouse moves into the surface.

Allows the surface to have custom functionality for this action, and can be called externally to simulate the action.

Parameters
actionPointer to an action.
stateState that the action handlers belong to.

Reimplemented in OpenXcom::ActionMenuItem.

void OpenXcom::InteractiveSurface::mouseOut ( Action action,
State state 
)
virtual

Processes a mouse hover out event.

Called every time the mouse moves out of the surface.

Allows the surface to have custom functionality for this action, and can be called externally to simulate the action.

Parameters
actionPointer to an action.
stateState that the action handlers belong to.

Reimplemented in OpenXcom::TextList, OpenXcom::BaseView, and OpenXcom::ActionMenuItem.

void OpenXcom::InteractiveSurface::mouseOver ( Action action,
State state 
)
virtual

Processes a mouse hover event.

Called every time the mouse moves over the surface.

Allows the surface to have custom functionality for this action, and can be called externally to simulate the action.

Parameters
actionPointer to an action.
stateState that the action handlers belong to.

Reimplemented in OpenXcom::Globe, OpenXcom::TextList, OpenXcom::Map, OpenXcom::BaseView, OpenXcom::Inventory, and OpenXcom::MiniBaseView.

void OpenXcom::InteractiveSurface::mousePress ( Action action,
State state 
)
virtual

Processes a mouse button press event.

Called every time there's a mouse press over the surface.

Allows the surface to have custom functionality for this action, and can be called externally to simulate the action.

Parameters
actionPointer to an action.
stateState that the action handlers belong to.

Reimplemented in OpenXcom::Globe, OpenXcom::TextList, OpenXcom::TextEdit, OpenXcom::Map, OpenXcom::TextButton, OpenXcom::Slider, OpenXcom::ScrollBar, OpenXcom::ArrowButton, OpenXcom::ImageButton, and OpenXcom::ToggleTextButton.

void OpenXcom::InteractiveSurface::mouseRelease ( Action action,
State state 
)
virtual

Processes a mouse button release event.

Called every time there's a mouse release over the surface.

Allows the surface to have custom functionality for this action, and can be called externally to simulate the action.

Parameters
actionPointer to an action.
stateState that the action handlers belong to.

Reimplemented in OpenXcom::Globe, OpenXcom::TextList, OpenXcom::Map, OpenXcom::TextButton, OpenXcom::Slider, OpenXcom::ScrollBar, OpenXcom::ArrowButton, and OpenXcom::ImageButton.

void OpenXcom::InteractiveSurface::onKeyboardPress ( ActionHandler  handler,
SDLKey  key = SDLK_ANY 
)

Hooks an action handler to pressing a key when the surface is focused.

Sets a function to be called every time a key is pressed when the surface is focused.

Parameters
handlerAction handler.
keyKeyboard button to check for (note: ignores key modifiers). Set to 0 for any key.
void OpenXcom::InteractiveSurface::onKeyboardRelease ( ActionHandler  handler,
SDLKey  key = SDLK_ANY 
)

Hooks an action handler to releasing a key when the surface is focused.

Sets a function to be called every time a key is released when the surface is focused.

Parameters
handlerAction handler.
keyKeyboard button to check for (note: ignores key modifiers). Set to 0 for any key.
void OpenXcom::InteractiveSurface::onMouseClick ( ActionHandler  handler,
Uint8  button = SDL_BUTTON_LEFT 
)

Hooks an action handler to a mouse click on the surface.

Sets a function to be called every time the surface is mouse clicked.

Parameters
handlerAction handler.
buttonMouse button to check for. Set to 0 for any button.
void OpenXcom::InteractiveSurface::onMouseIn ( ActionHandler  handler)

Hooks an action handler to moving the mouse into the surface.

Sets a function to be called every time the mouse moves into the surface.

Parameters
handlerAction handler.
void OpenXcom::InteractiveSurface::onMouseOut ( ActionHandler  handler)

Hooks an action handler to moving the mouse out of the surface.

Sets a function to be called every time the mouse moves out of the surface.

Parameters
handlerAction handler.
void OpenXcom::InteractiveSurface::onMouseOver ( ActionHandler  handler)

Hooks an action handler to moving the mouse over the surface.

Sets a function to be called every time the mouse moves over the surface.

Parameters
handlerAction handler.
void OpenXcom::InteractiveSurface::onMousePress ( ActionHandler  handler,
Uint8  button = 0 
)

Hooks an action handler to a mouse press over the surface.

Sets a function to be called every time the surface is mouse pressed.

Parameters
handlerAction handler.
buttonMouse button to check for. Set to 0 for any button.
void OpenXcom::InteractiveSurface::onMouseRelease ( ActionHandler  handler,
Uint8  button = 0 
)

Hooks an action handler to a mouse release over the surface.

Sets a function to be called every time the surface is mouse released.

Parameters
handlerAction handler.
buttonMouse button to check for. Set to 0 for any button.
void OpenXcom::InteractiveSurface::setFocus ( bool  focus)
virtual

Sets the focus of this surface.

Changes the surface's focus.

Surfaces will only receive keyboard events if focused.

Parameters
focusIs it focused?
void OpenXcom::InteractiveSurface::setListButton ( )

Check this surface to see if it's a textlist button.

Sets a flag for this button to say "i'm a member of a textList" to true.

void OpenXcom::InteractiveSurface::setVisible ( bool  visible)

Sets the surface's visibility.

Changes the visibility of the surface.

A hidden surface isn't blitted nor receives events.

Parameters
visibleNew visibility.
void OpenXcom::InteractiveSurface::unpress ( State state)
virtual

Unpresses the surface.

Simulates a "mouse button release".

Used in circumstances where the surface is unpressed without user input.

Parameters
statePointer to running state.

Reimplemented in OpenXcom::TextList.


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