____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

CViewport Class Reference

#include <ui.h>

List of all members.

Public Member Functions

 CViewport ()
bool IsInsideMapArea (int x, int y) const
 Check if X and Y pixels are within map area.
int Viewport2MapX (int x) const
 Convert screen Y pixel to map tile.
int Viewport2MapY (int y) const
 Convert map tile to screen X pixel.
int Map2ViewportX (int x) const
 Convert map tile to screen Y pixel.
int Map2ViewportY (int y) const
 Convert map pixel coordinates into viewport coordinates.
void MapPixel2Viewport (int &x, int &y) const
 Set the current map view to x,y(upper,left corner).
void Set (int x, int y, int offsetx, int offsety)
 Center map on point in viewport.
void Center (int x, int y, int offsetx, int offsety)
void Draw () const
 < Draw the full Viewport.
void DrawBorder () const
 Check if any part of an area is visible in viewport.
bool AnyMapAreaVisibleInViewport (int sx, int sy, int ex, int ey) const

Public Attributes

int X
 Screen pixel left corner x coordinate.
int Y
 Screen pixel upper corner y coordinate.
int EndX
 Screen pixel right x coordinate.
int EndY
 Screen pixel bottom y coordinate.
int MapX
 Map tile left corner x coordinate.
int MapY
 Map tile upper corner y coordinate.
int OffsetX
 X Offset within MapX.
int OffsetY
 Y Offset within MapY.
int MapWidth
 Width in map tiles.
int MapHeight
 Height in map tiles.
CUnitUnit
 Bound to this unit.

Protected Member Functions

void DrawMapBackgroundInViewport () const
 < Draw the map background
void DrawMapFogOfWar () const


Detailed Description

A map viewport.

A part of the map displayed on sceen.

CViewport::X CViewport::Y CViewport::EndX CViewport::EndY

upper left corner of this viewport is located at pixel coordinates (X, Y) with respect to upper left corner of stratagus's window, similarly lower right corner of this viewport is (EndX, EndY) pixels away from the UL corner of stratagus's window.

CViewport::MapX CViewport::MapY CViewport::MapWidth CViewport::MapHeight

Tile coordinates of UL corner of this viewport with respect to UL corner of the whole map.

CViewport::Unit

Viewport is bound to a unit. If the unit moves the viewport changes the position together with the unit.

Todo:
binding to a group.

Definition at line 148 of file ui.h.


Constructor & Destructor Documentation

CViewport::CViewport (  )  [inline]

Definition at line 150 of file ui.h.


Member Function Documentation

bool CViewport::IsInsideMapArea ( int  x,
int  y 
) const

Check if X and Y pixels are within map area.

Convert screen X pixel to map tile

Definition at line 79 of file map_draw.cpp.

References CMap::Info, Map, CMapInfo::MapHeight, CMapInfo::MapWidth, MapX, MapY, OffsetX, OffsetY, TileSizeX, TileSizeY, X, and Y.

Referenced by UIHandleButtonDown(), UIHandleMouseMove(), and UISelectStateButtonDown().

int CViewport::Viewport2MapX ( int  x  )  const

Convert screen Y pixel to map tile.

Convert viewport x coordinate to map tile x coordinate.

Parameters:
x X coordinate into this viewport (in pixels, relative to origin of Stratagus's window - not the viewport itself!).
Returns:
X map tile coordinate.

Definition at line 110 of file map_draw.cpp.

References CMap::Info, Map, CMapInfo::MapWidth, MapX, OffsetX, TileSizeX, and X.

Referenced by DrawBuildingCursor(), DrawMapCursor(), EditorCallbackButtonDown(), EditorCallbackKeyDown(), EditorCallbackMouse(), UIHandleButtonDown(), UIHandleButtonUp(), and UIHandleMouseMove().

int CViewport::Viewport2MapY ( int  y  )  const

Convert map tile to screen X pixel.

Convert viewport y coordinate to map tile y coordinate.

Parameters:
y Y coordinate into this viewport (in pixels, relative to origin of Stratagus's window - not the viewport itself!).
Returns:
Y map tile coordinate.

Definition at line 125 of file map_draw.cpp.

References CMap::Info, Map, CMapInfo::MapHeight, MapY, OffsetY, TileSizeY, and Y.

Referenced by DrawBuildingCursor(), DrawMapCursor(), EditorCallbackButtonDown(), EditorCallbackKeyDown(), EditorCallbackMouse(), UIHandleButtonDown(), UIHandleButtonUp(), and UIHandleMouseMove().

int CViewport::Map2ViewportX ( int  x  )  const

Convert map tile to screen Y pixel.

Convert a map tile X coordinate into a viewport x pixel coordinate.

Parameters:
x The map tile's X coordinate.
Returns:
X screen coordinate in pixels (relative to origin of Stratagus's window).

Definition at line 139 of file map_draw.cpp.

References MapX, OffsetX, TileSizeX, and X.

Referenced by CUnit::Draw(), DrawMapCursor(), DrawUnitSelection(), GetOrderPosition(), ShowOrder(), and ShowSingleOrder().

int CViewport::Map2ViewportY ( int  y  )  const

Convert map pixel coordinates into viewport coordinates.

Convert a map tile Y coordinate into a viewport y pixel coordinate.

Parameters:
y The map tile's Y coordinate.
Returns:
Y screen coordinate in pixels (relative to origin of Stratagus's window).

Definition at line 152 of file map_draw.cpp.

References MapY, OffsetY, TileSizeY, and Y.

Referenced by CUnit::Draw(), DrawMapCursor(), DrawUnitSelection(), GetOrderPosition(), ShowOrder(), and ShowSingleOrder().

void CViewport::MapPixel2Viewport ( int &  x,
int &  y 
) const

Set the current map view to x,y(upper,left corner).

Convert map pixel coordinates into viewport coordinates.

Definition at line 160 of file map_draw.cpp.

References MapX, MapY, OffsetX, OffsetY, TileSizeX, TileSizeY, X, and Y.

Referenced by CParticleManager::getScreenPos().

void CViewport::Set ( int  x,
int  y,
int  offsetx,
int  offsety 
)

Center map on point in viewport.

Change viewpoint of map viewport v to x,y.

Parameters:
x X map tile position.
y Y map tile position.
offsetx X offset in tile.
offsety Y offset in tile.

Definition at line 174 of file map_draw.cpp.

References EndX, EndY, CMap::Info, Map, CUserInterface::MapArea, MapHeight, CMapInfo::MapHeight, MapWidth, CMapInfo::MapWidth, MapX, MapY, OffsetX, OffsetY, CMapArea::ScrollPaddingBottom, CMapArea::ScrollPaddingLeft, CMapArea::ScrollPaddingRight, CMapArea::ScrollPaddingTop, TileSizeX, TileSizeY, UI, X, and Y.

Referenced by Center(), DoScrollArea(), EditorCallbackButtonDown(), EditorCallbackMouse(), FinishViewportModeConfiguration(), MouseScrollMap(), and UiRecallMapPosition().

void CViewport::Center ( int  x,
int  y,
int  offsetx,
int  offsety 
)

Center map viewport v on map tile (x,y).

Parameters:
x X map tile position.
y Y map tile position.
offsetx X offset in tile.
offsety Y offset in tile.

Definition at line 220 of file map_draw.cpp.

References EndX, EndY, Set(), TileSizeX, TileSizeY, X, and Y.

Referenced by CclCenterMap(), CenterOnMessage(), CreateGame(), UiCenterOnGroup(), UiCenterOnSelected(), UiFindIdleWorker(), UIHandleButtonDown(), UIHandleMouseMove(), and UISelectStateButtonDown().

void CViewport::DrawMapBackgroundInViewport (  )  const [protected]

< Draw the map background

Draw the map fog of war

Draw the map backgrounds.

StephanR: variables explained below for screen:

 *---------------------------------------*
 |                                       |
 |        *-----------------------*      |<-TheUi.MapY,dy (in pixels)
 |        |   |   |   |   |   |   |      |        |
 |        |   |   |   |   |   |   |      |        |
 |        |---+---+---+---+---+---|      |        |
 |        |   |   |   |   |   |   |      |        |MapHeight (in tiles)
 |        |   |   |   |   |   |   |      |        |
 |        |---+---+---+---+---+---|      |        |
 |        |   |   |   |   |   |   |      |        |
 |        |   |   |   |   |   |   |      |        |
 |        *-----------------------*      |<-ey,UI.MapEndY (in pixels)
 |                                       |
 |                                       |
 *---------------------------------------*
          ^                       ^
        dx|-----------------------|ex,UI.MapEndX (in pixels)
            UI.MapX MapWidth (in tiles)
 (in pixels)
 

Definition at line 252 of file map_draw.cpp.

References CGraphic::DrawClip(), CVideo::DrawRectangleClip(), Editor, CPatchType::getGraphic(), CPatchManager::getPatches(), CPatchType::getTileHeight(), CPatchType::getTileWidth(), CPatch::getType(), CPatch::getX(), CPatch::getY(), Map, MapX, MapY, OffsetX, OffsetY, CMap::PatchManager, CEditor::PatchOutlineColor, CEditor::Running, CEditor::ShowPatchOutlines, TileSizeX, TileSizeY, Video, X, Y, and y.

Referenced by Draw().

void CViewport::DrawMapFogOfWar (  )  const [protected]

void CViewport::Draw (  )  const

void CViewport::DrawBorder (  )  const

Check if any part of an area is visible in viewport.

Draw border around the viewport

Definition at line 336 of file map_draw.cpp.

References ColorBlack, ColorOrange, CVideo::DrawRectangle(), EndX, EndY, CUserInterface::NumViewports, CUserInterface::SelectedViewport, UI, Video, X, and Y.

Referenced by Draw().

bool CViewport::AnyMapAreaVisibleInViewport ( int  sx,
int  sy,
int  ex,
int  ey 
) const

Check if any part of an area is visible in a viewport.

Parameters:
sx X map tile position of area in map to be checked.
sy Y map tile position of area in map to be checked.
ex X map tile position of area in map to be checked.
ey Y map tile position of area in map to be checked.
Returns:
True if any part of area is visible, false otherwise

Definition at line 70 of file map_draw.cpp.

References MapHeight, MapWidth, MapX, and MapY.

Referenced by MissileVisibleInViewport().


Member Data Documentation

Bound to this unit.

Definition at line 194 of file ui.h.

Referenced by CclDefineViewports(), SaveViewports(), UIHandleButtonDown(), and UiTrackUnit().


The documentation for this class was generated from the following files:

Generated on Sat Feb 21 00:28:24 2009 for Bos Wars by  doxygen 1.5.6