/* draws everything else */ void draw_1dtetris (TWidget *wid, ttk_surface srf) { char buffer[8]; if (score == 0) snprintf(buffer, 8, "%d", score); else snprintf(buffer, 8, "%d00", score); // draw playfield ttk_fillrect (srf, 0, 0, w, HWH, ttk_makecol(BLACK)); ttk_rect (srf, pf_x, 6, pf_x+pf_w, 6+pf_h, ttk_makecol(WHITE)); ttk_line (srf, pf_x+1, 6, pf_x+pf_w-2, 6, ttk_makecol(BLACK)); // draw next frame ttk_rect (srf, nf_x, nf_y, nf_x+nf_w, nf_y+nf_h, ttk_makecol(WHITE)); ttk_text (srf, ttk_textfont, nf_x+1, nf_y-ttk_text_height(ttk_textfont), ttk_makecol(WHITE), "next"); // draw score frame ttk_rect (srf, sf_x, nf_y, sf_x+sf_w, nf_y+nf_w, ttk_makecol(WHITE)); ttk_text (srf, ttk_textfont, sf_x+1, nf_y-ttk_text_height(ttk_textfont), ttk_makecol(WHITE), "score"); ttk_text (srf, ttk_textfont, sf_x+sf_w-ttk_text_width(ttk_textfont, buffer)-3, nf_y + (nf_w/2 - ttk_text_height(ttk_textfont)/2), ttk_makecol(WHITE), buffer); // draw moving brick draw_brick(srf, pf_x, 7-(sq_size*brick_length), brick_length, brick_depth); // draw next brick draw_brick(srf, nf_x+sq_size/2, nf_y+sq_size/2, next_length, 0); // hide bad programming skills for users eyes :) ttk_fillrect (srf, pf_x, 0, pf_x+pf_w, 6, ttk_makecol(BLACK)); }
void draw_mymodule (PzWidget *wid, ttk_surface srf) { // Draw the message char *p = text; int y = wid->y + 5; while (*p) { char svch; if (strchr (p, '\n')) { svch = *strchr (p, '\n'); *strchr (p, '\n') = 0; } else { svch = 0; } ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), p); p += strlen (p); y += ttk_text_height (ttk_textfont) + 1; *p = svch; if (*p) p++; } y += 3; // Dividing line ttk_line (srf, wid->x + 5, y, wid->x + wid->w - 5, y, ttk_makecol (DKGREY)); y += 3; // The image ttk_blit_image (image, srf, wid->x + (wid->w - imgw) / 2, wid->y + (wid->h - imgh) / 2); y += imgh; // The message #define MSG "Press a button to quit." ttk_text (srf, ttk_menufont, wid->x + (wid->w - ttk_text_width (ttk_menufont, MSG)) / 2, wid->y + wid->h - ttk_text_height (ttk_menufont) - 5, ttk_makecol (BLACK), MSG); }
void transfer_alt_stat_draw (PzWidget *wid, ttk_surface srf) { char buf[128]; stat_data *stats = (stat_data *)wid->data; int y = wid->y + 5; ttk_color color = ttk_ap_getx ("window.fg")->color; ttk_text (srf, ttk_textfont, wid->x + 5, y, color, _("Selected:")); y += ttk_text_height (ttk_textfont) + 1; sprintf(buf, "%i tracks.", stats->num_files); ttk_text (srf, ttk_textfont, wid->x + 5, y, color, buf); /* ttk_text (srf, ttk_textfont, wid->x + 5, y, color, _("Tracks:")); sprintf(buf, "%i", stats->num_tracks); printf("textwid: %i\n", ttk_text_width(ttk_textfont, buf)); ttk_text (srf, ttk_textfont, wid->w - ttk_text_width(ttk_textfont, buf) - 6, y, color, buf); */ y += ttk_text_height (ttk_textfont) + 1; sprintf(buf, "%s bytes.", humanize_size(stats->total_bytes)); ttk_text (srf, ttk_textfont, wid->x + 5, y, color, buf); y += ttk_text_height (ttk_textfont) + 1; }
TWidget * ti_create_tim_widget(int ht, int wd) { int sh, sw; TWidget * wid; ttk_get_screensize(&sw, &sh, 0); wid = ttk_new_widget( ((wd>0)?(sw-wd):(-wd)), sh-((ht<0)?(ttk_text_height(ttk_menufont)*(-ht)+1):ht) ); wid->h = ((ht<0)?(ttk_text_height(ttk_menufont)*(-ht)+1):ht); wid->w = ((wd>0)?(wd):(sw+wd)); wid->focusable = 1; return wid; }
static void settings_menu() { char str[35]; char buf[15]; int height; switch(ttk_screen->bpp){ case 2: texts = ttk_makecol(WHITE); break; case 16: texts = ttk_makecol(151, 124, 33); break; } height = ttk_text_height(ttk_menufont); ttk_blit_image (menu_sbg, iracer_srf, 0, 0); strcpy(str, "Laps: "); sprintf(buf, "%d", set_laps[settings.laps]); strcat(str, buf); ttk_text (iracer_srf, ttk_menufont, 5, bgh/4, (option==0)?texts:ttk_makecol(BLACK), str); strcpy(str, "Speed: "); sprintf(buf, "%d CC", set_cc[settings.cc]); strcat(str, buf); ttk_text (iracer_srf, ttk_menufont, 5, bgh/4+(height+2), (option==1)?texts:ttk_makecol(BLACK), str); strcpy(str, "Time Limit: "); sprintf(buf, "%s", onoff_opts[settings.gdif]); strcat(str, buf); ttk_text (iracer_srf, ttk_menufont, 5, bgh/4+(2*height+4), (option==2)?texts:ttk_makecol(BLACK), str); ttk_text (iracer_srf, ttk_menufont, 5, bgh/4+(3*height+6), (option==3)?texts:ttk_makecol(BLACK), "Save Settings"); }
TWindow *new_stringview_window(char *buf, char *title) { TWindow *ret = ttk_new_window(); ttk_add_widget (ret, ttk_new_textarea_widget (ret->w, ret->h, buf, ttk_textfont, ttk_text_height (ttk_textfont) + 2)); ttk_window_title (ret, title); return ret; }
TWindow * new_mkdir_window(ttk_menu_item * item) { TWindow * ret; TWidget * wid; TWidget * wid2; ret = ttk_new_window(_("Make Directory")); wid = ti_new_standard_text_widget(10, 10+ttk_text_height(ttk_textfont)*2, ret->w-20, 10+ttk_text_height(ttk_textfont), 0, "", tix_mkdir_callback); ttk_add_widget(ret, wid); wid2 = ttk_new_widget(10, 10); wid2->w = ret->w-20; wid2->h = ttk_text_height(ttk_menufont); wid2->draw = tix_mkdir_draw; ttk_add_widget(ret, wid2); ttk_show_window(ret); ti_widget_start(wid); return 0; }
static void pp_place_text(PzWidget *wid, ttk_surface srf, void *text, int num) { int w, h; w = ttk_text_width(ttk_menufont, (char *)text); h = ttk_text_height(ttk_menufont); ttk_text(srf, ttk_menufont, w < wid->w ? (wid->w - w) / 2 : 8, h*num - (2*h)/3, ttk_ap_getx("window.fg")->color, (char *)text); }
TWindow *pz_new_textview_window(char *filename) { TWindow *ret; char *buf = NULL; char tmp[4096]; FILE *fp; long len, cs; if ((fp = fopen(filename, "r")) == NULL) { pz_perror(filename); return TTK_MENU_DONOTHING; } fseek(fp, 0L, SEEK_END); len = ftell(fp); rewind(fp); if (len == 0) { cs = 0; while (fgets(tmp, 4096, fp) != NULL) { len = buf ? strlen(buf) : 0; if (len + (long)strlen(tmp) > cs) { cs += 8192; if ((buf = realloc(buf, cs)) == NULL) { pz_error(_("Memory allocation failed")); fclose(fp); return TTK_MENU_DONOTHING; } } strncpy(buf + len, tmp, cs - len); } if (buf == NULL) { pz_message(_("Empty file")); fclose(fp); return TTK_MENU_DONOTHING; } } else { cs = len; if ((buf = malloc(len + 1)) == NULL) { pz_error(_("Memory allocation failed")); fclose(fp); return TTK_MENU_DONOTHING; } while (cs > 0) cs -= fread(buf + (len - cs), 1, cs, fp); *(buf + len) = '\0'; } fclose(fp); ret = ttk_new_window(); ret->data = 0x12345678; ttk_add_widget(ret, ttk_new_textarea_widget(ret->w, ret->h, buf, ttk_textfont, ttk_text_height(ttk_textfont)+2)); ttk_window_title(ret, strrchr(filename, '/')? strrchr(filename, '/') + 1:filename); free(buf); /* strdup'd in textarea */ return ret; }
TWindow * new_rename_window(ttk_menu_item * item) { TWindow * ret; TWidget * wid; TWidget * wid2; tix_rename_oldname = strdup(item->data); ret = ttk_new_window(_("Rename")); wid = ti_new_standard_text_widget(10, 10+ttk_text_height(ttk_textfont)*2, ret->w-20, 10+ttk_text_height(ttk_textfont), 0, tix_rename_oldname, tix_rename_callback); ttk_add_widget(ret, wid); wid2 = ttk_new_widget(10, 10); wid2->w = ret->w-20; wid2->h = ttk_text_height(ttk_menufont); wid2->draw = tix_rename_draw; ttk_add_widget(ret, wid2); ti_widget_start(wid); ttk_show_window(ret); return 0; }
TWindow * podwrite_mh_save(ttk_menu_item * item) { TWindow * ret; TWidget * wid; ret = ttk_new_window(_("Save to...")); wid = ti_new_standard_text_widget(10, 40, ret->w-20, 10+ttk_text_height(ttk_textfont), 0, (podwrite_filename?podwrite_filename:"/mnt/Notes/"), podwrite_save_callback); ttk_add_widget(ret, wid); // ret = pz_finish_window(ret); ttk_show_window(ret); ti_widget_start(wid); return ret; }
PzWindow *transfer_alt_menu(track_list *tlist, ipod_t src_ipod, queue_fcn qfunc, ttk_menu_item *qitem) { TWindow *ret; ret = pz_new_window(_("Transfer"), PZ_WINDOW_NORMAL); ret->data = 0x12345678; /* Show data up top: number of tracks, total size */ int num_tracks = 0, size=0; track_item *titem = tlist->head; while (titem) { num_tracks++; ipod_track_t track = ipod_track_get_by_track_id(src_ipod, titem->track_id); size += ipod_track_get_attribute(track, IPOD_TRACK_SIZE); ipod_track_free(track); titem = titem->next; } /* Add the status widget */ PzWidget *stats_wid = pz_new_widget(transfer_alt_stat_draw, NULL); stat_data *stats = (stat_data *)malloc(sizeof(stat_data)); stats->num_files = num_tracks; stats->total_bytes = size; stats_wid->data = stats; stats_wid->w = ret->w; ttk_add_widget(ret, stats_wid); /* Draw the Menu */ int menu_height = (ttk_text_height(ttk_menufont) + 4) * (qfunc? 3 : 2); TWidget *menu = ttk_new_menu_widget (transfer_menu_default, ttk_menufont, ttk_screen->w - ttk_screen->wx, menu_height); menu->y = ttk_screen->h - ttk_screen->wy - menu_height; transfer_menu_default[1].data = transfer_menu_default[3].data = tlist; if (remote_ipod) ttk_menu_append (menu, transfer_menu_default + 1); if (qfunc) { enqueue_data *eqdata = (enqueue_data *)malloc(sizeof(enqueue_data)); eqdata->qfunc = qfunc; eqdata->item = qitem; transfer_menu_default[2].data = eqdata; transfer_menu_default[2].free_data = 1; ttk_menu_append(menu, transfer_menu_default + 2); } ttk_menu_append (menu, transfer_menu_default + 3); ttk_add_widget(ret, menu); return pz_finish_window(ret); }
static int piezomaker_save() { { TWindow *ret; TWidget *wid; ret = ttk_new_window(_("Save to...")); wid = ti_new_standard_text_widget(10, 40, ret->w-20, 10+ttk_text_height(ttk_textfont), 0, "/untitled.pzm", piezomaker_save_callback); ttk_add_widget(ret, wid); ttk_show_window(ret); ti_widget_start(wid); } return 0; }
void draw_about_remote_ipod_widget (PzWidget *wid, ttk_surface srf) { // Draw the message int y = wid->y + 5; ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), "Test"); y += ttk_text_height (ttk_textfont) + 1; ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), "Test2"); y += ttk_text_height (ttk_textfont) + 1; if (check_kernel_module("tsb43aa82")) ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), "tsb43aa82 loaded"); else ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), "tsb43aa82 NOT loaded"); y += ttk_text_height (ttk_textfont) + 1; if (check_kernel_module("scsi_mod")) ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), "scsi_mod loaded"); else ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), "scsi_mod NOT loaded"); y += ttk_text_height (ttk_textfont) + 1; if (check_kernel_module("sd_mod")) ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), "sd_mod loaded"); else ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), "sd_mod NOT loaded"); y += ttk_text_height (ttk_textfont) + 1; if (check_kernel_module("sbp2")) ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), "sbp2 loaded"); else ttk_text (srf, ttk_textfont, wid->x + 5, y, ttk_makecol (BLACK), "sbp2 NOT loaded"); y += ttk_text_height (ttk_textfont) + 1; y += 3; // Dividing line ttk_line (srf, wid->x + 5, y, wid->x + wid->w - 5, y, ttk_makecol (DKGREY)); y += 3; // The message #define MSG "Press a button to quit." ttk_text (srf, ttk_menufont, wid->x + (wid->w - ttk_text_width (ttk_menufont, MSG)) / 2, wid->y + wid->h - ttk_text_height (ttk_menufont) - 5, ttk_makecol (BLACK), MSG); }
TWindow *new_textview_window(char *filename) { struct stat st; if (stat (filename, &st) < 0) return 0; char *buf = malloc (st.st_size); if (!buf) return 0; int fd = open (filename, O_RDONLY); if (fd < 0) return 0; read (fd, buf, st.st_size); close (fd); TWindow *ret = ttk_new_window(); ttk_add_widget (ret, ttk_new_textarea_widget (ret->w, ret->h, buf, ttk_textfont, ttk_text_height (ttk_textfont) + 2)); ttk_window_title (ret, strrchr (filename, '/')? strrchr (filename, '/') + 1 : filename); free (buf); // strdup'd in textarea return ret; }
static PzWindow *set_Header() { PzWindow * ret; TWidget * wid; char headername[256]; snprintf(headername, 256, pz_get_string_setting(pz_global_config, HEADERNAME)); if(text_available()){ ret = pz_new_window(_("Set Header Name"), PZ_WINDOW_NORMAL); wid = textw(10, 40, ret->w-20, 10+ttk_text_height(ttk_textfont), 0, headername, pz_set_header); ttk_add_widget(ret, wid); textwstart(wid); return pz_finish_window(ret); } else { pz_warning("Install module text input"); return TTK_MENU_UPONE; } }
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "pz.h" void draw_lack_of_text_input_method (TWidget *this, ttk_surface srf) { ttk_text (srf, ttk_menufont, this->x + 3, this->y + 1, ttk_makecol (BLACK), _("No text input method selected.")); ttk_text (srf, ttk_menufont, this->x + this->w - ttk_text_width (ttk_menufont, _("[press a key]")) - 3, this->y + 3 + ttk_text_height (ttk_menufont), ttk_makecol (BLACK), _("[press a key]")); } int close_lack_of_text_input_method (TWidget *this, int button, int time) { ttk_input_end(); return 0; } TWidget *new_lack_of_text_input_method() { TWidget *ret = ttk_new_widget (0, 0); ret->w = ttk_screen->w; ret->h = 2 * (ttk_text_height (ttk_menufont) + 2); ret->draw = draw_lack_of_text_input_method; ret->button = close_lack_of_text_input_method;