/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * 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.
 */
#ifndef __GDISPLAY_H__
#define __GDISPLAY_H__

#include "gimage.h"
#include "info_dialog.h"
#include "selection.h"

/*
 *  Global variables
 *
 */

/*  some useful macros  */

#define  SCALESRC(g)    (g->scale & 0x00ff)
#define  SCALEDEST(g)   (g->scale >> 8)
#define  SCALE(g,x)     ((x * SCALEDEST(g)) / SCALESRC(g))
#define  UNSCALE(g,x)   ((x * SCALESRC(g)) / SCALEDEST(g))

#define LOWPASS(x) ((x>0) ? x : 0)
#define HIGHPASS(x,y) ((x>y) ? y : x)


typedef enum
{
  SelectionOff,
  SelectionLayerOff,
  SelectionOn,
  SelectionPause,
  SelectionResume
} SelectionControl;

typedef struct frame_manager_t frame_manager_t;
typedef struct base_frame_manager base_frame_manager;

typedef struct GDisplay GDisplay;
struct GDisplay
{
  int ID;                         /*  ID of the image referenced by this 
				   *  display.  *Not unique*, since many
				   *  displaus can reference the same image.  */
  int unique_id;                  /* A *unique* id for this display           */

  GtkWidget *shell;               /*  shell widget for this gdisplay          */
  GtkWidget *canvas;              /*  canvas widget for this gdisplay         */
  GtkWidget *hsb, *vsb;           /*  widgets for scroll bars                 */
  GtkWidget *hrule, *vrule;       /*  widgets for rulers                      */
  GtkWidget *origin;              /*  widgets for rulers                      */
  GtkWidget *popup;               /*  widget for popup menu                   */
  GtkWidget *menubar;             /*  widget for menubar across the top       */
  GtkItemFactory *menubar_fac;    /*  Factory for menubar                     */
 
  GtkWidget *statusarea;          /*  hbox holding the statusbar and stuff    */
  GtkWidget *statusbar;           /*  widget for statusbar		      */ 

  InfoDialog *window_info_dialog; /*  dialog box for image information        */

  GtkAdjustment *hsbdata;         /*  horizontal data information             */
  GtkAdjustment *vsbdata;         /*  vertical data information               */

  GImage *gimage;	          /*  pointer to the associated gimage struct */
  int instance;                   /*  the instance # of this gdisplay as      */
                                  /*  taken from the gimage at creation       */

  int depth;   		          /*  depth of our drawables                  */
  int disp_width;                 /*  width of drawing area in the window     */
  int disp_height;                /*  height of drawing area in the window    */
  int disp_xoffset;
  int disp_yoffset;

  int offset_x, offset_y;         /*  offset of display image into raw image  */
  int scale;        	          /*  scale factor from original raw image    */

/* from gimp 1.2.4 */
  gboolean dot_for_dot;		  /*  is monitor resolution being ignored?    */

  short draw_guides;              /*  should the guides be drawn?             */
  short snap_to_guides;           /*  should the guides be snapped to?        */

  Selection *select;              /*  Selection object                        */

  GdkGC *scroll_gc;               /*  GC for scrolling */

  GSList *update_areas;           /*  Update areas list                       */
  GSList *display_areas;          /*  Display areas list                      */

  GdkCursorType current_cursor;   /*  Currently installed cursor              */

 
   short draw_cursor;		  /* should we draw software cursor ? */
   int cursor_x;			  /* software cursor X value */
   int cursor_y;			  /* software cursor Y value */
   short proximity;		  /* is a device in proximity of gdisplay ? */
   short have_cursor;		  /* is cursor currently drawn ? */

  char framemanager;		  /* is one if the display has a frame_manager
				     associated with it */

  frame_manager_t *frame_manager; /* link to the frame manager */ 
  
  base_frame_manager *bfm; 	  /* link to the frame manager */ 
};

extern GSList *display_list;


/* member function declarations */

GDisplay * gdisplay_new                    (GImage *, unsigned int);
GDisplay * gdisplay_fm                     (GImage *, unsigned int, GDisplay*);
void       gdisplay_remove_and_delete      (GDisplay *);
gfloat     gdisplay_mask_value             (GDisplay *, int, int);
int        gdisplay_mask_bounds            (GDisplay *, int *, int *, int *, int *);
void       gdisplay_transform_coords       (GDisplay *, int, int, int *, int *, int);
void       gdisplay_untransform_coords     (GDisplay *, int, int, int *,
					    int *, int, int);
void       gdisplay_transform_coords_f     (GDisplay *, double, double, double *,
					    double *, int);
void       gdisplay_untransform_coords_f   (GDisplay *, double, double, double *,
					    double *, int);
void       gdisplay_install_tool_cursor    (GDisplay *, GdkCursorType);
void       gdisplay_remove_tool_cursor     (GDisplay *);
void       gdisplay_set_menu_sensitivity   (GDisplay *);
void       gdisplay_expose_area            (GDisplay *, int, int, int, int);
void       gdisplay_expose_guide           (GDisplay *, Guide *);
void       gdisplay_expose_full            (GDisplay *);
void       gdisplay_flush                  (GDisplay *);
void       gdisplay_draw_guides            (GDisplay *);
void       gdisplay_draw_guide             (GDisplay *, Guide *, int);
Guide*     gdisplay_find_guide             (GDisplay *, int, int);
void       gdisplay_snap_point             (GDisplay *, double , double, double *, double *);
void       gdisplay_snap_rectangle         (GDisplay *, int, int, int, int, int *, int *);
void	   gdisplay_update_cursor	   (GDisplay *, int, int);

/*  function declarations  */

GDisplay * gdisplay_get_from_gimage        (GImage *image);
GDisplay * gdisplay_active                 (void);
GDisplay * gdisplay_get_ID                 (int);
GDisplay * gdisplay_get_unique_id          (int);
void       gdisplays_update_title          (int);
void       gdisplay_add_update_area  (GDisplay *, int, int, int, int);
void       gdisplays_update_area           (int, int, int, int, int);
void       gdisplays_expose_guides         (int);
void       gdisplays_expose_guide          (int, Guide *);
void       gdisplays_update_full           (int);
void       gdisplays_shrink_wrap           (int);
void       gdisplays_expose_full           (void);
void       gdisplays_selection_visibility  (int, SelectionControl);
int        gdisplays_dirty                 (void);
void       gdisplays_delete                (void);
void 	   gdisplays_delete_image 	   (GImage *image);
void       gdisplays_flush                 (void);

GDisplay* gdisplay_find_display (int ID);


#endif /*  __GDISPLAY_H__  */
