Exemple #1
0
void
ghack_map_clear(GtkWidget *win, gpointer data)
{
    int i;

    for (i = 0; i < ROWNO * COLNO; i++) {
        if (GNOME_IS_CANVAS_IMAGE(ghack_map.map[i])) {
            gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ghack_map.map[i]));
        }
        if (GNOME_IS_CANVAS_IMAGE(ghack_map.overlay[i])) {
            gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ghack_map.overlay[i]));
        }
    }
    gnome_canvas_update_now(GNOME_CANVAS(ghack_map.canvas));
}
Exemple #2
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();
}
Exemple #3
0
static int canvasFunc( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   const char *cmds[] = { "delete", "configure", "cget", "isMapped",
         "getCurrentSize", "update", "raise", "lower", 
         "create", "itemDelete", "itemShow",
         "itemConfigure", "itemCget", "itemCommand", 
         "affine", "scale", "move", "rotate",
         "windowToCanvas", "canvasToWindow",
         "findItemAt", "getBounds", "findWithTag",
         NULL };
   enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx, IsMappedIdx,
         GetCurSizeIdx, UpdateIdx, RaiseIdx, LowerIdx,
         CreateIdx, ItemDeleteIdx, ItemShowIdx,
         ItemConfigureIdx, ItemCgetIdx, ItemCommandIdx, 
         AffineIdx, ScaleIdx, MoveIdx, RotateIdx,
         WindowToCanvasIdx, CanvasToWindowIdx,
         FindItemAtIdx, GetBoundsIdx, GetIDsFromTagIdx };
   CanvasParams *para = (CanvasParams *)data;
   GtkWidget    *widget = GTK_WIDGET( para->canvas );
   int idx;

   if( objc < 2 )
   {
      Tcl_WrongNumArgs( interp, 1, objv, "command" );
      return TCL_ERROR;
   }

   if( Tcl_GetIndexFromObj( interp, objv[1], cmds, "command", 
         TCL_EXACT, &idx ) != TCL_OK )
      return TCL_ERROR;

   switch( idx )
   {
      case DeleteIdx:
            return gnoclDelete( interp, widget, objc, objv );

      case ConfigureIdx:
            {
               int ret = TCL_ERROR;
               if( gnoclParseAndSetOptions( interp, objc - 1, objv + 1, 
                     canvasOptions, G_OBJECT( widget ) ) == TCL_OK )
               {

                  if( canvasOptions[antialiasedIdx].status 
                        == GNOCL_STATUS_CHANGED )
                  {
                     Tcl_SetResult( interp, "antialiasing cannot be changed "
                           "after creation", TCL_STATIC );
                  }
                  else
                     ret = configure( interp, para, canvasOptions );
               }
               gnoclClearOptions( canvasOptions );
               return ret;
            }
            break;
      case CgetIdx:
            {
               int     idx;
               switch( gnoclCget( interp, objc, objv, G_OBJECT( widget ), 
                     canvasOptions, &idx ) )
               {
                  case GNOCL_CGET_ERROR:  
                           return TCL_ERROR;
                  case GNOCL_CGET_HANDLED:
                           return TCL_OK;
                  case GNOCL_CGET_NOTHANDLED:
                           return cget( interp, para->canvas, 
                                 canvasOptions, idx );
               }
               break;
            }
      case IsMappedIdx:
            return isMapped( interp, widget, objc, objv );
      case GetCurSizeIdx:
            return getCurSize( interp, widget, objc, objv );
      case UpdateIdx:
            if( objc != 2 )
            {
               Tcl_WrongNumArgs( interp, 2, objv, NULL );
               return TCL_ERROR;
            }
            gnome_canvas_update_now( para->canvas );
            break;
      case CreateIdx:
            return canvasCreateItem( interp, objc, objv, para );
      case RaiseIdx:
      case LowerIdx:
      case ItemDeleteIdx:
      case ItemShowIdx:
      case ItemConfigureIdx:
      case ItemCgetIdx:
      case ItemCommandIdx:
      case AffineIdx:
      case ScaleIdx:
      case MoveIdx:
      case RotateIdx:
      case GetBoundsIdx:
      case GetIDsFromTagIdx:
            {
               GPtrArray *items;
               int       ret;

               if( objc < 3 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, 
                        "tag-or-id ?option val ...?" );
                  return TCL_ERROR;
               }
               if( gnoclCanvasItemsFromTagOrId( interp, para, 
                     Tcl_GetString( objv[2] ), &items ) != TCL_OK )
                  return TCL_ERROR;

               switch( idx )
               {
                  case RaiseIdx:
                  case LowerIdx:
                     ret = itemRaise( interp, objc, objv, para, items,
                           idx == RaiseIdx );
                     break;
                  case ItemDeleteIdx:
                     ret = itemDelete( interp, objc, objv, para, items );
                     break;
                  case ItemShowIdx:
                     ret = itemShow( interp, objc, objv, para, items );
                     break;
                  case ItemConfigureIdx:
                     ret = itemConfigure( interp, objc, objv, para, items );
                     break;
                  case ItemCgetIdx:
                     ret = itemCget( interp, objc, objv, para, items );
                     break;
                  case ItemCommandIdx:
                     ret = itemCommand( interp, objc, objv, para, items );
                     break;
                  case AffineIdx:
                     ret = affine( interp, objc, objv, para, items, Affine );
                     break;
                  case ScaleIdx:
                     ret = affine( interp, objc, objv, para, items, Scale );
                     break;
                  case MoveIdx:
                     ret = affine( interp, objc, objv, para, items, Move );
                     break;
                  case RotateIdx:
                     ret = affine( interp, objc, objv, para, items, Rotate );
                     break;
                  case GetBoundsIdx:
                     ret = itemBounds( interp, objc, objv, para, items );
                     break;
                  case GetIDsFromTagIdx:
                     ret = getIDs( interp, objc, objv, para, items );
                     break;
                  default:
                     assert( 0 );
               }
               if( items )
                  g_ptr_array_free( items, 0 );
               return ret;
            }
            break; 
      case WindowToCanvasIdx:
            return windowToCanvas( interp, objc, objv, para, 0 );
      case CanvasToWindowIdx:
            return windowToCanvas( interp, objc, objv, para, 1 );
      case FindItemAtIdx:
            return findItemAt( interp, objc, objv, para );
   }

   return TCL_OK;
}