summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDusan Durech <dusan@debian.debian>2009-04-23 19:17:56 +0200
committerDusan Durech <dusan@debian.debian>2009-04-23 19:22:10 +0200
commit9866f48c8716996cd67ccb008471f73f8fc1baa6 (patch)
tree5e4a11273ab1c82b06090d97c94a6a18e8fcfe3f /src
parent112e8071a8d96f9251ef265e31bd11a4662a893d (diff)
support statusbar (need write label)| fix kiks with keycontrol.conf| fix memory leak in font.c
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/client/font.c2
-rw-r--r--src/screen/setting.c24
-rw-r--r--src/screen/settingKeys.c6
-rw-r--r--src/widget/widget.h1
-rw-r--r--src/widget/widget_statusbar.c153
-rw-r--r--src/widget/widget_statusbar.h25
7 files changed, 211 insertions, 3 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fed8130..be72ad3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -67,7 +67,8 @@ 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
+ ${WORKDIR}/widget/widget_choicegroup ${WORKDIR}/widget/widget_statusbar
+ ${WORKDIR}/widget/widget
)
SET ( SRC_audio
diff --git a/src/client/font.c b/src/client/font.c
index 731e86d..b64785e 100644
--- a/src/client/font.c
+++ b/src/client/font.c
@@ -52,6 +52,7 @@ void font_init()
fontconfig_quit();
if (TTF_Init() == -1) {
+ free(font_file);
fprintf(stderr, "%s\n", SDL_GetError());
return;
}
@@ -63,6 +64,7 @@ void font_init()
DEBUG_MSG(_("Loading font: \"%s\"\n"), font_file);
+ free(font_file);
isFontInit = TRUE;
}
diff --git a/src/screen/setting.c b/src/screen/setting.c
index 8403056..34e067a 100644
--- a/src/screen/setting.c
+++ b/src/screen/setting.c
@@ -35,6 +35,7 @@
#include "widget_textfield.h"
#include "widget_check.h"
#include "widget_select.h"
+#include "widget_statusbar.h"
static widget_t *image_backgorund;
@@ -77,6 +78,8 @@ static widget_t *textfield_name_player2;
static widget_t *check_ai;
+static widget_t *statusbar;
+
static textFile_t *configFile;
static void hotkey_escape()
@@ -145,6 +148,8 @@ void setting_draw()
check_draw(check_ai);
+ statusbar_draw(statusbar);
+
button_draw(button_back);
button_draw(button_keys);
}
@@ -175,6 +180,8 @@ void setting_event()
check_event(check_ai);
+ statusbar_event(statusbar);
+
button_event(button_back);
button_event(button_keys);
}
@@ -423,6 +430,21 @@ void setting_init()
image_bonus_4x = wid_image_new(580 + WIDGET_CHECK_WIDTH, 250, image_get(IMAGE_GROUP_BASE, "panel_4x"));;
image_bonus_hidden = wid_image_new(580 + WIDGET_CHECK_WIDTH, 300, image_get(IMAGE_GROUP_BASE, "panel_hidden"));;
+ statusbar = statusbar_new(400, 350);
+ statusbar_add(statusbar, check[GUN_DUAL_SIMPLE], "abc\n123\nkoniec");
+ statusbar_add(statusbar, check[GUN_SCATTER], "check 1");
+ statusbar_add(statusbar, check[GUN_TOMMY], "check 2");
+ statusbar_add(statusbar, check[GUN_LASSER], "check 3");
+ statusbar_add(statusbar, check[GUN_MINE], "check 4");
+ statusbar_add(statusbar, check[GUN_BOMBBALL], "check 5");
+
+ statusbar_add(statusbar, check[BONUS_SPEED], "check 6");
+ statusbar_add(statusbar, check[BONUS_SHOT], "check 7");
+ statusbar_add(statusbar, check[BONUS_TELEPORT], "check 8");
+ statusbar_add(statusbar, check[BONUS_GHOST], "check 9");
+ statusbar_add(statusbar, check[BONUS_4X], "check 10");
+ statusbar_add(statusbar, check[BONUS_HIDDEN], "check 11");
+
screen_register( screen_new("setting", screen_startSetting, setting_event,
setting_draw, stopScreenSetting));
@@ -533,6 +555,8 @@ void setting_quit()
check_destroy(check[i]);
}
+ statusbar_destroy(statusbar);
+
button_destroy(button_back);
button_destroy(button_keys);
}
diff --git a/src/screen/settingKeys.c b/src/screen/settingKeys.c
index 9293e9d..f4338ab 100644
--- a/src/screen/settingKeys.c
+++ b/src/screen/settingKeys.c
@@ -143,8 +143,10 @@ void key_table_init()
keycontrolFile = text_file_new(path);
- fprintf(stderr, _("I was unable to create file: %s\n"), path);
- return;
+ if (keycontrolFile == NULL) {
+ fprintf(stderr, _("I was unable to create file: %s\n"), path);
+ return;
+ }
}
setKeytableFromConfigFile(keycontrolFile);
diff --git a/src/widget/widget.h b/src/widget/widget.h
index ad0f9a6..c21ace4 100644
--- a/src/widget/widget.h
+++ b/src/widget/widget.h
@@ -14,6 +14,7 @@
# define WIDGET_TYPE_CHOICE 6
# define WIDGET_TYPE_IMAGE 7
# define WIDGET_TYPE_SELECT 8
+# define WIDGET_TYPE_STATUSBAR 9
typedef struct widget_struct {
int type;
diff --git a/src/widget/widget_statusbar.c b/src/widget/widget_statusbar.c
new file mode 100644
index 0000000..0c20c7f
--- /dev/null
+++ b/src/widget/widget_statusbar.c
@@ -0,0 +1,153 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "interface.h"
+#include "image.h"
+#include "font.h"
+#include "widget_statusbar.h"
+#include "widget.h"
+
+typedef struct item_struct {
+ widget_t *widget;
+ list_t *text;
+} item_t;
+
+static item_t* item_new(widget_t *widget, char *text)
+{
+ item_t *item;
+ char *copy;
+ char *s;
+
+ assert( widget != NULL );
+ assert( text != NULL );
+
+ item = malloc(sizeof(item_t));
+ item->widget = widget;
+ item->text = list_new();
+
+ copy = strdup(text);
+
+ s = strtok(copy, "\n");
+
+ while( s != NULL )
+ {
+ list_add(item->text, strdup(s));
+ s = strtok(NULL, "\n");
+ }
+
+ free(copy);
+
+ return item;
+}
+
+static void item_destroy(item_t *item)
+{
+ assert( item != NULL );
+
+ list_destroy_item(item->text, free);
+ free(item);
+}
+
+widget_t *statusbar_new(int x, int y)
+{
+ widget_statusbar_t *new;
+
+ new = malloc(sizeof(widget_statusbar_t));
+ new->selectElement = WIDGET_STATUSBAR_NONE_SELECT_ELEMENT;
+ new->listElement = list_new();
+
+ return widget_new(WIDGET_TYPE_STATUSBAR, x, y, WIDGET_STATUSBAR_WIDTH, WIDGET_STATUSBAR_HEIGHT, new);
+}
+
+void statusbar_add(widget_t *widget, widget_t * widget_catch, char *text)
+{
+ widget_statusbar_t *p;
+
+ assert(widget != NULL);
+ assert(widget_catch != NULL);
+ assert(text != NULL);
+ assert(widget->type == WIDGET_TYPE_STATUSBAR);
+
+ p = (widget_statusbar_t *) widget->private_data;
+
+ list_add(p->listElement, item_new(widget_catch, text) );
+}
+
+void statusbar_draw(widget_t * widget)
+{
+ static image_t *g_image = NULL;
+ widget_statusbar_t *p;
+
+ assert(widget != NULL);
+ assert(widget->type == WIDGET_TYPE_STATUSBAR);
+
+ p = (widget_statusbar_t *) widget->private_data;
+
+ if (g_image == NULL) {
+ g_image = image_add("frame.png", IMAGE_ALPHA, "frame", IMAGE_GROUP_BASE);
+ }
+
+ image_draw(g_image, widget->x, widget->y, 0, 0, g_image->w, g_image->h);
+
+ if( p->selectElement != WIDGET_STATUSBAR_NONE_SELECT_ELEMENT )
+ {
+ item_t *item;
+ int i;
+
+ item = (item_t *)p->listElement->list[p->selectElement];
+
+ for( i = 0 ; i < item->text->count ; i++ )
+ {
+ char *s;
+
+ s = (char *) item->text->list[i];
+ font_draw(s, widget->x, widget->y+i*(font_get_size()+5), COLOR_WHITE);
+ }
+ }
+}
+
+void statusbar_event(widget_t * widget)
+{
+ widget_statusbar_t *p;
+ int x, y;
+ int i;
+
+ assert(widget != NULL);
+ assert(widget->type == WIDGET_TYPE_STATUSBAR);
+
+ p = (widget_statusbar_t *) widget->private_data;
+
+ interface_get_mouse_position(&x, &y);
+
+ p->selectElement = WIDGET_STATUSBAR_NONE_SELECT_ELEMENT;
+
+ for( i = 0 ; i < p->listElement->count ; i++ )
+ {
+ item_t *item;
+
+ item = (item_t *)p->listElement->list[i];
+
+ if( x >= item->widget->x && x <= item->widget->x+item->widget->w &&
+ y >= item->widget->y && y <= item->widget->y+item->widget->h )
+ {
+ p->selectElement = i;
+ }
+ }
+}
+
+void statusbar_destroy(widget_t * widget)
+{
+ widget_statusbar_t *p;
+
+ assert(widget != NULL);
+ assert(widget->type == WIDGET_TYPE_STATUSBAR);
+
+ p = (widget_statusbar_t *) widget->private_data;
+
+ list_destroy_item(p->listElement, item_destroy);
+ free(p);
+
+ widget_destroy(widget);
+}
diff --git a/src/widget/widget_statusbar.h b/src/widget/widget_statusbar.h
new file mode 100644
index 0000000..6b81cf3
--- /dev/null
+++ b/src/widget/widget_statusbar.h
@@ -0,0 +1,25 @@
+
+#ifndef WIDGET_STATUSBAR_H
+
+# define WIDGET_STATUSBAR_H
+
+# include "main.h"
+# include "widget.h"
+# include "list.h"
+
+typedef struct widget_statusbar {
+ list_t *listElement;
+ int selectElement;
+} widget_statusbar_t;
+
+# define WIDGET_STATUSBAR_NONE_SELECT_ELEMENT -1
+# define WIDGET_STATUSBAR_WIDTH 250
+# define WIDGET_STATUSBAR_HEIGHT 65
+
+extern widget_t *statusbar_new(int x, int y);
+extern void statusbar_add(widget_t *widget, widget_t * widget_catch, char *text);
+extern void statusbar_draw(widget_t * widget);
+extern void statusbar_event(widget_t * widget);
+extern void statusbar_destroy(widget_t * widget);
+
+#endif