summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h2
-rw-r--r--data/image/choice.pngbin0 -> 1206 bytes
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/base/checkFront.c4
-rwxr-xr-xsrc/base/list.c2
-rwxr-xr-xsrc/base/modules.c2
-rw-r--r--src/base/proto.c7
-rw-r--r--src/client/keyboardBuffer.c6
-rw-r--r--src/client/keyboardBuffer.h14
-rw-r--r--src/client/saveDialog.c15
-rw-r--r--src/client/saveLoad.c10
-rwxr-xr-xsrc/modules/modAI.c9
-rw-r--r--src/screen/screen_analyze.c17
-rw-r--r--src/screen/screen_browser.c32
-rw-r--r--src/screen/screen_choiceArena.c39
-rw-r--r--src/screen/screen_credits.c17
-rw-r--r--src/screen/screen_gameType.c184
-rw-r--r--src/screen/screen_mainMenu.c17
-rw-r--r--src/screen/screen_setting.c157
-rw-r--r--src/screen/screen_settingKeys.c93
-rw-r--r--src/screen/screen_table.c22
-rw-r--r--src/screen/screen_world.c10
-rw-r--r--src/screen/screen_world.h4
-rw-r--r--src/widget/widget.c52
-rw-r--r--src/widget/widget.h33
-rw-r--r--src/widget/widget_button.c55
-rw-r--r--src/widget/widget_button.h13
-rw-r--r--src/widget/widget_buttonimage.c55
-rw-r--r--src/widget/widget_buttonimage.h13
-rw-r--r--src/widget/widget_catchkey.c61
-rw-r--r--src/widget/widget_catchkey.h14
-rw-r--r--src/widget/widget_check.c64
-rw-r--r--src/widget/widget_check.h12
-rw-r--r--src/widget/widget_choicegroup.c96
-rw-r--r--src/widget/widget_choicegroup.h13
-rw-r--r--src/widget/widget_image.c33
-rw-r--r--src/widget/widget_image.h10
-rw-r--r--src/widget/widget_label.c40
-rw-r--r--src/widget/widget_label.h11
-rw-r--r--src/widget/widget_select.c95
-rw-r--r--src/widget/widget_select.h18
-rw-r--r--src/widget/widget_textfield.c88
-rw-r--r--src/widget/widget_textfield.h13
43 files changed, 950 insertions, 504 deletions
diff --git a/config.h b/config.h
index 6bf91d3..07b2696 100644
--- a/config.h
+++ b/config.h
@@ -1 +1 @@
-#define TUXANCI_VERSION "svn200"
+#define TUXANCI_VERSION "svn201"
diff --git a/data/image/choice.png b/data/image/choice.png
new file mode 100644
index 0000000..b76ae41
--- /dev/null
+++ b/data/image/choice.png
Binary files differ
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9650be7..039b6ff 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -64,7 +64,7 @@ SET ( SRC_client
${WORKDIR}/widget/widget_textfield ${WORKDIR}/widget/widget_label
${WORKDIR}/widget/widget_buttonimage ${WORKDIR}/widget/widget_image
${WORKDIR}/widget/widget_select ${WORKDIR}/widget/widget_catchkey
- ${WORKDIR}/widget/widget_choicegroup
+ ${WORKDIR}/widget/widget_choicegroup ${WORKDIR}/widget/widget
)
SET ( SRC_audio
diff --git a/src/base/checkFront.c b/src/base/checkFront.c
index 2f6e00a..536de1b 100644
--- a/src/base/checkFront.c
+++ b/src/base/checkFront.c
@@ -60,7 +60,7 @@ void eventMsgInCheckFront(client_t *client)
int i;
currentTime = getMyTime();
- for(i = 0; i < client->listSendMsg->count; i++) {
+ for (i = 0; i < client->listSendMsg->count; i++) {
checkfront_t *this;
this = (checkfront_t *)client->listSendMsg->list[i];
@@ -93,7 +93,7 @@ void delMsgInCheckFront(list_t *listCheckFront, int id)
{
int i;
- for( i = 0 ; i < listCheckFront->count ; i++ ) {
+ for (i = 0 ; i < listCheckFront->count ; i++ ) {
checkfront_t *this;
this = (checkfront_t *)listCheckFront->list[i];
diff --git a/src/base/list.c b/src/base/list.c
index b59f64b..72ea95e 100755
--- a/src/base/list.c
+++ b/src/base/list.c
@@ -164,4 +164,4 @@ void destroyListItem(list_t *p, void *f)
for (i = 0; i < p->count; i++)
fce(p->list[i]);
destroyList(p);
-} \ No newline at end of file
+}
diff --git a/src/base/modules.c b/src/base/modules.c
index f03decd..fd9087f 100755
--- a/src/base/modules.c
+++ b/src/base/modules.c
@@ -160,7 +160,7 @@ static module_t* newModule(char *name)
ret->fce_cmd = getFce(ret, "cmdArena");
ret->fce_recvMsg = getFce(ret, "recvMsg");
#ifdef DEBUG
- printf(_("Loading module: \"%s\""), name);
+ printf(_("Loading module: \"%s\"\n"), name);
#endif
if (ret->fce_init(&export_fce) != 0) {
fprintf(stderr, _("Failed initialization of module \"%s\""), name);
diff --git a/src/base/proto.c b/src/base/proto.c
index cb54bab..6c4113f 100644
--- a/src/base/proto.c
+++ b/src/base/proto.c
@@ -351,6 +351,7 @@ void proto_recv_init_client(char *msg)
int x, y, n;
int check_id;
int recv_count;
+ arena_t *arena;
assert( msg != NULL );
@@ -370,7 +371,9 @@ void proto_recv_init_client(char *msg)
}
setWorldArena( getArenaIdFormNetName(arena_name) );
- setMaxCountRound(n);
+ arena = getCurrentArena();
+
+ arena->max_countRound = n;
tux = newTux();
replaceTuxID(tux, id);
@@ -381,7 +384,7 @@ void proto_recv_init_client(char *msg)
getSettingNameRight(tux->name);
- addObjectToSpace(getCurrentArena()->spaceTux, tux);
+ addObjectToSpace(arena->spaceTux, tux);
}
#endif
diff --git a/src/client/keyboardBuffer.c b/src/client/keyboardBuffer.c
index 29cd9d4..1eb1ff2 100644
--- a/src/client/keyboardBuffer.c
+++ b/src/client/keyboardBuffer.c
@@ -21,7 +21,7 @@ static SDL_keysym emptyKey;
/*
* Inicializuje klavesovy buffer. Parametr udava pocet klaves.
*/
-void initKeyboardBuffer(uint32_t size){
+void initKeyboardBuffer(int size){
assert(size>0);
assert(keyboardBuffer==NULL);
@@ -103,7 +103,7 @@ SDL_keysym popKeyFromKeyboardBuffer(){
/*
* Velikost bufferu.
*/
-uint32_t getKeyboardBufferSize(){
+int getKeyboardBufferSize(){
assert(keyboardBuffer!=NULL);
return keyboardBuffer->size;
}
@@ -111,7 +111,7 @@ uint32_t getKeyboardBufferSize(){
/*
* Pocet klaves v bufferu.
*/
-uint32_t KeyboardBufferCount(){
+int KeyboardBufferCount(){
assert(keyboardBuffer!=NULL);
return keyboardBuffer->count;
}
diff --git a/src/client/keyboardBuffer.h b/src/client/keyboardBuffer.h
index 13b1183..911eca7 100644
--- a/src/client/keyboardBuffer.h
+++ b/src/client/keyboardBuffer.h
@@ -16,18 +16,18 @@
typedef struct {
SDL_keysym *buff; /* buffer klaves (kod dle SDLKey enumu) */
- uint32_t size; /* aktualni velikost alokovaneho bufferu (v poctu uchovatelnych klaves) */
- uint32_t count; /* pocet klaves aktualne v bufferu */
- uint32_t begin; /* ukazatel na zacatek bufferu (tj. kam se pridavaji klavesy) */
- uint32_t end; /* ukazatel na konec bufferu (tj. odkud se odebiraji klavesy) */
+ int size; /* aktualni velikost alokovaneho bufferu (v poctu uchovatelnych klaves) */
+ int count; /* pocet klaves aktualne v bufferu */
+ int begin; /* ukazatel na zacatek bufferu (tj. kam se pridavaji klavesy) */
+ int end; /* ukazatel na konec bufferu (tj. odkud se odebiraji klavesy) */
} keyboardBuffer_t;
-extern void initKeyboardBuffer(uint32_t size);
+extern void initKeyboardBuffer(int size);
extern void clearKeyboardBuffer();
extern bool_t pushKeyToKeyboardBuffer(SDL_keysym key);
extern SDL_keysym popKeyFromKeyboardBuffer();
-extern uint32_t getKeyboardBufferSize();
-extern uint32_t KeyboardBufferCount();
+extern int getKeyboardBufferSize();
+extern int KeyboardBufferCount();
extern bool_t isAnyKeyInKeyboardBuffer();
extern void quitKeyboardBuffer();
diff --git a/src/client/saveDialog.c b/src/client/saveDialog.c
index 0595d1e..462c219 100644
--- a/src/client/saveDialog.c
+++ b/src/client/saveDialog.c
@@ -16,6 +16,7 @@
#include "font.h"
#include "saveLoad.h"
+#include "widget.h"
#include "widget_label.h"
#include "widget_button.h"
#include "widget_textfield.h"
@@ -24,11 +25,11 @@ static image_t *g_background;
static bool_t activeSaveDialog;
static my_time_t lastActive;
-static widget_label_t *widgetLabelMsg;
-static widget_textfield_t *widgetTextFieldName;
+static widget_t *widgetLabelMsg;
+static widget_t *widgetTextFieldName;
-static widget_button_t *widgetButtonSave;
-static widget_button_t *widgetButtonBack;
+static widget_t *widgetButtonSave;
+static widget_t *widgetButtonBack;
static void switchTerm()
{
@@ -44,13 +45,13 @@ static void switchTerm()
static void eventWidget(void *p)
{
- widget_button_t *button;
+ widget_t *button;
- button = (widget_button_t *)p;
+ button = (widget_t *)p;
if( button == widgetButtonSave )
{
- saveArena(widgetTextFieldName->text, getCurrentArena());
+ saveArena(getTextFromWidgetTextfield(widgetTextFieldName), getCurrentArena());
switchTerm();
}
diff --git a/src/client/saveLoad.c b/src/client/saveLoad.c
index a31bc64..475613d 100644
--- a/src/client/saveLoad.c
+++ b/src/client/saveLoad.c
@@ -12,6 +12,7 @@
#include "tux.h"
#include "shot.h"
#include "item.h"
+#include "modules.h"
#include "saveLoad.h"
@@ -104,8 +105,9 @@ static arena_t* loadArenaFromLine(char *line)
sscanf(line, "%s %s %d %d", cmd, name, &countRound, &max_countRound);
setWorldArena( getArenaIdFormNetName(name) );
- setMaxCountRound(max_countRound);
+
arena = getCurrentArena();
+ arena->max_countRound = max_countRound;
arena->countRound = countRound;
return arena;
@@ -141,6 +143,12 @@ static void loadTuxFromLine(char *line, arena_t *arena)
setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT);
}
+ if( tux->control == TUX_CONTROL_AI )
+ {
+ loadModule("libmodAI");
+ setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT);
+ }
+
moveObjectInSpace(arena->spaceTux, tux, x, y);
tux->status = status;
tux->position = position;
diff --git a/src/modules/modAI.c b/src/modules/modAI.c
index ccd444a..372e8cb 100755
--- a/src/modules/modAI.c
+++ b/src/modules/modAI.c
@@ -209,10 +209,6 @@ static void eventTuxAI(tux_t *tux)
int countLimit = 0;
int countDo = 0;
- listAlternative = newList();
- listDst = newList();
- listFork = newList();
-
export_fce->fce_getTuxProportion(tux, &x, &y, &w, &h);
//printf("tux AI %d %d\n", x, y);
@@ -225,6 +221,10 @@ static void eventTuxAI(tux_t *tux)
return;
}
+ listAlternative = newList();
+ listDst = newList();
+ listFork = newList();
+
shotTux(arena, tux, rivalTux);
export_fce->fce_getTuxProportion(rivalTux, &rival_x, &rival_y, NULL, NULL);
@@ -330,6 +330,7 @@ static void eventTuxAI(tux_t *tux)
export_fce->fce_actionTux(tux, recRoute);
}
+ destroyListItem(listFork, destroyAlternative);
destroyListItem(listAlternative, destroyAlternative);
destroyListItem(listDst, destroyAlternative);
/*
diff --git a/src/screen/screen_analyze.c b/src/screen/screen_analyze.c
index 7723f94..ee42a90 100644
--- a/src/screen/screen_analyze.c
+++ b/src/screen/screen_analyze.c
@@ -17,18 +17,19 @@
#include "screen_mainMenu.h"
#include "screen_analyze.h"
+#include "widget.h"
#include "widget_label.h"
#include "widget_button.h"
#include "widget_image.h"
-static widget_image_t *image_backgorund;
+static widget_t *image_backgorund;
static list_t *listWidgetLabelName;
static list_t *listWidgetLabelScore;
static list_t *listAnalyze;
-static widget_label_t *widgetLabelMsg;
+static widget_t *widgetLabelMsg;
-static widget_button_t *button_ok;
+static widget_t *button_ok;
static analyze_t* newAnalyze(char *name, int score)
{
@@ -56,20 +57,20 @@ void startScreenAnalyze()
void drawScreenAnalyze()
{
- widget_label_t *this;
+ widget_t *this;
int i;
drawWidgetImage(image_backgorund);
for( i = 0 ; i < listWidgetLabelName->count ; i++ )
{
- this = (widget_label_t *)(listWidgetLabelName->list[i]);
+ this = (widget_t *)(listWidgetLabelName->list[i]);
drawWidgetLabel(this);
}
for( i = 0 ; i < listWidgetLabelScore->count ; i++ )
{
- this = (widget_label_t *)(listWidgetLabelScore->list[i]);
+ this = (widget_t *)(listWidgetLabelScore->list[i]);
drawWidgetLabel(this);
}
@@ -90,9 +91,9 @@ void stopScreenAnalyze()
static void eventWidget(void *p)
{
- widget_button_t *button;
+ widget_t *button;
- button = (widget_button_t *)(p);
+ button = (widget_t *)(p);
if( button == button_ok )
{
diff --git a/src/screen/screen_browser.c b/src/screen/screen_browser.c
index 5ec15b9..bb2f1a7 100644
--- a/src/screen/screen_browser.c
+++ b/src/screen/screen_browser.c
@@ -45,6 +45,7 @@ extern int errno;
#include "screen_gameType.h"
#include "screen_browser.h"
+#include "widget.h"
#include "widget_image.h"
#include "widget_label.h"
#include "widget_button.h"
@@ -52,20 +53,20 @@ extern int errno;
#define SERVER_TIMEOUT 200
-static widget_image_t *image_backgorund;
+static widget_t *image_backgorund;
-static widget_button_t *button_play;
-static widget_button_t *button_back;
-static widget_button_t *button_refresh;
+static widget_t *button_play;
+static widget_t *button_back;
+static widget_t *button_refresh;
-static widget_label_t *label_server;
-static widget_label_t *label_version;
-static widget_label_t *label_address;
-static widget_label_t *label_arena;
-static widget_label_t *label_players;
-static widget_label_t *label_ping;
+static widget_t *label_server;
+static widget_t *label_version;
+static widget_t *label_address;
+static widget_t *label_arena;
+static widget_t *label_players;
+static widget_t *label_ping;
-static widget_select_t *select_server;
+static widget_t *select_server;
static server_t server_list;
@@ -148,9 +149,9 @@ void stopScreenBrowser()
static void eventWidget(void *p)
{
- widget_button_t *button;
+ widget_t *button;
- button = (widget_button_t *)(p);
+ button = (widget_t *)(p);
if( button == button_play )
{
@@ -192,7 +193,7 @@ server_t *server_getcurr ()
server_t *server;
for (server = server_list.next; server != &server_list; server = server->next) {
- if (i == select_server->select)
+ if (i == getWidgetSelectIndex(select_server))
return server;
i ++;
@@ -613,8 +614,11 @@ static int LoadServers ()
static int RefreshServers ()
{
+/*
destroyListItem(select_server->list, free);
select_server->list = newList();
+*/
+ removeAllFromWidgetSelect(select_server);
struct in_addr srv;
diff --git a/src/screen/screen_choiceArena.c b/src/screen/screen_choiceArena.c
index dc88d84..336a9aa 100644
--- a/src/screen/screen_choiceArena.c
+++ b/src/screen/screen_choiceArena.c
@@ -18,15 +18,16 @@
#include "screen_mainMenu.h"
#include "screen_choiceArena.h"
+#include "widget.h"
#include "widget_label.h"
#include "widget_button.h"
#include "widget_image.h"
#include "widget_buttonimage.h"
-static widget_image_t *image_backgorund;
+static widget_t *image_backgorund;
-static widget_button_t *button_play;
-static widget_button_t *button_back;
+static widget_t *button_play;
+static widget_t *button_back;
static list_t *listWidgetButtonimage;
static int choiceArenaId;
@@ -49,8 +50,8 @@ void drawScreenChoiceArena()
for( i = 0 ; i < listWidgetButtonimage->count ; i++ )
{
- widget_buttonimage_t *this;
- this = (widget_buttonimage_t *) listWidgetButtonimage->list[i];
+ widget_t *this;
+ this = (widget_t *) listWidgetButtonimage->list[i];
drawWidgetButtonimage(this);
}
}
@@ -64,8 +65,8 @@ void eventScreenChoiceArena()
for( i = 0 ; i < listWidgetButtonimage->count ; i++ )
{
- widget_buttonimage_t *this;
- this = (widget_buttonimage_t *) listWidgetButtonimage->list[i];
+ widget_t *this;
+ this = (widget_t *) listWidgetButtonimage->list[i];
eventWidgetButtonimage(this);
}
}
@@ -76,25 +77,25 @@ void stopScreenChoiceArena()
static void eventWidgetButtonImage(void *p)
{
- widget_buttonimage_t *buttonimage;
+ widget_t *buttonimage;
int i;
- buttonimage = (widget_buttonimage_t *)(p);
+ buttonimage = (widget_t *)(p);
for( i = 0 ; i < listWidgetButtonimage->count ; i++ )
{
- widget_buttonimage_t *this;
+ widget_t *this;
- this = (widget_buttonimage_t *)(listWidgetButtonimage->list[i]);
+ this = (widget_t *)(listWidgetButtonimage->list[i]);
if( buttonimage == this )
{
- this->active = 1;
+ setWidgetButtonimageActive(this, TRUE);
choiceArenaId = i;
}
else
{
- this->active = 0;
+ setWidgetButtonimageActive(this, FALSE);
}
}
}
@@ -106,19 +107,19 @@ int getChoiceArenaId()
void setChoiceArenaId(int n)
{
- widget_buttonimage_t *widget_buttonimage;
+ widget_t *widget_buttonimage;
choiceArenaId = n;
- widget_buttonimage = (widget_buttonimage_t *)listWidgetButtonimage->list[choiceArenaId];
- widget_buttonimage->active = TRUE;
+ widget_buttonimage = (widget_t *)listWidgetButtonimage->list[choiceArenaId];
+ setWidgetButtonimageActive(widget_buttonimage, TRUE);
}
static void eventWidget(void *p)
{
- widget_button_t *button;
+ widget_t *button;
- button = (widget_button_t *)(p);
+ button = (widget_t *)(p);
if( button == button_play )
{
@@ -147,7 +148,7 @@ void initScreenChoiceArena()
for( i = 0 ; i < getArenaCount() ; i++ )
{
- widget_buttonimage_t *widget_buttonimage;
+ widget_t *widget_buttonimage;
int x, y;
image = addImageData(getArenaImage(i), IMAGE_NO_ALPHA, "none", IMAGE_GROUP_BASE);
diff --git a/src/screen/screen_credits.c b/src/screen/screen_credits.c
index ffb6b5f..5a8e9b8 100644
--- a/src/screen/screen_credits.c
+++ b/src/screen/screen_credits.c
@@ -17,12 +17,13 @@
#include "screen_credits.h"
+#include "widget.h"
#include "widget_image.h"
#include "widget_label.h"
#include "widget_button.h"
-static widget_image_t *image_backgorund;
-static widget_button_t *button_back;
+static widget_t *image_backgorund;
+static widget_t *button_back;
static list_t *listWidgetLabel;
static textFile_t *textFile;
static int offset;
@@ -48,8 +49,8 @@ void drawScreenCredits()
{
int z;
- widget_label_t *this;
- this = (widget_label_t *)listWidgetLabel->list[i];
+ widget_t *this;
+ this = (widget_t *)listWidgetLabel->list[i];
z = this->y;
this->y += offset;
@@ -84,9 +85,9 @@ void stopScreenCredits()
static void eventWidget(void *p)
{
- widget_button_t *button;
+ widget_t *button;
- button = (widget_button_t *)(p);
+ button = (widget_t *)(p);
if( button == button_back )
{
@@ -112,7 +113,7 @@ void initScreenCredits()
textFile = loadTextFile(PATH_DATA SCREEN_CREDITS_FILE);
for( i = 0 ; i < textFile->text->count ; i++ )
{
- widget_label_t *label;
+ widget_t *label;
char *line;
line = (char *)textFile->text->list[i];
label = newWidgetLabel(line, WINDOW_SIZE_X/2-WINDOW_SIZE_X/4,
@@ -126,7 +127,7 @@ void initScreenCredits()
for( i = 0 ; i < 5 ; i++ )
{
creditExists = 0;
- widget_label_t *label;
+ widget_t *label;
char *line;
line = "Credit file not found...";
label = newWidgetLabel(line, WINDOW_SIZE_X/2, (WINDOW_SIZE_Y-100)+i*20,
diff --git a/src/screen/screen_gameType.c b/src/screen/screen_gameType.c
index 986b5dd..7dab4e4 100644
--- a/src/screen/screen_gameType.c
+++ b/src/screen/screen_gameType.c
@@ -22,38 +22,69 @@
#include "screen_gameType.h"
#include "screen_setting.h"
+#include "widget.h"
#include "widget_label.h"
#include "widget_button.h"
#include "widget_image.h"
#include "widget_textfield.h"
#include "widget_choicegroup.h"
+#include "widget_check.h"
#include "widget_select.h"
-static widget_image_t *image_backgorund;
+static widget_t *image_backgorund;
-static widget_button_t *button_back;
-static widget_button_t *button_play;
-static widget_button_t *button_browser;
+static widget_t *button_back;
+static widget_t *button_play;
+static widget_t *button_browser;
-static widget_label_t *label_none;
-static widget_label_t *label_server;
-static widget_label_t *label_client;
-static widget_label_t *label_load_session;
+static widget_t *label_none;
+static widget_t *label_server;
+static widget_t *label_client;
+static widget_t *label_load_session;
-static widget_label_t *label_ip;
-static widget_label_t *label_port;
-static widget_label_t *label_session;
+static widget_t *label_ip;
+static widget_t *label_port;
+static widget_t *label_session;
static list_t *listChoiceGroup;
-static widget_choicegroup_t *check_none;
-static widget_choicegroup_t *check_server;
-static widget_choicegroup_t *check_client;
-static widget_choicegroup_t *check_load_session;
+static widget_t *check_none;
+static widget_t *check_server;
+static widget_t *check_client;
+static widget_t *check_load_session;
-static widget_textfield_t *textfield_ip;
-static widget_textfield_t *textfield_port;
+static widget_t *textfield_ip;
+static widget_t *textfield_port;
-static widget_select_t *selectSession;
+static widget_t *selectSession;
+
+static void loadSession(widget_t *p)
+{
+ director_t *director;
+ int i;
+
+ director = loadDirector(getHomeDirector());
+
+ removeAllFromWidgetSelect(p);
+
+ if( director == NULL )
+ {
+ return;
+ }
+
+ for( i = 0 ; i < director->list->count ; i++ )
+ {
+ char *line;
+
+ line = director->list->list[i];
+
+ if( strstr(line, ".sav") != NULL )
+ {
+ addToWidgetSelect(p, line);
+ }
+ }
+
+ destroyDirector(director);
+}
void startScreenGameType()
{
@@ -61,9 +92,12 @@ void startScreenGameType()
playMusic("menu", MUSIC_GROUP_BASE);
#endif
- check_none->status = TRUE;
- check_server->status = FALSE;
- check_client->status = FALSE;
+ setWidgetChoiceStatus(check_none, TRUE);
+ setWidgetChoiceStatus(check_server, FALSE);
+ setWidgetChoiceStatus(check_client, FALSE);
+ setWidgetChoiceStatus(check_load_session, FALSE);
+
+ loadSession(selectSession);
}
void drawScreenGameType()
@@ -74,9 +108,9 @@ void drawScreenGameType()
for( i = 0 ; i < listChoiceGroup->count ; i++ )
{
- widget_choicegroup_t *this;
+ widget_t *this;
- this = (widget_choicegroup_t *)listChoiceGroup->list[i];
+ this = (widget_t *)listChoiceGroup->list[i];
drawWidgetChoicegroup(this);
}
@@ -85,7 +119,7 @@ void drawScreenGameType()
drawWidgetLabel(label_client);
drawWidgetLabel(label_load_session);
- if( check_server->status == TRUE || check_client->status == TRUE )
+ if( getWidgetChoiceStatus(check_server) == TRUE || getWidgetChoiceStatus(check_client) == TRUE )
{
drawWidgetLabel(label_port);
drawWidgetTextfield(textfield_port);
@@ -93,7 +127,7 @@ void drawScreenGameType()
drawWidgetTextfield(textfield_ip);
}
- if( check_load_session->status == TRUE )
+ if( getWidgetChoiceStatus(check_load_session) == TRUE )
{
drawWidgetLabel(label_session);
drawWidgetSelect(selectSession);
@@ -107,7 +141,7 @@ void drawScreenGameType()
}
#endif
- if( check_client->status == TRUE )
+ if( getWidgetChoiceStatus(check_client) == TRUE )
drawWidgetButton(button_browser);
drawWidgetButton(button_back);
@@ -121,19 +155,19 @@ void eventScreenGameType()
for( i = 0 ; i < listChoiceGroup->count ; i++ )
{
- widget_choicegroup_t *this;
+ widget_t *this;
- this = (widget_choicegroup_t *)listChoiceGroup->list[i];
+ this = (widget_t *)listChoiceGroup->list[i];
eventWidgetChoicegroup(this);
}
- if( check_server->status == TRUE || check_client->status == TRUE )
+ if( getWidgetChoiceStatus(check_server) == TRUE || getWidgetChoiceStatus(check_client) == TRUE )
{
eventWidgetTextfield(textfield_ip);
eventWidgetTextfield(textfield_port);
}
- if( check_load_session->status == TRUE )
+ if( getWidgetChoiceStatus(check_load_session) == TRUE )
{
eventWidgetSelect(selectSession);
}
@@ -141,7 +175,7 @@ void eventScreenGameType()
eventWidgetButton(button_back);
eventWidgetButton(button_play);
- if( check_client->status == TRUE )
+ if( getWidgetChoiceStatus(check_client) == TRUE )
eventWidgetButton(button_browser);
}
@@ -151,9 +185,9 @@ void stopScreenGameType()
static void eventWidget(void *p)
{
- widget_button_t *button;
+ widget_t *button;
- button = (widget_button_t *)(p);
+ button = (widget_t *)(p);
if( button == button_back )
{
@@ -188,33 +222,6 @@ static void eventWidget(void *p)
}
}
-static void loadSession(widget_select_t *p)
-{
- director_t *director;
- int i;
-
- director = loadDirector(getHomeDirector());
-
- if( director == NULL )
- {
- return;
- }
-
- for( i = 0 ; i < director->list->count ; i++ )
- {
- char *line;
-
- line = director->list->list[i];
-
- if( strstr(line, ".sav") != NULL )
- {
- addToWidgetSelect(p, strdup(line));
- }
- }
-
- destroyDirector(director);
-}
-
void initScreenGameType()
{
image_t *image;
@@ -234,15 +241,15 @@ void initScreenGameType()
if( isParamFlag("--server") )
{
- check_server->status = TRUE;
+ setWidgetChoiceStatus(check_server, TRUE);
}
else if( isParamFlag("--client") )
{
- check_client->status = TRUE;
+ setWidgetChoiceStatus(check_client, TRUE);
}
else
{
- check_none->status = TRUE;
+ setWidgetChoiceStatus(check_none, TRUE);
}
label_none = newWidgetLabel(getMyText("NONE"), 130, 145, WIDGET_LABEL_LEFT);
@@ -264,8 +271,7 @@ void initScreenGameType()
WIDGET_TEXTFIELD_FILTER_NUM,
300, 280);
- selectSession = newWidgetSelect(300, 175, eventWidget);
- loadSession(selectSession);
+ selectSession = newWidgetSelect(300, 185, eventWidget);
registerScreen( newScreen("gameType", startScreenGameType, eventScreenGameType,
drawScreenGameType, stopScreenGameType) );
@@ -273,25 +279,41 @@ void initScreenGameType()
int setSettingGameType(int status)
{
- check_none->status = status;
+ if( status == NET_GAME_TYPE_NONE )
+ {
+ setWidgetChoiceStatus(check_none, TRUE);
+ return 0;
+ }
- return 0;
+ if( status == NET_GAME_TYPE_SERVER )
+ {
+ setWidgetChoiceStatus(check_server, TRUE);
+ return 0;
+ }
+
+ if( status == NET_GAME_TYPE_CLIENT )
+ {
+ setWidgetChoiceStatus(check_client, TRUE);
+ return 0;
+ }
+
+ return -1;
}
int getSettingGameType()
{
- if( check_none->status == TRUE ||
- check_load_session->status == TRUE )
+ if( getWidgetChoiceStatus(check_none) == TRUE ||
+ getWidgetChoiceStatus(check_load_session) == TRUE )
{
return NET_GAME_TYPE_NONE;
}
- if( check_server->status == TRUE )
+ if( getWidgetChoiceStatus(check_server) == TRUE )
{
return NET_GAME_TYPE_SERVER;
}
- if( check_client->status == TRUE )
+ if( getWidgetChoiceStatus(check_client) == TRUE )
{
return NET_GAME_TYPE_CLIENT;
}
@@ -303,7 +325,7 @@ int getSettingGameType()
char* getGemeTypeLoadSession()
{
- if( check_load_session->status == TRUE )
+ if( getWidgetChoiceStatus(check_load_session) == TRUE )
{
return getWidgetSelectItem(selectSession);
}
@@ -313,36 +335,42 @@ char* getGemeTypeLoadSession()
int setSettingIP(char *address)
{
- strcpy (textfield_ip->text, address);
+ char str[STR_SIZE];
+
+ strcpy (str, address);
+ setWidgetTextFiledText(textfield_ip, str);
return 1;
}
char* getSettingIP()
{
- return textfield_ip->text;
+ return getTextFromWidgetTextfield(textfield_ip);
}
int setSettingPort(int port)
{
- sprintf (textfield_port->text, "%d", port);
+ char str[STR_SIZE];
+
+ sprintf (str, "%d", port);
+ setWidgetTextFiledText(textfield_port, str);
return 0;
}
int getSettingPort()
{
- return atoi( textfield_port->text );
+ return atoi( getTextFromWidgetTextfield(textfield_port) );
}
int getSettingProto()
{
- if( strstr(textfield_ip->text, ".") != NULL )
+ if( strstr(getTextFromWidgetTextfield(textfield_ip), ".") != NULL )
{
return PROTO_UDPv4;
}
- if( strstr(textfield_ip->text, ":") != NULL )
+ if( strstr(getTextFromWidgetTextfield(textfield_ip), ":") != NULL )
{
return PROTO_UDPv6;
}
diff --git a/src/screen/screen_mainMenu.c b/src/screen/screen_mainMenu.c
index eb07cab..8c6e656 100644
--- a/src/screen/screen_mainMenu.c
+++ b/src/screen/screen_mainMenu.c
@@ -17,19 +17,20 @@
#include "screen_mainMenu.h"
#include "screen_setting.h"
+#include "widget.h"
#include "widget_label.h"
#include "widget_button.h"
#include "widget_textfield.h"
#include "widget_check.h"
#include "widget_image.h"
-static widget_image_t *image_backgorund;
+static widget_t *image_backgorund;
-static widget_button_t *button_play;
-static widget_button_t *button_setting;
-static widget_button_t *button_table;
-static widget_button_t *button_credits;
-static widget_button_t *button_end;
+static widget_t *button_play;
+static widget_t *button_setting;
+static widget_t *button_table;
+static widget_t *button_credits;
+static widget_t *button_end;
void startScreenMainMenu()
{
@@ -64,9 +65,9 @@ void stopScreenMainMenu()
static void eventWidget(void *p)
{
- widget_button_t *button;
+ widget_t *button;
- button = (widget_button_t *)(p);
+ button = (widget_t *)(p);
if( button == button_play )
{
diff --git a/src/screen/screen_setting.c b/src/screen/screen_setting.c
index 20e097f..1f77d2a 100644
--- a/src/screen/screen_setting.c
+++ b/src/screen/screen_setting.c
@@ -28,6 +28,7 @@
#include "screen_settingKeys.h"
#include "screen_choiceArena.h"
+#include "widget.h"
#include "widget_label.h"
#include "widget_button.h"
#include "widget_image.h"
@@ -35,46 +36,46 @@
#include "widget_check.h"
#include "widget_select.h"
-static widget_image_t *image_backgorund;
+static widget_t *image_backgorund;
-static widget_button_t *button_back;
-static widget_button_t *button_keys; // setting of keycontrols
+static widget_t *button_back;
+static widget_t *button_keys; // setting of keycontrols
-static widget_label_t *label_count_round;
-static widget_label_t *label_name_player1;
-static widget_label_t *label_name_player2;
-static widget_label_t *label_ai;
+static widget_t *label_count_round;
+static widget_t *label_name_player1;
+static widget_t *label_name_player2;
+static widget_t *label_ai;
#ifndef NO_SOUND
-static widget_label_t *label_music;
-static widget_label_t *label_sound;
+static widget_t *label_music;
+static widget_t *label_sound;
#endif
-static widget_check_t *check[ITEM_COUNT];
+static widget_t *check[ITEM_COUNT];
#ifndef NO_SOUND
-static widget_check_t *check_music;
-static widget_check_t *check_sound;
+static widget_t *check_music;
+static widget_t *check_sound;
#endif
-static widget_image_t *image_gun_dual_revolver;
-static widget_image_t *image_gun_scatter;
-static widget_image_t *image_gun_tommy;
-static widget_image_t *image_gun_lasser;
-static widget_image_t *image_gun_mine;
-static widget_image_t *image_gun_bombball;
+static widget_t *image_gun_dual_revolver;
+static widget_t *image_gun_scatter;
+static widget_t *image_gun_tommy;
+static widget_t *image_gun_lasser;
+static widget_t *image_gun_mine;
+static widget_t *image_gun_bombball;
-static widget_image_t *image_bonus_speed;
-static widget_image_t *image_bonus_shot;
-static widget_image_t *image_bonus_teleport;
-static widget_image_t *image_bonus_ghost;
-static widget_image_t *image_bonus_4x;
-static widget_image_t *image_bonus_hidden;
+static widget_t *image_bonus_speed;
+static widget_t *image_bonus_shot;
+static widget_t *image_bonus_teleport;
+static widget_t *image_bonus_ghost;
+static widget_t *image_bonus_4x;
+static widget_t *image_bonus_hidden;
-static widget_textfield_t *textfield_count_cound;
-static widget_textfield_t *textfield_name_player1;
-static widget_textfield_t *textfield_name_player2;
+static widget_t *textfield_count_cound;
+static widget_t *textfield_name_player1;
+static widget_t *textfield_name_player2;
-static widget_check_t *check_ai;
+static widget_t *check_ai;
static textFile_t *configFile;
@@ -103,7 +104,7 @@ void drawScreenSetting()
drawWidgetTextfield(textfield_count_cound);
drawWidgetTextfield(textfield_name_player1);
- if ( check_ai->status == 0 )
+ if ( getWidgetCheckStatus(check_ai) == FALSE )
{
drawWidgetLabel(label_name_player2);
drawWidgetTextfield(textfield_name_player2);
@@ -151,7 +152,7 @@ void eventScreenSetting()
eventWidgetTextfield(textfield_count_cound);
eventWidgetTextfield(textfield_name_player1);
- if ( check_ai->status == 0 )
+ if ( getWidgetCheckStatus(check_ai) == FALSE )
{
eventWidgetTextfield(textfield_name_player2);
}
@@ -183,11 +184,11 @@ void stopScreenSetting()
static void eventWidget(void *p)
{
- widget_button_t *button;
- widget_check_t *check;
+ widget_t *button;
+ widget_t *check;
- button = (widget_button_t *)(p);
- check = (widget_check_t *)(p);
+ button = (widget_t *)(p);
+ check = (widget_t *)(p);
if( button == button_back )
{
@@ -201,12 +202,12 @@ static void eventWidget(void *p)
#ifndef NO_SOUND
if( check == check_music )
{
- setMusicActive( check_music->status );
+ setMusicActive( getWidgetCheckStatus(check_music) );
}
if( check == check_sound )
{
- setSoundActive( check_sound->status );
+ setSoundActive( getWidgetCheckStatus(check_sound) );
}
#endif
}
@@ -244,40 +245,40 @@ static void initSettingFile()
setWidgetTextFiledText(textfield_name_player2, val);
loadValueFromConfigFile(configFile, "GUN_DUAL_SIMPLE", val, STR_SIZE, "YES");
- check[GUN_DUAL_SIMPLE]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[GUN_DUAL_SIMPLE], isYesOrNO(val));
loadValueFromConfigFile(configFile, "GUN_SCATTER", val, STR_SIZE, "YES");
- check[GUN_SCATTER]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[GUN_SCATTER], isYesOrNO(val));
loadValueFromConfigFile(configFile, "GUN_TOMMY", val, STR_SIZE, "YES");
- check[GUN_TOMMY]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[GUN_TOMMY], isYesOrNO(val));
loadValueFromConfigFile(configFile, "GUN_LASSER", val, STR_SIZE, "YES");
- check[GUN_LASSER]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[GUN_LASSER], isYesOrNO(val));
loadValueFromConfigFile(configFile, "GUN_MINE", val, STR_SIZE, "YES");
- check[GUN_MINE]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[GUN_MINE], isYesOrNO(val));
loadValueFromConfigFile(configFile, "GUN_BOMBBALL", val, STR_SIZE, "YES");
- check[GUN_BOMBBALL]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[GUN_BOMBBALL], isYesOrNO(val));
loadValueFromConfigFile(configFile, "BONUS_SPEED", val, STR_SIZE, "YES");
- check[BONUS_SPEED]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[BONUS_SPEED], isYesOrNO(val));
loadValueFromConfigFile(configFile, "BONUS_SHOT", val, STR_SIZE, "YES");
- check[BONUS_SHOT]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[BONUS_SHOT], isYesOrNO(val));
loadValueFromConfigFile(configFile, "BONUS_TELEPORT", val, STR_SIZE, "YES");
- check[BONUS_TELEPORT]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[BONUS_TELEPORT], isYesOrNO(val));
loadValueFromConfigFile(configFile, "BONUS_GHOST", val, STR_SIZE, "YES");
- check[BONUS_GHOST]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[BONUS_GHOST], isYesOrNO(val));
loadValueFromConfigFile(configFile, "BONUS_4X", val, STR_SIZE, "YES");
- check[BONUS_4X]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[BONUS_4X], isYesOrNO(val));
loadValueFromConfigFile(configFile, "BONUS_HIDDEN", val, STR_SIZE, "YES");
- check[BONUS_HIDDEN]->status = isYesOrNO(val);
+ setWidgetCheckStatus(check[BONUS_HIDDEN], isYesOrNO(val));
loadValueFromConfigFile(configFile, "AI", val, STR_SIZE, "NO");
- check_ai->status = isYesOrNO(val);
+ setWidgetCheckStatus(check_ai, isYesOrNO(val));
#ifndef NO_SOUND
loadValueFromConfigFile(configFile, "MUSIC", val, STR_SIZE, "YES");
- check_music->status = isYesOrNO(val);
+ setWidgetCheckStatus(check_music, isYesOrNO(val));
loadValueFromConfigFile(configFile, "SOUND", val, STR_SIZE, "YES");
- check_sound->status = isYesOrNO(val);
+ setWidgetCheckStatus(check_sound, isYesOrNO(val));
#endif
loadValueFromConfigFile(configFile, "ARENA", val, STR_SIZE, "FAGN");
@@ -296,32 +297,32 @@ static void saveAndDestroyConfigFile()
return;
}
- setValueInConfigFile(configFile, "COUNT_ROUND", textfield_count_cound->text );
- setValueInConfigFile(configFile, "NAME_PLAYER_RIGHT", textfield_name_player1->text );
- setValueInConfigFile(configFile, "NAME_PLAYER_LEFT", textfield_name_player2->text );
+ setValueInConfigFile(configFile, "COUNT_ROUND", getTextFromWidgetTextfield(textfield_count_cound));
+ setValueInConfigFile(configFile, "NAME_PLAYER_RIGHT", getTextFromWidgetTextfield(textfield_name_player1));
+ setValueInConfigFile(configFile, "NAME_PLAYER_LEFT", getTextFromWidgetTextfield(textfield_name_player2));
- setValueInConfigFile(configFile, "GUN_DUAL_SIMPLE", getYesOrNo(check[GUN_DUAL_SIMPLE]->status) );
- setValueInConfigFile(configFile, "GUN_SCATTER", getYesOrNo(check[GUN_SCATTER]->status) );
- setValueInConfigFile(configFile, "GUN_TOMMY", getYesOrNo(check[GUN_TOMMY]->status) );
- setValueInConfigFile(configFile, "GUN_LASSER", getYesOrNo(check[GUN_LASSER]->status) );
- setValueInConfigFile(configFile, "GUN_MINE", getYesOrNo(check[GUN_MINE]->status) );
- setValueInConfigFile(configFile, "GUN_BOMBBALL", getYesOrNo(check[GUN_BOMBBALL]->status) );
+ setValueInConfigFile(configFile, "GUN_DUAL_SIMPLE", getYesOrNo(getWidgetCheckStatus(check[GUN_DUAL_SIMPLE])));
+ setValueInConfigFile(configFile, "GUN_SCATTER", getYesOrNo(getWidgetCheckStatus(check[GUN_SCATTER])));
+ setValueInConfigFile(configFile, "GUN_TOMMY", getYesOrNo(getWidgetCheckStatus(check[GUN_TOMMY])));
+ setValueInConfigFile(configFile, "GUN_LASSER", getYesOrNo(getWidgetCheckStatus(check[GUN_LASSER])));
+ setValueInConfigFile(configFile, "GUN_MINE", getYesOrNo(getWidgetCheckStatus(check[GUN_MINE])));
+ setValueInConfigFile(configFile, "GUN_BOMBBALL", getYesOrNo(getWidgetCheckStatus(check[GUN_BOMBBALL])));
- setValueInConfigFile(configFile, "BONUS_SPEED", getYesOrNo(check[BONUS_SPEED]->status) );
- setValueInConfigFile(configFile, "BONUS_SHOT", getYesOrNo(check[BONUS_SHOT]->status) );
- setValueInConfigFile(configFile, "BONUS_TELEPORT", getYesOrNo(check[BONUS_TELEPORT]->status) );
- setValueInConfigFile(configFile, "BONUS_GHOST", getYesOrNo(check[BONUS_GHOST]->status) );
- setValueInConfigFile(configFile, "BONUS_4X", getYesOrNo(check[BONUS_4X]->status) );
- setValueInConfigFile(configFile, "BONUS_HIDDEN", getYesOrNo(check[BONUS_HIDDEN]->status) );
+ setValueInConfigFile(configFile, "BONUS_SPEED", getYesOrNo(getWidgetCheckStatus(check[BONUS_SPEED])));
+ setValueInConfigFile(configFile, "BONUS_SHOT", getYesOrNo(getWidgetCheckStatus(check[BONUS_SHOT])));
+ setValueInConfigFile(configFile, "BONUS_TELEPORT", getYesOrNo(getWidgetCheckStatus(check[BONUS_TELEPORT])));
+ setValueInConfigFile(configFile, "BONUS_GHOST", getYesOrNo(getWidgetCheckStatus(check[BONUS_GHOST])));
+ setValueInConfigFile(configFile, "BONUS_4X", getYesOrNo(getWidgetCheckStatus(check[BONUS_4X])));
+ setValueInConfigFile(configFile, "BONUS_HIDDEN", getYesOrNo(getWidgetCheckStatus(check[BONUS_HIDDEN])));
- setValueInConfigFile(configFile, "AI", getYesOrNo(check_ai->status) );
+ setValueInConfigFile(configFile, "AI", getYesOrNo(getWidgetCheckStatus(check_ai)));
#ifndef NO_SOUND
- setValueInConfigFile(configFile, "MUSIC", getYesOrNo(check_music->status) );
- setValueInConfigFile(configFile, "SOUND", getYesOrNo(check_sound->status) );
+ setValueInConfigFile(configFile, "MUSIC", getYesOrNo(getWidgetCheckStatus(check_music)));
+ setValueInConfigFile(configFile, "SOUND", getYesOrNo(getWidgetCheckStatus(check_sound)));
#endif
- setValueInConfigFile(configFile, "ARENA", getArenaNetName(getChoiceArenaId()) );
+ setValueInConfigFile(configFile, "ARENA", getArenaNetName(getChoiceArenaId()));
saveTextFile(configFile);
destroyTextFile(configFile);
@@ -442,29 +443,29 @@ void initScreenSetting()
void getSettingNameRight(char *s)
{
- strcpy(s, textfield_name_player1->text);
+ strcpy(s, getTextFromWidgetTextfield(textfield_name_player1));
}
void getSettingNameLeft(char *s)
{
- if( check_ai->status )
+ if( getWidgetCheckStatus(check_ai) )
{
strcpy(s, NAME_AI);
}
else
{
- strcpy(s, textfield_name_player2->text);
+ strcpy(s, getTextFromWidgetTextfield(textfield_name_player2));
}
}
void getSettingCountRound(int *n)
{
- *n = atoi( textfield_count_cound->text );
+ *n = atoi( getTextFromWidgetTextfield(textfield_count_cound) );
}
bool_t isSettingAI()
{
- return check_ai->status;
+ return getWidgetCheckStatus(check_ai);
}
bool_t isSettingAnyItem()
@@ -473,7 +474,7 @@ bool_t isSettingAnyItem()
for( i = GUN_DUAL_SIMPLE ; i <= GUN_BOMBBALL ; i++ )
{
- if( check[i]->status == TRUE )
+ if( getWidgetCheckStatus(check[i]) == TRUE )
{
return TRUE;
}
@@ -481,7 +482,7 @@ bool_t isSettingAnyItem()
for( i = BONUS_SPEED ; i < BONUS_HIDDEN ; i++ )
{
- if( check[i]->status == TRUE )
+ if( getWidgetCheckStatus(check[i]) == TRUE )
{
return TRUE;
}
@@ -492,7 +493,7 @@ bool_t isSettingAnyItem()
bool_t isSettingItem(int item)
{
- return check[item]->status;
+ return getWidgetCheckStatus(check[item]);
}
void quitScreenSetting()
diff --git a/src/screen/screen_settingKeys.c b/src/screen/screen_settingKeys.c
index 91ec0f6..970c38d 100644
--- a/src/screen/screen_settingKeys.c
+++ b/src/screen/screen_settingKeys.c
@@ -21,6 +21,8 @@
#include "screen_mainMenu.h"
#include "screen_setting.h"
#include "screen_settingKeys.h"
+
+#include "widget.h"
#include "widget_button.h"
#include "widget_image.h"
#include "widget_catchkey.h"
@@ -28,38 +30,38 @@
static int keytable[KEY_LENGTH];
static textFile_t *keycontrolFile;
-static widget_image_t *image_backgorund;
-static widget_button_t *button_back;
+static widget_t *image_backgorund;
+static widget_t *button_back;
// key names
-static widget_label_t *tux_right;
-static widget_label_t *tux_right_keyup;
-static widget_label_t *tux_right_keydown;
-static widget_label_t *tux_right_keyleft;
-static widget_label_t *tux_right_keyright;
-static widget_label_t *tux_right_keyswitch;
-static widget_label_t *tux_right_keyfire;
-static widget_label_t *tux_left;
-static widget_label_t *tux_left_keyup;
-static widget_label_t *tux_left_keydown;
-static widget_label_t *tux_left_keyleft;
-static widget_label_t *tux_left_keyright;
-static widget_label_t *tux_left_keyswitch;
-static widget_label_t *tux_left_keyfire;
+static widget_t *tux_right;
+static widget_t *tux_right_keyup;
+static widget_t *tux_right_keydown;
+static widget_t *tux_right_keyleft;
+static widget_t *tux_right_keyright;
+static widget_t *tux_right_keyswitch;
+static widget_t *tux_right_keyfire;
+static widget_t *tux_left;
+static widget_t *tux_left_keyup;
+static widget_t *tux_left_keydown;
+static widget_t *tux_left_keyleft;
+static widget_t *tux_left_keyright;
+static widget_t *tux_left_keyswitch;
+static widget_t *tux_left_keyfire;
// key values
-static widget_catchkey_t *tux_right_keyup_val;
-static widget_catchkey_t *tux_right_keydown_val;
-static widget_catchkey_t *tux_right_keyleft_val;
-static widget_catchkey_t *tux_right_keyright_val;
-static widget_catchkey_t *tux_right_keyswitch_val;
-static widget_catchkey_t *tux_right_keyfire_val;
-static widget_catchkey_t *tux_left_keyup_val;
-static widget_catchkey_t *tux_left_keydown_val;
-static widget_catchkey_t *tux_left_keyleft_val;
-static widget_catchkey_t *tux_left_keyright_val;
-static widget_catchkey_t *tux_left_keyswitch_val;
-static widget_catchkey_t *tux_left_keyfire_val;
+static widget_t *tux_right_keyup_val;
+static widget_t *tux_right_keydown_val;
+static widget_t *tux_right_keyleft_val;
+static widget_t *tux_right_keyright_val;
+static widget_t *tux_right_keyswitch_val;
+static widget_t *tux_right_keyfire_val;
+static widget_t *tux_left_keyup_val;
+static widget_t *tux_left_keydown_val;
+static widget_t *tux_left_keyleft_val;
+static widget_t *tux_left_keyright_val;
+static widget_t *tux_left_keyswitch_val;
+static widget_t *tux_left_keyfire_val;
-//static widget_catchkey_t *catcher;
+//static widget_t *catcher;
// todo add key images
// possible variant will be reusing widget_image for current widget_label so there wont
// be key names but only images
@@ -179,11 +181,11 @@ static void refreshKeytable()
}
static void eventWidget(void *p)
{
- widget_button_t *button;
- widget_catchkey_t *catcher;
+ widget_t *button;
+ widget_t *catcher;
- button = (widget_button_t *)(p);
- catcher = (widget_catchkey_t *)(p);
+ button = (widget_t *)(p);
+ catcher = (widget_t *)(p);
if (button == button_back)
setScreen("setting");
//events on value
@@ -268,29 +270,29 @@ void quitKeyTable()
void saveKeyTable(textFile_t *configFile) {
char str[STR_SIZE];
- sprintf(str,"%d",tux_left_keyup_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_left_keyup_val));
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_UP", str);
- sprintf(str,"%d",tux_left_keydown_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_left_keydown_val));
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_DOWN", str);
- sprintf(str,"%d",tux_left_keyleft_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_left_keyleft_val));
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_LEFT", str);
- sprintf(str,"%d",tux_left_keyright_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_left_keyright_val));
setValueInConfigFile(configFile, "TUX_LEFT_MOVE_RIGHT", str);
- sprintf(str,"%d",tux_left_keyfire_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_left_keyfire_val));
setValueInConfigFile(configFile, "TUX_LEFT_SHOOT", str);
- sprintf(str,"%d",tux_left_keyswitch_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_left_keyswitch_val));
setValueInConfigFile(configFile, "TUX_LEFT_SWITCH_WEAPON", str);
- sprintf(str,"%d",tux_right_keyup_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_right_keyup_val));
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_UP", str);
- sprintf(str,"%d",tux_right_keydown_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_right_keydown_val));
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_DOWN", str);
- sprintf(str,"%d",tux_right_keyleft_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_right_keyleft_val));
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_LEFT", str);
- sprintf(str,"%d",tux_right_keyright_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_right_keyright_val));
setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_RIGHT", str);
- sprintf(str,"%d",tux_right_keyfire_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_right_keyfire_val));
setValueInConfigFile(configFile, "TUX_RIGHT_SHOOT", str);
- sprintf(str,"%d",tux_right_keyswitch_val->key);
+ sprintf(str,"%d", getWidgetCatchKey(tux_right_keyswitch_val));
setValueInConfigFile(configFile, "TUX_RIGHT_SWITCH_WEAPON", str);
saveTextFile(configFile);
}
@@ -311,6 +313,7 @@ void quitScreenSettingKeys()
destroyWidgetLabel(tux_left_keyup);
destroyWidgetLabel(tux_left_keydown);
destroyWidgetLabel(tux_left_keyright);
+ destroyWidgetLabel(tux_left_keyleft);
destroyWidgetLabel(tux_left_keyswitch);
destroyWidgetLabel(tux_left_keyfire);
// key values
diff --git a/src/screen/screen_table.c b/src/screen/screen_table.c
index 1f53b8d..3c26c0a 100644
--- a/src/screen/screen_table.c
+++ b/src/screen/screen_table.c
@@ -23,8 +23,8 @@
#include "widget_label.h"
#include "widget_button.h"
-static widget_image_t *image_backgorund;
-static widget_button_t *button_back;
+static widget_t *image_backgorund;
+static widget_t *button_back;
static list_t *listWidgetLabelNumer;
static list_t *listWidgetLabelName;
@@ -49,22 +49,22 @@ void drawScreenTable()
for( i = 0 ; i < listWidgetLabelNumer->count ; i++ )
{
- widget_label_t *this;
- this = (widget_label_t *)listWidgetLabelNumer->list[i];
+ widget_t *this;
+ this = (widget_t *)listWidgetLabelNumer->list[i];
drawWidgetLabel(this);
}
for( i = 0 ; i < listWidgetLabelName->count ; i++ )
{
- widget_label_t *this;
- this = (widget_label_t *)listWidgetLabelName->list[i];
+ widget_t *this;
+ this = (widget_t *)listWidgetLabelName->list[i];
drawWidgetLabel(this);
}
for( i = 0 ; i < listWidgetLabelScore->count ; i++ )
{
- widget_label_t *this;
- this = (widget_label_t *)listWidgetLabelScore->list[i];
+ widget_t *this;
+ this = (widget_t *)listWidgetLabelScore->list[i];
drawWidgetLabel(this);
}
}
@@ -80,9 +80,9 @@ void stopScreenTable()
static void eventWidget(void *p)
{
- widget_button_t *button;
+ widget_t *button;
- button = (widget_button_t *)(p);
+ button = (widget_t *)(p);
if( button == button_back )
{
@@ -117,7 +117,7 @@ static void setWidgetLabel()
for( i = 0 ; i < SCREEN_TABLE_MAX_PLAYERS ; i++ )
{
- widget_label_t *label;
+ widget_t *label;
char name[STR_NAME_SIZE];
char score[STR_NUM_SIZE];
char num[STR_NUM_SIZE];
diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c
index e619bbb..4229556 100644
--- a/src/screen/screen_world.c
+++ b/src/screen/screen_world.c
@@ -78,16 +78,6 @@ void setWorldArena(int id)
#endif
}
-void setMaxCountRound(int n)
-{
- arena->max_countRound = n;
-}
-
-int getMaxCountRound()
-{
- return arena->max_countRound;
-}
-
void setWorldEnd()
{
isEndWorld = TRUE;
diff --git a/src/screen/screen_world.h b/src/screen/screen_world.h
index 0ba4b41..a0358a7 100644
--- a/src/screen/screen_world.h
+++ b/src/screen/screen_world.h
@@ -15,10 +15,8 @@
extern bool_t isScreenWorldInicialized();
extern void initWorld();
extern void setWorldArena(int id);
-extern void setLagServer(my_time_t lag);
-extern void countRoundInc();
extern void setWorldEnd();
-extern void setMaxCountRound(int n);
+extern void countRoundInc();
extern tux_t* getControlTux(int control_type);
extern void setControlTux(tux_t *tux, int control_type);
extern void tuxControl(tux_t *p);
diff --git a/src/widget/widget.c b/src/widget/widget.c
new file mode 100644
index 0000000..2d9ee19
--- /dev/null
+++ b/src/widget/widget.c
@@ -0,0 +1,52 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+
+#include "widget.h"
+#include "widget_label.h"
+
+widget_t* newWidget(int type, int x, int y, int w, int h, void *private_data)
+{
+ widget_t *new;
+
+ new = malloc( sizeof(widget_t) );
+ new->type = type;
+ new->x = x;
+ new->y = y;
+ new->w = w;
+ new->h = h;
+ new->private_data = private_data;
+
+ return new;
+}
+
+void widgetSetLocation(widget_t *p, int x, int y)
+{
+ p->x = x;
+ p->y = y;
+}
+
+void widgetGetLocation(widget_t *p, int *x, int *y)
+{
+ if( x != NULL )*x = p->x;
+ if( y != NULL )*y = p->y;
+}
+
+void widgetSetSize(widget_t *p, int w, int h)
+{
+ p->w = w;
+ p->h = h;
+}
+
+void widgetGetSize(widget_t *p, int *w, int *h)
+{
+ if( w != NULL )*w = p->w;
+ if( h != NULL )*h = p->h;
+}
+
+void destroyWidget(widget_t *p)
+{
+ free(p);
+}
diff --git a/src/widget/widget.h b/src/widget/widget.h
new file mode 100644
index 0000000..0fcb86c
--- /dev/null
+++ b/src/widget/widget.h
@@ -0,0 +1,33 @@
+
+#ifndef WIDGET_H
+
+#define WIDGET_H
+
+#include "main.h"
+
+#define WIDGET_TYPE_LABEL 1
+#define WIDGET_TYPE_BUTTON 2
+#define WIDGET_TYPE_BUTTONIMAGE 3
+#define WIDGET_TYPE_TEXTFILED 4
+#define WIDGET_TYPE_CATCHKEY 4
+#define WIDGET_TYPE_CHECK 5
+#define WIDGET_TYPE_CHOICE 6
+#define WIDGET_TYPE_IMAGE 7
+#define WIDGET_TYPE_SELECT 8
+
+typedef struct widget_struct
+{
+ int type;
+ int x, y;
+ int w, h;
+ void *private_data;
+} widget_t;
+
+extern widget_t* newWidget(int type, int x, int y, int w, int h, void *private_data);
+extern void widgetSetLocation(widget_t *p, int x, int y);
+extern void widgetGetLocation(widget_t *p, int *x, int *y);
+extern void widgetSetSize(widget_t *p, int w, int h);
+extern void widgetGetSize(widget_t *p, int *w, int *h);
+extern void destroyWidget(widget_t *p);
+
+#endif
diff --git a/src/widget/widget_button.c b/src/widget/widget_button.c
index 4cff900..add6adf 100644
--- a/src/widget/widget_button.c
+++ b/src/widget/widget_button.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
+#include <assert.h>
#include "main.h"
@@ -7,28 +8,32 @@
#include "image.h"
#include "font.h"
+#include "widget.h"
#include "widget_button.h"
-widget_button_t* newWidgetButton(char *text, int x, int y, void (*fce_event)(void *))
+widget_t* newWidgetButton(char *text, int x, int y, void (*fce_event)(void *))
{
widget_button_t *new;
new = malloc( sizeof(widget_button_t) );
new->text = strdup(text);
- new->x = x;
- new->y = y;
new->fce_event = fce_event;
- getTextSize(text, &new->w, &new->h);
+ getTextSize(text, &(new->w), &(new->h));
- return new;
+ return newWidget(WIDGET_TYPE_BUTTON, x, y, WIDGET_BUTTON_WIDTH, WIDGET_BUTTON_HEIGHT, new);
}
-void drawWidgetButton(widget_button_t *p)
+void drawWidgetButton(widget_t *widget)
{
+ widget_button_t *p;
static image_t *g_button0 = NULL;
static image_t *g_button1 = NULL;
int x, y;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTON );
+
+ p = (widget_button_t *) widget->private_data;
getMousePosition(&x, &y);
if( g_button0 == NULL )
@@ -41,25 +46,33 @@ void drawWidgetButton(widget_button_t *p)
g_button1 = addImageData("button1.png", IMAGE_ALPHA, "button1", IMAGE_GROUP_BASE);
}
- if( x >= p->x && x <= p->x+WIDGET_BUTTON_WIDTH &&
- y >= p->y && y <= p->y+WIDGET_BUTTON_HEIGHT )
+ if( x >= widget->x && x <= widget->x+WIDGET_BUTTON_WIDTH &&
+ y >= widget->y && y <= widget->y+WIDGET_BUTTON_HEIGHT )
{
- drawImage(g_button1, p->x, p->y, 0, 0, g_button0->w, g_button0->h);
+ drawImage(g_button1, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h);
}
else
{
- drawImage(g_button0, p->x, p->y, 0, 0, g_button0->w, g_button0->h);
+ drawImage(g_button0, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h);
}
//drawFont(p->text, p->x+WIDGET_BUTTON_WIDTH/2-p->w/2, p->y+p->h/2, COLOR_WHITE);
- drawFont(p->text, p->x + WIDGET_BUTTON_WIDTH/2 - p->w/2, p->y + WIDGET_BUTTON_HEIGHT/2 - p->h/2, COLOR_WHITE);
+ drawFont(p->text,
+ widget->x + WIDGET_BUTTON_WIDTH/2 - p->w/2,
+ widget->y + WIDGET_BUTTON_HEIGHT/2 - p->h/2, COLOR_WHITE);
}
-void eventWidgetButton(widget_button_t *p)
+void eventWidgetButton(widget_t *widget)
{
+ widget_button_t *p;
static int time = 0;
int x, y;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTON );
+
+ p = (widget_button_t *) widget->private_data;
+
if( time > 0)
{
time--;
@@ -68,17 +81,27 @@ void eventWidgetButton(widget_button_t *p)
getMousePosition(&x, &y);
- if( x >= p->x && x <= p->x+WIDGET_BUTTON_WIDTH &&
- y >= p->y && y <= p->y+WIDGET_BUTTON_HEIGHT &&
+ if( x >= widget->x && x <= widget->x+WIDGET_BUTTON_WIDTH &&
+ y >= widget->y && y <= widget->y+WIDGET_BUTTON_HEIGHT &&
isMouseClicked() )
{
time = WIDGET_BUTTON_TIME;
- p->fce_event(p);
+ printf("event\n");
+ p->fce_event(widget);
}
}
-void destroyWidgetButton(widget_button_t *p)
+void destroyWidgetButton(widget_t *widget)
{
+ widget_button_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTON );
+
+ p = (widget_button_t *) widget->private_data;
+
free(p->text);
free(p);
+
+ destroyWidget(widget);
}
diff --git a/src/widget/widget_button.h b/src/widget/widget_button.h
index 5090e55..4bdf7c0 100644
--- a/src/widget/widget_button.h
+++ b/src/widget/widget_button.h
@@ -4,6 +4,7 @@
#define WIDGET_BUTTON_H
#include "main.h"
+#include "widget.h"
#define WIDGET_BUTTON_TIME 10
@@ -12,16 +13,14 @@
typedef struct widget_button
{
- int x, y;
- int w, h;
char *text;
+ int w, h;
void (*fce_event)(void *);
} widget_button_t;
-extern widget_button_t* newWidgetButton(char *text, int x, int y, void (*fce_event)(void *));
-extern void drawWidgetButton(widget_button_t *p);
-extern void eventWidgetButton(widget_button_t *p);
-extern void destroyWidgetButton(widget_button_t *p);
+extern widget_t* newWidgetButton(char *text, int x, int y, void (*fce_event)(void *));
+extern void drawWidgetButton(widget_t *widget);
+extern void eventWidgetButton(widget_t *widget);
+extern void destroyWidgetButton(widget_t *widget);
#endif
-
diff --git a/src/widget/widget_buttonimage.c b/src/widget/widget_buttonimage.c
index 6dfbe66..27e94a3 100644
--- a/src/widget/widget_buttonimage.c
+++ b/src/widget/widget_buttonimage.c
@@ -1,37 +1,61 @@
#include <stdlib.h>
+#include <assert.h>
+
#include "main.h"
#include "interface.h"
#include "font.h"
#include "image.h"
+
+#include "widget.h"
#include "widget_buttonimage.h"
-widget_buttonimage_t* newWidgetButtonimage(image_t *image, int x, int y, void (*fce_event)(void *))
+widget_t* newWidgetButtonimage(image_t *image, int x, int y, void (*fce_event)(void *))
{
widget_buttonimage_t *new;
new = malloc( sizeof(widget_buttonimage_t) );
new->image = image;
- new->x = x;
- new->y = y;
new->w = image->w/2;
new->h = image->h;
new->active = 0;
new->fce_event = fce_event;
- return new;
+ return newWidget(WIDGET_TYPE_BUTTONIMAGE, x, y, new->w, new->h, new);
}
-void drawWidgetButtonimage(widget_buttonimage_t *p)
+void setWidgetButtonimageActive(widget_t *widget, bool_t active)
{
- drawImage(p->image, p->x, p->y, p->active*p->w, 0, p->w, p->h);
+ widget_buttonimage_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTONIMAGE );
+
+ p = (widget_buttonimage_t *)widget->private_data;
+ p->active = active;
}
-void eventWidgetButtonimage(widget_buttonimage_t *p)
+void drawWidgetButtonimage(widget_t *widget)
{
+ widget_buttonimage_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTONIMAGE );
+
+ p = (widget_buttonimage_t *)widget->private_data;
+ drawImage(p->image, widget->x, widget->y, p->active*p->w, 0, p->w, p->h);
+}
+
+void eventWidgetButtonimage(widget_t *widget)
+{
+ widget_buttonimage_t *p;
static int time = 0;
int x, y;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTONIMAGE );
+
+ p = (widget_buttonimage_t *) widget->private_data;
if( time > 0)
{
time--;
@@ -40,16 +64,25 @@ void eventWidgetButtonimage(widget_buttonimage_t *p)
getMousePosition(&x, &y);
- if( x >= p->x && x <= p->x+p->w &&
- y >= p->y && y <= p->y+p->h &&
+ if( x >= widget->x && x <= widget->x+p->w &&
+ y >= widget->y && y <= widget->y+p->h &&
isMouseClicked() )
{
time = WIDGET_BUTTONIMAGE_TIME;
- p->fce_event(p);
+ p->active = 1;
+ p->fce_event(widget);
}
}
-void destroyWidgetButtonimage(widget_buttonimage_t *p)
+void destroyWidgetButtonimage(widget_t *widget)
{
+ widget_buttonimage_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTONIMAGE );
+
+ p = (widget_buttonimage_t *) widget->private_data;
+
free(p);
+ destroyWidget(widget);
}
diff --git a/src/widget/widget_buttonimage.h b/src/widget/widget_buttonimage.h
index e85ce70..c57b143 100644
--- a/src/widget/widget_buttonimage.h
+++ b/src/widget/widget_buttonimage.h
@@ -7,21 +7,22 @@
#define WIDGET_BUTTONIMAGE_TIME 10
+#include "widget.h"
+
typedef struct widget_buttonimageimage
{
- int x, y;
int w, h;
int active;
image_t *image;
void (*fce_event)(void *);
} widget_buttonimage_t;
-extern widget_buttonimage_t* newWidgetButtonimage(image_t *image, int x, int y,
+extern widget_t* newWidgetButtonimage(image_t *image, int x, int y,
void (*fce_event)(void *));
-extern void drawWidgetButtonimage(widget_buttonimage_t *p);
-extern void eventWidgetButtonimage(widget_buttonimage_t *p);
-extern void destroyWidgetButtonimage(widget_buttonimage_t *p);
+extern void setWidgetButtonimageActive(widget_t *widget, bool_t active);
+extern void drawWidgetButtonimage(widget_t *widget);
+extern void eventWidgetButtonimage(widget_t *widget);
+extern void destroyWidgetButtonimage(widget_t *widget);
#endif
-
diff --git a/src/widget/widget_catchkey.c b/src/widget/widget_catchkey.c
index 793c76a..bd281db 100644
--- a/src/widget/widget_catchkey.c
+++ b/src/widget/widget_catchkey.c
@@ -1,40 +1,59 @@
#include <stdlib.h>
+#include <assert.h>
#include "main.h"
#include "interface.h"
#include "font.h"
+
+#include "widget.h"
#include "widget_catchkey.h"
-widget_catchkey_t* newWidgetCatchkey(int key, int x, int y, void *event)
+widget_t* newWidgetCatchkey(int key, int x, int y, void *event)
{
widget_catchkey_t *new;
new = malloc( sizeof(widget_catchkey_t) );
-
- new->x = x;
- new->y = y;
new->key = key;
new->fce_event = event;
new->active = FALSE;
- return new;
+ return newWidget(WIDGET_TYPE_CATCHKEY, x, y, WIDGET_CATCHKEY_WIDTH, WIDGET_CATCHKEY_HEIGHT, new);
}
-int getWidgetCatchKey(widget_catchkey_t *p)
+int getWidgetCatchKey(widget_t *widget)
{
+ widget_catchkey_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CATCHKEY );
+
+ p = (widget_catchkey_t *) widget->private_data;
+
return p->key;
}
-void setWidgetCatchKey(widget_catchkey_t *p, int key)
+void setWidgetCatchKey(widget_t *widget, int key)
{
+ widget_catchkey_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CATCHKEY );
+
+ p = (widget_catchkey_t *) widget->private_data;
+
p->key = key;
}
-void drawWidgetCatchkey(widget_catchkey_t *p)
+void drawWidgetCatchkey(widget_t *widget)
{
+ widget_catchkey_t *p;
char *name;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CATCHKEY );
+
+ p = (widget_catchkey_t *) widget->private_data;
name = NULL;
if( p->key != WIDGET_CATCHKEY_NOKEY )
@@ -49,11 +68,11 @@ void drawWidgetCatchkey(widget_catchkey_t *p)
if( p->active )
{
- drawFont(name, p->x, p->y, COLOR_RED);
+ drawFont(name, widget->x, widget->y, COLOR_RED);
}
else
{
- drawFont(name, p->x, p->y, COLOR_WHITE);
+ drawFont(name, widget->x, widget->y, COLOR_WHITE);
}
}
@@ -82,16 +101,22 @@ static int getPessAnyKey()
return WIDGET_CATCHKEY_NOKEY;
}
-void eventWidgetCatchkey(widget_catchkey_t *p)
+void eventWidgetCatchkey(widget_t *widget)
{
+ widget_catchkey_t *p;
int x, y;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CATCHKEY );
+
+ p = (widget_catchkey_t *) widget->private_data;
getMousePosition(&x, &y);
if( isMouseClicked() )
{
- if( x >= p->x && x <= p->x+WIDGET_CATCHKEY_WIDTH &&
- y >= p->y && y <= p->y+WIDGET_CATCHKEY_HEIGHT )
+ if( x >= widget->x && x <= widget->x+WIDGET_CATCHKEY_WIDTH &&
+ y >= widget->y && y <= widget->y+WIDGET_CATCHKEY_HEIGHT )
{
p->active = TRUE;
}
@@ -115,7 +140,15 @@ void eventWidgetCatchkey(widget_catchkey_t *p)
}
}
-void destroyWidgetCatchkey(widget_catchkey_t *p)
+void destroyWidgetCatchkey(widget_t *widget)
{
+ widget_catchkey_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CATCHKEY );
+
+ p = (widget_catchkey_t *) widget->private_data;
+
free(p);
+ destroyWidget(widget);
}
diff --git a/src/widget/widget_catchkey.h b/src/widget/widget_catchkey.h
index 4b09d20..cec2110 100644
--- a/src/widget/widget_catchkey.h
+++ b/src/widget/widget_catchkey.h
@@ -3,6 +3,7 @@
#define WIDGET_CATCHKEY_H
#include "main.h"
+#include "widget.h"
#define WIDGET_CATCHKEY_WIDTH 110
#define WIDGET_CATCHKEY_HEIGHT 12
@@ -11,18 +12,17 @@
typedef struct widget_catchkey_struct
{
- int x, y;
int w, h;
int key;
bool_t active;
void (*fce_event)(void *p);
} widget_catchkey_t;
-extern widget_catchkey_t* newWidgetCatchkey(int key, int x, int y, void *event);
-extern int getWidgetCatchKey(widget_catchkey_t *p);
-extern void setWidgetCatchKey(widget_catchkey_t *p, int key);
-extern void drawWidgetCatchkey(widget_catchkey_t *p);
-extern void eventWidgetCatchkey(widget_catchkey_t *p);
-extern void destroyWidgetCatchkey(widget_catchkey_t *p);
+extern widget_t* newWidgetCatchkey(int key, int x, int y, void *event);
+extern int getWidgetCatchKey(widget_t *p);
+extern void setWidgetCatchKey(widget_t *p, int key);
+extern void drawWidgetCatchkey(widget_t *p);
+extern void eventWidgetCatchkey(widget_t *p);
+extern void destroyWidgetCatchkey(widget_t *p);
#endif
diff --git a/src/widget/widget_check.c b/src/widget/widget_check.c
index 584b6da..2d94238 100644
--- a/src/widget/widget_check.c
+++ b/src/widget/widget_check.c
@@ -1,30 +1,38 @@
#include <stdlib.h>
+#include <assert.h>
+
#include "main.h"
#include "interface.h"
#include "image.h"
+
+#include "widget.h"
#include "widget_check.h"
-widget_check_t* newWidgetCheck(int x, int y, bool_t status, void (*fce_event)(void *))
+widget_t* newWidgetCheck(int x, int y, bool_t status, void (*fce_event)(void *))
{
widget_check_t *new;
new = malloc( sizeof(widget_check_t) );
- new->x = x;
- new->y = y;
new->time = 0;
new->status = status;
new->fce_event = fce_event;
- return new;
+ return newWidget(WIDGET_TYPE_CHECK, x, y, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT, new);
}
-void drawWidgetCheck(widget_check_t *p)
+void drawWidgetCheck(widget_t *widget)
{
+ widget_check_t *p;
static image_t *g_check = NULL;
int x, y;
int offset;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHECK );
+
+ p = (widget_check_t *) widget->private_data;
+
getMousePosition(&x, &y);
if( g_check == NULL )
@@ -41,13 +49,19 @@ void drawWidgetCheck(widget_check_t *p)
offset = WIDGET_CHECK_WIDTH;
}
- drawImage(g_check, p->x, p->y, offset, 0, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT);
+ drawImage(g_check, widget->x, widget->y, offset, 0, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT);
}
-void eventWidgetCheck(widget_check_t *p)
+void eventWidgetCheck(widget_t *widget)
{
+ widget_check_t *p;
int x, y;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHECK );
+
+ p = (widget_check_t *) widget->private_data;
+
if( p->time > 0 )
{
p->time--;
@@ -56,8 +70,8 @@ void eventWidgetCheck(widget_check_t *p)
getMousePosition(&x, &y);
- if( x >= p->x && x <= p->x+WIDGET_CHECK_WIDTH &&
- y >= p->y && y <= p->y+WIDGET_CHECK_HEIGHT &&
+ if( x >= widget->x && x <= widget->x+WIDGET_CHECK_WIDTH &&
+ y >= widget->y && y <= widget->y+WIDGET_CHECK_HEIGHT &&
isMouseClicked() )
{
if( p->status == TRUE )
@@ -78,7 +92,37 @@ void eventWidgetCheck(widget_check_t *p)
}
}
-void destroyWidgetCheck(widget_check_t *p)
+bool_t getWidgetCheckStatus(widget_t *widget)
{
+ widget_check_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHECK );
+
+ p = (widget_check_t *) widget->private_data;
+
+ return p->status;
+}
+
+void setWidgetCheckStatus(widget_t *widget, bool_t status)
+{
+ widget_check_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHECK );
+
+ p = (widget_check_t *) widget->private_data;
+ p->status = status;
+}
+
+void destroyWidgetCheck(widget_t *widget)
+{
+ widget_check_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHECK );
+
+ p = (widget_check_t *) widget->private_data;
free(p);
+ destroyWidget(widget);
}
diff --git a/src/widget/widget_check.h b/src/widget/widget_check.h
index 2e3a3a3..c8b13b0 100644
--- a/src/widget/widget_check.h
+++ b/src/widget/widget_check.h
@@ -4,6 +4,7 @@
#define WIDGET_CHECK_H
#include "main.h"
+#include "widget.h"
#define WIDGET_CHECK_TIME_SWITCH_STATUS 5
@@ -12,16 +13,17 @@
typedef struct widget_check
{
- int x, y;
bool_t status;
int time;
void (*fce_event)(void *);
} widget_check_t;
-extern widget_check_t* newWidgetCheck(int x, int y, bool_t status, void (*fce_event)(void *));
-extern void drawWidgetCheck(widget_check_t *p);
-extern void eventWidgetCheck(widget_check_t *p);
-extern void destroyWidgetCheck(widget_check_t *p);
+extern widget_t* newWidgetCheck(int x, int y, bool_t status, void (*fce_event)(void *));
+extern void drawWidgetCheck(widget_t *widget);
+extern void eventWidgetCheck(widget_t *widget);
+extern bool_t getWidgetCheckStatus(widget_t *widget);
+extern void setWidgetCheckStatus(widget_t *widget, bool_t status);
+extern void destroyWidgetCheck(widget_t *widget);
#endif
diff --git a/src/widget/widget_choicegroup.c b/src/widget/widget_choicegroup.c
index 5404461..fc4fd01 100644
--- a/src/widget/widget_choicegroup.c
+++ b/src/widget/widget_choicegroup.c
@@ -5,35 +5,44 @@
#include "main.h"
#include "interface.h"
#include "image.h"
+
+#include "widget.h"
#include "widget_choicegroup.h"
-widget_choicegroup_t* newWidgetChoicegroup(int x, int y, bool_t status, list_t *list, void (*fce_event)(void *))
+widget_t* newWidgetChoicegroup(int x, int y, bool_t status, list_t *list, void (*fce_event)(void *))
{
widget_choicegroup_t *new;
+ widget_t *widget;
new = malloc( sizeof(widget_choicegroup_t) );
- new->x = x;
- new->y = y;
new->time = 0;
new->status = status;
new->fce_event = fce_event;
new->list = list;
- addList(new->list, new);
- return new;
+ widget = newWidget(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT, new);
+ addList(new->list, widget);
+
+ return widget;
}
-void drawWidgetChoicegroup(widget_choicegroup_t *p)
+void drawWidgetChoicegroup(widget_t *widget)
{
+ widget_choicegroup_t *p;
static image_t *g_choicegroup = NULL;
int x, y;
int offset;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHOICE );
+
+ p = (widget_choicegroup_t *) widget->private_data;
+
getMousePosition(&x, &y);
if( g_choicegroup == NULL )
{
- g_choicegroup = addImageData("check.png", IMAGE_ALPHA, "choicegroup", IMAGE_GROUP_BASE);
+ g_choicegroup = addImageData("choice.png", IMAGE_ALPHA, "choicegroup", IMAGE_GROUP_BASE);
}
if( p->status == TRUE )
@@ -45,36 +54,73 @@ void drawWidgetChoicegroup(widget_choicegroup_t *p)
offset = WIDGET_CHOICEGROUP_WIDTH;
}
- drawImage(g_choicegroup, p->x, p->y, offset, 0, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT);
+ drawImage(g_choicegroup, widget->x, widget->y, offset, 0, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT);
}
-static void setActive(widget_choicegroup_t *p)
+void setWidgetChoiceActive(widget_t *widget)
{
+ widget_choicegroup_t *p;
int i;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHOICE );
+
+ p = (widget_choicegroup_t *) widget->private_data;
+
for( i = 0 ; i < p->list->count ; i++ )
{
- widget_choicegroup_t *this;
+ widget_t *this;
+ widget_choicegroup_t *thisChoice;
- this = (widget_choicegroup_t *) p->list->list[i];
+ this = (widget_t *) p->list->list[i];
+ thisChoice = (widget_choicegroup_t *) this->private_data;
- if( this == p )
+ if( widget == this )
{
- this->status = TRUE;
- this->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS;
- this->fce_event(p);
+ thisChoice->status = TRUE;
+ thisChoice->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS;
+ thisChoice->fce_event(p);
}
else
{
- this->status = FALSE;
+ thisChoice->status = FALSE;
}
}
}
-void eventWidgetChoicegroup(widget_choicegroup_t *p)
+bool_t getWidgetChoiceStatus(widget_t *widget)
+{
+ widget_choicegroup_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHOICE );
+
+ p = (widget_choicegroup_t *) widget->private_data;
+
+ return p->status;
+}
+
+void setWidgetChoiceStatus(widget_t *widget, bool_t status)
+{
+ widget_choicegroup_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHOICE );
+
+ p = (widget_choicegroup_t *) widget->private_data;
+ p->status = status;
+}
+
+void eventWidgetChoicegroup(widget_t *widget)
{
+ widget_choicegroup_t *p;
int x, y;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHOICE );
+
+ p = (widget_choicegroup_t *) widget->private_data;
+
if( p->time > 0 )
{
p->time--;
@@ -83,21 +129,27 @@ void eventWidgetChoicegroup(widget_choicegroup_t *p)
getMousePosition(&x, &y);
- if( x >= p->x && x <= p->x+WIDGET_CHOICEGROUP_WIDTH &&
- y >= p->y && y <= p->y+WIDGET_CHOICEGROUP_HEIGHT &&
+ if( x >= widget->x && x <= widget->x+WIDGET_CHOICEGROUP_WIDTH &&
+ y >= widget->y && y <= widget->y+WIDGET_CHOICEGROUP_HEIGHT &&
isMouseClicked() )
{
- setActive(p);
+ setWidgetChoiceActive(widget);
}
}
-void destroyWidgetChoicegroup(widget_choicegroup_t *p)
+void destroyWidgetChoicegroup(widget_t *widget)
{
+ widget_choicegroup_t *p;
int index;
- index = searchListItem(p->list, p);
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_CHOICE );
+
+ p = (widget_choicegroup_t *) widget->private_data;
+ index = searchListItem(p->list, widget);
assert( index != -1 );
delList(p->list, index);
free(p);
+ destroyWidget(widget);
}
diff --git a/src/widget/widget_choicegroup.h b/src/widget/widget_choicegroup.h
index 93d88fc..05e6532 100644
--- a/src/widget/widget_choicegroup.h
+++ b/src/widget/widget_choicegroup.h
@@ -5,6 +5,7 @@
#include "main.h"
#include "list.h"
+#include "widget.h"
#define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5
@@ -13,19 +14,21 @@
typedef struct widget_choicegroup
{
- int x, y;
bool_t status;
int time;
void (*fce_event)(void *);
list_t *list;
} widget_choicegroup_t;
-extern widget_choicegroup_t* newWidgetChoicegroup(int x, int y, bool_t status,
+extern widget_t* newWidgetChoicegroup(int x, int y, bool_t status,
list_t *list, void (*fce_event)(void *));
-extern void drawWidgetChoicegroup(widget_choicegroup_t *p);
-extern void eventWidgetChoicegroup(widget_choicegroup_t *p);
-extern void destroyWidgetChoicegroup(widget_choicegroup_t *p);
+extern void drawWidgetChoicegroup(widget_t *p);
+extern void setWidgetChoiceActive(widget_t *widget);
+extern bool_t getWidgetChoiceStatus(widget_t *widget);
+extern void setWidgetChoiceStatus(widget_t *widget, bool_t status);
+extern void eventWidgetChoicegroup(widget_t *p);
+extern void destroyWidgetChoicegroup(widget_t *p);
#endif
diff --git a/src/widget/widget_image.c b/src/widget/widget_image.c
index 8be8080..926a714 100644
--- a/src/widget/widget_image.c
+++ b/src/widget/widget_image.c
@@ -1,35 +1,52 @@
#include <stdlib.h>
+#include <assert.h>
#include <stdlib.h>
#include "main.h"
#include "image.h"
#include "interface.h"
#include "font.h"
+
+#include "widget.h"
#include "widget_image.h"
-widget_image_t* newWidgetImage(int x, int y, image_t *image)
+widget_t* newWidgetImage(int x, int y, image_t *image)
{
widget_image_t *new;
new = malloc( sizeof(widget_image_t) );
- new->x = x;
- new->y = y;
new->image = image;
- return new;
+ return newWidget(WIDGET_TYPE_IMAGE, x, y, image->w, image->h, new);
}
-void drawWidgetImage(widget_image_t *p)
+void drawWidgetImage(widget_t *widget)
{
- drawImage(p->image, p->x, p->y, 0, 0, p->image->w, p->image->h);
+ widget_image_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_IMAGE );
+
+ p = (widget_image_t *) widget->private_data;
+ drawImage(p->image, widget->x, widget->y, 0, 0, p->image->w, p->image->h);
}
-void eventWidgetImage(widget_image_t *p)
+void eventWidgetImage(widget_t *widget)
{
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_IMAGE );
}
-void destroyWidgetImage(widget_image_t *p)
+void destroyWidgetImage(widget_t *widget)
{
+ widget_image_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_IMAGE );
+
+ p = (widget_image_t *) widget->private_data;
+
free(p);
+ destroyWidget(widget);
}
diff --git a/src/widget/widget_image.h b/src/widget/widget_image.h
index 8a038da..6f661e4 100644
--- a/src/widget/widget_image.h
+++ b/src/widget/widget_image.h
@@ -5,17 +5,17 @@
#include "main.h"
#include "interface.h"
+#include "widget.h"
typedef struct widget_image
{
- int x, y;
image_t *image;
} widget_image_t;
-extern widget_image_t* newWidgetImage(int x, int y, image_t *image);
-extern void drawWidgetImage(widget_image_t *p);
-extern void eventWidgetImage(widget_image_t *p);
-extern void destroyWidgetImage(widget_image_t *p);
+extern widget_t* newWidgetImage(int x, int y, image_t *image);
+extern void drawWidgetImage(widget_t *p);
+extern void eventWidgetImage(widget_t *p);
+extern void destroyWidgetImage(widget_t *p);
#endif
diff --git a/src/widget/widget_label.c b/src/widget/widget_label.c
index 15dea4d..c0b3f35 100644
--- a/src/widget/widget_label.c
+++ b/src/widget/widget_label.c
@@ -1,47 +1,65 @@
#include <stdlib.h>
+#include <assert.h>
#include "main.h"
#include "interface.h"
#include "font.h"
#include "widget_label.h"
+#include "widget.h"
-widget_label_t* newWidgetLabel(char *text, int x, int y, int bind)
+widget_t* newWidgetLabel(char *text, int x, int y, int bind)
{
widget_label_t *new;
new = malloc( sizeof(widget_label_t) );
new->text = strdup(text);
- new->x = x;
- new->y = y;
new->bind = bind;
- getTextSize(text, &new->w, &new->h);
+ getTextSize(text, &(new->w), &(new->h));
- return new;
+ return newWidget(WIDGET_TYPE_LABEL, x, y, new->w, new->h, new);
}
-void drawWidgetLabel(widget_label_t *p)
+void drawWidgetLabel(widget_t *widget)
{
+ widget_label_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_LABEL );
+
+ p = (widget_label_t *) widget->private_data;
+
switch( p->bind )
{
case WIDGET_LABEL_RIGHT :
- drawFont(p->text, p->x+p->w, p->y + p->h/2, COLOR_WHITE);
+ drawFont(p->text, widget->x+p->w, widget->y + p->h/2, COLOR_WHITE);
break;
case WIDGET_LABEL_LEFT :
- drawFont(p->text, p->x, p->y + p->h/2, COLOR_WHITE);
+ drawFont(p->text, widget->x, widget->y + widget->h/2, COLOR_WHITE);
break;
case WIDGET_LABEL_CENTER :
- drawFont(p->text, p->x-p->w/2, p->y + p->h/2, COLOR_WHITE);
+ drawFont(p->text, widget->x-p->w/2, widget->y + p->h/2, COLOR_WHITE);
break;
}
}
-void eventWidgetLabel(widget_label_t *p)
+void eventWidgetLabel(widget_t *widget)
{
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_LABEL );
}
-void destroyWidgetLabel(widget_label_t *p)
+void destroyWidgetLabel(widget_t *widget)
{
+ widget_label_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_LABEL );
+
+ p = (widget_label_t *) widget->private_data;
+
free(p->text);
free(p);
+
+ destroyWidget(widget);
}
diff --git a/src/widget/widget_label.h b/src/widget/widget_label.h
index f976bbc..0893d68 100644
--- a/src/widget/widget_label.h
+++ b/src/widget/widget_label.h
@@ -4,10 +4,10 @@
#define WIDGET_LABEL_H
#include "main.h"
+#include "widget.h"
typedef struct widget_label
{
- int x, y;
int w, h;
char *text;
int bind;
@@ -17,10 +17,9 @@ typedef struct widget_label
#define WIDGET_LABEL_LEFT 2
#define WIDGET_LABEL_CENTER 3
-extern widget_label_t* newWidgetLabel(char *text, int x, int y, int bind);
-extern void drawWidgetLabel(widget_label_t *p);
-extern void eventWidgetLabel(widget_label_t *p);
-extern void destroyWidgetLabel(widget_label_t *p);
+extern widget_t* newWidgetLabel(char *text, int x, int y, int bind);
+extern void drawWidgetLabel(widget_t *widget);
+extern void eventWidgetLabel(widget_t *widget);
+extern void destroyWidgetLabel(widget_t *widget);
#endif
-
diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c
index 3ab5638..0ec90c1 100644
--- a/src/widget/widget_select.c
+++ b/src/widget/widget_select.c
@@ -1,36 +1,35 @@
#include <stdlib.h>
+#include <assert.h>
+
#include "main.h"
#include "interface.h"
#include "font.h"
+
+#include "widget.h"
#include "widget_select.h"
-/*
-typedef struct widget_select
-{
- int x, y;
- int w, h;
- list_t *list;
- void (*fce_event)(void *);
-} widget_select_t;
-*/
-
-widget_select_t* newWidgetSelect(int x, int y, void (*fce_event)(void *))
+widget_t* newWidgetSelect(int x, int y, void (*fce_event)(void *))
{
widget_select_t *new;
new = malloc( sizeof(widget_select_t) );
- new->x = x;
- new->y = y;
new->select = -1;
new->fce_event = fce_event;
new->list = newList();
- return new;
+ return newWidget(WIDGET_TYPE_SELECT, x, y, 0, 0, new);
}
-char* getWidgetSelectItem(widget_select_t *p)
+char* getWidgetSelectItem(widget_t *widget)
{
+ widget_select_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_SELECT );
+
+ p = (widget_select_t *)widget->private_data;
+
if( p->select == -1 )
{
return NULL;
@@ -39,25 +38,56 @@ char* getWidgetSelectItem(widget_select_t *p)
return (char *)p->list->list[p->select];
}
-void addToWidgetSelect(widget_select_t *p, char *s)
+int getWidgetSelectIndex(widget_t *widget)
+{
+ widget_select_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_SELECT );
+
+ p = (widget_select_t *)widget->private_data;
+
+ return p->select;
+}
+
+void addToWidgetSelect(widget_t *widget, char *s)
{
+ widget_select_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_SELECT );
+
+ p = (widget_select_t *)widget->private_data;
+
addList(p->list, strdup(s) );
}
-void removeAllFromWidgetSelect(widget_select_t *p)
+void removeAllFromWidgetSelect(widget_t *widget)
{
+ widget_select_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_SELECT );
+
+ p = (widget_select_t *)widget->private_data;
+
while( p->list->count > 0 )
{
delListItem(p->list, 0, free);
}
}
-void drawWidgetSelect(widget_select_t *p)
+void drawWidgetSelect(widget_t *widget)
{
+ widget_select_t *p;
int x, y, w, h;
int i;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_SELECT );
+
getMousePosition(&x, &y);
+ p = (widget_select_t *)widget->private_data;
for( i = 0 ; i < p->list->count ; i++ )
{
@@ -67,29 +97,34 @@ void drawWidgetSelect(widget_select_t *p)
getTextSize(line, &w, &h);
- if( x > p->x && y > p->y + i*20 && x < p->x+w && y < p->y + i*20 + h )
+ if( x > widget->x && y > widget->y + i*20 && x < widget->x+w && y < widget->y + i*20 + h )
{
- drawFont(line, p->x, p->y + i*20, COLOR_YELLOW);
+ drawFont(line, widget->x, widget->y + i*20, COLOR_YELLOW);
}
else
{
if( p->select == i )
{
- drawFont(line, p->x, p->y + i*20, COLOR_RED);
+ drawFont(line, widget->x, widget->y + i*20, COLOR_RED);
}
else
{
- drawFont(line, p->x, p->y + i*20, COLOR_WHITE);
+ drawFont(line, widget->x, widget->y + i*20, COLOR_WHITE);
}
}
}
}
-void eventWidgetSelect(widget_select_t *p)
+void eventWidgetSelect(widget_t *widget)
{
+ widget_select_t *p;
int x, y, w, h;
int i;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_SELECT );
+
+ p = (widget_select_t *)widget->private_data;
getMousePosition(&x, &y);
for( i = 0 ; i < p->list->count ; i++ )
@@ -100,7 +135,9 @@ void eventWidgetSelect(widget_select_t *p)
getTextSize(line, &w, &h);
- if( x > p->x && y > p->y + i*20 && x < p->x+w && y < p->y + i*20 + h && isMouseClicked() )
+ if( x > widget->x && y > widget->y + i*20 &&
+ x < widget->x+w && y < widget->y + i*20 + h &&
+ isMouseClicked() )
{
p->select = i;
p->fce_event(p);
@@ -108,8 +145,16 @@ void eventWidgetSelect(widget_select_t *p)
}
}
-void destroyWidgetSelect(widget_select_t *p)
+void destroyWidgetSelect(widget_t *widget)
{
+ widget_select_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_SELECT );
+
+ p = (widget_select_t *)widget->private_data;
+
destroyListItem(p->list, free);
free(p);
+ destroyWidget(widget);
}
diff --git a/src/widget/widget_select.h b/src/widget/widget_select.h
index 0f5f712..a0be1b1 100644
--- a/src/widget/widget_select.h
+++ b/src/widget/widget_select.h
@@ -5,24 +5,24 @@
#include "main.h"
#include "list.h"
-
+#include "widget.h"
typedef struct widget_select
{
- int x, y;
int w, h;
list_t *list;
int select;
void (*fce_event)(void *);
} widget_select_t;
-extern widget_select_t* newWidgetSelect(int x, int y, void (*fce_event)(void *));
-extern char* getWidgetSelectItem(widget_select_t *p);
-extern void addToWidgetSelect(widget_select_t *p, char *s);
-extern void removeAllFromWidgetSelect(widget_select_t *p);
-extern void drawWidgetSelect(widget_select_t *p);
-extern void eventWidgetSelect(widget_select_t *p);
-extern void destroyWidgetSelect(widget_select_t *p);
+extern widget_t* newWidgetSelect(int x, int y, void (*fce_event)(void *));
+extern char* getWidgetSelectItem(widget_t *widget);
+extern int getWidgetSelectIndex(widget_t *widget);
+extern void addToWidgetSelect(widget_t *widget, char *s);
+extern void removeAllFromWidgetSelect(widget_t *widget);
+extern void drawWidgetSelect(widget_t *widget);
+extern void eventWidgetSelect(widget_t *widget);
+extern void destroyWidgetSelect(widget_t *widget);
#endif
diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c
index ee1cf76..0e5576b 100644
--- a/src/widget/widget_textfield.c
+++ b/src/widget/widget_textfield.c
@@ -1,14 +1,18 @@
#include <stdlib.h>
+#include <assert.h>
+
#include "main.h"
#include "interface.h"
#include "font.h"
#include "image.h"
+
+#include "widget.h"
#include "widget_textfield.h"
//#define ZZEEXX86_READKEY
-widget_textfield_t* newWidgetTextfield(char *text, int filter, int x, int y)
+widget_t* newWidgetTextfield(char *text, int filter, int x, int y)
{
widget_textfield_t *new;
@@ -16,8 +20,6 @@ widget_textfield_t* newWidgetTextfield(char *text, int filter, int x, int y)
memset(new, 0, sizeof(widget_textfield_t));
strcpy(new->text, text);
- new->x = x;
- new->y = y;
new->time = 0;
new->timeBlick = 0;
new->atime = 0;
@@ -25,16 +27,19 @@ widget_textfield_t* newWidgetTextfield(char *text, int filter, int x, int y)
new->filter = filter;
getTextSize(text, &new->w, &new->h);
- return new;
+ return newWidget(WIDGET_TYPE_TEXTFILED, x, y, WIDGET_TEXTFIELD_WIDTH, WIDGET_TEXTFIELD_HEIGHT, new);
}
-static void drawBackground(widget_textfield_t *p)
+static void drawBackground(widget_t *widget)
{
static image_t *g_textfield0 = NULL;
static image_t *g_textfield1 = NULL;
- //int x, y;
+ widget_textfield_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_TEXTFILED );
- //getMousePosition(&x, &y);
+ p = (widget_textfield_t *) widget->private_data;
if( g_textfield0 == NULL )
{
@@ -48,17 +53,23 @@ static void drawBackground(widget_textfield_t *p)
if( p->active )
{
- drawImage(g_textfield1, p->x, p->y, 0, 0, g_textfield1->w, g_textfield1->h);
+ drawImage(g_textfield1, widget->x, widget->y, 0, 0, g_textfield1->w, g_textfield1->h);
}
else
{
- drawImage(g_textfield0, p->x, p->y, 0, 0, g_textfield0->w, g_textfield0->h);
+ drawImage(g_textfield0, widget->x, widget->y, 0, 0, g_textfield0->w, g_textfield0->h);
}
}
-static void drawText(widget_textfield_t *p)
+static void drawText(widget_t *widget)
{
char str[STR_SIZE];
+ widget_textfield_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_TEXTFILED );
+
+ p = (widget_textfield_t *) widget->private_data;
strcpy(str, p->text);
@@ -77,23 +88,48 @@ static void drawText(widget_textfield_t *p)
}
//drawFont(str, p->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, p->y+p->h/2, COLOR_WHITE);
- drawFont(str, p->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, p->y+WIDGET_TEXTFIELD_HEIGHT/2-p->h/2, COLOR_WHITE);
//printf("p->y: %d\nheight: %d\n p->h: %d\n", p->y, WIDGET_TEXTFIELD_HEIGHT, p->h);
+
+ drawFont(str,
+ widget->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X,
+ widget->y+WIDGET_TEXTFIELD_HEIGHT/2-p->h/2,
+ COLOR_WHITE);
}
-void drawWidgetTextfield(widget_textfield_t *p)
+void drawWidgetTextfield(widget_t *widget)
{
- drawBackground(p);
- drawText(p);
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_TEXTFILED );
+
+ drawBackground(widget);
+ drawText(widget);
}
-void setWidgetTextFiledText(widget_textfield_t *p, char *text)
+void setWidgetTextFiledText(widget_t *widget, char *text)
{
+ widget_textfield_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_TEXTFILED );
+
+ p = (widget_textfield_t *) widget->private_data;
+
memset(p->text, 0, STR_SIZE);
strcpy(p->text, text);
getTextSize(text, &p->w, &p->h);
}
+char* getTextFromWidgetTextfield(widget_t *widget)
+{
+ widget_textfield_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_TEXTFILED );
+
+ p = (widget_textfield_t *) widget->private_data;
+ return p->text;
+}
+
static void checkText(widget_textfield_t *p)
{
int len;
@@ -408,16 +444,22 @@ static void readKey(widget_textfield_t *p)
}
#endif
-void eventWidgetTextfield(widget_textfield_t *p)
+void eventWidgetTextfield(widget_t *widget)
{
+ widget_textfield_t *p;
int x, y;
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_TEXTFILED );
+
+ p = (widget_textfield_t *) widget->private_data;
+
getMousePosition(&x, &y);
if( isMouseClicked() )
{
- if( x >= p->x && x <= p->x+WIDGET_TEXTFIELD_WIDTH &&
- y >= p->y && y <= p->y+WIDGET_TEXTFIELD_HEIGHT )
+ if( x >= widget->x && x <= widget->x+WIDGET_TEXTFIELD_WIDTH &&
+ y >= widget->y && y <= widget->y+WIDGET_TEXTFIELD_HEIGHT )
{
p->active = TRUE;
}
@@ -430,8 +472,16 @@ void eventWidgetTextfield(widget_textfield_t *p)
readKey(p);
}
-void destroyWidgetTextfield(widget_textfield_t *p)
+void destroyWidgetTextfield(widget_t *widget)
{
+ widget_textfield_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_TEXTFILED );
+
+ p = (widget_textfield_t *) widget->private_data;
+
free(p);
+ destroyWidget(widget);
}
diff --git a/src/widget/widget_textfield.h b/src/widget/widget_textfield.h
index 11b135c..00a147b 100644
--- a/src/widget/widget_textfield.h
+++ b/src/widget/widget_textfield.h
@@ -4,6 +4,7 @@
#define WIDGET_TEXTFIELD_H
#include "main.h"
+#include "widget.h"
#define WIDGET_TEXTFIELD_WIDTH 175
#define WIDGET_TEXTFIELD_HEIGHT 36
@@ -21,7 +22,6 @@
typedef struct widget_textfield
{
- int x, y;
int w, h;
int canWrite;
int timeBlick;
@@ -32,11 +32,12 @@ typedef struct widget_textfield
bool_t active;
} widget_textfield_t;
-extern widget_textfield_t* newWidgetTextfield(char *text, int filter, int x, int y);
-extern void setWidgetTextFiledText(widget_textfield_t *p, char *text);
-extern void drawWidgetTextfield(widget_textfield_t *p);
-extern void eventWidgetTextfield(widget_textfield_t *p);
-extern void destroyWidgetTextfield(widget_textfield_t *p);
+extern widget_t* newWidgetTextfield(char *text, int filter, int x, int y);
+extern void setWidgetTextFiledText(widget_t *widget, char *text);
+extern char* getTextFromWidgetTextfield(widget_t *widget);
+extern void drawWidgetTextfield(widget_t *widget);
+extern void eventWidgetTextfield(widget_t *widget);
+extern void destroyWidgetTextfield(widget_t *widget);
#endif