src/viewport.h
changeset 8224 c5a64d87cc54
parent 8223 2f64b8462e66
child 8225 cd84a95b6630
equal deleted inserted replaced
8223:2f64b8462e66 8224:c5a64d87cc54
     1 /* $Id$ */
       
     2 
       
     3 /** @file viewport.h */
       
     4 
       
     5 #ifndef VIEWPORT_H
       
     6 #define VIEWPORT_H
       
     7 
       
     8 #include "zoom_type.h"
       
     9 #include "window_type.h"
       
    10 #include "vehicle_type.h"
       
    11 #include "gfx_func.h"
       
    12 #include "gui.h"
       
    13 
       
    14 struct ViewPort {
       
    15 	int left,top;                       // screen coordinates for the viewport
       
    16 	int width, height;                  // screen width/height for the viewport
       
    17 
       
    18 	int virtual_left, virtual_top;      // virtual coordinates
       
    19 	int virtual_width, virtual_height;  // these are just width << zoom, height << zoom
       
    20 
       
    21 	ZoomLevel zoom;
       
    22 };
       
    23 
       
    24 void SetSelectionRed(bool);
       
    25 
       
    26 /* viewport.cpp */
       
    27 void InitViewports();
       
    28 void DeleteWindowViewport(Window *w);
       
    29 void AssignWindowViewport(Window *w, int x, int y,
       
    30 	int width, int height, uint32 follow_flags, ZoomLevel zoom);
       
    31 ViewPort *IsPtInWindowViewport(const Window *w, int x, int y);
       
    32 Point GetTileBelowCursor();
       
    33 void UpdateViewportPosition(Window *w);
       
    34 
       
    35 enum {
       
    36 	ZOOM_IN   = 0,
       
    37 	ZOOM_OUT  = 1,
       
    38 	ZOOM_NONE = 2, // hack, used to update the button status
       
    39 };
       
    40 
       
    41 bool DoZoomInOutWindow(int how, Window *w);
       
    42 void ZoomInOrOutToCursorWindow(bool in, Window * w);
       
    43 Point GetTileZoomCenterWindow(bool in, Window * w);
       
    44 void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out);
       
    45 
       
    46 static inline void MaxZoomInOut(int how, Window *w)
       
    47 {
       
    48 	while (DoZoomInOutWindow(how, w)) {};
       
    49 }
       
    50 
       
    51 /**
       
    52  * Some values for constructing bounding boxes (BB). The Z positions under bridges are:
       
    53  * z=0..5  Everything that can be built under low bridges.
       
    54  * z=6     reserved, currently unused.
       
    55  * z=7     Z separator between bridge/tunnel and the things under/above it.
       
    56  */
       
    57 enum {
       
    58 	BB_HEIGHT_UNDER_BRIDGE = 6, ///< Everything that can be built under low bridges, must not exceed this Z height.
       
    59 	BB_Z_SEPARATOR  = 7,        ///< Separates the bridge/tunnel from the things under/above it.
       
    60 };
       
    61 
       
    62 void OffsetGroundSprite(int x, int y);
       
    63 
       
    64 void DrawGroundSprite(SpriteID image, SpriteID pal, const SubSprite *sub = NULL);
       
    65 void DrawGroundSpriteAt(SpriteID image, SpriteID pal, int32 x, int32 y, byte z, const SubSprite *sub = NULL);
       
    66 void AddSortableSpriteToDraw(SpriteID image, SpriteID pal, int x, int y, int w, int h, int dz, int z, bool transparent = false, int bb_offset_x = 0, int bb_offset_y = 0, int bb_offset_z = 0, const SubSprite *sub = NULL);
       
    67 void *AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2);
       
    68 void AddChildSpriteScreen(SpriteID image, SpriteID pal, int x, int y, bool transparent = false, const SubSprite *sub = NULL);
       
    69 
       
    70 
       
    71 void StartSpriteCombine();
       
    72 void EndSpriteCombine();
       
    73 
       
    74 void HandleViewportClicked(const ViewPort *vp, int x, int y);
       
    75 void PlaceObject();
       
    76 void SetRedErrorSquare(TileIndex tile);
       
    77 void SetTileSelectSize(int w, int h);
       
    78 void SetTileSelectBigSize(int ox, int oy, int sx, int sy);
       
    79 
       
    80 Vehicle *CheckMouseOverVehicle();
       
    81 
       
    82 /** Viewport place method (type of highlighted area and placed objects) */
       
    83 enum ViewportPlaceMethod {
       
    84 	VPM_X_OR_Y          = 0, ///< drag in X or Y direction
       
    85 	VPM_FIX_X           = 1, ///< drag only in X axis
       
    86 	VPM_FIX_Y           = 2, ///< drag only in Y axis
       
    87 	VPM_RAILDIRS        = 3, ///< all rail directions
       
    88 	VPM_X_AND_Y         = 4, ///< area of land in X and Y directions
       
    89 	VPM_X_AND_Y_LIMITED = 5, ///< area of land of limited size
       
    90 	VPM_SIGNALDIRS      = 6, ///< similiar to VMP_RAILDIRS, but with different cursor
       
    91 };
       
    92 
       
    93 /** Viewport highlight mode (for highlighting tiles below cursor) */
       
    94 enum ViewportHighlightMode {
       
    95 	VHM_NONE    = 0, ///< default
       
    96 	VHM_RECT    = 1, ///< rectangle (stations, depots, ...)
       
    97 	VHM_POINT   = 2, ///< point (lower land, raise land, level land, ...)
       
    98 	VHM_SPECIAL = 3, ///< special mode used for highlighting while dragging (and for tunnels/docks)
       
    99 	VHM_DRAG    = 4, ///< dragging items in the depot windows
       
   100 	VHM_RAIL    = 5, ///< rail pieces
       
   101 };
       
   102 
       
   103 void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method);
       
   104 void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, byte process);
       
   105 void VpSetPresizeRange(uint from, uint to);
       
   106 void VpSetPlaceSizingLimit(int limit);
       
   107 
       
   108 /* highlighting draw styles */
       
   109 typedef byte HighLightStyle;
       
   110 enum HighLightStyles {
       
   111 	HT_NONE   = 0x00,
       
   112 	HT_RECT   = 0x80,
       
   113 	HT_POINT  = 0x40,
       
   114 	HT_LINE   = 0x20,    ///< used for autorail highlighting (longer streches)
       
   115 	                     ///< (uses lower bits to indicate direction)
       
   116 	HT_RAIL   = 0x10,    ///< autorail (one piece)
       
   117 	                     ///< (uses lower bits to indicate direction)
       
   118 	HT_DRAG_MASK = 0xF0, ///< masks the drag-type
       
   119 
       
   120 	/* lower bits (used with HT_LINE and HT_RAIL):
       
   121 	 * (see ASCII art in autorail.h for a visual interpretation) */
       
   122 	HT_DIR_X  = 0,    ///< X direction
       
   123 	HT_DIR_Y  = 1,    ///< Y direction
       
   124 	HT_DIR_HU = 2,    ///< horizontal upper
       
   125 	HT_DIR_HL = 3,    ///< horizontal lower
       
   126 	HT_DIR_VL = 4,    ///< vertical left
       
   127 	HT_DIR_VR = 5,    ///< vertical right
       
   128 	HT_DIR_MASK = 0x7 ///< masks the drag-direction
       
   129 };
       
   130 
       
   131 struct TileHighlightData {
       
   132 	Point size;
       
   133 	Point outersize;
       
   134 	Point pos;
       
   135 	Point offs;
       
   136 
       
   137 	Point new_pos;
       
   138 	Point new_size;
       
   139 	Point new_outersize;
       
   140 
       
   141 	Point selend, selstart;
       
   142 
       
   143 	byte dirty;
       
   144 	byte sizelimit;
       
   145 
       
   146 	byte drawstyle;      // lower bits 0-3 are reserved for detailed highlight information information
       
   147 	byte new_drawstyle;  // only used in UpdateTileSelection() to as a buffer to compare if there was a change between old and new
       
   148 	byte next_drawstyle; // queued, but not yet drawn style
       
   149 
       
   150 	ViewportHighlightMode place_mode;
       
   151 	bool make_square_red;
       
   152 	WindowClass window_class;
       
   153 	WindowNumber window_number;
       
   154 
       
   155 	ViewportPlaceMethod select_method;
       
   156 	byte select_proc;
       
   157 
       
   158 	TileIndex redsq;
       
   159 };
       
   160 
       
   161 
       
   162 /* common button handler */
       
   163 bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, ViewportHighlightMode mode, PlaceProc *placeproc);
       
   164 
       
   165 VARDEF Point _tile_fract_coords;
       
   166 
       
   167 extern TileHighlightData _thd;
       
   168 
       
   169 
       
   170 void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom);
       
   171 
       
   172 void SetObjectToPlaceWnd(CursorID icon, SpriteID pal, ViewportHighlightMode mode, Window *w);
       
   173 void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, WindowClass window_class, WindowNumber window_num);
       
   174 
       
   175 void ResetObjectToPlace();
       
   176 
       
   177 bool ScrollWindowTo(int x, int y, Window *w, bool instant = false);
       
   178 
       
   179 bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
       
   180 bool ScrollMainWindowTo(int x, int y, bool instant = false);
       
   181 
       
   182 #endif /* VIEWPORT_H */