Beispiel #1
0
static void
create_same_board (char *fname)
{
	gtk_widget_push_visual (gdk_imlib_get_visual ());
	gtk_widget_push_colormap (gdk_imlib_get_colormap ());

	draw_area = gtk_drawing_area_new ();

        gtk_widget_pop_colormap ();
	gtk_widget_pop_visual ();

	gtk_widget_set_events (draw_area, gtk_widget_get_events (draw_area) | GAME_EVENTS);

	gtk_box_pack_start_defaults (GTK_BOX(vb), draw_area);
	gtk_widget_realize (draw_area);
  
	gtk_widget_show (draw_area);

	load_scenario (fname);
	gtk_drawing_area_size (GTK_DRAWING_AREA (draw_area),
			       STONE_COLS  * STONE_SIZE,
			       STONE_LINES * STONE_SIZE);
	gtk_signal_connect (GTK_OBJECT(draw_area), "event", (GtkSignalFunc) area_event, 0);
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    int has_rc=0;

    GtkWidget *mainWin;
    GtkWidget *table;
    GtkWidget *menu_bar;
    GtkWidget *index_page;
    GtkWidget *button;
    GtkWidget *label, *box, *sbox, *pbox;
    GtkWidget *vseparator;
    GtkWidget *post_process_button;
    GtkStyle *style;

    GtkWidget *gpixmap;
    GdkPixmap *pixmap;
    GdkBitmap *bitmap;
    char title[256];
    char *envhome;

#ifdef ENABLE_NLS
    bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
    textdomain (PACKAGE);
#endif

    signal(SIGSEGV, crash);

#ifdef sun
    __progname = argv[0];
#endif

    Thumbnails.next = NULL;
    Images.next=NULL;

    /* Set the priority (taken from PhotoPC photopc.c) */
#ifdef linux
    if (geteuid() == 0) {
        struct sched_param sp;
        int rc,minp,maxp;

        minp=sched_get_priority_min(SCHED_FIFO);
        maxp=sched_get_priority_max(SCHED_FIFO);
        sp.sched_priority=minp+(maxp-minp)/2;
        if ((rc=sched_setscheduler(0,SCHED_FIFO,&sp)) == -1)
            fprintf(stderr,"failed to set priority\n");
    }
#endif

    filesel_cwd = (char *)malloc(sizeof(char)*1024);
    getcwd(filesel_cwd, 1024);
    strcat(filesel_cwd, "/");

    /* Make sure there's a .gphoto directory in their home ---- */

    envhome = getenv("HOME");
    gphotoDir = (char *)malloc(sizeof(char)*(strlen(envhome)+9));
    memset(gphotoDir, 0, sizeof(char)*(strlen(envhome)+9));
    sprintf(gphotoDir, "%s/.gphoto", envhome);
    (void)mkdir(gphotoDir, 0744);

    /* Command line mode anyone? ----------------------------- */
    if (argc > 1) {
        command_line_mode = 1;
        has_rc = load_config();
        command_line(argc, argv);
    } else
        command_line_mode = 0;


    /* Check for DISPLAY. If not set, exit */
    if (!getenv("DISPLAY")) {
        printf(N_("Error: $DISPLAY variable is not set\n"));
        printf(N_("Please run \"gphoto -h\" for command-line options.\n"));
        _exit(0);
    }

    fprintf(stdout,
            N_("gPhoto %s (%s)\n"),
            VERSION, __DATE__);
    fprintf(stdout,
            N_("Copyright (C) 1998-2000 Scott Fritzinger <*****@*****.**>\n\n"));
    fprintf(stdout,
            N_("Usage: gphoto [-h] [-c] [-n] [-s # filename] [-t # filename]\n"));
    fprintf(stdout, N_("              [-d #] [-p filename] [-l filename]\n"));

    gtk_init(&argc, &argv);
#if 1 /* by fujisawa */
    gdk_imlib_init();
#endif
    gtk_widget_push_visual(gdk_imlib_get_visual());
    gtk_widget_push_colormap(gdk_imlib_get_colormap());

    library_name = gtk_label_new("");

    has_rc = load_config();

    /* set up the main window -------------------------------- */
    mainWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_container_border_width(GTK_CONTAINER(mainWin), 0);
    sprintf(title, "gPhoto %s", VERSION);
    gtk_window_set_title(GTK_WINDOW(mainWin), title);
    gtk_signal_connect(GTK_OBJECT(mainWin), "delete_event",
                       GTK_SIGNAL_FUNC(delete_event), NULL);
    gtk_widget_set_usize(mainWin, 730, 480);
    gtk_widget_realize(mainWin);

    /* set up the menu --------------------------------------- */
    menu_bar = gtk_vbox_new(FALSE, 0);
    create_menu(menu_bar);
    gtk_widget_show_all(menu_bar);

    /* button bar -------------------------------------------- */
    box = gtk_hbox_new(FALSE, 0);
    create_toolbar(box, mainWin);
    gtk_widget_show(box);
    gtk_container_border_width(GTK_CONTAINER(box), 5);

    /* accelerator keys--------------------------------------- */
    gtk_accel_group_attach(mainag,GTK_OBJECT(mainWin));

    /* Index Page notebook ----------------------------------- */
    index_page = gtk_table_new(1,1,FALSE);
    gtk_widget_show(index_page);
    index_window = gtk_scrolled_window_new(NULL,NULL);
    index_vp=gtk_viewport_new(NULL,NULL);
    gtk_container_add(GTK_CONTAINER(index_window), index_vp);
    gtk_widget_show(index_vp);
    gtk_widget_show(index_window);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(index_window),
                                   GTK_POLICY_AUTOMATIC,
                                   GTK_POLICY_AUTOMATIC);
    gtk_table_attach_defaults(GTK_TABLE(index_page),index_window,0,1,0,1);

    notebook = gtk_notebook_new();
    gtk_widget_show(notebook);
    gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);

    label = gtk_label_new(N_("Image Index"));
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), index_page,
                             label);

    sbox = gtk_hbox_new(FALSE, 5);
    gtk_widget_show(sbox);

    status_bar = gtk_label_new("");
    gtk_widget_show(status_bar);
    gtk_label_set_justify(GTK_LABEL(status_bar), GTK_JUSTIFY_LEFT);
    gtk_box_pack_start(GTK_BOX(sbox), status_bar, FALSE, FALSE, 0);
    update_status("Select \"Camera->Download Index->Thumbnails\" to begin.");
    progress = gtk_progress_bar_new();

    gtk_widget_show(progress);
    gtk_box_pack_end(GTK_BOX(sbox), progress, FALSE, FALSE, 0);

    vseparator = gtk_vseparator_new();
    gtk_widget_show(vseparator);
    gtk_box_pack_end(GTK_BOX(sbox), vseparator, FALSE, FALSE, 0);

    post_process = 0;
    post_process_button = gtk_button_new();
    gtk_widget_show(post_process_button);
    gtk_button_set_relief(GTK_BUTTON(post_process_button),GTK_RELIEF_NONE);
    gtk_signal_connect (GTK_OBJECT(post_process_button), "clicked",
                        GTK_SIGNAL_FUNC(post_process_change), mainWin);
    gtk_box_pack_end(GTK_BOX(sbox), post_process_button, FALSE, FALSE, 0);

    pbox = gtk_hbox_new(FALSE, 3);
    gtk_widget_show(pbox);
    gtk_container_add(GTK_CONTAINER(post_process_button), pbox);

    style = gtk_widget_get_style(mainWin);
    pixmap = gdk_pixmap_create_from_xpm_d(mainWin->window, &bitmap,
                                          &style->bg[GTK_STATE_NORMAL],(gchar **)post_processing_off_xpm);
    post_process_pixmap = gtk_pixmap_new(pixmap, bitmap);
    gtk_widget_show(post_process_pixmap);
    gtk_box_pack_start(GTK_BOX(pbox),post_process_pixmap,FALSE,FALSE,0);

    label = gtk_label_new("Post Process");
    gtk_widget_show(label);
    gtk_box_pack_start(GTK_BOX(pbox),label,FALSE,FALSE,0);

    vseparator = gtk_vseparator_new();
    gtk_widget_show(vseparator);
    gtk_box_pack_end(GTK_BOX(sbox), vseparator, FALSE, FALSE, 0);

    gtk_widget_show(library_name);
    /*	gtk_widget_set_usize(library_name, 200, 16);*/
    gtk_label_set_justify(GTK_LABEL(library_name), GTK_JUSTIFY_LEFT);
    button = gtk_button_new();
    gtk_widget_show(button);
    gtk_button_set_relief(GTK_BUTTON(button),GTK_RELIEF_NONE);
    gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
                              GTK_SIGNAL_FUNC(port_dialog), NULL);
    gtk_container_add(GTK_CONTAINER(button), library_name);
    gtk_box_pack_end(GTK_BOX(sbox), button, FALSE, FALSE, 0);

    pixmap = gdk_pixmap_create_from_xpm_d(mainWin->window, &bitmap,
                                          &style->bg[GTK_STATE_NORMAL],
                                          (gchar **)splash_xpm);
    gpixmap = gtk_pixmap_new(pixmap, bitmap);
    gtk_widget_show(gpixmap);

    /* Main window layout ------------------------------------ */
    table =gtk_table_new(4,1,FALSE);
    gtk_container_add(GTK_CONTAINER(mainWin), table);
    gtk_widget_show(table);
    gtk_table_attach(GTK_TABLE(table),menu_bar, 0, 1, 0, 1,
                     GTK_FILL|GTK_EXPAND, GTK_FILL, 0 , 0);
    gtk_table_attach(GTK_TABLE(table), box, 0, 1, 1, 2,
                     GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
    gtk_table_attach_defaults(GTK_TABLE(table),notebook, 0, 1, 2, 3);
    gtk_table_attach(GTK_TABLE(table),sbox, 0, 1, 3, 4,
                     GTK_FILL|GTK_EXPAND, GTK_FILL, 0 , 0);

    index_table = gtk_hbox_new(FALSE, 0);
    gtk_widget_show(index_table);
    gtk_container_add( GTK_CONTAINER(index_vp), index_table);

    gtk_box_pack_start(GTK_BOX(index_table), gpixmap, TRUE, FALSE, 0);

    /* If not command-line mode... --------------------------- */
    gtk_widget_show(mainWin);
    if (!has_rc) {
        /* put anything here to do on the first run */
        developer_dialog_create();
        error_dialog(
            "Could not load config file.\n"
            "Resetting to defaults.\n"
            "Click on \"Select Port-Camera Model\n"
            "in the Configure menu to set your\n"
            "camera model and serial port\n");
    }
    gtk_main();
    return 0;
}
Beispiel #3
0
GtkWidget *
ghack_init_map_window()
{
    GtkWidget *vbox;
    GtkWidget *hbox;
    GtkWidget *table;
    GtkWidget *frame;
    GtkWidget *w;
    GtkWidget *hSeparator;
    GtkAdjustment *adj;
    GnomeCanvasImage *bg;
    double width, height, x, y;
    int i;

    width = COLNO * ghack_glyph_width();
    height = ROWNO * ghack_glyph_height();

    vbox = gtk_vbox_new(FALSE, 4);
    gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
    gtk_widget_show(vbox);

    /* Add in a horiz seperator */
    hSeparator = gtk_hseparator_new();
    gtk_box_pack_start(GTK_BOX(vbox), hSeparator, FALSE, FALSE, 2);
    gtk_widget_show(hSeparator);

    hbox = gtk_hbox_new(FALSE, 4);
    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
    gtk_widget_show(hbox);

    /* Create the Zoom spinbutton.
    */
    ghack_map.zoom = 1.0;
    w = gtk_label_new("Zoom:");
    gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0);
    gtk_widget_show(w);
    adj =
        GTK_ADJUSTMENT(gtk_adjustment_new(1.00, 0.5, 3.00, 0.05, 0.50, 0.50));
    w = gtk_spin_button_new(adj, 0.5, 2);
    gtk_widget_set_usize(w, 50, 0);
    gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0);
    gtk_widget_show(w);

    /* Canvas and scrollbars
    */
    gtk_widget_push_visual(gdk_imlib_get_visual());
    gtk_widget_push_colormap(gdk_imlib_get_colormap());
    ghack_map.canvas = GNOME_CANVAS(gnome_canvas_new());
    // gtk_widget_push_visual(gdk_rgb_get_visual());
    // gtk_widget_push_colormap(gdk_rgb_get_cmap());
    // ghack_map.canvas = GNOME_CANVAS (gnome_canvas_new_aa());

    gtk_widget_pop_colormap();
    gtk_widget_pop_visual();
    gtk_widget_show(GTK_WIDGET(ghack_map.canvas));

    table = gtk_table_new(2, 2, FALSE);
    gtk_table_set_row_spacings(GTK_TABLE(table), 4);
    gtk_table_set_col_spacings(GTK_TABLE(table), 4);
    gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
    gtk_widget_show(table);

    frame = gtk_frame_new(NULL);
    ghack_map.frame = frame;
    gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
    gtk_table_attach(GTK_TABLE(table), frame, 0, 1, 0, 1,
                     GTK_EXPAND | GTK_FILL | GTK_SHRINK,
                     GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0);
    gtk_widget_show(frame);

    gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(ghack_map.canvas));
    gnome_canvas_set_scroll_region(GNOME_CANVAS(ghack_map.canvas), 0, 0,
                                   width + 2 * ghack_glyph_width(),
                                   height + 2 * ghack_glyph_height());

    gnome_canvas_set_pixels_per_unit(GNOME_CANVAS(ghack_map.canvas), 1.0);

    w = gtk_hscrollbar_new(GTK_LAYOUT(ghack_map.canvas)->hadjustment);
    gtk_table_attach(GTK_TABLE(table), w, 0, 1, 1, 2,
                     GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL, 0, 0);
    gtk_widget_show(w);

    w = gtk_vscrollbar_new(GTK_LAYOUT(ghack_map.canvas)->vadjustment);
    gtk_table_attach(GTK_TABLE(table), w, 1, 2, 0, 1, GTK_FILL,
                     GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0);
    gtk_widget_show(w);

    myCanvasGroup = GNOME_CANVAS_GROUP(gnome_canvas_item_new(
                                           gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)),
                                           gnome_canvas_group_get_type(), "x", 0.0, "y", 0.0, NULL));

    /* Tile the map background with a pretty image */
    background = gdk_imlib_load_image((char *) "mapbg.xpm");
    if (background == NULL) {
        g_warning(
            "Bummer! Failed to load the map background image (mapbg.xpm)!");
    } else {
        gdk_imlib_render(background, background->rgb_width,
                         background->rgb_height);

        /* Tile the map background */
        for (y = 0; y < height + background->rgb_height;
                y += background->rgb_height) {
            for (x = 0; x < width + background->rgb_width;
                    x += background->rgb_width) {
                bg = GNOME_CANVAS_IMAGE(gnome_canvas_item_new(
                                            myCanvasGroup, gnome_canvas_image_get_type(), "x",
                                            (double) x, "y", (double) y, "width",
                                            (double) background->rgb_width, "height",
                                            (double) background->rgb_height, "image", background,
                                            "anchor", (GtkAnchorType) GTK_ANCHOR_CENTER, NULL));
                gnome_canvas_item_lower_to_bottom(GNOME_CANVAS_ITEM(bg));
            }
        }
    }

    /* ghack_map.map is an array of canvas images.  Each cell of
     * the array will contain one tile.  Here, we create the
     * space for the cells and then create the cells for easy
     * access later.
    */
    for (i = 0, y = 0; y < height; y += ghack_glyph_height()) {
        for (x = 0; x < width; x += ghack_glyph_width()) {
            ghack_map.map[i++] = GNOME_CANVAS_IMAGE(gnome_canvas_item_new(
                    myCanvasGroup, gnome_canvas_image_get_type(), "x", (double) x,
                    "y", (double) y, "width", (double) ghack_glyph_width(),
                    "height", (double) ghack_glyph_height(), "anchor",
                    GTK_ANCHOR_NORTH_WEST, NULL));
        }
    }

    /* Set up the pet mark image */
    petmark = gdk_imlib_create_image_from_xpm_data(pet_mark_xpm);
    if (petmark == NULL) {
        g_warning("Bummer! Failed to load the pet_mark image!");
    } else {
        gdk_imlib_render(petmark, petmark->rgb_width, petmark->rgb_height);

        /* ghack_map.overlay is an array of canvas images used to
         * overlay tile images...
         */
        for (i = 0, y = 0; y < height; y += ghack_glyph_height()) {
            for (x = 0; x < width; x += ghack_glyph_width()) {
                ghack_map.overlay[i] =
                    GNOME_CANVAS_IMAGE(gnome_canvas_item_new(
                                           myCanvasGroup, gnome_canvas_image_get_type(), "x",
                                           (double) x, "y", (double) y, "width",
                                           (double) petmark->rgb_width, "height",
                                           (double) petmark->rgb_height, "image", petmark,
                                           "anchor", GTK_ANCHOR_NORTH_WEST, NULL));
                gnome_canvas_item_lower_to_bottom(
                    GNOME_CANVAS_ITEM(ghack_map.overlay[i++]));
            }
        }
    }

    /* Resize the canvas when the spinbutton changes
    */
    gtk_signal_connect(GTK_OBJECT(adj), "value_changed",
                       (GtkSignalFunc) ghack_map_window_zoom,
                       ghack_map.canvas);

    /* Game signals
    */
    gtk_signal_connect(GTK_OBJECT(vbox), "ghack_curs",
                       GTK_SIGNAL_FUNC(ghack_map_cursor_to), NULL);
    gtk_signal_connect(GTK_OBJECT(vbox), "ghack_putstr",
                       GTK_SIGNAL_FUNC(ghack_map_putstr), NULL);
    gtk_signal_connect(GTK_OBJECT(vbox), "ghack_print_glyph",
                       GTK_SIGNAL_FUNC(ghack_map_print_glyph), NULL);
    gtk_signal_connect(GTK_OBJECT(vbox), "ghack_clear",
                       GTK_SIGNAL_FUNC(ghack_map_clear), NULL);
    gtk_signal_connect(GTK_OBJECT(vbox), "ghack_display",
                       GTK_SIGNAL_FUNC(ghack_map_display), NULL);
    gtk_signal_connect(GTK_OBJECT(vbox), "ghack_cliparound",
                       GTK_SIGNAL_FUNC(ghack_map_cliparound), NULL);
    gtk_signal_connect(GTK_OBJECT(ghack_map.canvas), "button_press_event",
                       GTK_SIGNAL_FUNC(ghack_handle_button_press), NULL);
    gtk_signal_connect(GTK_OBJECT(ghack_map.canvas), "gnome_delay_output",
                       GTK_SIGNAL_FUNC(ghack_delay), NULL);

    return GTK_WIDGET(vbox);
}