Skip to content

Commit

Permalink
gui pattern editor in place
Browse files Browse the repository at this point in the history
  • Loading branch information
stg committed May 30, 2012
1 parent ed9ade3 commit 84577f2
Show file tree
Hide file tree
Showing 8 changed files with 438 additions and 44 deletions.
Binary file modified bin-win/gui.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion gui/loader.c
Expand Up @@ -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;
}
}
}
Expand Down
17 changes: 5 additions & 12 deletions gui/main.c
Expand Up @@ -56,6 +56,7 @@ enum {
};

enum {
EDIT_GRID,
EDIT_OK,
EDIT_COUNT
};
Expand Down Expand Up @@ -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]));
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
61 changes: 45 additions & 16 deletions gui/renderer.c
Expand Up @@ -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[] = "#!\"cù% '()|+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZú®¯³ÄÙÀÚ¿´ÃºÍ¼ÈÉ»awdsgyhbnvtumcri";
static const char font_chars[] = "#!\"cù%ñ'()|+,-./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 = {
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions gui/renderer.h
Expand Up @@ -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();

0 comments on commit 84577f2

Please sign in to comment.