summaryrefslogtreecommitdiff
path: root/src/widget
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-28 16:38:35 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-28 16:38:35 +0000
commit2d776fcd61be168e1ff0ff2e4a5e71835e7cea19 (patch)
tree7cf274897bf540d5332d446f583ffd066e4e2e1d /src/widget
parentb877ae23ac5d380ab3aa48d7724045cf4883b186 (diff)
- prekopanie adresarovej struktury, prva cast
git-svn-id: http://opensvn.csie.org/tuxanci_ng@77 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/widget')
-rw-r--r--src/widget/Makefile28
-rw-r--r--src/widget/widget_button.c84
-rw-r--r--src/widget/widget_button.h27
-rw-r--r--src/widget/widget_buttonimage.c55
-rw-r--r--src/widget/widget_buttonimage.h27
-rw-r--r--src/widget/widget_check.c84
-rw-r--r--src/widget/widget_check.h27
-rw-r--r--src/widget/widget_image.c35
-rw-r--r--src/widget/widget_image.h21
-rw-r--r--src/widget/widget_label.c47
-rw-r--r--src/widget/widget_label.h26
-rw-r--r--src/widget/widget_select.c97
-rw-r--r--src/widget/widget_select.h26
-rw-r--r--src/widget/widget_textfield.c194
-rw-r--r--src/widget/widget_textfield.h33
15 files changed, 811 insertions, 0 deletions
diff --git a/src/widget/Makefile b/src/widget/Makefile
new file mode 100644
index 0000000..cdb504b
--- /dev/null
+++ b/src/widget/Makefile
@@ -0,0 +1,28 @@
+
+all: widget_button.o widget_buttonimage.o widget_check.o widget_label.o widget_select.o widget_textfield.o widget_image.o
+
+widget_button.o: widget_button.c widget_button.h
+ $(CC) $(CFLAGS) -o widget_button.o -c widget_button.c
+
+widget_buttonimage.o: widget_buttonimage.c widget_buttonimage.h
+ $(CC) $(CFLAGS) -o widget_buttonimage.o -c widget_buttonimage.c
+
+widget_check.o: widget_check.c widget_check.h
+ $(CC) $(CFLAGS) -o widget_check.o -c widget_check.c
+
+widget_image.o: widget_image.c widget_image.h
+ $(CC) $(CFLAGS) -o widget_image.o -c widget_image.c
+
+widget_label.o: widget_label.c widget_label.h
+ $(CC) $(CFLAGS) -o widget_label.o -c widget_label.c
+
+widget_select.o: widget_select.c widget_select.h
+ $(CC) $(CFLAGS) -o widget_select.o -c widget_select.c
+
+widget_textfield.o: widget_textfield.c widget_textfield.h
+ $(CC) $(CFLAGS) -o widget_textfield.o -c widget_textfield.c
+
+clean:
+ rm -rf *.o
+
+
diff --git a/src/widget/widget_button.c b/src/widget/widget_button.c
new file mode 100644
index 0000000..7f0957b
--- /dev/null
+++ b/src/widget/widget_button.c
@@ -0,0 +1,84 @@
+
+#include <stdlib.h>
+
+#include "base/main.h"
+
+#include "client/interface.h"
+#include "client/image.h"
+#include "client/font.h"
+
+#include "widget_button.h"
+
+widget_button_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);
+
+ return new;
+}
+
+void drawWidgetButton(widget_button_t *p)
+{
+ static SDL_Surface *g_button0 = NULL;
+ static SDL_Surface *g_button1 = NULL;
+ int x, y;
+
+ getMousePosition(&x, &y);
+
+ if( g_button0 == NULL )
+ {
+ g_button0 = addImageData("button0.png", IMAGE_ALPHA, "button0", IMAGE_GROUP_BASE);
+ }
+
+ if( g_button1 == NULL )
+ {
+ 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 )
+ {
+ drawImage(g_button1, p->x, p->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);
+ }
+
+ //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);
+}
+
+void eventWidgetButton(widget_button_t *p)
+{
+ static int time = 0;
+ int x, y;
+
+ if( time > 0)
+ {
+ time--;
+ return;
+ }
+
+ getMousePosition(&x, &y);
+
+ if( x >= p->x && x <= p->x+WIDGET_BUTTON_WIDTH &&
+ y >= p->y && y <= p->y+WIDGET_BUTTON_HEIGHT &&
+ isMouseClicked() )
+ {
+ time = WIDGET_BUTTON_TIME;
+ p->fce_event(p);
+ }
+}
+
+void destroyWidgetButton(widget_button_t *p)
+{
+ free(p->text);
+ free(p);
+}
diff --git a/src/widget/widget_button.h b/src/widget/widget_button.h
new file mode 100644
index 0000000..1662407
--- /dev/null
+++ b/src/widget/widget_button.h
@@ -0,0 +1,27 @@
+
+#ifndef WIDGET_BUTTON_H
+
+#define WIDGET_BUTTON_H
+
+#include "base/main.h"
+
+#define WIDGET_BUTTON_TIME 10
+
+#define WIDGET_BUTTON_WIDTH 125
+#define WIDGET_BUTTON_HEIGHT 36
+
+typedef struct widget_button
+{
+ int x, y;
+ int w, h;
+ char *text;
+ 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);
+
+#endif
+
diff --git a/src/widget/widget_buttonimage.c b/src/widget/widget_buttonimage.c
new file mode 100644
index 0000000..7c59f3b
--- /dev/null
+++ b/src/widget/widget_buttonimage.c
@@ -0,0 +1,55 @@
+
+#include <stdlib.h>
+#include "base/main.h"
+#include "client/interface.h"
+#include "client/font.h"
+#include "client/image.h"
+#include "widget_buttonimage.h"
+
+widget_buttonimage_t* newWidgetButtonimage(SDL_Surface *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;
+}
+
+void drawWidgetButtonimage(widget_buttonimage_t *p)
+{
+ drawImage(p->image, p->x, p->y, p->active*p->w, 0, p->w, p->h);
+}
+
+void eventWidgetButtonimage(widget_buttonimage_t *p)
+{
+ static int time = 0;
+ int x, y;
+
+ if( time > 0)
+ {
+ time--;
+ return;
+ }
+
+ getMousePosition(&x, &y);
+
+ if( x >= p->x && x <= p->x+p->w &&
+ y >= p->y && y <= p->y+p->h &&
+ isMouseClicked() )
+ {
+ time = WIDGET_BUTTONIMAGE_TIME;
+ p->fce_event(p);
+ }
+}
+
+void destroyWidgetButtonimage(widget_buttonimage_t *p)
+{
+ free(p);
+}
diff --git a/src/widget/widget_buttonimage.h b/src/widget/widget_buttonimage.h
new file mode 100644
index 0000000..d30e5bf
--- /dev/null
+++ b/src/widget/widget_buttonimage.h
@@ -0,0 +1,27 @@
+
+#ifndef WIDGET_BUTTONIMAGE_H
+
+#include "base/main.h"
+
+#define WIDGET_BUTTONIMAGE_H
+
+#define WIDGET_BUTTONIMAGE_TIME 10
+
+typedef struct widget_buttonimageimage
+{
+ int x, y;
+ int w, h;
+ int active;
+ SDL_Surface *image;
+ void (*fce_event)(void *);
+} widget_buttonimage_t;
+
+extern widget_buttonimage_t* newWidgetButtonimage(SDL_Surface *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);
+
+#endif
+
diff --git a/src/widget/widget_check.c b/src/widget/widget_check.c
new file mode 100644
index 0000000..feb2414
--- /dev/null
+++ b/src/widget/widget_check.c
@@ -0,0 +1,84 @@
+
+#include <stdlib.h>
+#include "base/main.h"
+#include "client/interface.h"
+#include "client/image.h"
+#include "widget_check.h"
+
+widget_check_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;
+}
+
+void drawWidgetCheck(widget_check_t *p)
+{
+ static SDL_Surface *g_check = NULL;
+ int x, y;
+ int offset;
+
+ getMousePosition(&x, &y);
+
+ if( g_check == NULL )
+ {
+ g_check = addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE);
+ }
+
+ if( p->status == TRUE )
+ {
+ offset = 0;
+ }
+ else
+ {
+ offset = WIDGET_CHECK_WIDTH;
+ }
+
+ drawImage(g_check, p->x, p->y, offset, 0, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT);
+}
+
+void eventWidgetCheck(widget_check_t *p)
+{
+ int x, y;
+
+ if( p->time > 0 )
+ {
+ p->time--;
+ return;
+ }
+
+ getMousePosition(&x, &y);
+
+ if( x >= p->x && x <= p->x+WIDGET_CHECK_WIDTH &&
+ y >= p->y && y <= p->y+WIDGET_CHECK_HEIGHT &&
+ isMouseClicked() )
+ {
+ if( p->status == TRUE )
+ {
+ p->status = FALSE;
+ p->time = WIDGET_CHECK_TIME_SWITCH_STATUS;
+ }
+ else
+ {
+ p->status = TRUE;
+ p->time = WIDGET_CHECK_TIME_SWITCH_STATUS;
+ }
+
+ if( p->fce_event != NULL )
+ {
+ p->fce_event(p);
+ }
+ }
+}
+
+void destroyWidgetCheck(widget_check_t *p)
+{
+ free(p);
+}
diff --git a/src/widget/widget_check.h b/src/widget/widget_check.h
new file mode 100644
index 0000000..68aecd9
--- /dev/null
+++ b/src/widget/widget_check.h
@@ -0,0 +1,27 @@
+
+#ifndef WIDGET_CHECK_H
+
+#define WIDGET_CHECK_H
+
+#include "base/main.h"
+
+#define WIDGET_CHECK_TIME_SWITCH_STATUS 5
+
+#define WIDGET_CHECK_WIDTH 25
+#define WIDGET_CHECK_HEIGHT 25
+
+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);
+
+#endif
+
diff --git a/src/widget/widget_image.c b/src/widget/widget_image.c
new file mode 100644
index 0000000..5e1b743
--- /dev/null
+++ b/src/widget/widget_image.c
@@ -0,0 +1,35 @@
+
+#include <stdlib.h>
+
+#include <stdlib.h>
+#include "base/main.h"
+#include "client/image.h"
+#include "client/interface.h"
+#include "client/font.h"
+#include "widget_image.h"
+
+widget_image_t* newWidgetImage(int x, int y, SDL_Surface *image)
+{
+ widget_image_t *new;
+
+ new = malloc( sizeof(widget_image_t) );
+ new->x = x;
+ new->y = y;
+ new->image = image;
+
+ return new;
+}
+
+void drawWidgetImage(widget_image_t *p)
+{
+ drawImage(p->image, p->x, p->y, 0, 0, p->image->w, p->image->h);
+}
+
+void eventWidgetImage(widget_image_t *p)
+{
+}
+
+void destroyWidgetImage(widget_image_t *p)
+{
+ free(p);
+}
diff --git a/src/widget/widget_image.h b/src/widget/widget_image.h
new file mode 100644
index 0000000..85c98d7
--- /dev/null
+++ b/src/widget/widget_image.h
@@ -0,0 +1,21 @@
+
+#ifndef WIDGET_IMAGE_H
+
+#define WIDGET_IMAGE_H
+
+#include "base/main.h"
+#include "client/interface.h"
+
+typedef struct widget_image
+{
+ int x, y;
+ SDL_Surface *image;
+} widget_image_t;
+
+extern widget_image_t* newWidgetImage(int x, int y, SDL_Surface *image);
+extern void drawWidgetImage(widget_image_t *p);
+extern void eventWidgetImage(widget_image_t *p);
+extern void destroyWidgetImage(widget_image_t *p);
+
+#endif
+
diff --git a/src/widget/widget_label.c b/src/widget/widget_label.c
new file mode 100644
index 0000000..a472784
--- /dev/null
+++ b/src/widget/widget_label.c
@@ -0,0 +1,47 @@
+
+#include <stdlib.h>
+
+#include "base/main.h"
+#include "client/interface.h"
+#include "client/font.h"
+#include "widget_label.h"
+
+widget_label_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);
+
+ return new;
+}
+
+void drawWidgetLabel(widget_label_t *p)
+{
+ switch( p->bind )
+ {
+ case WIDGET_LABEL_RIGHT :
+ drawFont(p->text, p->x+p->w, p->y + p->h/2, COLOR_WHITE);
+ break;
+ case WIDGET_LABEL_LEFT :
+ drawFont(p->text, p->x, p->y + p->h/2, COLOR_WHITE);
+ break;
+ case WIDGET_LABEL_CENTER :
+ drawFont(p->text, p->x-p->w/2, p->y + p->h/2, COLOR_WHITE);
+ break;
+ }
+}
+
+void eventWidgetLabel(widget_label_t *p)
+{
+}
+
+void destroyWidgetLabel(widget_label_t *p)
+{
+ free(p->text);
+ free(p);
+}
diff --git a/src/widget/widget_label.h b/src/widget/widget_label.h
new file mode 100644
index 0000000..a3bb060
--- /dev/null
+++ b/src/widget/widget_label.h
@@ -0,0 +1,26 @@
+
+#ifndef WIDGET_LABEL_H
+
+#define WIDGET_LABEL_H
+
+#include "base/main.h"
+
+typedef struct widget_label
+{
+ int x, y;
+ int w, h;
+ char *text;
+ int bind;
+} widget_label_t;
+
+#define WIDGET_LABEL_RIGHT 1
+#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);
+
+#endif
+
diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c
new file mode 100644
index 0000000..f51239c
--- /dev/null
+++ b/src/widget/widget_select.c
@@ -0,0 +1,97 @@
+
+#include <stdlib.h>
+#include "base/main.h"
+#include "client/interface.h"
+#include "client/font.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_select_t *new;
+
+ new = malloc( sizeof(widget_select_t) );
+ new->x = x;
+ new->y = y;
+ new->select = 0;
+ new->fce_event = fce_event;
+ new->list = newList();
+
+ return new;
+}
+
+void addToWidgetSelect(widget_select_t *p, char *s)
+{
+ addList(p->list, strdup(s) );
+}
+
+void drawWidgetSelect(widget_select_t *p)
+{
+ int x, y, w, h;
+ int i;
+
+ getMousePosition(&x, &y);
+
+ for( i = 0 ; i < p->list->count ; i++ )
+ {
+ char *line;
+
+ line = (char *)p->list->list[i];
+
+ getTextSize(line, &w, &h);
+
+ if( x > p->x && y > p->y + i*20 && x < p->x+w && y < p->y + i*20 + h )
+ {
+ drawFont(line, p->x, p->y + i*20, COLOR_YELLOW);
+ }
+ else
+ {
+ if( p->select == i )
+ {
+ drawFont(line, p->x, p->y + i*20, COLOR_RED);
+ }
+ else
+ {
+ drawFont(line, p->x, p->y + i*20, COLOR_WHITE);
+ }
+ }
+ }
+}
+
+void eventWidgetSelect(widget_select_t *p)
+{
+ int x, y, w, h;
+ int i;
+
+ getMousePosition(&x, &y);
+
+ for( i = 0 ; i < p->list->count ; i++ )
+ {
+ char *line;
+
+ line = (char *)p->list->list[i];
+
+ getTextSize(line, &w, &h);
+
+ if( x > p->x && y > p->y + i*20 && x < p->x+w && y < p->y + i*20 + h && isMouseClicked() )
+ {
+ p->select = i;
+ p->fce_event(p);
+ }
+ }
+}
+
+void destroyWidgetSelect(widget_select_t *p)
+{
+ destroyListItem(p->list, free);
+ free(p);
+}
diff --git a/src/widget/widget_select.h b/src/widget/widget_select.h
new file mode 100644
index 0000000..2765f11
--- /dev/null
+++ b/src/widget/widget_select.h
@@ -0,0 +1,26 @@
+
+#ifndef WIDGET_SELECT_H
+
+#define WIDGET_SELECT_H
+
+#include "base/main.h"
+#include "base/list.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 void addToWidgetSelect(widget_select_t *p, char *s);
+extern void drawWidgetSelect(widget_select_t *p);
+extern void eventWidgetSelect(widget_select_t *p);
+extern void destroyWidgetSelect(widget_select_t *p);
+
+#endif
+
diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c
new file mode 100644
index 0000000..f9186c9
--- /dev/null
+++ b/src/widget/widget_textfield.c
@@ -0,0 +1,194 @@
+
+#include <stdlib.h>
+#include "base/main.h"
+#include "client/interface.h"
+#include "client/font.h"
+#include "client/image.h"
+#include "widget_textfield.h"
+
+widget_textfield_t* newWidgetTextfield(char *text, int x, int y)
+{
+ widget_textfield_t *new;
+
+ new = malloc( sizeof(widget_textfield_t) );
+ strcpy(new->text, text);
+ new->x = x;
+ new->y = y;
+ new->time = 0;
+ new->timeBlick = 0;
+ new->active = FALSE;
+ getTextSize(text, &new->w, &new->h);
+
+ return new;
+}
+
+static void drawBackground(widget_textfield_t *p)
+{
+ static SDL_Surface *g_textfield0 = NULL;
+ static SDL_Surface *g_textfield1 = NULL;
+ int x, y;
+
+ getMousePosition(&x, &y);
+
+ if( g_textfield0 == NULL )
+ {
+ g_textfield0 = addImageData("button0.png", IMAGE_ALPHA, "textfiled0", IMAGE_GROUP_BASE);
+ }
+
+ if( g_textfield1 == NULL )
+ {
+ g_textfield1 = addImageData("button1.png", IMAGE_ALPHA, "textfiled1", IMAGE_GROUP_BASE);
+ }
+
+ if( p->active )
+ {
+ drawImage(g_textfield1, p->x, p->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);
+ }
+}
+
+static void drawText(widget_textfield_t *p)
+{
+ char str[STR_SIZE];
+
+ strcpy(str, p->text);
+
+ if( p->timeBlick > WIDGET_TEXTFIELD_TIME_BLICK_CURSOR/2 &&
+ p->active == TRUE )
+ {
+ //strcat(str, ">");
+ strcat(str, "\f");
+ }
+
+ p->timeBlick++;
+
+ if( p->timeBlick == WIDGET_TEXTFIELD_TIME_BLICK_CURSOR )
+ {
+ p->timeBlick = 0;
+ }
+
+ //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);
+}
+
+void drawWidgetTextfield(widget_textfield_t *p)
+{
+ drawBackground(p);
+ drawText(p);
+}
+
+static void readKey(widget_textfield_t *p)
+{
+ Uint8 *mapa;
+ int len;
+ int i;
+
+ if( p->time > 0 )
+ {
+ p->time--;
+ return;
+ }
+
+ if( p->active == FALSE )
+ {
+ return;
+ }
+
+ mapa = SDL_GetKeyState(NULL);
+ len = strlen(p->text);
+
+ // mazanie posledneho klavesu
+ if( mapa[SDLK_BACKSPACE] == SDL_PRESSED )
+ {
+ if( len > 0 )
+ {
+ p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
+ p->text[len-1]='\0';
+ getTextSize(p->text, &p->w, &p->h);
+ }
+
+ return;
+ }
+
+ if( p->w > WIDGET_TEXTFIELD_WIDTH-40 )
+ {
+ return;
+ }
+
+ // klavesy abecedy
+ for(i=SDLK_SPACE /*SDLK_a*/;i<=SDLK_z;i++)
+ {
+ //if(width<TEXTFIELD_SIZE_X-20 && mapa[i]==SDL_PRESSED)
+ if( mapa[i] == SDL_PRESSED && len < STR_SIZE )
+ {
+ p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
+
+ strcat( p->text, SDL_GetKeyName(i) );
+ getTextSize(p->text, &p->w, &p->h);
+
+ if( mapa[SDLK_LSHIFT] == SDL_PRESSED ||
+ mapa[SDLK_RSHIFT] == SDL_PRESSED)
+ {
+ p->text[ strlen( p->text ) - 1 ] -= 32;
+ getTextSize(p->text, &p->w, &p->h);
+ return;
+ }
+ }
+ }
+
+ // aby ve jmene bulanka fungovaly take cislice alfanumericke klavesnice
+ for( i = SDLK_0 ; i <= SDLK_9 ; i++ )
+ {
+ if( mapa[i] == SDL_PRESSED && len < STR_SIZE )
+ {
+ p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
+ strcat( p->text, SDL_GetKeyName(i) );
+ getTextSize(p->text, &p->w, &p->h);
+ return;
+ }
+ }
+
+ // aby ve jmene bulanka fungovaly take cislice napsane na numericke klavesnici
+ for( i=SDLK_KP0 ; i<=SDLK_KP9 ; i++ )
+ {
+ if( mapa[i] == SDL_PRESSED && len < STR_SIZE )
+ {
+ p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
+ strncat( p->text, SDL_GetKeyName(i)+1, 1 ); // napr. "[4]"
+ getTextSize(p->text, &p->w, &p->h);
+ return;
+ }
+ }
+}
+
+void eventWidgetTextfield(widget_textfield_t *p)
+{
+ int x, y;
+
+ getMousePosition(&x, &y);
+
+ if( isMouseClicked() )
+ {
+ if( x >= p->x && x <= p->x+WIDGET_TEXTFIELD_WIDTH &&
+ y >= p->y && y <= p->y+WIDGET_TEXTFIELD_HEIGHT )
+ {
+ p->active = TRUE;
+ }
+ else
+ {
+ p->active = FALSE;
+ }
+ }
+
+ readKey(p);
+}
+
+void destroyWidgetTextfield(widget_textfield_t *p)
+{
+ free(p);
+}
+
diff --git a/src/widget/widget_textfield.h b/src/widget/widget_textfield.h
new file mode 100644
index 0000000..368f329
--- /dev/null
+++ b/src/widget/widget_textfield.h
@@ -0,0 +1,33 @@
+
+#ifndef WIDGET_TEXTFIELD_H
+
+#define WIDGET_TEXTFIELD_H
+
+#include "base/main.h"
+
+#define WIDGET_TEXTFIELD_WIDTH 188
+#define WIDGET_TEXTFIELD_HEIGHT 36
+
+#define WIDGET_TEXTFIELD_TEXT_OFFSET_X 10
+
+#define WIDGET_TEXTFIELD_TIME_READ_KEY 2
+#define WIDGET_TEXTFIELD_TIME_BLICK_CURSOR 20
+
+typedef struct widget_textfield
+{
+ int x, y;
+ int w, h;
+ int canWrite;
+ int timeBlick;
+ int time;
+ char text[STR_SIZE];
+ bool_t active;
+} widget_textfield_t;
+
+extern widget_textfield_t* newWidgetTextfield(char *text, int x, int y);
+extern void drawWidgetTextfield(widget_textfield_t *p);
+extern void eventWidgetTextfield(widget_textfield_t *p);
+extern void destroyWidgetTextfield(widget_textfield_t *p);
+
+#endif
+