guihandler.h File Reference

File containing the interface of guihandler module. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <assert.h>
#include <time.h>
#include <glade/glade.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <dirent.h>
#include "define.h"
#include "object.h"
#include "schemaGameUtility.h"
#include "bestroute.h"
#include "gameIOManager.h"
#include "schemaGameGenerator.h"

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void gui (int argc, char **argv)
 Initialization of the gui creation of the main window, setting of the menues (createmenubar) and linking the window events (delete_event, destroy, configure_event, expose_event and keypressed).
gboolean delete_event (GtkWidget *window, GdkEvent *event, gpointer data)
 Window close event, confirm' request on exit.
void new_tournament (GtkWidget *window, GtkWidget *widget, gpointer data)
 Create a new tournament, starting from level 1, and load the schema.
void drawschema ()
 Print the schema in the drawing area, using color and draw_brush functions.
gboolean configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer data)
 Create a new backing pixmap of the appropriate size.
gboolean expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data)
 Redraw the screen from the backing pixmap.
void draw_brush (GtkWidget *widget, gdouble x, gdouble y, gdouble width, gdouble height, char *col)
 Draw a rectangle in the drawing area.
void keypressed (GtkWidget *window, GdkEventKey *event, gpointer data)
 Check the key pressed by the player using checkKeyPressed function.
void checkKeyPressed (int keyval, char *key, GtkWidget *drawarea, unsigned int drawX, unsigned int drawY)
 Check the key value passed by keypressed function.
void updateSchemaCell (GtkWidget *drawarea, unsigned int drawX, unsigned int drawY)
 Updates schema values and invokes draw_brush function to drawing the new brush.
void win ()
 Show the summary of the game, after a schema is won.
void show_records (GtkWidget *widget, GtkWindow *window)
 Show records in a dialog window using the function read_record.
bool get_player_name (GtkWidget *window, gchar *input_text)
 Get player name from a dialog, to save the new record, call checkResponseNameError function to check the inserted characters.
bool checkResponseNameError (GtkWidget *window, char *input_text)
 Check if the input text is correct, using isallowedchar function.
void drawingAndSetSchemaInfo (double loadsuccess)
 Calls the function drawschema, writes informations about elapsed time into downlabel and sets values of schema game informations.
void open_game (GtkWidget *window, GtkWidget *widget, gpointer data)
 Open the selected game by player, using the newgame and drawschema functions.
void generate_game (GtkWidget *widget, GtkWindow *window)
 Generate a new game, saving it in the file selected by the player, and run it.
bool request_generate_parameters (GtkWindow *window, unsigned int *rows, unsigned int *cols, unsigned int *difficult)
 Create a new dialog window for input the necessary parameters to generate a new schema and check the inserted values with isallowedchar function.
bool checkResponseErrorGenerateParameters (GtkWindow *window, char *rows_text, char *cols_text, char *difficult_text, unsigned int *rows, unsigned int *cols, unsigned int *difficult)
 Check if the input text is correct, using isallowedchar function.
char * set_gtk_entry_text_from_num (unsigned int number, GtkWidget *entry)
 Set the text of widget (GTK_ENTRY) with the number passed as parameter.
void show_help (GtkWidget *widget, GtkWidget *window, gpointer data)
 Show HELP informations, in a dialog window.
void show_about (GtkWidget *widget, GtkWidget *window)
 Show all ABOUT informations in a dialog window.

Variables

static const char GLADE_GUI_FILE_NAME [] = "gui.glade"
 Glade GUI file name.
static const char MAIN_WINDOW_NAME [] = "mainwindow"
 Main window name.
static const char DRAW_AREA_NAME [] = "drawarea"
 Draw area name.
static const char DOWN_LABEL_NAME [] = "downlabel"
 Down label name.


Detailed Description

File containing the interface of guihandler module.

Definition in file guihandler.h.


Function Documentation

void checkKeyPressed ( int  keyval,
char *  key,
GtkWidget *  drawarea,
unsigned int  drawX,
unsigned int  drawY 
)

Check the key value passed by keypressed function.

If correct, invokes updateSchemaCell function to update the schema and draw the brush.

Parameters:
keyval Int value of the key pressed
key Output message
drawarea Reference to the drawarea
drawX Width length of the rectangle
drawY Height length of the rectangle

Definition at line 397 of file guihandler.c.

References stateOfGame::currentCol, stateOfGame::currentRow, D1, schemaProp::gameMap, isaccessible(), schemaProp::numCol, schemaProp::numRow, schemaData, and updateSchemaCell().

Referenced by keypressed().

Here is the call graph for this function:

Here is the caller graph for this function:

bool checkResponseErrorGenerateParameters ( GtkWindow *  window,
char *  rows_text,
char *  cols_text,
char *  difficult_text,
unsigned int *  rows,
unsigned int *  cols,
unsigned int *  difficult 
)

Check if the input text is correct, using isallowedchar function.

If it isn't correct, show a dialog with the error message.

Returns:
true if input text is correct, false otherwise.
Parameters:
window Reference to GtkWidget window
rows_text Input text for row field
cols_text Input text for columns field
difficult_text Input text for difficult field
rows Number of rows
cols Number of columns
difficult Difficult level

Definition at line 1141 of file guihandler.c.

References check_if_text_is_number(), D1, MAX_DIFFICULT, MAX_ERR_BUFFER_LEN, MAX_OTH_BUFFER_LEN, MAXC, MAXR, MIN_DIFFICULT, MINC, and MINR.

Referenced by request_generate_parameters().

Here is the call graph for this function:

Here is the caller graph for this function:

bool checkResponseNameError ( GtkWidget *  window,
char *  input_text 
)

Check if the input text is correct, using isallowedchar function.

If it isn't correct, show a dialog with the error message.

Returns:
true if input text is correct, false otherwise.

Definition at line 767 of file guihandler.c.

References D1, DIGITS, isallowedchar(), LOWERCASE, MAX_ERR_BUFFER_LEN, NULLCHAR, and UPPERCASE.

Referenced by get_player_name().

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean configure_event ( GtkWidget *  widget,
GdkEventConfigure *  event,
gpointer  data 
)

Create a new backing pixmap of the appropriate size.

Parameters:
widget Reference to GtkWidget widget
event Reference to the event
data Other data

Definition at line 255 of file guihandler.c.

References D1, drawschema(), and pixmap.

Referenced by gui().

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean delete_event ( GtkWidget *  window,
GdkEvent *  event,
gpointer  data 
)

Window close event, confirm' request on exit.

Parameters:
window Reference to GtkWidget window
event Reference to the event
data Other data

Definition at line 54 of file guihandler.c.

References D1, D2, D4, MAIN_WINDOW_NAME, and xml.

void draw_brush ( GtkWidget *  widget,
gdouble  x,
gdouble  y,
gdouble  width,
gdouble  height,
char *  col 
)

Draw a rectangle in the drawing area.

Parameters:
widget Reference to GtkWidget widget
x x position of the rectangle
y y position of the rectangle
width width length of the rectangle
height height length of the rectangle
col Colour

Definition at line 305 of file guihandler.c.

References color(), D3, DRAW_AREA_NAME, pixmap, and xml.

Referenced by drawschema(), and updateSchemaCell().

Here is the call graph for this function:

Here is the caller graph for this function:

void drawingAndSetSchemaInfo ( double  loadsuccess  ) 

Calls the function drawschema, writes informations about elapsed time into downlabel and sets values of schema game informations.

Parameters:
loadsuccess Time to load and validate schema

Definition at line 823 of file guihandler.c.

References stateOfGame::currentCol, stateOfGame::currentRow, D1, D2, DOWN_LABEL_NAME, drawschema(), schemaProp::gameMap, stateOfGame::iters, MAX_OTH_BUFFER_LEN, NULLCHAR, stateOfGame::playing, schemaData, schemaProp::startCol, schemaProp::startRow, stateOfGame::starttime, weight(), and xml.

Referenced by generate_game(), and open_game().

Here is the call graph for this function:

Here is the caller graph for this function:

void drawschema (  ) 

Print the schema in the drawing area, using color and draw_brush functions.

Definition at line 212 of file guihandler.c.

References CLOSE, color(), colorVisited(), D3, DRAW_AREA_NAME, draw_brush(), FREE, schemaProp::gameMap, schemaProp::numCol, schemaProp::numRow, schemaData, schemaProp::visitedCellInfo, and xml.

Referenced by configure_event(), drawingAndSetSchemaInfo(), and new_tournament().

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean expose_event ( GtkWidget *  widget,
GdkEventExpose *  event,
gpointer  data 
)

Redraw the screen from the backing pixmap.

Parameters:
widget Reference to GtkWidget widget
event Reference to the event
data Other data

Definition at line 285 of file guihandler.c.

References D5, and pixmap.

void generate_game ( GtkWidget *  widget,
GtkWindow *  window 
)

Generate a new game, saving it in the file selected by the player, and run it.

The parameters inserted by the player are checked with the function request_generate_parameters, and the schema is generated with the function generateSchema. The schema is drawn using drawschema function.

Parameters:
widget Reference to GtkWidget widget
window Reference to GtkWidget window

Definition at line 930 of file guihandler.c.

References stateOfGame::bestrouteweight, stateOfGame::currentlevel, D1, DOWN_LABEL_NAME, drawingAndSetSchemaInfo(), GAMES_DIR, generateSchema(), newgame(), stateOfGame::numOfRound, stateOfGame::playing, request_generate_parameters(), START_LEVEL, START_ROUND_NUMBER, START_TOTAL_POINTS, stateOfGame::totalpoints, and xml.

Here is the call graph for this function:

bool get_player_name ( GtkWidget *  window,
gchar *  input_text 
)

Get player name from a dialog, to save the new record, call checkResponseNameError function to check the inserted characters.

If the name is wrong and user 'says yes', asks again the name.

Returns:
true if function return a valid name, false otherwise.
Parameters:
window Reference to GtkWidget window
input_text Player name

Definition at line 687 of file guihandler.c.

References checkResponseNameError(), D1, D2, and MAX_RECORDNAME_LEN.

Referenced by win().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui ( int  argc,
char **  argv 
)

Initialization of the gui creation of the main window, setting of the menues (createmenubar) and linking the window events (delete_event, destroy, configure_event, expose_event and keypressed).

Parameters:
argc Corresponding of argc variable of main function
argv Corresponding of argv variables of main function

Definition at line 21 of file guihandler.c.

References configure_event(), DRAW_AREA_NAME, GLADE_GUI_FILE_NAME, initializeCurrentGameState(), MAIN_WINDOW_NAME, PRGLOGO, PRGNAME, PRGVERS, and xml.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void keypressed ( GtkWidget *  window,
GdkEventKey *  event,
gpointer  data 
)

Check the key pressed by the player using checkKeyPressed function.

Parameters:
window Reference to GtkWidget window
event Reference to the key event
data Other data

Definition at line 346 of file guihandler.c.

References checkKeyPressed(), stateOfGame::currentCol, stateOfGame::currentRow, D1, D2, DOOR, DOWN_LABEL_NAME, DRAW_AREA_NAME, schemaProp::gameMap, MAX_OTH_BUFFER_LEN, NULLCHAR, schemaProp::numCol, schemaProp::numRow, stateOfGame::playing, schemaData, win(), and xml.

Here is the call graph for this function:

void new_tournament ( GtkWidget *  window,
GtkWidget *  widget,
gpointer  data 
)

Create a new tournament, starting from level 1, and load the schema.

The schema name is obtained using get_schema_name function and the game starts using the newgame and drawschema functions.

Parameters:
window Reference to GtkWidget window
widget Reference to GtkWidget widget
data Other data

Definition at line 125 of file guihandler.c.

References stateOfGame::bestrouteweight, stateOfGame::currentCol, stateOfGame::currentlevel, stateOfGame::currentRow, D1, D2, DOWN_LABEL_NAME, drawschema(), schemaProp::gameMap, GAMES_DIR, GAMES_LEVEL_DIR, get_schema_name(), stateOfGame::iters, MAX_ERR_BUFFER_LEN, MAX_OTH_BUFFER_LEN, NEW_GAME_ROUND, newgame(), NULLCHAR, stateOfGame::numOfRound, stateOfGame::playing, schemaData, START_LEVEL, START_TOTAL_POINTS, schemaProp::startCol, schemaProp::startRow, stateOfGame::starttime, stateOfGame::totalpoints, weight(), and xml.

Referenced by win().

Here is the call graph for this function:

Here is the caller graph for this function:

void open_game ( GtkWidget *  window,
GtkWidget *  widget,
gpointer  data 
)

Open the selected game by player, using the newgame and drawschema functions.

Parameters:
window Reference to GtkWidget window
widget Reference to GtkWidget widget
data Other data

Definition at line 874 of file guihandler.c.

References stateOfGame::bestrouteweight, stateOfGame::currentlevel, D1, DOWN_LABEL_NAME, drawingAndSetSchemaInfo(), GAMES_DIR, newgame(), stateOfGame::numOfRound, stateOfGame::playing, START_LEVEL, START_ROUND_NUMBER, START_TOTAL_POINTS, stateOfGame::totalpoints, and xml.

Here is the call graph for this function:

bool request_generate_parameters ( GtkWindow *  window,
unsigned int *  rows,
unsigned int *  cols,
unsigned int *  difficult 
)

Create a new dialog window for input the necessary parameters to generate a new schema and check the inserted values with isallowedchar function.

The function becomes recursively if data are wrong and user 'says yes'.

Returns:
true if parameters are ok, false otherwise.
Parameters:
window Reference to GtkWidget window
rows Number of rows
cols Number of columns
difficult Level

Definition at line 1003 of file guihandler.c.

References checkResponseErrorGenerateParameters(), D1, D2, MAX_DIFFICULT, MAX_OTH_BUFFER_LEN, MAXC, MAXR, MIN_DIFFICULT, MINC, MINR, NULLCHAR, and set_gtk_entry_text_from_num().

Referenced by generate_game().

Here is the call graph for this function:

Here is the caller graph for this function:

char* set_gtk_entry_text_from_num ( unsigned int  number,
GtkWidget *  entry 
)

Set the text of widget (GTK_ENTRY) with the number passed as parameter.

Returns:
the number converted to string
Parameters:
number Number to convert
entry Entry to set

Definition at line 1116 of file guihandler.c.

References countDigits(), and D1.

Referenced by request_generate_parameters().

Here is the call graph for this function:

Here is the caller graph for this function:

void show_about ( GtkWidget *  widget,
GtkWidget *  window 
)

Show all ABOUT informations in a dialog window.

Parameters:
widget Reference to GtkWidget widget
window Reference to GtkWidget window

Definition at line 1255 of file guihandler.c.

References D1, D4, PRGAIMS, PRGAUTH, PRGCPYR, PRGLICS, PRGLOGO, PRGNAME, PRGVERS, and PRGWBLK.

void show_help ( GtkWidget *  widget,
GtkWidget *  window,
gpointer  data 
)

Show HELP informations, in a dialog window.

Parameters:
widget Reference to GtkWidget widget
window Reference to GtkWidget window
data Other data

Definition at line 1216 of file guihandler.c.

References D1, D4, MAIN_WINDOW_NAME, and xml.

void show_records ( GtkWidget *  widget,
GtkWindow *  window 
)

Show records in a dialog window using the function read_record.

Parameters:
widget Reference to GtkWidget widget
window Reference to GtkWidget window

Definition at line 626 of file guihandler.c.

References D1, gameRecord, MAX_OTH_BUFFER_LEN, NULLCHAR, readSetGameRecord(), and RECORD_FILE_NAME.

Referenced by win().

Here is the call graph for this function:

Here is the caller graph for this function:

void updateSchemaCell ( GtkWidget *  drawarea,
unsigned int  drawX,
unsigned int  drawY 
)

Updates schema values and invokes draw_brush function to drawing the new brush.

Parameters:
drawarea Reference to the drawarea
drawX Width length of the rectangle
drawY Height length of the rectangle

Definition at line 510 of file guihandler.c.

References colorVisited(), stateOfGame::currentCol, stateOfGame::currentRow, D1, draw_brush(), schemaProp::gameMap, stateOfGame::iters, schemaData, visitCell(), schemaProp::visitedCellInfo, and weight().

Referenced by checkKeyPressed().

Here is the call graph for this function:

Here is the caller graph for this function:

void win (  ) 

Show the summary of the game, after a schema is won.

The schema results are calculated with calcSchemaResults function. If tournament isn't finished, start a new one using the function new_game, otherwise it saves and shows the record invoking the functions get_player_name, save_record and show_records.

Definition at line 537 of file guihandler.c.

References calcSchemaResults(), stateOfGame::currentlevel, D1, D2, DOWN_LABEL_NAME, get_player_name(), MAIN_WINDOW_NAME, MAX_OTH_BUFFER_LEN, new_tournament(), NULLCHAR, stateOfGame::numOfRound, stateOfGame::playing, save_record(), show_records(), START_LEVEL, START_ROUND_NUMBER, START_TOTAL_POINTS, stateOfGame::totalpoints, and xml.

Referenced by keypressed().

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char DOWN_LABEL_NAME[] = "downlabel" [static]

Down label name.

Definition at line 35 of file guihandler.h.

Referenced by drawingAndSetSchemaInfo(), generate_game(), keypressed(), new_tournament(), open_game(), and win().

const char DRAW_AREA_NAME[] = "drawarea" [static]

Draw area name.

Definition at line 33 of file guihandler.h.

Referenced by draw_brush(), drawschema(), gui(), and keypressed().

const char GLADE_GUI_FILE_NAME[] = "gui.glade" [static]

Glade GUI file name.

Definition at line 29 of file guihandler.h.

Referenced by gui().

const char MAIN_WINDOW_NAME[] = "mainwindow" [static]

Main window name.

Definition at line 31 of file guihandler.h.

Referenced by delete_event(), gui(), show_help(), and win().


Generated on Fri Apr 2 18:27:56 2010 for SMLabyrinth by  doxygen 1.5.8