Exemplo n.º 1
0
static gboolean
bst_canvas_link_child_event (GnomeCanvasItem *item,
			     GdkEvent        *event)
{
  BstCanvasLink *clink;
  GtkWidget *widget = GTK_WIDGET (item->canvas);
  gboolean handled = FALSE;
  
  clink = BST_CANVAS_LINK (item);

  switch (event->type)
    {
    case GDK_ENTER_NOTIFY:
      if (!GTK_WIDGET_HAS_FOCUS (widget))
	gtk_widget_grab_focus (widget);
      handled = TRUE;
      break;
    case GDK_LEAVE_NOTIFY:
      handled = TRUE;
      break;
    case GDK_KEY_PRESS:
      switch (event->key.keyval)
	{
	case 'L':
	  gnome_canvas_item_lower (item, 1);
	  GNOME_CANVAS_NOTIFY (item);
	  break;
	case 'l':
	  gnome_canvas_item_lower_to_bottom (item);
	  GNOME_CANVAS_NOTIFY (item);
	  break;
	case 'R':
	  gnome_canvas_item_raise (item, 1);
	  GNOME_CANVAS_NOTIFY (item);
	  break;
	case 'r':
	  gnome_canvas_item_raise_to_top (item);
	  GNOME_CANVAS_NOTIFY (item);
	  break;
	}
      handled = TRUE;
      break;
    case GDK_KEY_RELEASE:
      handled = TRUE;
      break;
    default:
      break;
    }
  
  return handled;
}
Exemplo n.º 2
0
static int itemRaise( Tcl_Interp *interp, int objc, Tcl_Obj * const objv[], 
      CanvasParams *param, GPtrArray *items, int isRaise )
{
   int k;
   int position = 0;
   if( objc == 4 )
   {
      if( Tcl_GetIntFromObj( interp, objv[3], &position ) != TCL_OK )
         return TCL_ERROR;
      if( position == 0 )
         return TCL_OK;
      if( position < 0 )
      {
         position *= -1;
         isRaise = !isRaise;
      }
   }
   else if( objc > 4 )
   {
      Tcl_WrongNumArgs( interp, 3, objv, "?position?" );
      return TCL_ERROR;
   }

   if( items != NULL )
   {
      for( k = 0; k < items->len; ++k )
      {
         Gnocl_CanvasItemInfo *info = GET_INFO( items, k );
         if( isRaise )
         {
         /* TODO: with libgnomecanvas-2.2.1 raise_to_top works exactly once */
            if( objc == 3 )
               gnome_canvas_item_raise_to_top( info->item ); 
            else
               gnome_canvas_item_raise( info->item, position );
         }
         else
         {
            if( objc == 3 )
               gnome_canvas_item_lower_to_bottom( info->item );
            else
               gnome_canvas_item_lower( info->item, position );
         }
      }
   }

   return TCL_OK;
}
Exemplo n.º 3
0
static gboolean
bst_canvas_source_child_event (BstCanvasSource *csource,
			       GdkEvent        *event,
			       GnomeCanvasItem *child)
{
  GnomeCanvasItem *item = GNOME_CANVAS_ITEM (csource);
  GtkWidget *widget = GTK_WIDGET (item->canvas);
  gboolean handled = FALSE;
  
  csource = BST_CANVAS_SOURCE (item);

  switch (event->type)
    {
    case GDK_ENTER_NOTIFY:
      if (!GTK_WIDGET_HAS_FOCUS (widget))
	gtk_widget_grab_focus (widget);
      handled = TRUE;
      break;
    case GDK_LEAVE_NOTIFY:
      handled = TRUE;
      break;
    case GDK_KEY_PRESS:
      switch (event->key.keyval)
	{
	case 'L':
	case 'l':
	  gnome_canvas_item_lower_to_bottom (item);
	  GNOME_CANVAS_NOTIFY (item);
	  break;
	case 'R':
	case 'r':
	  gnome_canvas_item_raise_to_top (item);
	  GNOME_CANVAS_NOTIFY (item);
	  break;
	}
      handled = TRUE;
      break;
    case GDK_KEY_RELEASE:
      handled = TRUE;
      break;
    default:
      break;
    }
  
  return handled;
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
void
ghack_reinit_map_window()
{
    GnomeCanvasImage *bg;
    double width, height, x, y;
    int i;

    /* ghack_map_clear(NULL, NULL); */

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

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

    /* remove everything currently in the canvas map */
    gtk_object_destroy(GTK_OBJECT(myCanvasGroup));

    /* Put some groups back */
    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 */
    if (background != NULL) {
        /* 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));
        }
    }

    if (petmark != NULL) {
        /* 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++]));
            }
        }
    }

    ghack_map_cliparound(NULL, u.ux, u.uy, NULL);
    ghack_map_cursor_to(NULL, u.ux, u.uy, NULL);
    gnome_canvas_update_now(ghack_map.canvas);
    doredraw();
}