OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ViewportWindow.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
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  */
17 
18 /* A viewport to each player */
19 
20 #include "C4Include.h"
22 
23 #include "game/C4Viewport.h"
24 #include "editor/C4Console.h"
25 #include "landscape/C4Landscape.h"
26 #include "player/C4PlayerList.h"
27 
28 
29 #ifdef WITH_QT_EDITOR
31 #endif
32 
33 #ifdef WITH_QT_EDITOR
35 {
36  if (PlayerLock) return false;
37  scrollarea->ScrollBarsByViewPosition();
38  return true;
39 }
40 
42 {
44  scrollarea->setScrollBarVisibility(!PlayerLock);
46  return true;
47 }
48 
49 #elif defined(USE_WIN32_WINDOWS)
50 
51 void UpdateWindowLayout(HWND hwnd)
52 {
53  RECT rect;
54  GetWindowRect(hwnd,&rect);
55  MoveWindow(hwnd,rect.left,rect.top,rect.right-rect.left-1,rect.bottom-rect.top,true);
56  MoveWindow(hwnd,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,true);
57 }
58 
60 {
61  // Disable player lock
62  if (PlayerLock)
63  {
64  PlayerLock=false;
65  SetWindowLong(pWindow->hWindow,GWL_STYLE,C4ViewportWindowStyle | WS_HSCROLL | WS_VSCROLL);
66  UpdateWindowLayout(pWindow->hWindow);
68  }
69  // Enable player lock
70  else if (ValidPlr(Player))
71  {
72  PlayerLock=true;
73  SetWindowLong(pWindow->hWindow,GWL_STYLE,C4ViewportWindowStyle);
74  UpdateWindowLayout(pWindow->hWindow);
75  }
76  return true;
77 }
78 
80 {
81  if (PlayerLock) return false;
82  SCROLLINFO scroll;
83  scroll.cbSize=sizeof(SCROLLINFO);
84  // Vertical
85  scroll.fMask=SIF_POS;
86  GetScrollInfo(pWindow->hWindow,SB_VERT,&scroll);
87  SetViewY(float(scroll.nPos));
88  // Horizontal
89  scroll.fMask=SIF_POS;
90  GetScrollInfo(pWindow->hWindow,SB_HORZ,&scroll);
91  SetViewX(float(scroll.nPos));
92  return true;
93 }
94 
96 {
97  if (PlayerLock) return false;
98  SCROLLINFO scroll;
99  scroll.cbSize=sizeof(SCROLLINFO);
100  // Vertical
101  scroll.fMask=SIF_ALL;
102  scroll.nMin=0;
103  scroll.nMax = ::Landscape.GetHeight() * Zoom;
104  scroll.nPage=ViewHgt;
105  scroll.nPos=int(GetViewY() * Zoom);
106  SetScrollInfo(pWindow->hWindow,SB_VERT,&scroll,true);
107  // Horizontal
108  scroll.fMask=SIF_ALL;
109  scroll.nMin=0;
110  scroll.nMax=::Landscape.GetWidth() * Zoom;
111  scroll.nPage=ViewWdt;
112  scroll.nPos = int(GetViewX() * Zoom);
113  SetScrollInfo(pWindow->hWindow,SB_HORZ,&scroll,true);
114  return true;
115 }
116 
117 #endif
118 
120 {
121 #ifdef WITH_QT_EDITOR
122  if (viewport_widget)
123  viewport_widget->update();
124 #else
125  if (cvp)
126  {
128  cvp->Execute();
129  }
130 #endif
131 }
132 
134 {
135  C4Window* result;
136  const char * Title = Player == NO_OWNER ? LoadResStr("IDS_CNS_VIEWPORT") : ::Players.Get(Player)->GetName();
137  C4Rect r(0,0,800,500);
138  result = C4Window::Init(C4Window::W_Viewport, &Application, Title, &r);
139 
140  if (!result) return result;
141 
142  pSurface = new C4Surface(&Application, this);
143 #ifndef WITH_QT_EDITOR
144  // Position and size
145  RestorePosition(FormatString("Viewport%i", Player+1).getData(), Config.GetSubkeyPath("Console"));
146 #endif
147  return result;
148 }
149 
151 {
153 }
154 void C4ViewportWindow::EditCursorMove(int X, int Y, uint32_t state)
155 {
157 }
C4EditCursor EditCursor
Definition: C4Console.h:90
C4Config Config
Definition: C4Config.cpp:833
C4Console Console
Definition: C4Globals.cpp:45
C4Viewport * cvp
const char * GetSubkeyPath(const char *strSubkey)
Definition: C4Config.cpp:713
C4Surface * pSurface
Definition: C4Window.h:274
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
Definition: C4Rect.h:27
void PerformUpdate() override
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
int32_t ViewHgt
Definition: C4Viewport.h:36
C4Player * Get(int iPlayer) const
int32_t ViewWdt
Definition: C4Viewport.h:36
C4Landscape Landscape
C4PlayerList Players
bool RestorePosition(const char *szWindowName, const char *szSubKey, bool fHidden=false)
Definition: C4AppT.cpp:108
const int NO_OWNER
Definition: C4Constants.h:137
void SetViewX(float x)
Definition: C4Viewport.cpp:740
void SetViewY(float y)
Definition: C4Viewport.cpp:759
bool TogglePlayerLock()
Definition: C4Console.cpp:710
float Zoom
Definition: C4Viewport.h:101
int32_t GetHeight() const
bool Move(float iX, float iY, float zoom, DWORD dwKeyState)
C4ViewportList Viewports
Definition: C4Viewport.cpp:841
float GetViewY()
Definition: C4Viewport.h:75
const char * GetName() const
Definition: C4Player.h:151
float GetZoom()
Definition: C4Viewport.h:45
void Close() override
int32_t ValidPlr(int32_t plr)
#define C4ViewportWindowStyle
bool ScrollBarsByViewPosition()
Definition: C4Console.cpp:709
bool CloseViewport(int32_t iPlayer, bool fSilent)
Definition: C4Viewport.cpp:961
std::unique_ptr< C4ViewportWindow > pWindow
Definition: C4Viewport.h:110
virtual C4Window * Init(WindowKind windowKind, C4AbstractApp *pApp, const char *Title, const C4Rect *size)
Definition: C4AppT.cpp:106
#define X(sdl, oc)
void Execute()
Definition: C4Viewport.cpp:380
void EditCursorMove(int X, int Y, uint32_t)
float WindowToGameX(int32_t win_x)
Definition: C4Viewport.h:82
float GetViewX()
Definition: C4Viewport.h:73
int32_t Player
Definition: C4Viewport.h:105
C4Application Application
Definition: C4Globals.cpp:44
C4Window * Init(int32_t iPlayer)
int32_t GetWidth() const
bool ViewPositionByScrollBars()
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270