Difference between revisions of "GeButton"

From GriffinEngine
Jump to: navigation, search
 
 
(One intermediate revision by the same user not shown)
Line 15: Line 15:
 
=== Fields ===
 
=== Fields ===
 
{{note}} All coordinates are in pixels, relative to top-left corner of the window. '''Rotation is not supported in buttons.'''
 
{{note}} All coordinates are in pixels, relative to top-left corner of the window. '''Rotation is not supported in buttons.'''
*{{base|geObject2D}}<source> double x;      // x coordinate (px) </source>
+
*{{base|geObject2D}}<code> double x;      // x coordinate (px) </code>
*{{base|geObject2D}}<source> double y;      // y coordinate (px) </source>
+
*{{base|geObject2D}}<code> double y;      // y coordinate (px) </code>
*{{base|geObject2D}}<source> double s;      // scale - around axis point</source>
+
*{{base|geObject2D}}<code> double s;      // scale - around axis point</code>
*{{base|geObject2D}}<source> double w;      // width (px) </source>
+
*{{base|geObject2D}}<code> double w;      // width (px) </code>
*{{base|geObject2D}}<source> double h;      // height (px) </source>
+
*{{base|geObject2D}}<code> double h;      // height (px) </code>
*{{base|geObject2D}}<source> double alignX; // horizontal alignment offset - use Align() to set these </source>
+
*{{base|geObject2D}}<code> double alignX; // horizontal alignment offset - use Align() to set these </code>
*{{base|geObject2D}}<source> double alignY; // vertical alignment offset </source>
+
*{{base|geObject2D}}<code> double alignY; // vertical alignment offset </code>
*{{base|geObject2D}}<source> double axisX;  // horizontal axis offset - use SetAxis() to set these </source>
+
*{{base|geObject2D}}<code> double axisX;  // horizontal axis offset - use SetAxis() to set these </code>
*{{base|geObject2D}}<source> double axisY;  // vertical axis offset </source>
+
*{{base|geObject2D}}<code> double axisY;  // vertical axis offset </code>
*{{base|geObject2D}}<source> bool active;  // indicates whether object should be active/visible </source>
+
*{{base|geObject2D}}<code> bool active;  // indicates whether object should be active/visible </code>
*{{base|geSprite2D}}<source> geSprite* sprite; // currently displayed sprite </source>
+
*{{base|geSprite2D}}<code> geSprite* sprite; // currently displayed sprite </code>
*<source> geSprite* normalSprite; // sprite to display when idle </source>
+
*<code> geSprite* normalSprite; // sprite to display when idle </code>
*<source> geSprite* hoverSprite;  // sprite to display when mouse is over the button </source>
+
*<code> geSprite* hoverSprite;  // sprite to display when mouse is over the button </code>
*<source> geSprite* downSprite;  // sprite to display when the button is being pressed </source>
+
*<code> geSprite* downSprite;  // sprite to display when the button is being pressed </code>
*<source> geCallback onMouseOver; // callback function for when mouse moves over the button (optional) </source>
+
*<code> geCallback onMouseOver; // callback function for when mouse moves over the button (optional) </code>
*<source> geCallback onMouseOut;  // callback function for when mouse moves outside the button (optional) </source>
+
*<code> geCallback onMouseOut;  // callback function for when mouse moves outside the button (optional) </code>
*<source> geCallback onPress;    // callback function for when mouse is pressed on the button (optional) </source>
+
*<code> geCallback onPress;    // callback function for when mouse is pressed on the button (optional) </code>
*<source> geCallback onRelease;  // callback function for when mouse is pressed on the button (optional) </source>
+
*<code> geCallback onRelease;  // callback function for when mouse is pressed on the button (optional) </code>
*<source> bool pressed;          // true if button is being pressed </source>
+
*<code> bool pressed;          // true if button is being pressed </code>
*<source> bool hovered;          // true if mouse is over the button </source>
+
*<code> bool hovered;          // true if mouse is over the button </code>
  
 
=== Constructors ===
 
=== Constructors ===
*<source> geButton( double _x=0, double _y=0, double _w=0, double _h=0, geSprite* _normalSprite=0 ); </source>
+
*<code> geButton( double _x=0, double _y=0, double _w=0, double _h=0, geSprite* _normalSprite=0 ); </code>
*<source> geButton( const geButton& original ); // copy constructor</source>
+
*<code> geButton( const geButton& original ); // copy constructor</code>
  
 
=== Methods ===
 
=== Methods ===
*{{base|geObject2D}}<source> virtual void Align( int alignment = GE_ALIGN_TL, double _alignX = 0, double _alignY = 0 ); </source>
+
*{{base|geObject2D}}<code> virtual void Align( int alignment = GE_ALIGN_TL, double _alignX = 0, double _alignY = 0 ); </code>
*{{base|geObject2D}}<source> virtual void SetAxis( int axis = GE_ALIGN_CENTER, double _axisX = 0, double _axisY = 0 ); </source>
+
*{{base|geObject2D}}<code> virtual void SetAxis( int axis = GE_ALIGN_CENTER, double _axisX = 0, double _axisY = 0 ); </code>
  
  
 
{{ge}}
 
{{ge}}
 
{{hud}}
 
{{hud}}

Latest revision as of 08:24, 19 November 2017

A simple 2D button implementation. Callback functions can be assigned to be called when mouse is over/out/pressed/released. Note that the actual active area might not match the appearance of the button if rotation/scaling is applied.

Usage

Inheritance

Base classes


Reference

Fields

Note: All coordinates are in pixels, relative to top-left corner of the window. Rotation is not supported in buttons.
  • double x; // x coordinate (px)
  • double y; // y coordinate (px)
  • double s; // scale - around axis point
  • double w; // width (px)
  • double h; // height (px)
  • double alignX; // horizontal alignment offset - use Align() to set these
  • double alignY; // vertical alignment offset
  • double axisX; // horizontal axis offset - use SetAxis() to set these
  • double axisY; // vertical axis offset
  • bool active; // indicates whether object should be active/visible
  • geSprite* sprite; // currently displayed sprite
  • geSprite* normalSprite; // sprite to display when idle
  • geSprite* hoverSprite; // sprite to display when mouse is over the button
  • geSprite* downSprite; // sprite to display when the button is being pressed
  • geCallback onMouseOver; // callback function for when mouse moves over the button (optional)
  • geCallback onMouseOut; // callback function for when mouse moves outside the button (optional)
  • geCallback onPress; // callback function for when mouse is pressed on the button (optional)
  • geCallback onRelease; // callback function for when mouse is pressed on the button (optional)
  • bool pressed; // true if button is being pressed
  • bool hovered; // true if mouse is over the button

Constructors

  • geButton( double _x=0, double _y=0, double _w=0, double _h=0, geSprite* _normalSprite=0 );
  • geButton( const geButton& original ); // copy constructor

Methods

  • virtual void Align( int alignment = GE_ALIGN_TL, double _alignX = 0, double _alignY = 0 );
  • virtual void SetAxis( int axis = GE_ALIGN_CENTER, double _axisX = 0, double _axisY = 0 );