/* * Handle exposure events. */ static void doexposure(GR_EVENT_EXPOSURE *ep) { if (ep->wid == boardwid) { drawboard(); return; } if (ep->wid == statwid) { drawstatus(); return; } if (ep->wid == quitwid) { drawbutton(quitwid, "QUIT"); return; } if (ep->wid == savewid) { drawbutton(savewid, "SAVE GAME"); return; } if (ep->wid == newgamewid) { drawbutton(newgamewid, "NEW GAME"); return; } }
static void redraw_buttons() { gl_button *bt = firstbutton; while (bt != NULL) { drawbutton(bt); bt = bt->nextp; } }
horiz_butt() { int cmdtop=45,cmdbot; int space=100; cmdbot=ym-30; setbutton(&add,cmdtop,cmdbot,"Add Body"); drawbutton(&add); setbutton(&gravtn,cmdtop+space,cmdbot,"Gravity"); drawbutton(&gravtn); setbutton(&frictn,cmdtop+2*space,cmdbot,"Friction"); drawbutton(&frictn); setbutton(&delt,cmdtop+3*space,cmdbot,"Delete"); drawbutton(&delt); setbutton(&exit1,cmdtop+4*space,cmdbot,"EXIT"); drawbutton(&exit1); return 0; }
vert_butt() { int cmdtop=xm-60,cmdbot; int space=40; cmdbot=80; setbutton(&add,cmdtop,cmdbot,"Add Body"); drawbutton(&add); setbutton(&gravtn,cmdtop,cmdbot+space,"Gravity"); drawbutton(&gravtn); setbutton(&frictn,cmdtop,cmdbot+2*space,"Friction"); drawbutton(&frictn); setbutton(&delt,cmdtop,cmdbot+3*space,"Delete"); drawbutton(&delt); setbutton(&exit1,cmdtop,cmdbot+4*space,"EXIT"); drawbutton(&exit1); return 0; }
/**************************** BUTTONS ********************************/ gl_button *create_gl_button(double x, double y, double width, double height, int fg, int bg, int active_c, int *state, int type, char *label, void (*callback)(gl_button *, int)) { gl_button *newbutton; if ((newbutton = (gl_button *)malloc(sizeof(gl_button))) == NULL) return(NULL); if (firstbutton == NULL) { /* initialization */ check_vers(); qdevice(LEFTMOUSE); tie(LEFTMOUSE, MOUSEX, MOUSEY); firstbutton = actbutton = newbutton; } actbutton->nextp = newbutton; actbutton = newbutton; actbutton->nextp = NULL; actbutton->win = winget(); actbutton->x = x; actbutton->y = y; actbutton->width = width; actbutton->height = height; actbutton->fg = fg; actbutton->bg = bg; actbutton->active_c = active_c; actbutton->type = type; actbutton->changed = FALSE; if (state != NULL) actbutton->state = state; else { if ((actbutton->state = (int *)malloc(sizeof(int))) == NULL) return(NULL); *(actbutton->state) = 0; } if (label != NULL) { if ((actbutton->label = (char *)malloc(strlen(label) + 2)) != NULL) { *(actbutton->label) = ' '; strcpy(actbutton->label + 1, label); } } else actbutton->label = NULL; actbutton->callback = callback; drawbutton(actbutton); return(actbutton); }
void destroy_gl_button(gl_button *but) { gl_button *bt = firstbutton, *obt, *np; obt = bt; while (bt != NULL) { #ifdef DEBUG printf("dest_but: label = %s ", bt->label); #endif np = bt->nextp; if (bt == but) { #ifdef DEBUG printf("destroying\n"); #endif np = bt->nextp; obt->nextp = bt->nextp; if (firstbutton == bt) firstbutton = bt->nextp; bt->fg = bt->bg; *(bt->state) = 0; drawbutton(bt); if (bt->label != NULL) free(bt->label); free(bt); np = NULL; } #ifdef DEBUG puts(""); #endif obt = bt; bt = np; } #ifdef DEBUG bt = firstbutton; while (bt!=NULL) { printf("after destroy button: %s\n", bt->label); bt=bt->nextp; } #endif }
void ui_init(SDL_Surface *screen, button **buttons, bool edgeload, bool pause, bool keyboard, bool printer) { static button btn[nbuttons]; *buttons=btn; for(unsigned int i=0;i<nbuttons;i++) { btn[i].img=NULL; btn[i].tooltip=NULL; } char title[64]; snprintf(title, 64, "Spiffy - ZX Spectrum %s", name_from_machine(zx_machine)); SDL_WM_SetCaption(title, "Spiffy"); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_FillRect(screen, &(SDL_Rect){0, y_cntl, screen->w, 1}, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_FillRect(screen, &(SDL_Rect){0, y_cntl+1, screen->w, 63}, SDL_MapRGB(screen->format, 0, 0, 0)); // controls area SDL_FillRect(screen, &(SDL_Rect){0, y_cntl+64, screen->w, 16}, SDL_MapRGB(screen->format, 63, 63, 63)); // status bar if(keyboard) { for(unsigned int i=0;i<10;i++) km[i]=configIMG_Load(kmn[i]); SDL_FillRect(screen, &(SDL_Rect){0, y_keyb, screen->w, 1}, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_FillRect(screen, &(SDL_Rect){0, y_keyb+1, screen->w, 160}, SDL_MapRGB(screen->format, 0, 0, 0)); if(km[0]) SDL_BlitSurface(km[0], NULL, screen, &(SDL_Rect){0, y_keyb+1, screen->w, 160}); } if(printer) { SDL_FillRect(screen, &(SDL_Rect){0, y_prnt, screen->w, 1}, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_FillRect(screen, &(SDL_Rect){0, y_prnt+1, screen->w, 119}, SDL_MapRGB(screen->format, 31, 31, 31)); // printer area SDL_FillRect(screen, &(SDL_Rect){32, y_prnt+100, 256, 20}, SDL_MapRGB(screen->format, 191, 191, 195)); // printer paper } FILE *fimg; string img; fimg=configopen("buttons/load.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[0]=(button){.img=pbm_string(img), .posn={116, y_cntl+2, 17, 17}, .col=0x8f8f1f, .tooltip="Load a tape image or snapshot"}; free_string(&img); fimg=configopen("buttons/flash.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[1]=(button){.img=pbm_string(img), .posn={136, y_cntl+2, 17, 17}, .col=edgeload?0xffffff:0x1f1f1f, .tooltip=edgeload?"Disable edge-loader":"Enable edge-loader"}; free_string(&img); fimg=configopen("buttons/play.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[2]=(button){.img=pbm_string(img), .posn={156, y_cntl+2, 17, 17}, .col=0x3fbf5f, .tooltip="Play the virtual tape"}; free_string(&img); fimg=configopen("buttons/next.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[3]=(button){.img=pbm_string(img), .posn={176, y_cntl+2, 17, 17}, .col=0x07079f, .tooltip="Skip to the next tape block"}; free_string(&img); fimg=configopen("buttons/stop.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[4]=(button){.img=pbm_string(img), .posn={196, y_cntl+2, 17, 17}, .col=0x3f0707, .tooltip="Stop the tape at the end of each block"}; free_string(&img); fimg=configopen("buttons/rewind.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[5]=(button){.img=pbm_string(img), .posn={216, y_cntl+2, 17, 17}, .col=0x7f076f, .tooltip="Rewind to the beginning of the tape"}; free_string(&img); fimg=configopen("buttons/pause.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[6]=(button){.img=pbm_string(img), .posn={8, y_cntl+44, 17, 17}, .col=pause?0xbf6f07:0x7f6f07, .tooltip=pause?"Unpause the emulation":"Pause the emulation"}; free_string(&img); fimg=configopen("buttons/reset.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[7]=(button){.img=pbm_string(img), .posn={28, y_cntl+44, 17, 17}, .col=0xffaf07, .tooltip="Reset the Spectrum"}; free_string(&img); fimg=configopen("buttons/bug.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[8]=(button){.img=pbm_string(img), .posn={48, y_cntl+44, 17, 17}, .col=0xbfff3f, .tooltip="Start the debugger"}; free_string(&img); #ifdef AUDIO btn[9].posn=(SDL_Rect){76, 321, 7, 6}; btn[10].posn=(SDL_Rect){76, 328, 7, 6}; btn[11].posn=(SDL_Rect){136, 321, 7, 6}; btn[12].posn=(SDL_Rect){136, 328, 7, 6}; fimg=configopen("buttons/record.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[13]=(button){.img=pbm_string(img), .posn={8, y_cntl+24, 17, 17}, .col=0x7f0707, .tooltip="Record audio"}; drawbutton(screen, btn[13]); free_string(&img); #endif /* AUDIO */ fimg=configopen("buttons/snap.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[14]=(button){.img=pbm_string(img), .posn={68, y_cntl+44, 17, 17}, .col=0xbfbfbf, .tooltip="Save a snapshot"}; drawbutton(screen, btn[14]); free_string(&img); fimg=configopen("buttons/trec.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[15]=(button){.img=pbm_string(img), .posn={236, y_cntl+2, 17, 17}, .col=0x4f0f0f, .tooltip="Record tape"}; drawbutton(screen, btn[15]); free_string(&img); fimg=configopen("buttons/feed.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[16]=(button){.img=pbm_string(img), .posn={88, y_cntl+44, 17, 17}, .col=printer?0x3f276f:0x170f1f, .tooltip=printer?"ZX Printer: Paper feed":"ZX Printer is disabled"}; drawbutton(screen, btn[16]); free_string(&img); fimg=configopen("buttons/js_c.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[17]=(button){.img=pbm_string(img), .posn={108, y_cntl+44, 9, 9}, .col=0x3fff3f, .tooltip="Select CURSOR keystick"}; free_string(&img); fimg=configopen("buttons/js_s.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[18]=(button){.img=pbm_string(img), .posn={116, y_cntl+44, 9, 9}, .col=0x3f3f3f, .tooltip="Select SINCLAIR keystick"}; free_string(&img); fimg=configopen("buttons/js_k.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[19]=(button){.img=pbm_string(img), .posn={108, y_cntl+52, 9, 9}, .col=0x3f3f3f, .tooltip="Select KEMPSTON keystick"}; free_string(&img); fimg=configopen("buttons/js_x.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[20]=(button){.img=pbm_string(img), .posn={116, y_cntl+52, 9, 9}, .col=0x3f3f3f, .tooltip="Disable keystick"}; free_string(&img); ksupdate(screen, *buttons, JS_C); fimg=configopen("buttons/bw.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[21]=(button){.img=pbm_string(img), .posn={128, y_cntl+44, 17, 17}, .col=0x9f9f9f, .tooltip="Enable Black&White filter"}; drawbutton(screen, btn[21]); free_string(&img); fimg=configopen("buttons/scan.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[22]=(button){.img=pbm_string(img), .posn={148, y_cntl+44, 17, 17}, .col=0x5f5fcf, .tooltip="Enable TV Scanlines filter"}; drawbutton(screen, btn[22]); free_string(&img); fimg=configopen("buttons/blur.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[23]=(button){.img=pbm_string(img), .posn={168, y_cntl+44, 17, 17}, .col=0xbf3f3f, .tooltip="Enable Horizontal Blur filter"}; drawbutton(screen, btn[23]); free_string(&img); fimg=configopen("buttons/vblur.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[24]=(button){.img=pbm_string(img), .posn={188, y_cntl+44, 17, 17}, .col=0xbf3f3f, .tooltip="Enable Vertical Blur filter"}; drawbutton(screen, btn[24]); free_string(&img); fimg=configopen("buttons/misg.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[25]=(button){.img=pbm_string(img), .posn={208, y_cntl+44, 17, 17}, .col=0x1f5f1f, .tooltip="Enable Misaligned Green filter"}; drawbutton(screen, btn[25]); free_string(&img); fimg=configopen("buttons/slow.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[26]=(button){.img=pbm_string(img), .posn={228, y_cntl+44, 17, 17}, .col=0x8f8faf, .tooltip="Enable Slow Fade filter"}; drawbutton(screen, btn[26]); free_string(&img); fimg=configopen("buttons/pal.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[27]=(button){.img=pbm_string(img), .posn={248, y_cntl+44, 17, 17}, .col=0x4f4f4f, .tooltip="Enable PAL Chroma Distortion filter"}; drawbutton(screen, btn[27]); free_string(&img); for(unsigned int i=0;i<9;i++) drawbutton(screen, btn[i]); }
static int updatebutton(int x, int y, gl_button *bt) { Int32 xo, yo; Int16 xx, yy; Int32 oriwin = winget(); int oldstate; #ifdef DEBUG printf("updatebutton: button with label %s - ", bt->label); #endif winset(bt->win); locate_button(bt); getorigin(&xo, &yo); x -= xo; y -= yo; if (x < bt->scx0 || y > bt->scy0 || x > bt->scx1 || y < bt->scy1) { winset(oriwin); bt->changed = FALSE; #ifdef DEBUG printf("x = %d y = %d, btscx0 = %d btscx1 = %d btscy0 = %d btscy1 = %d\n", x, y, bt->scx0, bt->scx1, bt->scy0, bt->scy1); puts("click not inside - return(FALSE)"); #endif return(FALSE); } oldstate = *(bt->state); *(bt->state) = (bt->type == BUTTON)?TRUE:!oldstate; drawbutton(bt); while (qread(&xx) != LEFTMOUSE); /* wait for LEFTMOUSE release */ if (qtest()) qread(&xx); else { xx = getvaluator(MOUSEX); fprintf(stderr, "updatebutton: This should not happen, tie() seems to fail.\n"); } if (qtest()) qread(&yy); else { yy = getvaluator(MOUSEY); fprintf(stderr, "updatebutton: This should not happen, tie() seems to fail.\n"); } getorigin(&xo, &yo); x = xx - xo; y = yy - yo; if (!(bt->changed = !( x < bt->scx0 || y > bt->scy0 || x > bt->scx1 || y < bt->scy1 ) )) *(bt->state) = oldstate; if (bt->type == BUTTON) { *(bt->state) = FALSE; usleep(50000); } drawbutton(bt); if (oriwin != bt->win) winset(oriwin); if (bt->callback != NULL && bt->changed) { bt->callback(bt, *(bt->state)); } #ifdef DEBUG printf("return(%s)\n", bt->changed?"true":"false"); #endif return(bt->changed); }
static gboolean on_expose_event (GtkWidget * widget, GdkEventExpose * event, gpointer *project) { cairo_t *cr; GdkWindow *gdkw; gint i; gdkw = gtk_layout_get_bin_window (GTK_LAYOUT(widget)); cr = gdk_cairo_create (gdkw); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 1); if(!layoutexp) { for(i=0;i<=MAXLEN12;i++) { if(pertchart[i].name != NULL) { drawbutton(widget,pertchart[i].name,pertchart[i].x,pertchart[i].y,pertchart[i].type,project); } } for(i=0;i<Lin;i++) { cr = gdk_cairo_create (gdkw); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 1); cairo_move_to (cr, arrow[i].x1,arrow[i].y1); cairo_line_to (cr, arrow[i].x2,arrow[i].y2); cairo_move_to (cr, arrow[i].x2,arrow[i].y2); cairo_line_to (cr, arrow[i].x3,arrow[i].y3); cairo_move_to (cr, arrow[i].x3,arrow[i].y3); cairo_line_to (cr, arrow[i].x4,arrow[i].y4); cairo_stroke_preserve (cr); cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill (cr); cairo_destroy (cr); } } else { for(i=0;i<Lin;i++) { cr = gdk_cairo_create (gdkw); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 1); cairo_move_to (cr, arrow[i].x1,arrow[i].y1); cairo_line_to (cr, arrow[i].x2,arrow[i].y2); cairo_move_to (cr, arrow[i].x2,arrow[i].y2); cairo_line_to (cr, arrow[i].x3,arrow[i].y3); cairo_move_to (cr, arrow[i].x3,arrow[i].y3); cairo_line_to (cr, arrow[i].x4,arrow[i].y4); cairo_stroke_preserve (cr); cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill (cr); cairo_destroy (cr);} } layoutexp++; return FALSE; }