Back to index

extremetuxracer  0.5beta
Functions
callbacks.cpp File Reference
#include <GL/gl.h>
#include "ppgltk/FT/FTGLOutlineFont.h"
#include "callbacks.h"
#include "tcl_util.h"
#include "ppgltk/font.h"
#include "ppgltk/alg/color.h"

Go to the source code of this file.

Functions

static int pp_register_font_cb (ClientData cd, Tcl_Interp *ip, int argc, CONST84 char *argv[])
static int pp_bind_font_cb (ClientData cd, Tcl_Interp *ip, int argc, CONST84 char *argv[])
void register_common_callbacks (Tcl_Interp *ip)

Function Documentation

static int pp_bind_font_cb ( ClientData  cd,
Tcl_Interp *  ip,
int  argc,
CONST84 char *  argv[] 
) [static]

Definition at line 137 of file callbacks.cpp.

{
       bool error = false;

    CONST84 char *binding = NULL;
    CONST84 char *fontName = NULL;
    pp::Color *color = NULL;

       NEXT_ARG;

    while ( !error && argc > 0 ) {

       if ( strcmp( "-binding", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           binding = *argv;
       } else if ( strcmp( "-font", *argv ) == 0 ) {
           NEXT_ARG;
              if ( argc == 0 ) {
                     error = true;
                     break;
           }
           fontName = *argv;
       } else if ( strcmp( "-color", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
                     error = true;
                     break;
           }
              
              color = new pp::Color;
              
           if ( get_tcl_tuple( ip, *argv, (double*)color, 4 ) == 
               TCL_ERROR ) 
           {
                     error = true;
                     break;
           }
       } else {
           print_warning( TCL_WARNING, "pp_bind_font: unrecognized "
                        "parameter `%s'", *argv );
       }

       NEXT_ARG;
    }

    if ( binding == NULL || fontName == NULL ){
              error = true;
    }

    if ( error ) {
              return TCL_ERROR;
    }

       if(color){
              pp::Font::bindFont(binding, fontName, *color);
              delete color;
       }else{
              pp::Font::bindFont(binding, fontName);
       }   
    return TCL_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int pp_register_font_cb ( ClientData  cd,
Tcl_Interp *  ip,
int  argc,
CONST84 char *  argv[] 
) [static]

Definition at line 30 of file callbacks.cpp.

{
       bool error = false;
       double tmp_dbl;

    CONST84 char *binding = NULL;
    CONST84 char *fileName = NULL;
    bool isOutline = false;
    bool width_defined = false;
    GLfloat width;
    pp::Color color = pp::Color::white;
    unsigned int size = 30;

       if ( argc < 7 ) {
              Tcl_AppendResult(ip, argv[0], ": invalid number of arguments\n", 
                      "Usage: ", argv[0], " -binding <binding> -font <ttf file> -size <fontsize> [-color <color>]",
                      (char *)0 );
        return TCL_ERROR;
    } 
           
    NEXT_ARG;

    while ( !error && argc > 0 ) {

       if ( strcmp( "-binding", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           binding = *argv;
       } else if ( strcmp( "-font", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           fileName = *argv;
       } else if ( strcmp( "-size", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( Tcl_GetDouble ( ip, *argv, &tmp_dbl ) == TCL_ERROR ) {
              error = true;
              break;
           }
           size = int(tmp_dbl);
       } else if ( strcmp( "-color", *argv ) == 0 ) {
           NEXT_ARG;
           if ( argc == 0 ) {
              error = true;
              break;
           }
           if ( get_tcl_tuple( ip, *argv, (double*)&color, 4 ) == 
               TCL_ERROR ) 
           {
              error = true;
              break;
           }
    } else if ( strcmp( "-outline", *argv ) == 0 ) {
        isOutline = true;
       } else if ( strcmp( "-width", *argv ) == 0 ) {
        NEXT_ARG;
           if ( argc == 0 ) {
            error = true;
            break;
           }
        if(isOutline) {
            if ( Tcl_GetDouble ( ip, *argv, &tmp_dbl ) == TCL_ERROR ) {
                error = true;
                break;
           }
            width_defined = true;
           width = GLfloat(tmp_dbl);
        } else {
            print_warning( TCL_WARNING, "pp_load_font: -width parameter only needed for outline fonts !");
        }
       } else {
           print_warning( TCL_WARNING, "pp_load_font: unrecognized "
                        "parameter `%s'", *argv );
       }

       NEXT_ARG;
    }

    if ( binding == NULL || fileName == NULL ){
              error = true;
    }

    if ( error ) {
              return TCL_ERROR;
    }

       pp::Font::registerFont(binding, fileName, size, color, isOutline);
    
    if(width_defined) {
        FTGLOutlineFont* outlineFont = (FTGLOutlineFont*)(pp::Font::get(binding)->getFTFont());
        outlineFont->setWidth(width);
    }

    return TCL_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void register_common_callbacks ( Tcl_Interp *  ip)

Definition at line 206 of file callbacks.cpp.

{
    Tcl_CreateCommand (ip, "pp_load_font", pp_register_font_cb,   0,0);
    Tcl_CreateCommand (ip, "pp_bind_font", pp_bind_font_cb,   0,0);
}

Here is the call graph for this function:

Here is the caller graph for this function: