Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gui pattern editor in place

  • Loading branch information...
commit 84577f2de4fe7527319d509e2f30a80cf1cd5d5c 1 parent ed9ade3
@stg authored
View
BIN  bin-win/gui.exe
Binary file not shown
View
2  gui/loader.c
@@ -44,7 +44,7 @@ void image_convert(uint8_t *p_data) {
for(y=0;y<h;y++) {
for(x=0;x<w;x++) {
FreeImage_GetPixelColor(dib,x,y,&quad);
- p_data[y*w+x]=(quad.rgbRed+quad.rgbGreen+quad.rgbBlue)/3;
+ p_data[y*w+x]=((uint16_t)quad.rgbRed+(uint16_t)quad.rgbGreen+(uint16_t)quad.rgbBlue)/3;
}
}
}
View
17 gui/main.c
@@ -56,6 +56,7 @@ enum {
};
enum {
+ EDIT_GRID,
EDIT_OK,
EDIT_COUNT
};
@@ -193,8 +194,9 @@ static bool top_event(SDL_Event *event) {
view=VIEW_ADD;
return true;
} else if(p_ui==top[TOP_EDIT]) {
- ui_field_add(msg[MSG_TEXT],"THIS FEATURE IS UNDER\nDEVELOPMENT BUT WILL ALLOW\nPATTERN EDITING WHEN DONE.");
- view=VIEW_MSG;
+ p_item=ui_list_selected(top[TOP_LIST]);
+ ui_grid_set(edit[EDIT_GRID],&((uint8_t*)p_item->data)[4],((uint16_t*)p_item->data)[0],((uint16_t*)p_item->data)[1]);
+ view=VIEW_EDIT;
return true;
} else if(p_ui==top[TOP_DEL]) {
ui_list_remove(top[TOP_LIST],ui_list_selected(top[TOP_LIST]));
@@ -221,11 +223,6 @@ static bool top_event(SDL_Event *event) {
case 1:
quit = 1; // Set time to quit
return true;
- /*default: // keylogger
- char text[10];
- sprintf(text,"%i %i",((list_t*)top[TOP_LIST]->obj)->count,event->key.keysym.scancode);
- ui_list_add(top[TOP_LIST],text,0);
- */
}
break;
}
@@ -532,7 +529,7 @@ int main( int argc, char *argv[] ) {
// build edit pattern view
vedit=ui_fsview();
- //edit[EDIT_GRID]=ui_add(vedit,ui_grid(1,1,38,23));
+ edit[EDIT_GRID]=ui_add(vedit,ui_grid(1,1,38,23));
edit[EDIT_OK]=ui_add(vedit,ui_button(18,26,"OK"));
// build start emulator view
@@ -564,10 +561,6 @@ int main( int argc, char *argv[] ) {
free(p_text);
strcpy(p_item->data,p_mach->name);
}
- // TODO: remove
- // p_mach=machine_get(0);
- // ui_enable(top[TOP_ADD],true);
- // ENDTODO
// initial info text
ui_field_add(top[TOP_INFO],"CLICK FORMAT\nTO SELECT AND\nBEGIN WORKING\nWITH A SPECIFIC\nKNITTING MACHINE");
View
61 gui/renderer.c
@@ -14,22 +14,22 @@ typedef struct {
uint8_t nchar;
uint8_t cfont;
uint8_t nfont;
- int8_t ofsx;
- int8_t ofsy;
+ int8_t ofs;
+ int8_t bgc;
int16_t tick;
} termchar_t;
static termchar_t *term;
uint8_t r_w, r_h;
static SDL_Surface *font;
-static const char font_chars[] = "#!\"% '()|+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZú®¯³ÄÙÀÚ¿´ÃºÍ¼ÈÉ»awdsgyhbnvtumcri";
+static const char font_chars[] = "#!\"%ñ'()|+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZú®¯³ÄÙÀÚ¿´ÃºÍ¼ÈÉ»awdsgyhbnvtumcri";
static uint8_t write_index = 0;
#ifdef SDL2
static SDL_Renderer *renderer;
#endif
static SDL_Surface *screen;
static SDL_Surface *bg;
-static char cx = -1, cy, ct;
+static char cx = -1, cy, ct, cs;
#ifdef SDL2
static SDL_PixelFormat fmt_rgb = {
@@ -52,10 +52,11 @@ static SDL_PixelFormat fmt_rgb = {
#define ABS( v ) ( v < 0 ? -v : v )
#define TERM( x, y ) term[ (y) * r_w + (x) ]
-void r_cins( unsigned char x, unsigned char y ) {
+void r_cins( unsigned char x, unsigned char y, unsigned char style ) {
cx = x;
cy = y;
ct = 0;
+ cs = style;
}
void r_crem() {
@@ -225,20 +226,35 @@ void r_draw() {
}
if( TERM( x, y ).cchar ) {
- dstrect.x = ( x << 4 ) + TERM( x, y ).ofsx;
- dstrect.y = ( y << 4 ) + TERM( x, y ).ofsy;
+ dstrect.x = ( x << 4 ) + TERM( x, y ).ofs;
+ dstrect.y = ( y << 4 ) + TERM( x, y ).ofs;
srcrect.x = TERM( x, y ).cchar << 4;
srcrect.y = ( TERM( x, y ).tick >= 0 ? TERM( x, y ).tick << 4 : 240 ) + TERM( x, y ).cfont * 256;
+ if( TERM( x, y ).bgc ) {
+ SDL_FillRect( screen, &dstrect, 0 );
+ }
SDL_BlitSurface( font, &srcrect, screen, &dstrect );
}
}
}
if( cx >= 0 ) {
- srcrect.x = 0;
- srcrect.y = ( ct > 15 ? 240 : ct << 4 );
- dstrect.x = cx << 4;
- dstrect.y = cy << 4;
- SDL_BlitSurface( font, &srcrect, screen, &dstrect );
+ if( cs == 0 ) {
+ srcrect.x = 0;
+ srcrect.y = ( ct > 15 ? 240 : ct << 4 );
+ dstrect.x = cx << 4;
+ dstrect.y = cy << 4;
+ SDL_BlitSurface( font, &srcrect, screen, &dstrect );
+ } else {
+ for( x = 0; x < 2; x++ ) {
+ for( y = 0; y < 2; y++ ) {
+ srcrect.x = TERM( x + cx, y + cy ).cchar << 4;;
+ srcrect.y = ( ( ( ct - ( ( x + y ) << 1 ) ) & 31 ) > 15 ? 240 : ( ( ct - ( ( x + y ) << 1 ) ) & 31 ) << 4 );
+ dstrect.x = ( x + cx ) << 4;
+ dstrect.y = ( y + cy ) << 4;
+ SDL_BlitSurface( font, &srcrect, screen, &dstrect );
+ }
+ }
+ }
if( ++ct == 32 ) ct = 0;
}
#ifdef SDL2
@@ -295,12 +311,26 @@ void r_button( unsigned char x, unsigned char y, char*caption, unsigned char fb,
free(buf);
}
+void r_char( unsigned char x, unsigned char y, char c, unsigned char f, unsigned char b ) {
+ unsigned char j;
+ for( j = 0; j < sizeof( font_chars ) - 1; j++ ) {
+ if( font_chars[ j ] == c || c == ' ' ) {
+ if( TERM( x, y ).nchar != j || TERM( x, y ).nfont != f ) {
+ TERM( x, y ).nchar = j;
+ TERM( x, y ).nfont = f;
+ TERM( x, y ).bgc = b;
+ TERM( x, y ).tick = -( x + y );
+ }
+ }
+ }
+}
+
void r_write( unsigned char x, unsigned char y, char *s, unsigned char f ) {
unsigned char i, j, t = 0;
int len = strlen( s );
for( i = 0; i < len; i++ ) {
for( j = 0; j < sizeof( font_chars ) - 1; j++ ) {
- if( font_chars[ j ] == s[ i ] ) {
+ if( font_chars[ j ] == s[ i ] || s[ i ] == ' ' ) {
if( TERM( x, y ).nchar != j || TERM( x, y ).nfont != f ) {
TERM( x, y ).nchar = j;
TERM( x, y ).nfont = f;
@@ -354,12 +384,11 @@ void r_shine( unsigned char _x, unsigned char _y, unsigned char w, unsigned char
}
}
-void r_offset( unsigned char _x, unsigned char _y, unsigned char w, unsigned char h, char ox, char oy ) {
+void r_offset( unsigned char _x, unsigned char _y, unsigned char w, unsigned char h, char o ) {
unsigned char x, y;
for(y=0;y<h;y++) {
for(x=0;x<w;x++) {
- TERM(x+_x,y+_y).ofsx=ox;
- TERM(x+_x,y+_y).ofsy=oy;
+ TERM(x+_x,y+_y).ofs=o;
}
}
}
View
5 gui/renderer.h
@@ -5,15 +5,16 @@ void r_init( SDL_Surface *scr );
#endif
void r_clear();
void r_draw();
+void r_char( unsigned char x, unsigned char y, char c, unsigned char f, unsigned char b );
void r_write( unsigned char x, unsigned char y, char *s, unsigned char f );
void r_white( unsigned char x, unsigned char y, unsigned char w, unsigned char h );
-void r_cins( unsigned char x, unsigned char y );
+void r_cins( unsigned char x, unsigned char y, unsigned char style );
void r_crem();
void r_box( unsigned char x, unsigned char y, unsigned char w, unsigned char h, char*caption, unsigned char fb, unsigned char fc);
void r_button( unsigned char x, unsigned char y, char*caption, unsigned char fb, unsigned char fc);
void r_flash( unsigned char x, unsigned char y, unsigned char w, unsigned char h );
void r_shine( unsigned char x, unsigned char y, unsigned char w, unsigned char h );
void r_done( unsigned char x, unsigned char y, unsigned char w, unsigned char h );
-void r_offset( unsigned char _x, unsigned char _y, unsigned char w, unsigned char h, char ox, char oy );
+void r_offset( unsigned char _x, unsigned char _y, unsigned char w, unsigned char h, char o );
int r_knows( char c );
void r_free();
View
383 gui/ui.c
@@ -2,14 +2,18 @@
#include <stdbool.h>
#ifdef SDL2
#include <SDL2/SDL.h>
+#include <SDL2/SDL_keycode.h>
#else
#include <SDL/SDL.h>
+#define SDL_Keycode SDLKey
#endif
#include "renderer.h"
#include "ui.h"
/** GENERICS ********************************************************/
+static bool was_fullscreen=true;
+
SDL_mutex *mx_ui;
void ui_init() {
@@ -71,6 +75,329 @@ view_t* ui_view(uint8_t w,uint8_t h,char *caption) {
return p_obj;
}
+/** GRID EDITOR *****************************************************/
+
+uiobj_t* ui_grid(uint8_t x,uint8_t y,uint8_t w,uint8_t h) {
+ uiobj_t *p_ui=malloc(sizeof(uiobj_t));
+ grid_t *p_obj=malloc(sizeof(grid_t));
+ p_ui->x=x;
+ p_ui->y=y;
+ p_ui->w=w;
+ p_ui->h=h;
+ p_obj->l=0;
+ p_obj->t=0;
+ p_obj->x=0;
+ p_obj->y=0;
+ p_obj->data=NULL;
+ p_ui->type=UI_GRID;
+ p_ui->obj=p_obj;
+ return p_ui;
+}
+
+void ui_grid_set(uiobj_t *p_ui,void *p_data,uint16_t w,uint16_t h) {
+ grid_t *p_grid=p_ui->obj;
+ p_grid->data=p_data;
+ p_grid->l=0;
+ p_grid->t=0;
+ p_grid->x=0;
+ p_grid->y=0;
+ p_grid->w=w;
+ p_grid->h=h;
+ p_ui->state=1;
+}
+
+static bool grid_cset(uiobj_t *p_ui,int16_t x,int16_t y,char c,uint8_t bg) {
+ grid_t *p_grid=p_ui->obj;
+ view_t *p_view=p_ui->view;
+ uint8_t ax,ay;
+ if((x<0)||(x-(int16_t)p_grid->l>=0)) {
+ if((y<0)||(y-(int16_t)p_grid->t>=0)) {
+ if((x<0)||((x-(int16_t)p_grid->l)<p_ui->w)) {
+ if((y<0)||((y-(int16_t)p_grid->t)<p_ui->h)) {
+ if(x==-1) {
+ ax=p_ui->x+p_view->x-1;
+ } else if(x==-2) {
+ ax=p_ui->x+p_view->x+p_ui->w;
+ } else {
+ ax=x+p_ui->x+p_view->x-p_grid->l;
+ }
+ if(y==-1) {
+ ay=p_ui->y+p_view->y-1;
+ } else if(y==-2) {
+ ay=p_ui->y+p_view->y+p_ui->h;
+ } else {
+ ay=y+p_ui->y+p_view->y-p_grid->t;
+ }
+ r_char(ax,ay,c,0,bg);
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+static void grid_focus(uiobj_t *p_ui) {
+/* grid_t *p_grid=p_ui->obj;
+ view_t *p_view=p_ui->view;
+ if(p_grid->data) {
+ r_cins(p_ui->x+p_view->x-p_grid->l+p_grid->x*3+2,p_ui->y+p_view->y-p_grid->t+p_grid->y*3+2);
+ }
+*/
+ grid_t *p_grid=p_ui->obj;
+ view_t *p_view=p_ui->view;
+ if(p_grid->data) {
+ r_cins(p_ui->x+p_view->x-p_grid->l+p_grid->x*2+1,p_ui->y+p_view->y-p_grid->t+p_grid->y*2+1,1);
+ }
+
+}
+
+static void grid_draw(uiobj_t *p_ui) {
+/* grid_t *p_grid=p_ui->obj;
+ view_t *p_view=p_ui->view;
+ uint16_t x,y;
+ uint8_t bg;
+ if(p_ui->state&9) {
+ r_white(p_ui->x+p_view->x-1,p_ui->y+p_view->y-1,p_ui->w+2,p_ui->h+2);
+ if(p_grid->data) {
+ for(y=1;y<3*p_grid->h+1;y++) {
+ grid_cset(p_ui,0,y,'h',0);
+ grid_cset(p_ui,p_grid->w*3+1,y,'g',0);
+ if(((y-1)%15)==0) {
+ grid_cset(p_ui,-1,y ,'0'+(((y-1)/300)%10),0);
+ grid_cset(p_ui,-1,y+1,'0'+(((y-1)/ 30)%10),0);
+ grid_cset(p_ui,-1,y+2,'0'+(((y-1)/ 3)%10),0);
+ grid_cset(p_ui,-2,y ,'0'+(((y-1)/300)%10),0);
+ grid_cset(p_ui,-2,y+1,'0'+(((y-1)/ 30)%10),0);
+ grid_cset(p_ui,-2,y+2,'0'+(((y-1)/ 3)%10),0);
+ }
+ }
+ for(x=1;x<3*p_grid->w+1;x++) {
+ grid_cset(p_ui,x,0,'b',0);
+ grid_cset(p_ui,x,p_grid->h*3+1,'y',0);
+ if(((x-1)%15)==0) {
+ grid_cset(p_ui,x ,-1,'0'+(((x-1)/300)%10),0);
+ grid_cset(p_ui,x+1,-1,'0'+(((x-1)/ 30)%10),0);
+ grid_cset(p_ui,x+2,-1,'0'+(((x-1)/ 3)%10),0);
+ grid_cset(p_ui,x ,-2,'0'+(((x-1)/300)%10),0);
+ grid_cset(p_ui,x+1,-2,'0'+(((x-1)/ 30)%10),0);
+ grid_cset(p_ui,x+2,-2,'0'+(((x-1)/ 3)%10),0);
+ }
+ }
+ grid_cset(p_ui,0,0,'m',0);
+ grid_cset(p_ui,p_grid->w*3+1,0,'c',0);
+ grid_cset(p_ui,0,p_grid->h*3+1,'r',0);
+ grid_cset(p_ui,p_grid->w*3+1,p_grid->h*3+1,'i',0);
+ for(y=0;y<p_grid->h;y++) {
+ for(x=0;x<p_grid->w;x++) {
+ bg=(p_grid->data[x+y*p_grid->w]<0x80)?1:0;
+ grid_cset(p_ui,x*3+1,y*3+1,'t',bg);
+ grid_cset(p_ui,x*3+2,y*3+1,'y',bg);
+ grid_cset(p_ui,x*3+3,y*3+1,'u',bg);
+ grid_cset(p_ui,x*3+1,y*3+2,'g',bg);
+ grid_cset(p_ui,x*3+2,y*3+2,'ñ',bg);
+ grid_cset(p_ui,x*3+3,y*3+2,'h',bg);
+ grid_cset(p_ui,x*3+1,y*3+3,'v',bg);
+ grid_cset(p_ui,x*3+2,y*3+3,'b',bg);
+ grid_cset(p_ui,x*3+3,y*3+3,'n',bg);
+ }
+ }
+ if(p_grid->l) for(y=0;y<p_ui->h-0;y++) {
+ r_char(p_ui->x+p_view->x,p_ui->y+p_view->y+y,'a',0,0);
+ }
+ if(p_grid->w*3+2-p_grid->l>p_ui->w) for(y=0;y<p_ui->h-0;y++) {
+ r_char(p_ui->x+p_view->x+p_ui->w-1,p_ui->y+p_view->y+y,'d',0,0);
+ }
+ if(p_grid->t) for(x=0;x<p_ui->w-0;x++) {
+ r_char(p_ui->x+p_view->x+x,p_ui->y+p_view->y,'w',0,0);
+ }
+ if(p_grid->h*3+2-p_grid->t>p_ui->h) for(x=0;x<p_ui->w-0;x++) {
+ r_char(p_ui->x+p_view->x+x,p_ui->y+p_view->y+p_ui->h-1,'s',0,0);
+ }
+ if(p_ui->state&8) {
+ r_done(p_ui->x+p_view->x-1,p_ui->y+p_view->y-1,p_ui->w+2,p_ui->h+2);
+ }
+ }
+ }
+ if(p_ui->state&4) {
+ grid_focus(p_ui);
+ }
+ p_ui->state=0;
+*/
+ grid_t *p_grid=p_ui->obj;
+ view_t *p_view=p_ui->view;
+ uint16_t x,y;
+ uint8_t bg;
+ if(p_ui->state&9) {
+ r_white(p_ui->x+p_view->x-1,p_ui->y+p_view->y-1,p_ui->w+2,p_ui->h+2);
+ if(p_grid->data) {
+ for(y=1;y<2*p_grid->h+1;y++) {
+ grid_cset(p_ui,0,y,'h',0);
+ grid_cset(p_ui,p_grid->w*2+1,y,'g',0);
+ if(((y-1)%10)==0) {
+ grid_cset(p_ui,-1,y ,'0'+(((y-1)/200)%10),0);
+ grid_cset(p_ui,-1,y+1,'0'+(((y-1)/ 20)%10),0);
+ grid_cset(p_ui,-1,y+2,'0'+(((y-1)/ 2)%10),0);
+ grid_cset(p_ui,-2,y ,'0'+(((y-1)/200)%10),0);
+ grid_cset(p_ui,-2,y+1,'0'+(((y-1)/ 20)%10),0);
+ grid_cset(p_ui,-2,y+2,'0'+(((y-1)/ 2)%10),0);
+ }
+ }
+ for(x=1;x<2*p_grid->w+1;x++) {
+ grid_cset(p_ui,x,0,'b',0);
+ grid_cset(p_ui,x,p_grid->h*2+1,'y',0);
+ if(((x-1)%10)==0) {
+ grid_cset(p_ui,x ,-1,'0'+(((x-1)/200)%10),0);
+ grid_cset(p_ui,x+1,-1,'0'+(((x-1)/ 20)%10),0);
+ grid_cset(p_ui,x+2,-1,'0'+(((x-1)/ 2)%10),0);
+ grid_cset(p_ui,x ,-2,'0'+(((x-1)/200)%10),0);
+ grid_cset(p_ui,x+1,-2,'0'+(((x-1)/ 20)%10),0);
+ grid_cset(p_ui,x+2,-2,'0'+(((x-1)/ 2)%10),0);
+ }
+ }
+ grid_cset(p_ui,0,0,'m',0);
+ grid_cset(p_ui,p_grid->w*2+1,0,'c',0);
+ grid_cset(p_ui,0,p_grid->h*2+1,'r',0);
+ grid_cset(p_ui,p_grid->w*2+1,p_grid->h*2+1,'i',0);
+ for(y=0;y<p_grid->h;y++) {
+ for(x=0;x<p_grid->w;x++) {
+ bg=(p_grid->data[x+y*p_grid->w]<0x80)?1:0;
+ grid_cset(p_ui,x*2+1,y*2+1,'t',bg);
+ grid_cset(p_ui,x*2+2,y*2+1,'u',bg);
+ grid_cset(p_ui,x*2+1,y*2+2,'v',bg);
+ grid_cset(p_ui,x*2+2,y*2+2,'n',bg);
+ }
+ }
+ if(p_grid->l) for(y=0;y<p_ui->h-0;y++) {
+ r_char(p_ui->x+p_view->x,p_ui->y+p_view->y+y,'a',0,0);
+ }
+ if(p_grid->w*2+2-p_grid->l>p_ui->w) for(y=0;y<p_ui->h-0;y++) {
+ r_char(p_ui->x+p_view->x+p_ui->w-1,p_ui->y+p_view->y+y,'d',0,0);
+ }
+ if(p_grid->t) for(x=0;x<p_ui->w-0;x++) {
+ r_char(p_ui->x+p_view->x+x,p_ui->y+p_view->y,'w',0,0);
+ }
+ if(p_grid->h*2+2-p_grid->t>p_ui->h) for(x=0;x<p_ui->w-0;x++) {
+ r_char(p_ui->x+p_view->x+x,p_ui->y+p_view->y+p_ui->h-1,'s',0,0);
+ }
+ if(p_ui->state&8) {
+ r_done(p_ui->x+p_view->x-1,p_ui->y+p_view->y-1,p_ui->w+2,p_ui->h+2);
+ }
+ }
+ }
+ if(p_ui->state&4) {
+ grid_focus(p_ui);
+ }
+ p_ui->state=0;
+}
+
+static bool grid_key(uiobj_t *p_ui,SDL_Keycode sym) {
+/*
+ grid_t *p_grid=p_ui->obj;
+ switch(sym) {
+ case SDLK_LEFT:
+ if(p_grid->x>0) {
+ p_grid->x--;
+ p_ui->state|=4;
+ }
+ break;
+ case SDLK_RIGHT:
+ if(p_grid->x<p_grid->w-1) {
+ p_grid->x++;
+ p_ui->state|=4;
+ }
+ break;
+ case SDLK_UP:
+ if(p_grid->y>0) {
+ p_grid->y--;
+ p_ui->state|=4;
+ }
+ break;
+ case SDLK_DOWN:
+ if(p_grid->y<p_grid->h-1) {
+ p_grid->y++;
+ p_ui->state|=4;
+ }
+ break;
+ case SDLK_SPACE:
+ p_grid->data[p_grid->x+p_grid->y*p_grid->w]=p_grid->data[p_grid->x+p_grid->y*p_grid->w]<0x80?0xFF:0x00;
+ p_ui->state|=8;
+ return true;
+ }
+
+ if((p_grid->x*3+2)-2<p_grid->l) {
+ p_grid->l=(p_grid->x*3+2)-2;
+ p_ui->state|=8;
+ } else if( (p_grid->x*3+2)+3>p_grid->l+p_ui->w ) {
+ p_grid->l=(p_grid->x*3+2)+3-p_ui->w;
+ p_ui->state|=8;
+ }
+
+ if((p_grid->y*3+2)-2<p_grid->t) {
+ p_grid->t=(p_grid->y*3+2)-2;
+ p_ui->state|=8;
+ } else if( (p_grid->y*3+2)+3>p_grid->t+p_ui->h ) {
+ p_grid->t=(p_grid->y*3+2)+3-p_ui->h;
+ p_ui->state|=8;
+ }
+
+
+ return false;
+*/
+ grid_t *p_grid=p_ui->obj;
+ switch(sym) {
+ case SDLK_LEFT:
+ if(p_grid->x>0) {
+ p_grid->x--;
+ p_ui->state|=4;
+ }
+ break;
+ case SDLK_RIGHT:
+ if(p_grid->x<p_grid->w-1) {
+ p_grid->x++;
+ p_ui->state|=4;
+ }
+ break;
+ case SDLK_UP:
+ if(p_grid->y>0) {
+ p_grid->y--;
+ p_ui->state|=4;
+ }
+ break;
+ case SDLK_DOWN:
+ if(p_grid->y<p_grid->h-1) {
+ p_grid->y++;
+ p_ui->state|=4;
+ }
+ break;
+ case SDLK_SPACE:
+ p_grid->data[p_grid->x+p_grid->y*p_grid->w]=p_grid->data[p_grid->x+p_grid->y*p_grid->w]<0x80?0xFF:0x00;
+ p_ui->state|=8;
+ break;
+ default:
+ return true;
+ }
+
+ if((p_grid->x*2+2)-2<p_grid->l) {
+ p_grid->l=(p_grid->x*2+2)-2;
+ p_ui->state|=8;
+ } else if( (p_grid->x*2+2)+2>p_grid->l+p_ui->w ) {
+ p_grid->l=(p_grid->x*2+2)+2-p_ui->w;
+ p_ui->state|=8;
+ }
+
+ if((p_grid->y*2+2)-2<p_grid->t) {
+ p_grid->t=(p_grid->y*2+2)-2;
+ p_ui->state|=8;
+ } else if( (p_grid->y*2+2)+2>p_grid->t+p_ui->h ) {
+ p_grid->t=(p_grid->y*2+2)+2-p_ui->h;
+ p_ui->state|=8;
+ }
+
+ return sym=SDLK_SPACE;
+
+}
+
/** TEXT INPUT ******************************************************/
uiobj_t* ui_text(uint8_t x,uint8_t y,uint8_t w,char *caption) {
@@ -136,10 +463,10 @@ static void text_draw(uiobj_t *p_ui) {
static void text_focus(uiobj_t *p_ui) {
text_t *p_text=p_ui->obj;
view_t *p_view=p_ui->view;
- r_cins(p_view->x+p_ui->x+strlen(p_text->caption)+strlen(p_text->text),p_view->y+p_ui->y);
+ r_cins(p_view->x+p_ui->x+strlen(p_text->caption)+strlen(p_text->text),p_view->y+p_ui->y,0);
}
-static bool text_key(uiobj_t *p_ui,uint8_t sym) {
+static bool text_key(uiobj_t *p_ui,SDL_Keycode sym) {
text_t *p_text=p_ui->obj;
char key[2];
if((sym>=SDLK_0&&sym<=SDLK_9)||sym==SDLK_BACKSPACE) {
@@ -524,6 +851,8 @@ static void ui_refresh(view_t *p_view) {
break;
case UI_TEXT: text_draw(p_ui);
break;
+ case UI_GRID: grid_draw(p_ui);
+ break;
}
p_ui=p_ui->next;
}
@@ -548,7 +877,7 @@ static void ui_focusprev(view_t *p_view) {
if(p_ui&&p_ui!=p_view->focus) {
if(p_ui->enabled) {
switch(p_ui->type) {
- case UI_TEXT:
+ case UI_TEXT: case UI_GRID:
p_found=p_ui;
break;
}
@@ -561,6 +890,9 @@ static void ui_focusprev(view_t *p_view) {
case UI_TEXT:
text_focus(p_found);
break;
+ case UI_GRID:
+ grid_focus(p_found);
+ break;
}
}
}
@@ -578,6 +910,10 @@ static void ui_focusnext(view_t *p_view) {
p_view->focus=p_ui;
text_focus(p_ui);
return;
+ case UI_GRID:
+ p_view->focus=p_ui;
+ grid_focus(p_ui);
+ return;
}
}
}
@@ -611,17 +947,21 @@ void ui_display(view_t *p_view,bool(*events)(SDL_Event *e)) {
if(!p_view->fullscreen) {
r_white(p_view->x-3,p_view->y-3,p_view->w+6,p_view->h+6);
r_box(p_view->x-2,p_view->y-2,p_view->w+4,p_view->h+4,p_view->caption,0,3);
- } else if(p_view->state==1) {
- r_white(0,0,40,30);
- p_view->state=2;
+ } else {
+ r_white(0,0,40,30);
+ if(was_fullscreen) {
+ p_view->state=0;
+ } else {
+ p_view->state=1;
+ }
}
+ was_fullscreen=p_view->fullscreen;
while(!done) {
SDL_mutexP(mx_ui);
ui_refresh(p_view);
- if(p_view->fullscreen&p_view->state==0) p_view->state=1;
- if(p_view->state==2) {
+ if(p_view->state==1) {
r_done(0,0,40,30);
- p_view->state=1;
+ p_view->state=2;
}
r_draw();
while(SDL_PollEvent(&e)) {
@@ -663,6 +1003,13 @@ void ui_display(view_t *p_view,bool(*events)(SDL_Event *e)) {
done|=events(&e);
}
break;
+ case UI_GRID:
+ if(grid_key(p_view->focus,e.key.keysym.sym)) {
+ e.type=UI_CHANGE;
+ e.user.data1=p_view->focus;
+ done|=events(&e);
+ }
+ break;
}
}
}
@@ -674,9 +1021,9 @@ void ui_display(view_t *p_view,bool(*events)(SDL_Event *e)) {
if(p_ui!=p_ui_over) {
if(p_ui_down) {
if(p_ui==p_ui_down) {
- r_offset(p_ui_down->x+p_view->x,p_ui_down->y+p_view->y,p_ui_down->w,p_ui_down->h,2,2);
+ r_offset(p_ui_down->x+p_view->x,p_ui_down->y+p_view->y,p_ui_down->w,p_ui_down->h,2);
} else {
- r_offset(p_ui_down->x+p_view->x,p_ui_down->y+p_view->y,p_ui_down->w,p_ui_down->h,0,0);
+ r_offset(p_ui_down->x+p_view->x,p_ui_down->y+p_view->y,p_ui_down->w,p_ui_down->h,0);
}
} else {
if(p_ui_over) {
@@ -713,8 +1060,18 @@ void ui_display(view_t *p_view,bool(*events)(SDL_Event *e)) {
p_ui_down=find(p_view,x,y);
if(p_ui_down) {
switch(p_ui_down->type) {
+ case UI_GRID:
+ if(x>p_ui->x+p_view->x&&x<p_ui->x+p_view->x+p_ui->w-1
+ &&y>p_ui->y+p_view->y&&y<p_ui->y+p_view->y+p_ui->h-1) {
+ ((grid_t*)p_ui->obj)->x=(x-(p_ui->x+p_view->x)+((grid_t*)p_ui->obj)->l-1)>>1;
+ ((grid_t*)p_ui->obj)->y=(y-(p_ui->y+p_view->y)+((grid_t*)p_ui->obj)->t-1)>>1;
+ p_view->focus=p_ui_down;
+ grid_focus(p_ui_down);
+ grid_key(p_ui_down,SDLK_SPACE);
+ }
+ break;
case UI_BUTTON: case UI_TEXT:
- r_offset(p_ui->x+p_view->x,p_ui->y+p_view->y,p_ui->w,p_ui->h,2,2);
+ r_offset(p_ui->x+p_view->x,p_ui->y+p_view->y,p_ui->w,p_ui->h,2);
break;
case UI_LIST:
x-=p_ui->x+p_view->x;
@@ -736,7 +1093,7 @@ void ui_display(view_t *p_view,bool(*events)(SDL_Event *e)) {
case SDL_MOUSEBUTTONUP:
if(e.button.button==1) {
if(p_ui_down) {
- r_offset(p_ui_down->x+p_view->x,p_ui_down->y+p_view->y,p_ui_down->w,p_ui_down->h,0,0);
+ r_offset(p_ui_down->x+p_view->x,p_ui_down->y+p_view->y,p_ui_down->w,p_ui_down->h,0);
if(p_ui_over==p_ui_down) {
e.type=UI_CLICK;
e.user.data1=p_ui_down;
View
14 gui/ui.h
@@ -20,6 +20,16 @@ typedef struct {
} list_t;
typedef struct {
+ uint16_t l;
+ uint16_t t;
+ uint16_t x;
+ uint16_t y;
+ uint16_t w;
+ uint16_t h;
+ uint8_t *data;
+} grid_t;
+
+typedef struct {
char *caption;
} button_t;
@@ -63,6 +73,7 @@ enum {
UI_LIST='L',
UI_FIELD='F',
UI_TEXT='T',
+ UI_GRID='G',
UI_END=' '
};
@@ -81,6 +92,9 @@ view_t* ui_fsview();
view_t* ui_view(uint8_t w,uint8_t h,char *caption);
void ui_free_view(view_t *p_view);
+uiobj_t* ui_grid(uint8_t x,uint8_t y,uint8_t w,uint8_t h);
+void ui_grid_set(uiobj_t *p_ui,void *p_data,uint16_t w,uint16_t h);
+
uiobj_t* ui_text(uint8_t x,uint8_t y,uint8_t w,char *caption);
void ui_text_set(uiobj_t *p_ui,char *p_text);
char* ui_text_get(uiobj_t *p_ui);
View
BIN  ptn/face.bmp
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.