2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 1998 - 2000 , Matthes Bender
* Copyright ( c ) 2001 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2009 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
/* A viewport to each player */
# ifndef INC_C4Viewport
# define INC_C4Viewport
2016-04-03 18:07:56 +00:00
# include "graphics/C4FacetEx.h"
2009-05-08 13:28:41 +00:00
2015-12-28 17:24:09 +00:00
class C4ViewportWindow ;
class C4FoWRegion ;
2009-05-08 13:28:41 +00:00
class C4Viewport
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
friend class C4MouseControl ;
2010-03-28 17:58:21 +00:00
public :
C4Viewport ( ) ;
~ C4Viewport ( ) ;
// "display" coordinates
int32_t ViewWdt , ViewHgt ;
2015-01-03 21:51:02 +00:00
// position of landscape border (left,top,right, bottom) in viewport. 0 if there is not border
2015-01-07 16:29:48 +00:00
float BorderLeft , BorderTop , BorderRight , BorderBottom ;
2010-03-28 17:58:21 +00:00
int32_t DrawX , DrawY ;
// facets used for last drawing operations
2010-04-10 20:44:00 +00:00
C4TargetFacet last_game_draw_cgo , last_gui_draw_cgo ;
2010-03-28 17:58:21 +00:00
// factor between "landscape" and "display"
bool fIsNoOwnerViewport ; // this viewport is found for searches of NO_OWNER-viewports; even if it has a player assigned (for network obs)
2010-09-08 21:49:42 +00:00
2010-04-26 23:32:45 +00:00
float GetZoom ( ) { return Zoom ; }
2010-12-06 20:32:27 +00:00
void SetZoom ( float zoomValue ) ;
2015-02-12 22:05:55 +00:00
float GetGUIZoom ( ) const { return Clamp < float > ( float ( ViewWdt ) / 1280 , 0.5f , 1.0f ) ; }
2010-03-28 17:58:21 +00:00
void Execute ( ) ;
void ClearPointers ( C4Object * pObj ) ;
void SetOutputSize ( int32_t iDrawX , int32_t iDrawY , int32_t iOutX , int32_t iOutY , int32_t iOutWdt , int32_t iOutHgt ) ;
2013-12-04 16:36:27 +00:00
void CalculateZoom ( ) ;
2010-03-28 17:58:21 +00:00
void ChangeZoom ( float by_factor ) ;
2010-09-08 21:49:42 +00:00
void SetZoom ( float to_zoom , bool direct = false ) ;
void SetZoomLimits ( float to_min_zoom , float to_max_zoom ) ;
float GetZoomByViewRange ( int32_t size_x , int32_t size_y ) const ; // set zoom such that the supplied size is visible in the viewport
float GetZoomLimitMin ( ) const { return ZoomLimitMin ; }
float GetZoomLimitMax ( ) const { return ZoomLimitMax ; }
float GetZoomTarget ( ) const { return ZoomTarget ; }
2010-03-28 17:58:21 +00:00
bool Init ( int32_t iPlayer , bool fSetTempOnly ) ;
2010-12-06 20:31:37 +00:00
void DropFile ( const char * fileName , float x , float y ) ;
2010-03-28 17:58:21 +00:00
bool TogglePlayerLock ( ) ;
2012-04-08 23:15:30 +00:00
bool GetPlayerLock ( ) { return PlayerLock ; }
2010-03-28 17:58:21 +00:00
void NextPlayer ( ) ;
C4Rect GetOutputRect ( ) { return C4Rect ( OutX , OutY , ViewWdt , ViewHgt ) ; }
bool IsViewportMenu ( class C4Menu * pMenu ) ;
C4Viewport * GetNext ( ) { return Next ; }
int32_t GetPlayer ( ) { return Player ; }
void CenterPosition ( ) ;
2015-01-14 17:03:05 +00:00
void DisableFoW ( ) ;
void EnableFoW ( ) ;
2015-01-03 21:51:02 +00:00
public :
/** Return x-position of upper left corner of viewport in landscape coordinates */
float GetViewX ( ) { return viewX ; }
/** Return y-position of upper left corner of viewport in landscape coordinates */
float GetViewY ( ) { return viewY ; }
/** Return x-position of the center of viewport in landscape coordinates */
float GetViewCenterX ( ) { return viewX + ViewWdt / Zoom / 2 ; }
/** Return y-position of the center of viewport in landscape coordinates */
float GetViewCenterY ( ) { return viewY + ViewHgt / Zoom / 2 ; }
/** Scroll the viewport by x,y */
void ScrollView ( float byX , float byY ) ;
/** Set the view position. */
void SetViewX ( float x ) ;
void SetViewY ( float y ) ;
/** Set the view offset of the normal viewport center. Used by C4Script function SetViewOffset. */
void SetViewOffset ( int32_t x , int32_t y ) { viewOffsX = x ; viewOffsY = y ; }
private :
float viewX , viewY ; // current view position in landscape coordinates (upper left corner)
float targetViewX , targetViewY ; // target view position for smooth scrolling
int32_t viewOffsX , viewOffsY ; // desired view offset in landscape coordinates
void UpdateBordersX ( ) ;
void UpdateBordersY ( ) ;
2010-03-28 17:58:21 +00:00
protected :
2010-04-26 23:32:45 +00:00
float Zoom ;
float ZoomTarget ;
2010-09-08 21:49:42 +00:00
float ZoomLimitMin , ZoomLimitMax ;
2015-12-03 02:24:57 +00:00
int32_t ViewportOpenFrame ; // Game FrameCounter in which viewport was opened. Used to init zoom during initial fullscreen viewport movement chaos, but not change it later e.g. when other local players join.
2010-03-28 17:58:21 +00:00
int32_t Player ;
bool PlayerLock ;
int32_t OutX , OutY ;
bool ResetMenuPositions ;
C4Viewport * Next ;
2015-12-28 17:24:09 +00:00
std : : unique_ptr < C4ViewportWindow > pWindow ;
std : : unique_ptr < C4FoWRegion > pFoW ;
2010-03-28 17:58:21 +00:00
void DrawPlayerStartup ( C4TargetFacet & cgo ) ;
2016-01-10 14:50:21 +00:00
void Draw ( C4TargetFacet & cgo , bool fDrawGame , bool fDrawOverlay ) ;
2010-03-28 17:58:21 +00:00
void DrawOverlay ( C4TargetFacet & cgo , const ZoomData & GameZoom ) ;
void DrawMenu ( C4TargetFacet & cgo ) ;
void DrawPlayerInfo ( C4TargetFacet & cgo ) ;
2013-12-04 16:36:27 +00:00
void InitZoom ( ) ;
2010-03-28 17:58:21 +00:00
void BlitOutput ( ) ;
2015-12-03 03:11:28 +00:00
void AdjustZoomAndPosition ( ) ;
2010-12-11 18:50:38 +00:00
public :
2015-12-03 03:11:28 +00:00
void AdjustPosition ( bool immediate = false ) ;
2015-12-28 17:24:09 +00:00
C4ViewportWindow * GetWindow ( ) { return pWindow . get ( ) ; }
2010-03-28 17:58:21 +00:00
bool UpdateOutputSize ( ) ;
bool ViewPositionByScrollBars ( ) ;
bool ScrollBarsByViewPosition ( ) ;
2009-05-08 13:28:41 +00:00
# ifdef _WIN32
friend LRESULT APIENTRY ViewportWinProc ( HWND hwnd , UINT uMsg , WPARAM wParam , LPARAM lParam ) ;
# endif
friend class C4ViewportWindow ;
2010-09-29 01:44:05 +00:00
friend class C4ViewportList ;
2009-05-08 13:28:41 +00:00
friend class C4GraphicsSystem ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
2010-09-29 01:44:05 +00:00
class C4ViewportList {
public :
C4ViewportList ( ) ;
~ C4ViewportList ( ) ;
void Clear ( ) ;
void ClearPointers ( C4Object * pObj ) ;
void Execute ( bool DrawBackground ) ;
void SortViewportsByPlayerControl ( ) ;
void RecalculateViewports ( ) ;
2015-01-14 17:03:05 +00:00
void DisableFoW ( ) ;
void EnableFoW ( ) ;
2010-09-29 01:44:05 +00:00
bool CreateViewport ( int32_t iPlayer , bool fSilent = false ) ;
bool CloseViewport ( int32_t iPlayer , bool fSilent ) ;
int32_t GetViewportCount ( ) ;
2010-12-12 21:38:19 +00:00
C4Viewport * GetViewport ( int32_t iPlayer , C4Viewport * pPrev = NULL ) ;
2010-09-29 01:44:05 +00:00
C4Viewport * GetFirstViewport ( ) { return FirstViewport ; }
bool CloseViewport ( C4Viewport * cvp ) ;
2012-03-23 21:53:56 +00:00
# ifdef USE_WIN32_WINDOWS
2010-09-29 01:44:05 +00:00
C4Viewport * GetViewport ( HWND hwnd ) ;
# endif
2015-08-28 01:44:23 +00:00
int32_t GetAudibility ( int32_t iX , int32_t iY , int32_t * iPan , int32_t iAudibilityRadius = 0 , int32_t * outPlayer = NULL ) ;
2010-09-29 01:44:05 +00:00
bool ViewportNextPlayer ( ) ;
bool FreeScroll ( C4Vec2D vScrollBy ) ; // key callback: Scroll ownerless viewport by some offset
bool ViewportZoomOut ( ) ;
bool ViewportZoomIn ( ) ;
protected :
void MouseMoveToViewport ( int32_t iButton , int32_t iX , int32_t iY , DWORD dwKeyParam ) ;
void DrawFullscreenBackground ( ) ;
C4Viewport * FirstViewport ;
C4Facet ViewportArea ;
C4RectList BackgroundAreas ; // rectangles covering background without viewports in fullscreen
2010-09-29 21:58:59 +00:00
friend class C4GUI : : Screen ;
2010-09-29 01:44:05 +00:00
friend class C4GraphicsSystem ;
} ;
extern C4ViewportList Viewports ;
2009-05-08 13:28:41 +00:00
# endif