All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
Go to the documentation of this file.
1 /*
2  * OpenClonk,
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH,
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
18 /* A viewport to each player */
20 #ifndef INC_C4Viewport
21 #define INC_C4Viewport
23 #include "graphics/C4FacetEx.h"
25 class C4ViewportWindow;
26 class C4FoWRegion;
27 struct ZoomData;
30 {
31  friend class C4MouseControl;
32 public:
33  C4Viewport();
34  ~C4Viewport();
35  // "display" coordinates
36  int32_t ViewWdt,ViewHgt;
37  // position of landscape border (left,top,right, bottom) in viewport. 0 if there is not border
39  int32_t DrawX,DrawY;
40  // facets used for last drawing operations
42  // factor between "landscape" and "display"
43  bool fIsNoOwnerViewport; // this viewport is found for searches of NO_OWNER-viewports; even if it has a player assigned (for network obs)
45  float GetZoom() { return Zoom; }
46  void SetZoom(float zoomValue);
47  float GetGUIZoom() const { return Clamp<float>(float(ViewWdt)/1280,0.5f,1.0f); }
48  void Execute();
49  void ClearPointers(C4Object *pObj);
50  void SetOutputSize(int32_t iDrawX, int32_t iDrawY, int32_t iOutX, int32_t iOutY, int32_t iOutWdt, int32_t iOutHgt);
51  void CalculateZoom();
52  void ChangeZoom(float by_factor);
53  void SetZoom(float to_zoom, bool direct=false);
54  void SetZoomLimits(float to_min_zoom, float to_max_zoom);
55  float GetZoomByViewRange(int32_t size_x, int32_t size_y) const; // set zoom such that the supplied size is visible in the viewport
56  float GetZoomLimitMin() const { return ZoomLimitMin; }
57  float GetZoomLimitMax() const { return ZoomLimitMax; }
58  float GetZoomTarget() const { return ZoomTarget; }
59  bool Init(int32_t iPlayer, bool fSetTempOnly);
60  void DropFile(const char* fileName, float x, float y);
61  bool TogglePlayerLock();
62  bool GetPlayerLock() { return PlayerLock; }
63  void NextPlayer();
64  C4Rect GetOutputRect() { return C4Rect(OutX, OutY, ViewWdt, ViewHgt); }
65  bool IsViewportMenu(class C4Menu *pMenu);
66  C4Viewport *GetNext() { return Next; }
67  int32_t GetPlayer() { return Player; }
68  void CenterPosition();
69  void DisableFoW();
70  void EnableFoW();
71 public:
73  float GetViewX() { return viewX; }
75  float GetViewY() { return viewY; }
77  float GetViewCenterX() { return viewX + ViewWdt/Zoom/2; }
79  float GetViewCenterY() { return viewY + ViewHgt/Zoom/2; }
81  // Convert window coordinates to game coordinates
82  float WindowToGameX(int32_t win_x) { return GetViewX() + float(win_x) / Zoom; }
83  float WindowToGameY(int32_t win_y) { return GetViewY() + float(win_y) / Zoom; }
86  void ScrollView(float byX, float byY);
88  void SetViewX(float x);
89  void SetViewY(float y);
91  void SetViewOffset(int32_t x, int32_t y) { viewOffsX = x; viewOffsY = y; }
93 private:
94  float viewX,viewY; // current view position in landscape coordinates (upper left corner)
95  float targetViewX, targetViewY; // target view position for smooth scrolling
96  int32_t viewOffsX, viewOffsY; // desired view offset in landscape coordinates
98  void UpdateBordersX();
99  void UpdateBordersY();
100 protected:
101  float Zoom;
102  float ZoomTarget;
104  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.
105  int32_t Player;
107  int32_t OutX,OutY;
110  std::unique_ptr<C4ViewportWindow> pWindow;
111  std::unique_ptr<C4FoWRegion> pFoW;
112  void DrawPlayerStartup(C4TargetFacet &cgo);
113  void Draw(C4TargetFacet &cgo, bool fDrawGame, bool fDrawOverlay);
114  void DrawOverlay(C4TargetFacet &cgo, const ZoomData &GameZoom);
115  void DrawMenu(C4TargetFacet &cgo);
116  void DrawPlayerInfo(C4TargetFacet &cgo);
117  void InitZoom();
118  void BlitOutput();
119  void AdjustZoomAndPosition();
120 public:
121  float GetZoom() const { return Zoom; }
122  void AdjustPosition(bool immediate = false);
123  C4ViewportWindow* GetWindow() {return pWindow.get();}
124  bool UpdateOutputSize(int32_t new_width=0, int32_t new_height=0);
128 #ifdef WITH_QT_EDITOR
129  class C4ConsoleQtViewportScrollArea *scrollarea;
130 #endif
132 #ifdef _WIN32
133  friend LRESULT APIENTRY ViewportWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
134 #endif
135  friend class C4ViewportWindow;
136  friend class C4ViewportList;
137  friend class C4GraphicsSystem;
139 };
142 public:
143  C4ViewportList();
144  ~C4ViewportList();
145  void Clear();
146  void ClearPointers(C4Object *pObj);
147  void Execute(bool DrawBackground);
149  void RecalculateViewports();
150  void DisableFoW();
151  void EnableFoW();
152  bool CreateViewport(int32_t iPlayer, bool fSilent=false);
153  bool CloseViewport(int32_t iPlayer, bool fSilent);
154  int32_t GetViewportCount();
155  C4Viewport* GetViewport(int32_t iPlayer, C4Viewport* pPrev = nullptr);
157  bool CloseViewport(C4Viewport * cvp);
158 #ifdef USE_WIN32_WINDOWS
159  C4Viewport* GetViewport(HWND hwnd);
160 #endif
161  int32_t GetAudibility(int32_t iX, int32_t iY, int32_t *iPan, int32_t iAudibilityRadius = 0, int32_t *outPlayer = nullptr);
162  bool ViewportNextPlayer();
164  bool FreeScroll(C4Vec2D vScrollBy); // key callback: Scroll ownerless viewport by some offset
165  bool ViewportZoomOut();
166  bool ViewportZoomIn();
167 protected:
168  void MouseMoveToViewport(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam);
172  C4RectList BackgroundAreas; // rectangles covering background without viewports in fullscreen
173  friend class C4GUI::Screen;
174  friend class C4GraphicsSystem;
175 };
179 #endif
int32_t OutX
Definition: C4Viewport.h:107
void Draw(C4TargetFacet &cgo, bool fDrawGame, bool fDrawOverlay)
Definition: C4Viewport.cpp:200
float GetViewCenterY()
Definition: C4Viewport.h:79
C4Viewport * GetFirstViewport()
Definition: C4Viewport.h:156
int32_t OutY
Definition: C4Viewport.h:107
void InitZoom()
Definition: C4Viewport.cpp:426
int32_t DrawY
Definition: C4Viewport.h:39
void CalculateZoom()
Definition: C4Viewport.cpp:408
int32_t DrawX
Definition: C4Viewport.h:39
void RecalculateViewports()
Definition: C4Viewport.cpp:989
C4Facet ViewportArea
Definition: C4Viewport.h:171
void DrawFullscreenBackground()
Definition: C4Viewport.cpp:874
bool UpdateOutputSize(int32_t new_width=0, int32_t new_height=0)
Definition: C4Viewport.cpp:52
bool PlayerLock
Definition: C4Viewport.h:106
float WindowToGameY(int32_t win_y)
Definition: C4Viewport.h:83
C4Viewport * GetNext()
Definition: C4Viewport.h:66
Definition: C4Rect.h:27
Definition: C4Menu.h:122
void MouseMoveToViewport(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam)
C4Viewport * GetViewport(int32_t iPlayer, C4Viewport *pPrev=nullptr)
bool ViewportZoomIn()
bool IsViewportMenu(class C4Menu *pMenu)
Definition: C4Viewport.cpp:822
C4TargetFacet last_gui_draw_cgo
Definition: C4Viewport.h:41
void ChangeZoom(float by_factor)
Definition: C4Viewport.cpp:440
void BlitOutput()
Definition: C4Viewport.cpp:369
void SortViewportsByPlayerControl()
int32_t ViewHgt
Definition: C4Viewport.h:36
friend class C4ConsoleQtViewportView
Definition: C4Viewport.h:138
std::unique_ptr< C4FoWRegion > pFoW
Definition: C4Viewport.h:111
void DrawOverlay(C4TargetFacet &cgo, const ZoomData &GameZoom)
Definition: C4Viewport.cpp:115
int32_t GetAudibility(int32_t iX, int32_t iY, int32_t *iPan, int32_t iAudibilityRadius=0, int32_t *outPlayer=nullptr)
float GetZoomLimitMax() const
Definition: C4Viewport.h:57
void EnableFoW()
Definition: C4Viewport.cpp:695
void SetZoomLimits(float to_min_zoom, float to_max_zoom)
Definition: C4Viewport.cpp:459
int32_t ViewWdt
Definition: C4Viewport.h:36
float GetZoomTarget() const
Definition: C4Viewport.h:58
C4RectList BackgroundAreas
Definition: C4Viewport.h:172
bool ViewportNextPlayer()
bool fIsNoOwnerViewport
Definition: C4Viewport.h:43
void SetZoom(float zoomValue)
Definition: C4Viewport.cpp:495
bool ResetMenuPositions
Definition: C4Viewport.h:108
void ScrollView(float byX, float byY)
Definition: C4Viewport.cpp:734
void DisableFoW()
Definition: C4Viewport.cpp:690
C4Viewport * FirstViewport
Definition: C4Viewport.h:170
C4Rect GetOutputRect()
Definition: C4Viewport.h:64
void SetViewOffset(int32_t x, int32_t y)
Definition: C4Viewport.h:91
void SetViewX(float x)
Definition: C4Viewport.cpp:740
void DrawPlayerInfo(C4TargetFacet &cgo)
Definition: C4Viewport.cpp:650
void NextPlayer()
Definition: C4Viewport.cpp:808
void SetViewY(float y)
Definition: C4Viewport.cpp:759
void AdjustPosition(bool immediate=false)
Definition: C4Viewport.cpp:544
bool CreateViewport(int32_t iPlayer, bool fSilent=false)
Definition: C4Viewport.cpp:917
bool FreeScroll(C4Vec2D vScrollBy)
bool TogglePlayerLock()
Definition: C4Console.cpp:710
float Zoom
Definition: C4Viewport.h:101
void CenterPosition()
Definition: C4Viewport.cpp:630
C4ViewportList Viewports
Definition: C4Viewport.cpp:841
C4TargetFacet last_game_draw_cgo
Definition: C4Viewport.h:41
void DrawMenu(C4TargetFacet &cgo)
Definition: C4Viewport.cpp:143
float GetZoomLimitMin() const
Definition: C4Viewport.h:56
C4Viewport * Next
Definition: C4Viewport.h:109
bool Init(int32_t iPlayer, bool fSetTempOnly)
Definition: C4Viewport.cpp:658
float GetViewY()
Definition: C4Viewport.h:75
float BorderBottom
Definition: C4Viewport.h:38
float GetZoomByViewRange(int32_t size_x, int32_t size_y) const
Definition: C4Viewport.cpp:467
void AdjustZoomAndPosition()
Definition: C4Viewport.cpp:502
int32_t GetPlayer()
Definition: C4Viewport.h:67
float GetViewCenterX()
Definition: C4Viewport.h:77
C4ViewportWindow * GetWindow()
Definition: C4Viewport.h:123
float GetZoom()
Definition: C4Viewport.h:45
bool ScrollBarsByViewPosition()
Definition: C4Console.cpp:709
void DrawPlayerStartup(C4TargetFacet &cgo)
Definition: C4Viewport.cpp:709
float GetGUIZoom() const
Definition: C4Viewport.h:47
bool CloseViewport(int32_t iPlayer, bool fSilent)
Definition: C4Viewport.cpp:961
void ClearPointers(C4Object *pObj)
Definition: C4Viewport.cpp:956
std::unique_ptr< C4ViewportWindow > pWindow
Definition: C4Viewport.h:110
int32_t GetViewportCount()
float GetZoom() const
Definition: C4Viewport.h:121
float ZoomTarget
Definition: C4Viewport.h:102
void DropFile(const char *fileName, float x, float y)
Definition: C4Viewport.cpp:47
void ClearPointers(C4Object *pObj)
Definition: C4Viewport.cpp:803
bool ViewportZoomOut()
void Execute(bool DrawBackground)
Definition: C4Viewport.cpp:860
float BorderTop
Definition: C4Viewport.h:38
void Execute()
Definition: C4Viewport.cpp:380
LRESULT APIENTRY ViewportWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
float WindowToGameX(int32_t win_x)
Definition: C4Viewport.h:82
int32_t ViewportOpenFrame
Definition: C4Viewport.h:104
uint32_t DWORD
float GetViewX()
Definition: C4Viewport.h:73
int32_t Player
Definition: C4Viewport.h:105
float ZoomLimitMax
Definition: C4Viewport.h:103
void SetOutputSize(int32_t iDrawX, int32_t iDrawY, int32_t iOutX, int32_t iOutY, int32_t iOutWdt, int32_t iOutHgt)
Definition: C4Viewport.cpp:778
float BorderRight
Definition: C4Viewport.h:38
bool GetPlayerLock()
Definition: C4Viewport.h:62
bool ViewPositionByScrollBars()
float BorderLeft
Definition: C4Viewport.h:38
float ZoomLimitMin
Definition: C4Viewport.h:103