#include "guihandler.h"
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. | |
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. | |
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. | |
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 GdkPixmap * | pixmap = NULL |
Used to create and editing rectangular images made up of colored pixels. | |
GladeXML * | xml |
Used to read informations from Glade build-in GUI. | |
currentGameState | gameState |
Variable of type currentGameState that contains the state variables of the game. |
Definition in file guihandler.c.
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.
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().
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.
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().
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.
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().
gboolean configure_event | ( | GtkWidget * | widget, | |
GdkEventConfigure * | event, | |||
gpointer | data | |||
) |
Create a new backing pixmap of the appropriate size.
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().
gboolean delete_event | ( | GtkWidget * | window, | |
GdkEvent * | event, | |||
gpointer | data | |||
) |
Window close event, confirm' request on exit.
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.
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().
void drawingAndSetSchemaInfo | ( | double | loadsuccess | ) |
Calls the function drawschema, writes informations about elapsed time into downlabel and sets values of schema game informations.
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().
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().
gboolean expose_event | ( | GtkWidget * | widget, | |
GdkEventExpose * | event, | |||
gpointer | data | |||
) |
Redraw the screen from the backing pixmap.
widget | Reference to GtkWidget widget | |
event | Reference to the event | |
data | Other data |
Definition at line 285 of file guihandler.c.
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.
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.
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.
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().
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).
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().
void keypressed | ( | GtkWidget * | window, | |
GdkEventKey * | event, | |||
gpointer | data | |||
) |
Check the key pressed by the player using checkKeyPressed function.
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.
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.
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().
void open_game | ( | GtkWidget * | window, | |
GtkWidget * | widget, | |||
gpointer | data | |||
) |
Open the selected game by player, using the newgame and drawschema functions.
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.
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'.
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().
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.
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().
void show_about | ( | GtkWidget * | widget, | |
GtkWidget * | window | |||
) |
void show_help | ( | GtkWidget * | widget, | |
GtkWidget * | window, | |||
gpointer | data | |||
) |
Show HELP informations, in a dialog window.
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.
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().
void updateSchemaCell | ( | GtkWidget * | drawarea, | |
unsigned int | drawX, | |||
unsigned int | drawY | |||
) |
Updates schema values and invokes draw_brush function to drawing the new brush.
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().
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().
Variable of type currentGameState that contains the state variables of the game.
Definition at line 17 of file guihandler.c.
Referenced by initializeCurrentGameState().
GdkPixmap* pixmap = NULL [static] |
Used to create and editing rectangular images made up of colored pixels.
Definition at line 10 of file guihandler.c.
Referenced by configure_event(), draw_brush(), and expose_event().
GladeXML* xml |
Used to read informations from Glade build-in GUI.
Definition at line 13 of file guihandler.c.
Referenced by delete_event(), draw_brush(), drawingAndSetSchemaInfo(), drawschema(), generate_game(), gui(), keypressed(), new_tournament(), open_game(), show_help(), and win().