int main(int argc, char **argv) { GtkWidget *info_dialog; if (argc != 1) { if (argc == 2 && !strncmp(argv[1], "-cal", 4) && strlen(argv[1]) == 4) { calendar_only = TRUE; } else { fprintf(stderr, "OSMO v%s - %s\n", VERSION, _("a handy personal organizer")); fprintf(stderr, "Copyright (c) 2007 Tomasz Maka <*****@*****.**>\n\n"); fprintf(stderr, "%s: %s [%s]\n\n", _("usage"), argv[0], _("options")); fprintf(stderr, "%s:\n", _("options")); fprintf(stderr, " -cal : %s\n", _("show small calendar window")); exit (-1); } } prefs_read_config (); gtk_init (&argc, &argv); if(check_if_app_is_running() == FALSE) { gtk_set_locale(); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); gui_create_window (); gtk_main (); prefs_write_config (); unlink(prefs_get_config_filename (RUN_FLAG_FILE)); } else { sprintf(tmpbuf, _("Another copy of OSMO is already running or it has been stopped uncleanly (in this case please remove '%s' file and try again)."), prefs_get_config_filename (RUN_FLAG_FILE)); info_dialog = gtk_message_dialog_new (GTK_WINDOW_TOPLEVEL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, tmpbuf); gtk_window_set_title(GTK_WINDOW(info_dialog), _("Error")); gtk_window_set_position(GTK_WINDOW(info_dialog), GTK_WIN_POS_CENTER); gtk_widget_show (info_dialog); gtk_dialog_run(GTK_DIALOG(info_dialog)); gtk_widget_destroy(info_dialog); } return 0; }
void save_game_menu(void) { gui_window *save_win; gui_button *okay_btn; save_session = gui_create_session(); save_win = gui_create_window(250, 250, 300, 100, save_session); okay_btn = gui_create_button(357, 320, 85, 22, "Okay", save_session); gui_button_set_callback(okay_btn, okay_btn_handle); gui_session_show_all(save_session); epiar_render_text(gui_font_normal, white, 0, AFONT_RENDER_BLENDED, screen, 330, 280, "Feature not implemented"); gui_main(save_session); SDL_ShowCursor(1); gui_session_destroy_all(save_session); gui_destroy_session(save_session); }
void demo_init_gui(void) { InitBMPINFO(&icon); LoadBmp(&icon, "icon.bmp"); load_fonts(); gui_desktop_enable(); gui_desktop_set_color(CLRSCR_COLOR2); form = gui_create_widget(GUI_WIDGET_FORM, 180, 120, 632, 500, 0, 0, 0, FORM_STYLE_XP_BORDER|FORM_STYLE_TITLE); if(!form) goto err; gui_form_init_private(form, 128); gui_form_set_caption(form, "控件演示"); gui_form_set_icon(form, &icon); edit = gui_create_widget(GUI_WIDGET_EDIT, 80, 270, 460, 48, color, bkcolor, 0, style); if(!edit) goto err; gui_edit_init_private(edit, 128); gui_edit_set_text(edit, "这是一个文本框"); button = gui_create_widget(GUI_WIDGET_BUTTON, 235+156, 142+100, 236, 32, COLOR_YELLOW, 64, font16, 0); /*BUTTON_STYLE_CLIENT_BDR*/ if(!edit) goto err; gui_button_init_private(button, 128); gui_button_set_caption(button, "将那个Label盖住"); test = gui_create_widget(GUI_WIDGET_EDIT, 80, 330, 460, 32, 0, 0, 0, 0); if(!test) goto err; gui_edit_init_private(test, 128); gui_edit_set_text(test, ""); label = gui_create_widget(GUI_WIDGET_LABEL, 80, 380, 460, 64, COLOR_WHITE, 66, font48, LABEL_STYLE_SUBSIDE); if(!edit) goto err; gui_label_init_private(label, 128); gui_label_set_text(label, "Startting..."); view = gui_create_widget(GUI_WIDGET_VIEW, 80, 48, 460, 200, 0, 0, 0, VIEW_STYLE_NONE_FIRST|VIEW_STYLE_FIELDS_TITLE|VIEW_STYLE_STATISTIC_BAR); if(!view) goto err; init_view(view); progress1 = gui_create_widget(GUI_WIDGET_PROGRESS, 80, 251, 460, 14, 0, 0, 0, PROGRESS_STYLE_BORDER); if(!progress1) goto err; gui_progress_init_private(progress1, 100); dialog = input_dialog_initialize(&abcde); if(!dialog) goto err; gui_widget_link(NULL, form); gui_widget_link(form, view); gui_widget_link(form, edit); gui_widget_link(form, label); gui_widget_link(form, progress1); gui_widget_link(form, test); gui_widget_link(NULL, dialog); gui_widget_link(NULL, button); window1 = gui_create_window(form); gui_show_window(window1); window2 = gui_create_window(dialog); gui_show_window(window2); window3 = gui_create_window(button); gui_show_window(window3); gui_form_set_caption(form, os_get_description()); StartGUI(); err: return; }
int main(int argc, char *argv[]) { DATAFILE *datf; BITMAP *scrFlip; BITMAP *scrMap; PALETTE pal; WINDOW *winInfo; long frames = 0L; float start_time, end_time; MAP *map, *overlay; int x = 0, y = 0; int old_x = -1, old_y = -1; int dx = 1, dy = 1; int view_w, view_h; int do_idle = 1; char s[128]; // Default screen resolution to 320x200. screen_width = 320; screen_height = 200; // Read command line args. Set screen size accordingly. if (argc > 2) { screen_width = atoi(argv[1]); screen_height = atoi(argv[2]); } right_size = 0; bottom_size = 0; printf("screen: %dX%d\n", screen_width, screen_height); // Initialize Allegro. Great library! allegro_init(); install_timer(); install_keyboard(); // Set graphics mode. if (set_gfx_mode(GFX_AUTODETECT, screen_width, screen_height, 0, 0) == -1) { printf("Cannot set video mode to %d, %d.\n", screen_width, screen_height); return 1; } // load comic font from ex4. datf = load_datafile_object("ex.dat", "comic12"); if (datf == NULL) { allegro_exit(); printf("Error loading ex.dat\n"); return 1; } text_mode(-1); // load map //printf("loading map\n"); map = load_map("tile1.wmp", "tile1.spr", pal); if (map == NULL) { allegro_exit(); printf("Error loading map file.\n"); return 1; } // load overlay //printf("loading overlay\n"); overlay = load_map("tile1ovr.wmp", NULL, NULL); if (overlay == NULL) { allegro_exit(); printf("Error loading overlay file.\n"); return 1; } map_settileset(overlay, map->tileset); // Allocate buffers for our rendering. //printf("allocating buffers\n"); scrFlip = create_bitmap(SCREEN_W, SCREEN_H); clear(scrFlip); scrMap = create_bitmap(SCREEN_W + map->t_width*2, SCREEN_H + map->t_height*2); // set palette //printf("setting palette\n"); gui_setpalette(pal); // Build rgb_table. text_mode(makecol8(0, 0, 0)); textout_centre(screen, font, "Building RGB table.", SCREEN_W>>1, 10, 100); create_rgb_table(&rgb_table, pal, rgb_table_callback); rgb_map = &rgb_table; // Build lighting table. text_mode(makecol8(0, 0, 0)); textout_centre(screen, font, "Building lighting table.", SCREEN_W>>1, 10, 100); create_light_table(&light_table, pal, 64, 64, 64, rgb_table_callback); // Build translucency table. text_mode(makecol8(0, 0, 0)); textout_centre(screen, font, "Building translucency table.", SCREEN_W>>1, 10, 100); create_trans_table(&trans_table, pal, 128, 128, 128, rgb_table_callback); color_map = &trans_table; // initialize gui gui_initialize(&light_table, &trans_table); // set map and overlay color tables map_settables(map, &trans_table, &light_table); map_settables(overlay, &trans_table, &light_table); // create info window winInfo = gui_create_window(128, 200, WB_THICK, WD_TRANSLUCENT); gui_move_window(winInfo, SCREEN_W-winInfo->window.w, 0); // set up vars. view_w = scrMap->w/map->t_width; view_h = scrMap->h/map->t_height; // setup time_to_blit interrupt. LOCK_VARIABLE(time_to_blit); LOCK_FUNCTION(time_to_blit_timer); install_int_ex(time_to_blit_timer, BPS_TO_TIMER(30)); missed_frames = 0; // main loop. start_time = clock(); while (1) { idle_time = 0; if (do_idle) while (!time_to_blit) idle_proc(); // lock it in at around 30 fps. time_to_blit = 0; if (idle_time < lowest_idle) lowest_idle = idle_time; if (idle_time > highest_idle) highest_idle = idle_time; // render map if (map_getx_tile(map, x) != old_x || map_gety_tile(map, y) != old_y) { render_map(map, scrMap, 0, 0, x, y, view_w, view_h); render_map(overlay, scrMap, 0, 0, x, y, view_w, view_h); old_x = map_getx_tile(map, x); old_y = map_gety_tile(map, y); } blit(scrMap, scrFlip, map_getx_offset(map, x), map_gety_offset(map, y), 0, 0, SCREEN_W-right_size, SCREEN_H-bottom_size); gui_clear_window(winInfo, makecol8(0, 0, 0)); gui_textout_centre_window(winInfo, "Map Demo", 2, makecol8(255, 0, 0), -1); sprintf(s, "X: %d, Y: %d", x, y); gui_textout_centre_window(winInfo, s, 14, makecol8(0, 0, 255), -1); sprintf(s, "DX: %d, DY: %d", dx, dy); gui_textout_centre_window(winInfo, s, 24, makecol8(0, 0, 255), -1); sprintf(s, "X Ofs: %d", map_getx_offset(map, x)); gui_textout_centre_window(winInfo, s, 34, makecol8(0, 0, 255), -1); sprintf(s, "Y Ofs: %d", map_gety_offset(map, y)); gui_textout_centre_window(winInfo, s, 44, makecol8(0, 0, 255), -1); sprintf(s, "Idle: %d", idle_time); gui_textout_centre_window(winInfo, s, 64, makecol8(0, 255, 255), -1); sprintf(s, "Missed: %d", missed_frames); gui_textout_centre_window(winInfo, s, 74, makecol8(0, 255, 255), -1); gui_draw_window(winInfo, scrFlip); // blit it //vsync(); blit(scrFlip, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); // check keys if (key[KEY_SPACE]) { break; } if (key[KEY_LSHIFT]) do_idle = 0; else do_idle = 1; if (key[KEY_CONTROL]) gui_set_window_styles(winInfo, -1, WD_BLIT); else gui_set_window_styles(winInfo, -1, WD_TRANSLUCENT); if (key[KEY_PGDN]) { dx--; if (dx < 1) dx = 1; dy--; if (dy < 1) dy = 1; } if (key[KEY_PGUP]) { dx++; dy++; } if (key[KEY_RIGHT]) { x+=dx; if (x > (map->w_width-1) - SCREEN_W) { x-=dx; } } if (key[KEY_DOWN]) { y+=dy; if (y > (map->w_height-1) - SCREEN_H) { y-=dy; } } if (key[KEY_LEFT]) { x-=dx; if (x < 0) { x = 0; } } if (key[KEY_UP]) { y-=dy; if (y < 0) { y = 0; } } // Increment frame counter. frames++; } end_time = clock(); // Clean up. unload_datafile_object(datf); destroy_map(map); overlay->tileset=NULL; destroy_map(overlay); destroy_bitmap(scrFlip); destroy_bitmap(scrMap); // Close down allegro. allegro_exit(); // Report. printf("Tile Map, Copyright 1997 by Scott Deming.\n"); printf("\nHow'd we do?\n"); printf("===============================================================================\n"); printf(" Time: %3.2f\n", (float) ((end_time-start_time) / 100)); printf("Frames: %lu\n", frames); printf(" FPS: %3.2f\n", (float) (float) frames / (float) ((end_time-start_time) / 100)); printf("Missed: %d\n", missed_frames); printf(" Idle: %d (lowest was %d, highest %d)\n", idle_time, lowest_idle, highest_idle); printf("Screen: %dX%d\n", screen_width, screen_height); printf("-------------------------------------------------------------------------------\n"); printf("Note: If \"Idle\" starts to get close to zero then things should be done to\n"); printf(" speed things up. When idle proc hits zero, we'll start missing frames\n"); printf(" (indicated by \"Missed\") and things can start to get a bit jerky.\n"); printf(" If \"Missed\" is greater than 0, start optimizing.\n"); printf(" If you turned off the 30 fps timer halt then your lowest idle will be 0.\n"); return 0; }
int main(int argc, char **argv) { GUI *appGUI = NULL; CALENDAR *cal = NULL; TASKS *tsk = NULL; CONTACTS *cnt = NULL; NOTES *nte = NULL; OPTIONS *opt = NULL; GtkWidget *info_dialog; gchar tmpbuf[BUFFER_SIZE]; gint response = -1; struct flock *s_lock = NULL; int fhandle; GOptionContext *cmd_context; gboolean cmd_calendar = FALSE; gboolean cmd_check_events = FALSE; gint cmd_check_ndays_events = 0; gchar *cmd_cfg_path = NULL; gboolean cmd_tiny_gui = FALSE; GOptionEntry cmd_options[] = { { "calendar", 'c', 0, G_OPTION_ARG_NONE, &cmd_calendar, N_("Show small calendar window"), NULL }, { "check", 'e', 0, G_OPTION_ARG_NONE, &cmd_check_events, N_("Check for events since last run"), NULL }, { "days", 'd', 0, G_OPTION_ARG_INT, &cmd_check_ndays_events, N_("Number of days to check forward for events (default: 0)"), NULL }, { "config", 's', 0, G_OPTION_ARG_STRING, &cmd_cfg_path, N_("Set absolute path for settings and data files"), "PATH" }, { "tinygui", 't', 0, G_OPTION_ARG_NONE, &cmd_tiny_gui, N_("Modify GUI to use Osmo on low resolutions"), NULL }, { NULL } }; appGUI = g_new0 (GUI, 1); g_return_val_if_fail (appGUI != NULL, -1); cal = g_new0 (CALENDAR, 1); g_return_val_if_fail (cal != NULL, -1); tsk = g_new0 (TASKS, 1); g_return_val_if_fail (tsk != NULL, -1); cnt = g_new0 (CONTACTS, 1); g_return_val_if_fail (cnt != NULL, -1); nte = g_new0 (NOTES, 1); g_return_val_if_fail (nte != NULL, -1); opt = g_new0 (OPTIONS, 1); g_return_val_if_fail (opt != NULL, -1); /* register modules */ appGUI->cal = cal; appGUI->tsk = tsk; appGUI->cnt = cnt; appGUI->nte = nte; appGUI->opt = opt; appGUI->run_date = utl_get_current_julian (); appGUI->run_time = get_seconds_for_today (); appGUI->key_counter = 0; /* default values */ appGUI->hovering_over_link = FALSE; appGUI->hand_cursor = NULL; appGUI->regular_cursor = NULL; appGUI->gui_url_tag = NULL; appGUI->trayicon_popup_menu = NULL; appGUI->calendar_only = FALSE; appGUI->check_events = FALSE; appGUI->tiny_gui = FALSE; appGUI->save_status = 0; appGUI->print_font_size = 10; appGUI->cal->date = g_date_new (); g_return_val_if_fail (appGUI->cal->date != NULL, -1); g_date_set_time_t (appGUI->cal->date, time (NULL)); appGUI->tsk->id_counter = 0; appGUI->tsk->tasks_panel_status = FALSE; appGUI->tsk->tasks_filter_disabled = FALSE; appGUI->tsk->tasks_list_store = NULL; appGUI->tsk->notifications = NULL; appGUI->cnt->photo_image = NULL; appGUI->cnt->contacts_uim_widget = NULL; appGUI->cnt->contacts_panel_status = FALSE; appGUI->cnt->contacts_filter_disabled = TRUE; appGUI->cnt->export_button = NULL; appGUI->cnt->output_file_entry = NULL; appGUI->opt->options_counter = 0; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); if (argc == 2 && (!strncmp(argv[1], "--help", 6) || (argv[1][0] == '-' && argv[1][1] == '?'))) { fprintf(stderr, "\nOSMO v%s - %s\n", VERSION, _("a handy personal organizer")); fprintf(stderr, "Copyright (c) 2007-2008 Tomasz Maka <*****@*****.**>\n\n"); } cmd_context = g_option_context_new(NULL); g_option_context_add_main_entries(cmd_context, cmd_options, TRANSLATION_DOMAIN); g_option_context_parse(cmd_context, &argc, &argv, NULL); g_option_context_free(cmd_context); appGUI->calendar_only = cmd_calendar; appGUI->check_events = cmd_check_events; appGUI->check_ndays_events = cmd_check_ndays_events; appGUI->config_path = cmd_cfg_path; appGUI->tiny_gui = cmd_tiny_gui; if (prefs_get_config_filename (CONFIG_FILENAME, appGUI) == NULL) { fprintf(stderr, "%s\n", _("ERROR: Cannot create config files")); goto finish; } s_lock = g_new0 (struct flock, 1); s_lock->l_type = F_WRLCK; s_lock->l_whence = SEEK_SET; s_lock->l_start = 0; s_lock->l_len = 0; prefs_read_config (appGUI); close(creat(prefs_get_config_filename (RUN_FLAG_FILE, appGUI), S_IRUSR | S_IWUSR)); /* create lock file */ gtk_init (&argc, &argv); fhandle = open(prefs_get_config_filename (RUN_FLAG_FILE, appGUI), O_RDWR); if (fhandle) { if (fcntl(fhandle, F_SETLK, s_lock) == -1) { close (fhandle); g_snprintf (tmpbuf, BUFFER_SIZE, "%s %s\n\n%s", _("Another copy of OSMO is already running."), _("Simultaneously use two or more copies of OSMO can be a cause of data loss."), _("Do you really want to continue?")); info_dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW_TOPLEVEL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, tmpbuf); gtk_window_set_title(GTK_WINDOW(info_dialog), _("Warning")); gtk_window_set_position(GTK_WINDOW(info_dialog), GTK_WIN_POS_CENTER); gtk_widget_show (info_dialog); response = gtk_dialog_run(GTK_DIALOG(info_dialog)); gtk_widget_destroy(info_dialog); if (response == GTK_RESPONSE_NO || response == GTK_RESPONSE_DELETE_EVENT) { goto finish; } } } notify_init("Osmo notification"); if (appGUI->calendar_only != TRUE) { /* setup timer at 1000ms (1s) interval */ g_timeout_add (1000, (GtkFunction) time_handler, appGUI); } config.run_counter++; if (gui_create_window (appGUI) == TRUE) { gtk_main (); } if (appGUI->calendar_only == FALSE) { config.lastrun_date = utl_get_current_julian (); config.lastrun_time = get_seconds_for_today(); } if (appGUI->check_events == FALSE) { prefs_write_config (appGUI); } if (fhandle) { s_lock->l_type = F_UNLCK; fcntl(fhandle, F_SETLK, s_lock); close (fhandle); } finish: g_date_free (appGUI->cal->date); g_free (opt); g_free (nte); g_free (cnt); g_free (tsk); g_free (cal); g_free (appGUI); g_free (s_lock); return 0; }
int main (int argc, char **argv) { struct timeval timer; gchar buffer[PATH_MAX]; GUI *appGUI = NULL; CHART *chr = NULL; STATISTICS *sts = NULL; TEST *tst = NULL; OPTIONS *opt = NULL; #ifdef MAEMO osso_context_t *osso_context = NULL; /* initialize maemo application */ osso_context = osso_initialize(APP_NAME, APP_VER, TRUE, NULL); if (osso_context == NULL) { fprintf (stderr, "osso_initialize failed.\n"); exit (1); } #endif appGUI = g_new0 (GUI, 1); g_return_val_if_fail (appGUI != NULL, -1); chr = g_new0 (CHART, 1); g_return_val_if_fail (chr != NULL, -1); sts = g_new0 (STATISTICS, 1); g_return_val_if_fail (sts != NULL, -1); tst = g_new0 (TEST, 1); g_return_val_if_fail (tst != NULL, -1); opt = g_new0 (OPTIONS, 1); g_return_val_if_fail (opt != NULL, -1); /* register modules */ appGUI->chr = chr; appGUI->sts = sts; appGUI->tst = tst; appGUI->opt = opt; /* default values */ appGUI->old_kana_type = -1; appGUI->chr->chart_window = NULL; appGUI->tst->any_key = FALSE; appGUI->tst->test_state = FALSE; appGUI->sts->active_tab = -1; appGUI->opt->active_tab = -1; /* preferences update */ g_snprintf (buffer, PATH_MAX, "%s%c%s", g_get_home_dir(), G_DIR_SEPARATOR, CONFIG_DIRNAME); if (g_file_test(buffer, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) != TRUE) { prefs_read_config (CONFIG_FILENAME_OLD, CONFIG_DIRNAME_OLD); prefs_write_config (CONFIG_FILENAME, CONFIG_DIRNAME); if (g_file_test(prefs_get_config_filename (STATS_FILENAME_OLD, CONFIG_DIRNAME_OLD), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) == TRUE) { stats_read_list (STATS_FILENAME_OLD, CONFIG_DIRNAME_OLD, appGUI); } stats_write_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI); } prefs_read_config (CONFIG_FILENAME, CONFIG_DIRNAME); stats_read_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI); /* init */ #ifdef MAEMO hildon_gtk_init (&argc, &argv); #else gtk_init (&argc, &argv); #endif setlocale (LC_ALL, ""); #if defined(WIN32) || defined(WIN64) /* Set the locale directory as subdirectory of application path */ char WINLOCALEDIR[MAX_PATH]; strcpy(WINLOCALEDIR, g_path_get_dirname(argv[0])); strcat(WINLOCALEDIR, "\\share\\locale"); bindtextdomain (PACKAGE, WINLOCALEDIR); #else bindtextdomain (PACKAGE, LOCALEDIR); #endif bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); /* set seed */ gettimeofday(&timer, NULL); #if defined(WIN32) || defined(WIN64) srand((long)time(NULL)); #else srand48(timer.tv_usec + getpid()); #endif #ifdef MAEMO show_splash_screen (); #endif gui_create_window (appGUI); gtk_main (); stats_write_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI); stats_free_list (appGUI); prefs_write_config (CONFIG_FILENAME, CONFIG_DIRNAME); g_free (opt); g_free (tst); g_free (sts); g_free (chr); g_free (appGUI); #ifdef MAEMO /* deinitialize OSSO */ osso_deinitialize (osso_context); #endif return 0; }