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

TextField [Ming wrapper class]

The source

TextField.h
#ifndef TEXTFIELD_H
#define TEXTFIELD_H

#include <string>

#include "ming.h"
#include "Font.h"
#include "Action.h"
#include "Character_.h"

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

  public:
    TextField(Font font, int size, float x, float y, std::string const& txt, byte r, byte g, byte b, byte a=0xff);

//  /* Returns advance */
    void  Add        (std::string const& txt);
  
//  void  Kerning    (int k);  // ???? Kerning = Spacing ????
    void  Coordinates(float x, float y);
    void  Color      (byte r, byte g, byte b, byte a=0xff);
    void  setFont    (Font const& font);
    void  Size       (int size);
    void  Size       (int size, const Font&);

    void  Rect       (float width, float height);

		void  ReadOnly   (bool);
		void  Password   (bool);
		void  Wordwrap   (bool);

    /*  The following tags are permitted if using HTML:
          <p>...</p>,
          <br>
          <a href='must_be_present'>...</a>
          <font face='...' size='...' color='#rrggbb'>...</font>
          <b>bold Text</b>
          <i>italic</i>
          <u>underlined</u>
          <li>...</li><li>...</li><li>....</li> (Note, <ul> and <ol> not permitted,
             numbered lists not possible
          <textformat 
            leftmargin='in_twips 
            rightmargin='in_twips 
            indent='in_twips 
            blockindent='in_twips' 
            leading='leading_in_twips 
            tabstops='ts1,ts2,tsn'>... </textformat>
          <tab>advancing to next tabstop [as defined in textformat]

    */
		void  HTML       (bool);
		void  DrawBox    (bool);
		void  NoSelect   (bool);
		void  AutoSize   (bool);
		void  Multline   (bool);

    /* Links the content of this TextField to a variable */
    void  Variable   (std::string const&);

//    float Width      (std::string const& txt);

  private:
    SWFTextField text_;
		int flags_;

		void Flags(bool, int);

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

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

// TODO: x and y used?
TextField::TextField(Font font, int size, float x, float y, std::string const& txt, byte r, byte g, byte b, byte a) {
  flags_=0;
  text_ = newSWFTextField();

  setFont    (font);
  Size       (size, font);
  Color      (r,g,b,a);
  //Coordinates(x, y);
  //SWFText_setSpacing(text_, 0);
  Add        (txt);
}

void TextField::Flags(bool b, int f) {
  if (b) flags_ |=  f;
  else   flags_ &= ~f;
  SWFTextField_setFlags(text_, flags_);
}

void TextField::ReadOnly(bool b) {
  Flags(b, SWFTEXTFIELD_NOEDIT);
}

void TextField::Password(bool b) {
  Flags(b, SWFTEXTFIELD_PASSWORD);
}

void TextField::Multline(bool b) {
  Flags(b, SWFTEXTFIELD_MULTILINE);
}

void TextField::Wordwrap(bool b) {
  Flags(b, SWFTEXTFIELD_WORDWRAP);
}

void TextField::HTML(bool b) {
  Flags(b, SWFTEXTFIELD_HTML);
}

void TextField::DrawBox(bool b) {
  Flags(b, SWFTEXTFIELD_HTML);
}

void TextField::NoSelect(bool b) {
  Flags(b, SWFTEXTFIELD_NOSELECT);
}

void TextField::AutoSize(bool b) {
  Flags(b, SWFTEXTFIELD_AUTOSIZE);
}

void TextField::Add(std::string const& txt) {
  SWFTextField_addString(text_, txt.c_str());
}

//void Text::Kerning(int k) {
//  SWFText_setSpacing(text_, k);
//}
//// ???? Kerning = Spacing ????
//void TextField::Coordinates(float x, float y) {
//  SWFTextField_setXY(text_, x, y);
//}

void TextField::Color(byte r, byte g, byte b, byte a) {
  SWFTextField_setColor(text_, r, g, b, a);
}

void TextField::setFont(Font const& font) {
  SWFTextField_setFont(text_, reinterpret_cast<SWFBlock>(font.font_));
}

void TextField::Size(int size) {
  SWFTextField_setHeight(text_, size);
}

void TextField::Rect(float width, float height) {
  SWFTextField_setBounds(text_, width, height);
}

void TextField::Size(int size, const Font& f) {
  Size(size);
  SWFTextField_setFieldHeight(text_, f.LineHeight(size));
}

void TextField::Variable(std::string const& variable) {
  SWFTextField_setVariableName(text_, variable.c_str());
}

SWFBlock_s* TextField::swf_block() const {
  return reinterpret_cast<SWFBlock_s*>(text_);
}

Examples

The following examples demonstrate this class: