Back to index

extremetuxracer  0.5beta
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
pp::Textarea Class Reference

#include <textarea.h>

Inheritance diagram for pp::Textarea:
Inheritance graph
[legend]
Collaboration diagram for pp::Textarea:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Textarea (pp::Vec2d pos, pp::Vec2d size, const char *binding, const char *text)
 ~Textarea ()
void setText (const char *text)
void setPosition (pp::Vec2d pos)
void upButtonClick ()
void downButtonClick ()
void draw ()
void setSensitive (bool sensitive)
bool getSensitive ()
void setVisible (bool visible)
void setActive (bool active)
bool isInBox (const int x, const int y) const
void mouseDown (int button, int x, int y)
void mouseUp (int button, int x, int y)
void mouseMotion (int x, int y)
virtual bool keyboardEvent (SDLKey key, SDLMod mod, bool release)
void removeFocus ()
void setFocus (bool focus=true)
bool hasFocus ()
void simulateMouseClick ()
double getWidth () const
double getHeight () const

Public Attributes

pp::Signal0 signalClicked
pp::Alignment alignment
 the alignment of the widgets.

Protected Member Functions

virtual void performClickAction ()

Protected Attributes

pp::Vec2d m_position
pp::Vec2d m_size
bool m_clicked
 is the box currently pushed down?
bool m_focused
 is the mouse pointer currently in the box?
bool m_sensitive
 is the widget sensitive (click event and font)
bool m_visible
 is the box being drawn by the UI manager?
bool m_active
 is the box receiving mouse events?
bool m_hasFocus

Private Member Functions

void calcTextRegionDims ()
void updateButtonPositions ()
void createLines ()
void updateButtonEnabledStates ()
void drawTextLines ()

Private Attributes

double m_arrowWidth
double m_borderWidth
double m_textPad
double m_textRegionHeight
double m_textRegionWidth
pp::Fontmp_font
pp::Color m_borderColor
pp::Color m_backgroundColor
pp::Buttonmp_upButton
pp::Buttonmp_downButton
char * mp_textOrig
char * mp_textLines
std::list< char * > m_lines
std::list< char * >::iterator mi_topLine

Detailed Description

Definition at line 35 of file textarea.h.


Constructor & Destructor Documentation

pp::Textarea::Textarea ( pp::Vec2d  pos,
pp::Vec2d  size,
const char *  binding,
const char *  text 
)

Definition at line 39 of file textarea.cpp.

{
    char *tempbinding;
    pp::Vec2d ll, ur;
       
       m_position = pos;
       m_size = size;
       
    m_arrowWidth = DEFAULT_ARROW_REGION_WIDTH;
    m_borderWidth = DEFAULT_BORDER_WIDTH;
    m_textPad = DEFAULT_TEXT_PAD;
       
    calcTextRegionDims();

       mp_font = pp::Font::get(binding);
       
    m_borderColor = theme.foreground;
    m_backgroundColor = theme.background;

    /* 
     * Create buttons 
     */
    mp_upButton = new pp::Button(
              pp::Vec2d( 0, 0 ), /* position will be set later */
              pp::Vec2d(DEFAULT_ARROW_BUTTON_WIDTH, DEFAULT_ARROW_BUTTON_HEIGHT),
              NULL,
              NULL );

    tempbinding = "textarea_arrows";

    ll = pp::Vec2d( 2.0/64.0, 17.0/64.0 );
    ur = pp::Vec2d( 29.0/64.0, 32.0/64.0 );
    mp_upButton->setImage( tempbinding, ll, ur, pp::Color::white );

    ll = pp::Vec2d( 34.0/64.0, 17.0/64.0 );
    ur = pp::Vec2d( 61.0/64.0, 32.0/64.0 );
    mp_upButton->setDisabledImage( tempbinding, ll, ur, pp::Color::white );

    ll = pp::Vec2d( 34.0/64.0, 49.0/64.0 );
    ur = pp::Vec2d( 61.0/64.0, 64.0/64.0 );
    mp_upButton->setHilitImage( tempbinding, ll, ur, pp::Color::white );

    ll = pp::Vec2d( 2.0/64.0, 49.0/64.0 );
    ur = pp::Vec2d( 29.0/64.0, 64.0/64.0 );
    mp_upButton->setClickedImage( tempbinding, ll, ur, pp::Color::white );
       
       mp_upButton->setActive(true);
    mp_upButton->signalClicked.Connect(pp::CreateSlot(this,&Textarea::upButtonClick));

    mp_downButton = new pp::Button(
              pp::Vec2d( 0, 0 ), /* position will be set later */
              pp::Vec2d(DEFAULT_ARROW_BUTTON_WIDTH,DEFAULT_ARROW_BUTTON_HEIGHT),
              NULL,
              NULL );

    tempbinding = "textarea_arrows";

    ll = pp::Vec2d( 2.0/64.0, 1.0/64.0 );
    ur = pp::Vec2d( 29.0/64.0, 16.0/64.0 );
    mp_downButton->setImage(tempbinding, ll, ur, pp::Color::white );

    ll = pp::Vec2d( 34.0/64.0, 1.0/64.0 );
    ur = pp::Vec2d( 61.0/64.0, 16.0/64.0 );
    mp_downButton->setDisabledImage(tempbinding, ll, ur, pp::Color::white );

    ll = pp::Vec2d( 34.0/64.0, 33.0/64.0 );
    ur = pp::Vec2d( 61.0/64.0, 48.0/64.0 );
    mp_downButton->setHilitImage(tempbinding, ll, ur, pp::Color::white );

    ll = pp::Vec2d( 2.0/64.0, 33.0/64.0 );
    ur = pp::Vec2d( 29.0/64.0, 48.0/64.0 );
    mp_downButton->setClickedImage(tempbinding, ll, ur, pp::Color::white );

       mp_downButton->setActive(true);
    mp_downButton->signalClicked.Connect(pp::CreateSlot(this,&Textarea::downButtonClick));

       updateButtonPositions();
    

    if ( text == NULL ) {
              text = "";
    }
       
       
    mp_textOrig = new char[strlen( text ) + 1];
       strcpy( mp_textOrig, text );

    mp_textLines = NULL;

    createLines();

    updateButtonEnabledStates();

    this->m_visible = false;
    this->m_active = false;
}

Here is the call graph for this function:

Definition at line 137 of file textarea.cpp.

{
    setVisible( false );
    setActive( false );

    if ( mp_upButton != NULL ) {
              delete mp_upButton;
    }
    if ( mp_downButton != NULL ) {
              delete mp_downButton;
    }

    if ( mp_textLines != NULL ) {
              delete( mp_textLines );
    }

    if ( mp_textOrig != NULL ) {
              delete( mp_textOrig );
    }  
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 159 of file textarea.cpp.

Here is the caller graph for this function:

void pp::Textarea::createLines ( ) [private]

Definition at line 181 of file textarea.cpp.

{
       /*font_t font;

    if ( !get_font_binding( m_binding, font ) ) {
              print_warning( IMPORTANT_WARNING,
                     "Couldn't get font for binding %s", m_binding );
              return;
    }
       */
       
       
       if ( mp_textLines != NULL ) {
              delete mp_textLines;
              mp_textLines = NULL;
    }

    if ( !m_lines.empty() ) {
              m_lines.clear();
    }
       
       char *cur_ptr;
       char *newline_ptr;
       
       mp_textLines = new char[strlen(mp_textOrig)+1];
       strcpy(mp_textLines,mp_textOrig);
       
       
    cur_ptr = mp_textLines;

       while ( *cur_ptr != '\0' ){
              newline_ptr = strchr( cur_ptr, '\n' );
              if( newline_ptr!=NULL){
                     *newline_ptr = '\0';
              }
              
              //if( string_width( cur_ptr, &font ) > m_textRegionWidth ) {
              if( mp_font->advance(cur_ptr) > m_textRegionWidth ) {
              
                     //text is too long for linear_attenuation
                     //try to find a suiteable space within this line
                     char* old_space_ptr = NULL;
                     char* space_ptr = strrchr( cur_ptr, ' ' );
                     
                     while (space_ptr !=NULL){
                            *space_ptr = '\0';
                            if(mp_font->advance(cur_ptr) < m_textRegionWidth ){
                                   if(newline_ptr!=NULL){
                                          *newline_ptr = '\n';
                                   }
                                   newline_ptr = space_ptr;
                                   break;
                            }
                            
                            if(old_space_ptr !=NULL){
                                   *old_space_ptr = ' ';
                            }
                            old_space_ptr = space_ptr;
                            space_ptr = strrchr( cur_ptr, ' ' );
                     }
                     if(old_space_ptr !=NULL){
                            *old_space_ptr = ' ';
                     }
              }
              m_lines.push_back(cur_ptr);
       
              if(newline_ptr==NULL){
                     break;
              }
              cur_ptr=newline_ptr+1;
       }
       
    mi_topLine = m_lines.begin();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 317 of file textarea.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Textarea::draw ( ) [virtual]

Implements pp::Widget.

Definition at line 354 of file textarea.cpp.

{
       glDisable( GL_TEXTURE_2D );

    glColor3dv( (double*)&m_borderColor );

    glRectf( m_position.x, 
            m_position.y,
            m_position.x + m_size.x,
            m_position.y + m_size.y );

    glColor3dv( (double*)&m_backgroundColor );

    glRectf( m_position.x + m_borderWidth, 
            m_position.y + m_borderWidth,
            m_position.x + m_size.x - m_borderWidth,
            m_position.y + m_size.y - m_borderWidth );

    glEnable( GL_TEXTURE_2D );

       drawTextLines();

    if ( mp_upButton != NULL ) {
              mp_upButton->draw();
    }

    if ( mp_downButton != NULL ) {
              mp_downButton->draw(); 
    }
}      

Here is the call graph for this function:

void pp::Textarea::drawTextLines ( ) [private]

Definition at line 327 of file textarea.cpp.

{
       if (m_lines.empty())return;
       
       std::list<char*>::iterator it;
       float desc = mp_font->descender();
       float asc = mp_font->ascender();
       float y = m_position.y + m_size.y - m_borderWidth - m_textPad - asc;
       float x = m_position.x + m_borderWidth + m_textPad;
       
       for(it=mi_topLine; it!=m_lines.end(); it++){
              mp_font->draw(*it, x, y);
              
              //float desc = mp_font->descender();
              //float asc = mp_font->ascender();
              
              y-=asc-desc;
              if(y < m_position.y + m_borderWidth) {
                     if ( mp_downButton ) {
                     mp_downButton->setSensitive( true );
                     }
                     break;
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

double pp::Widget::getHeight ( ) const [inline, inherited]

Definition at line 84 of file widget.h.

{return m_size.y;};

Here is the caller graph for this function:

bool pp::Widget::getSensitive ( ) [inline, inherited]

Definition at line 63 of file widget.h.

{ return m_sensitive; };

Here is the caller graph for this function:

double pp::Widget::getWidth ( ) const [inline, inherited]

Definition at line 83 of file widget.h.

{return m_size.x;};

Here is the caller graph for this function:

bool pp::Widget::hasFocus ( ) [inline, inherited]

Definition at line 77 of file widget.h.

{return m_hasFocus;};

Here is the caller graph for this function:

bool pp::Widget::isInBox ( const int  x,
const int  y 
) const [inherited]

Definition at line 96 of file widget.cpp.

{
    return (bool) (
       ( x >= m_position.x ) &&
       ( x <= m_position.x + m_size.x ) &&
       ( y >= m_position.y ) &&
       ( y <= m_position.y + m_size.y ) );
}

Here is the caller graph for this function:

virtual bool pp::Widget::keyboardEvent ( SDLKey  key,
SDLMod  mod,
bool  release 
) [inline, virtual, inherited]

Reimplemented in pp::Entry.

Definition at line 73 of file widget.h.

{return false;};

Here is the caller graph for this function:

void pp::Widget::mouseDown ( int  button,
int  x,
int  y 
) [inherited]

Definition at line 127 of file widget.cpp.

{
    if ( button != SDL_BUTTON_LEFT ) {
              return;
    }

    if ( !isInBox(x, y) ) {
              return;
    }

    if ( !m_sensitive ) {
              return;
    }

    if ( m_clicked == false ) {
              print_debug( DEBUG_UI, "Button is down" );
              m_clicked = true;
              UIMgr.setDirty();
    }
}

Here is the call graph for this function:

void pp::Widget::mouseMotion ( int  x,
int  y 
) [inherited]

Definition at line 106 of file widget.cpp.

{
    if ( !m_sensitive ) {
              return;
    }

    if ( isInBox(x, y) ) {
              if ( m_focused == false ) {
                     print_debug( DEBUG_UI, "Mouse entered button" );
                  m_focused = true;
                  UIMgr.setDirty();
              }
    } else {
              if ( m_focused == true ) {
                     print_debug( DEBUG_UI, "Mouse left button" );
                  m_focused = false;
                  UIMgr.setDirty();
              }
    }
}

Here is the call graph for this function:

void pp::Widget::mouseUp ( int  button,
int  x,
int  y 
) [inherited]

Definition at line 149 of file widget.cpp.

{
       if ( button != SDL_BUTTON_LEFT ) {
              return;
       }

    if ( !m_sensitive ) {
              return;
    }

    if ( !isInBox(x, y) ) {
              if ( m_clicked ) {
                  print_debug( DEBUG_UI, "Button is up (not clicked)" );
                  m_clicked = false;
                  UIMgr.setDirty();
              }
              return;
    } 

    if ( m_clicked ) {
              m_clicked = false;
              print_debug( DEBUG_UI, "Button was clicked" );
              performClickAction();
              UIMgr.setDirty();
    }
}

Here is the call graph for this function:

void pp::Widget::performClickAction ( ) [protected, virtual, inherited]

Reimplemented in pp::SSButton, and pp::Entry.

Definition at line 89 of file widget.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Widget::removeFocus ( ) [inherited]

Definition at line 183 of file widget.cpp.

{
       m_hasFocus=false;
}

Here is the caller graph for this function:

void pp::Widget::setActive ( bool  active) [inherited]

Definition at line 73 of file widget.cpp.

{
    if ( !m_active && active ) {
              UIMgr.setDirty();
    } else if ( m_active && !active ) {
              UIMgr.setDirty();
    }

    m_active = active;

    if ( !active ) {
              setVisible( false );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Widget::setFocus ( bool  focus = true) [inherited]

Definition at line 189 of file widget.cpp.

{
       if(focus!=m_hasFocus){
              UIMgr.grabFocus(this,focus);
              m_hasFocus=focus;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from pp::Widget.

Definition at line 299 of file textarea.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Widget::setSensitive ( bool  sensitive) [inherited]

Reimplemented in pp::Listbox< T >, pp::Listbox< multisample_t >, pp::Listbox< bpp_t >, pp::Listbox< button_t >, pp::Listbox< bps_t >, pp::Listbox< CourseData >, pp::Listbox< resolution_t >, pp::Listbox< model_t >, pp::Listbox< freq_t >, pp::Listbox< CupData >, pp::Listbox< HighscoreData >, and pp::Listbox< EventData >.

Definition at line 42 of file widget.cpp.

{
       if ( m_sensitive != sensitive ) {
              UIMgr.setDirty();
    }

    m_sensitive = sensitive;

    if ( !m_sensitive ) {
              m_clicked = false;
              m_focused = false;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Textarea::setText ( const char *  text)

Definition at line 278 of file textarea.cpp.

{
    if ( mp_textOrig != NULL ) {
              delete mp_textOrig;
              mp_textOrig = NULL;
    }

    if ( text == NULL ) {
              text = "";
    }

    text = _(text);

    mp_textOrig = new char[strlen( text ) + 1];
       strcpy( mp_textOrig, text );
       
    createLines();
    updateButtonEnabledStates();   
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Widget::setVisible ( bool  visible) [inherited]

Definition at line 57 of file widget.cpp.

{
    /* This check is necessary to prevent infinite mutual recursion */
    if ( m_active != visible ) {
              setActive( visible );
    }

    if ( !m_visible && visible ) {
              UIMgr.setDirty();
    } else if ( m_visible && !visible ) {
              UIMgr.setDirty();
    }
    m_visible = visible;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Widget::simulateMouseClick ( ) [inherited]

Definition at line 177 of file widget.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 307 of file textarea.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 257 of file textarea.cpp.

{
    if ( m_lines.empty() ) {
              /* No lines */
              mp_upButton->setSensitive( false );
              mp_downButton->setSensitive( false );
    } else {
              if ( mi_topLine == m_lines.begin() ) {
                  mp_upButton->setSensitive( false );
              } else {
                  mp_upButton->setSensitive( true );
              }
              if ( mi_topLine == --m_lines.end() ) {
                  mp_downButton->setSensitive( false );
              } else {
                  mp_downButton->setSensitive( true );
              }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 166 of file textarea.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

the alignment of the widgets.

Definition at line 90 of file widget.h.

bool pp::Widget::m_active [protected, inherited]

is the box receiving mouse events?

Definition at line 52 of file widget.h.

double pp::Textarea::m_arrowWidth [private]

Definition at line 37 of file textarea.h.

Definition at line 46 of file textarea.h.

Definition at line 45 of file textarea.h.

double pp::Textarea::m_borderWidth [private]

Definition at line 38 of file textarea.h.

bool pp::Widget::m_clicked [protected, inherited]

is the box currently pushed down?

Definition at line 40 of file widget.h.

bool pp::Widget::m_focused [protected, inherited]

is the mouse pointer currently in the box?

Definition at line 43 of file widget.h.

bool pp::Widget::m_hasFocus [protected, inherited]

Definition at line 54 of file widget.h.

std::list<char*> pp::Textarea::m_lines [private]

Definition at line 51 of file textarea.h.

pp::Vec2d pp::Widget::m_position [protected, inherited]

Definition at line 36 of file widget.h.

bool pp::Widget::m_sensitive [protected, inherited]

is the widget sensitive (click event and font)

Definition at line 46 of file widget.h.

pp::Vec2d pp::Widget::m_size [protected, inherited]

Definition at line 37 of file widget.h.

double pp::Textarea::m_textPad [private]

Definition at line 39 of file textarea.h.

Definition at line 40 of file textarea.h.

Definition at line 41 of file textarea.h.

bool pp::Widget::m_visible [protected, inherited]

is the box being drawn by the UI manager?

Definition at line 49 of file widget.h.

std::list<char*>::iterator pp::Textarea::mi_topLine [private]

Definition at line 52 of file textarea.h.

Definition at line 48 of file textarea.h.

Definition at line 43 of file textarea.h.

char* pp::Textarea::mp_textLines [private]

Definition at line 50 of file textarea.h.

char* pp::Textarea::mp_textOrig [private]

Definition at line 49 of file textarea.h.

Definition at line 47 of file textarea.h.

Definition at line 84 of file widget.h.


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