René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

Button [Ming wrapper class]

The source

Button.h
#ifndef BUTTON_H
#define BUTTON_H

#include "ming.h"

#include "Shape.h"
#include "Text.h"
#include "Action.h"
#include "Character_.h"

/*---------------------------------------------------------
  A Button has three visible states:
      o Up:   This is the default state which is displayed
              when the movie starts and when the mouse is
              not over the button.  

      o  Over This is the state when the mouse IS hovering
              over the button.

      o  Down This is the state when the mouse is pressed 
              inside the button's Hit Area.


  Hit Area:   The hit area defines (by means of one
              or more Character_'s) the area over which 
              the mouse must hover to make the mouse go 
              into the Over state.  Also, the button 
              only goes to the down state if the Mouse 
              is pressed over the hit area.


  Examples:   ButtonTest.cpp
*/

class Button : public Character_ {
  friend class Movie;
  friend class MovieClip;

  public:
    Button();
    
    /*
      flags can be a or'd combination of
      SWFBUTTON_UP, SWFBUTTON_DOWN, SWFBUTTON_OVER and SWFBUTTON_HIT
    */
    void Add(Character_ const&, byte flags);

    /* flags: any ore'd combination of 
             SWFBUTTON_MOUSEOVER       SWFBUTTON_MOUSEOUT   SWFBUTTON_MOUSEUP
             SWFBUTTON_MOUSEUPOUTSIDE  SWFBUTTON_MOUSEDOWN  SWFBUTTON_DRAGOUT
             SWFBUTTON_DRAGOVER                                            */
    void Add(Action const& a, byte flags); 

  private:
    SWFButton button_;

  protected:
    // HACK?
    virtual SWFBlock_s* swf_block() const;
};

#endif
Button.cpp
#include "Button.h"
#include "TextField.h"

Button::Button() {
  button_ = newSWFButton();
}

void Button::Add(Character_ const& c, byte flags) {
  SWFButton_addShape(button_, reinterpret_cast<SWFCharacter_s*>(c.swf_block()), flags);
}

void Button::Add(Action const& a, byte flags) {
  SWFButton_addAction(button_, a.action_, flags);
}

SWFBlock_s* Button::swf_block() const {
  return reinterpret_cast<SWFBlock_s*>(button_);
}

Examples

The following examples demonstrate this class: