Changeset - r16300:dae54be93b98
[Not reviewed]
master
0 3 0
alberth - 14 years ago 2010-10-23 18:28:20
alberth@openttd.org
(svn r21018) -Doc: Add Doxygen comments to some function.
3 files changed with 24 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/main_gui.cpp
Show inline comments
 
@@ -83,98 +83,103 @@ void HandleOnEditText(const char *str)
 
	_rename_id = _rename_what = -1;
 
}
 

	
 
/**
 
 * This code is shared for the majority of the pushbuttons.
 
 * Handles e.g. the pressing of a button (to build things), playing of click sound and sets certain parameters
 
 *
 
 * @param w Window which called the function
 
 * @param widget ID of the widget (=button) that called this function
 
 * @param cursor How should the cursor image change? E.g. cursor with depot image in it
 
 * @param mode Tile highlighting mode, e.g. drawing a rectangle or a dot on the ground
 
 * @param placeproc Procedure which will be called when someone clicks on the map
 
 * @return true if the button is clicked, false if it's unclicked
 
 */
 
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode, PlaceProc *placeproc)
 
{
 
	if (w->IsWidgetDisabled(widget)) return false;
 

	
 
	SndPlayFx(SND_15_BEEP);
 
	w->SetDirty();
 

	
 
	if (w->IsWidgetLowered(widget)) {
 
		ResetObjectToPlace();
 
		return false;
 
	}
 

	
 
	SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number);
 
	w->LowerWidget(widget);
 
	_place_proc = placeproc;
 
	return true;
 
}
 

	
 

	
 
void CcPlaySound10(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (result.Succeeded()) SndPlayTileFx(SND_12_EXPLOSION, tile);
 
}
 

	
 
#ifdef ENABLE_NETWORK
 
void ShowNetworkGiveMoneyWindow(CompanyID company)
 
{
 
	_rename_id = company;
 
	_rename_what = 3;
 
	ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, 180, NULL, CS_NUMERAL, QSF_NONE);
 
}
 
#endif /* ENABLE_NETWORK */
 

	
 

	
 
/* Zooms a viewport in a window in or out
 
 * No button handling or what so ever */
 
/**
 
 * Zooms a viewport in a window in or out.
 
 * @param how Zooming direction.
 
 * @param w   Window owning the viewport.
 
 * @return Returns \c true if zooming step could be done, \c false if further zooming is not possible.
 
 * @note No button handling or what so ever is done.
 
 */
 
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
 
{
 
	ViewPort *vp;
 

	
 
	assert(w != NULL);
 
	vp = w->viewport;
 

	
 
	switch (how) {
 
		case ZOOM_NONE:
 
			/* On initialisation of the viewport we don't do anything. */
 
			break;
 

	
 
		case ZOOM_IN:
 
			if (vp->zoom == ZOOM_LVL_MIN) return false;
 
			vp->zoom = (ZoomLevel)((int)vp->zoom - 1);
 
			vp->virtual_width >>= 1;
 
			vp->virtual_height >>= 1;
 

	
 
			w->viewport->scrollpos_x += vp->virtual_width >> 1;
 
			w->viewport->scrollpos_y += vp->virtual_height >> 1;
 
			w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x;
 
			w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y;
 
			w->viewport->follow_vehicle = INVALID_VEHICLE;
 
			break;
 
		case ZOOM_OUT:
 
			if (vp->zoom == ZOOM_LVL_MAX) return false;
 
			vp->zoom = (ZoomLevel)((int)vp->zoom + 1);
 

	
 
			w->viewport->scrollpos_x -= vp->virtual_width >> 1;
 
			w->viewport->scrollpos_y -= vp->virtual_height >> 1;
 
			w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x;
 
			w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y;
 

	
 
			vp->virtual_width <<= 1;
 
			vp->virtual_height <<= 1;
 
			w->viewport->follow_vehicle = INVALID_VEHICLE;
 
			break;
 
	}
 
	if (vp != NULL) { // the vp can be null when how == ZOOM_NONE
 
		vp->virtual_left = w->viewport->scrollpos_x;
 
		vp->virtual_top = w->viewport->scrollpos_y;
 
	}
 
	/* Update the windows that have zoom-buttons to perhaps disable their buttons */
 
	w->InvalidateData();
 
	return true;
 
}
 

	
 
void ZoomInOrOutToCursorWindow(bool in, Window *w)
src/viewport.cpp
Show inline comments
 
@@ -1841,101 +1841,111 @@ bool HandleViewportClicked(const ViewPor
 
	if (CheckClickOnSign(vp, x, y)) return true;
 
	CheckClickOnLandscape(vp, x, y);
 

	
 
	if (v != NULL) {
 
		DEBUG(misc, 2, "Vehicle %d (index %d) at %p", v->unitnumber, v->index, v);
 
		if (IsCompanyBuildableVehicleType(v)) {
 
			v = v->First();
 
			if (_ctrl_pressed && v->owner == _local_company) {
 
				StartStopVehicle(v, true);
 
			} else {
 
				ShowVehicleViewWindow(v);
 
			}
 
		}
 
		return true;
 
	}
 
	return CheckClickOnLandscape(vp, x, y);
 
}
 

	
 

	
 
/**
 
 * Scrolls the viewport in a window to a given location.
 
 * @param x       Desired x location of the map to scroll to (world coordinate).
 
 * @param y       Desired y location of the map to scroll to (world coordinate).
 
 * @param z       Desired z location of the map to scroll to (world coordinate). Use \c -1 to scroll to the height of the map at the \a x, \a y location.
 
 * @param w       %Window containing the viewport.
 
 * @param instant Jump to the location instead of slowly moving to it.
 
 * @return Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position).
 
 */
 
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
 
{
 
	/* The slope cannot be acquired outside of the map, so make sure we are always within the map. */
 
	if (z == -1) z = GetSlopeZ(Clamp(x, 0, MapSizeX() * TILE_SIZE - 1), Clamp(y, 0, MapSizeY() * TILE_SIZE - 1));
 

	
 
	Point pt = MapXYZToViewport(w->viewport, x, y, z);
 
	w->viewport->follow_vehicle = INVALID_VEHICLE;
 

	
 
	if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y) return false;
 

	
 
	if (instant) {
 
		w->viewport->scrollpos_x = pt.x;
 
		w->viewport->scrollpos_y = pt.y;
 
	}
 

	
 
	w->viewport->dest_scrollpos_x = pt.x;
 
	w->viewport->dest_scrollpos_y = pt.y;
 
	return true;
 
}
 

	
 
/**
 
 * Scrolls the viewport of the main window to a given location.
 
 * @param tile    Desired tile to center on.
 
 * @param instant Jump to the location instead of slowly moving to it.
 
 * @return Destination of the viewport was changed (to activate other actions when the viewport is already at the desired position).
 
 */
 
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
 
{
 
	return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, -1, instant);
 
}
 

	
 
/**
 
 * Set a tile to display a red error square.
 
 * @param tile Tile that should show the red error square.
 
 */
 
void SetRedErrorSquare(TileIndex tile)
 
{
 
	TileIndex old;
 

	
 
	old = _thd.redsq;
 
	_thd.redsq = tile;
 

	
 
	if (tile != old) {
 
		if (tile != INVALID_TILE) MarkTileDirtyByTile(tile);
 
		if (old  != INVALID_TILE) MarkTileDirtyByTile(old);
 
	}
 
}
 

	
 
/**
 
 * Highlight \a w by \a h tiles at the cursor.
 
 * @param w Width of the highlighted tiles rectangle.
 
 * @param h Height of the highlighted tiles rectangle.
 
 */
 
void SetTileSelectSize(int w, int h)
 
{
 
	_thd.new_size.x = w * TILE_SIZE;
 
	_thd.new_size.y = h * TILE_SIZE;
 
	_thd.new_outersize.x = 0;
 
	_thd.new_outersize.y = 0;
 
}
 

	
 
void SetTileSelectBigSize(int ox, int oy, int sx, int sy)
 
{
 
	_thd.offs.x = ox * TILE_SIZE;
 
	_thd.offs.y = oy * TILE_SIZE;
 
	_thd.new_outersize.x = sx * TILE_SIZE;
 
	_thd.new_outersize.y = sy * TILE_SIZE;
 
}
 

	
 
/** returns the best autorail highlight type from map coordinates */
 
static HighLightStyle GetAutorailHT(int x, int y)
 
{
 
	return HT_RAIL | _autorail_piece[x & TILE_UNIT_MASK][y & TILE_UNIT_MASK];
 
}
 

	
 
/**
 
 * Updates tile highlighting for all cases.
 
 * Uses _thd.selstart and _thd.selend and _thd.place_mode (set elsewhere) to determine _thd.pos and _thd.size
 
 * Also drawstyle is determined. Uses _thd.new.* as a buffer and calls SetSelectionTilesDirty() twice,
 
 * Once for the old and once for the new selection.
 
 * _thd is TileHighlightData, found in viewport.h
 
 */
 
void UpdateTileSelection()
src/viewport_type.h
Show inline comments
 
@@ -6,100 +6,104 @@
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file viewport_type.h Types related to viewports. */
 

	
 
#ifndef VIEWPORT_TYPE_H
 
#define VIEWPORT_TYPE_H
 

	
 
#include "zoom_type.h"
 
#include "strings_type.h"
 

	
 
/**
 
 * Data structure for viewport, display of a part of the world
 
 */
 
struct ViewPort {
 
	int left;    ///< Screen coordinate left egde of the viewport
 
	int top;     ///< Screen coordinate top edge of the viewport
 
	int width;   ///< Screen width of the viewport
 
	int height;  ///< Screen height of the viewport
 

	
 
	int virtual_left;    ///< Virtual left coordinate
 
	int virtual_top;     ///< Virtual top coordinate
 
	int virtual_width;   ///< width << zoom
 
	int virtual_height;  ///< height << zoom
 

	
 
	ZoomLevel zoom;
 
};
 

	
 
/** Margings for the viewport sign */
 
enum ViewportSignMargin {
 
	VPSM_LEFT   = 1, ///< Left margin
 
	VPSM_RIGHT  = 1, ///< Right margin
 
	VPSM_TOP    = 1, ///< Top margin
 
	VPSM_BOTTOM = 1, ///< Bottom margin
 
};
 

	
 
/** Location information about a sign as seen on the viewport */
 
struct ViewportSign {
 
	int32 center;        ///< The center position of the sign
 
	int32 top;           ///< The top of the sign
 
	uint16 width_normal; ///< The width when not zoomed out (normal font)
 
	uint16 width_small;  ///< The width when zoomed out (small font)
 

	
 
	void UpdatePosition(int center, int top, StringID str);
 
	void MarkDirty() const;
 
};
 

	
 
/**
 
 * Directions of zooming.
 
 * @see DoZoomInOutWindow
 
 */
 
enum ZoomStateChange {
 
	ZOOM_IN   = 0,
 
	ZOOM_OUT  = 1,
 
	ZOOM_NONE = 2, // hack, used to update the button status
 
	ZOOM_IN   = 0, ///< Zoom in (get more detailed view).
 
	ZOOM_OUT  = 1, ///< Zoom out (get helicopter view).
 
	ZOOM_NONE = 2, ///< Hack, used to update the button status.
 
};
 

	
 
/**
 
 * Some values for constructing bounding boxes (BB). The Z positions under bridges are:
 
 * z=0..5  Everything that can be built under low bridges.
 
 * z=6     reserved, currently unused.
 
 * z=7     Z separator between bridge/tunnel and the things under/above it.
 
 */
 
static const uint BB_HEIGHT_UNDER_BRIDGE = 6; ///< Everything that can be built under low bridges, must not exceed this Z height.
 
static const uint BB_Z_SEPARATOR         = 7; ///< Separates the bridge/tunnel from the things under/above it.
 

	
 
/** Viewport place method (type of highlighted area and placed objects) */
 
enum ViewportPlaceMethod {
 
	VPM_X_OR_Y          =    0, ///< drag in X or Y direction
 
	VPM_FIX_X           =    1, ///< drag only in X axis
 
	VPM_FIX_Y           =    2, ///< drag only in Y axis
 
	VPM_X_AND_Y         =    3, ///< area of land in X and Y directions
 
	VPM_X_AND_Y_LIMITED =    4, ///< area of land of limited size
 
	VPM_FIX_HORIZONTAL  =    5, ///< drag only in horizontal direction
 
	VPM_FIX_VERTICAL    =    6, ///< drag only in vertical direction
 
	VPM_X_LIMITED       =    7, ///< Drag only in X axis with limited size
 
	VPM_Y_LIMITED       =    8, ///< Drag only in Y axis with limited size
 
	VPM_RAILDIRS        = 0x40, ///< all rail directions
 
	VPM_SIGNALDIRS      = 0x80, ///< similiar to VMP_RAILDIRS, but with different cursor
 
};
 
DECLARE_ENUM_AS_BIT_SET(ViewportPlaceMethod)
 

	
 
/**
 
 * Drag and drop selection process, or, what to do with an area of land when
 
 * you've selected it.
 
 */
 
enum ViewportDragDropSelectionProcess {
 
	DDSP_DEMOLISH_AREA,        ///< Clear area
 
	DDSP_RAISE_AND_LEVEL_AREA, ///< Raise / level area
 
	DDSP_LOWER_AND_LEVEL_AREA, ///< Lower / level area
 
	DDSP_LEVEL_AREA,           ///< Level area
 
	DDSP_CREATE_DESERT,        ///< Fill area with desert
 
	DDSP_CREATE_ROCKS,         ///< Fill area with rocks
 
	DDSP_CREATE_WATER,         ///< Create a canal
 
	DDSP_CREATE_RIVER,         ///< Create rivers
 
	DDSP_PLANT_TREES,          ///< Plant trees
 
	DDSP_BUILD_BRIDGE,         ///< Bridge placement
 

	
 
	/* Rail specific actions */
 
	DDSP_PLACE_RAIL,           ///< Rail placement
 
	DDSP_BUILD_SIGNALS,        ///< Signal placement
 
	DDSP_BUILD_STATION,        ///< Station placement
 
	DDSP_REMOVE_STATION,       ///< Station removal
0 comments (0 inline, 0 general)