OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Viewport Class Reference

#include <C4Viewport.h>

Collaboration diagram for C4Viewport:
[legend]

Public Member Functions

 C4Viewport ()
 
 ~C4Viewport ()
 
float GetZoom ()
 
void SetZoom (float zoomValue)
 
float GetGUIZoom () const
 
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)
 
void CalculateZoom ()
 
void ChangeZoom (float by_factor)
 
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
 
float GetZoomLimitMin () const
 
float GetZoomLimitMax () const
 
float GetZoomTarget () const
 
bool Init (int32_t iPlayer, bool fSetTempOnly)
 
void DropFile (const char *fileName, float x, float y)
 
bool TogglePlayerLock ()
 
bool GetPlayerLock ()
 
void NextPlayer ()
 
C4Rect GetOutputRect ()
 
bool IsViewportMenu (class C4Menu *pMenu)
 
C4ViewportGetNext ()
 
int32_t GetPlayer ()
 
void CenterPosition ()
 
void DisableFoW ()
 
void EnableFoW ()
 
float GetViewX ()
 
float GetViewY ()
 
float GetViewCenterX ()
 
float GetViewCenterY ()
 
float WindowToGameX (int32_t win_x)
 
float WindowToGameY (int32_t win_y)
 
void ScrollView (float byX, float byY)
 
void SetViewX (float x)
 
void SetViewY (float y)
 
void SetViewOffset (int32_t x, int32_t y)
 
float GetZoom () const
 
void AdjustPosition (bool immediate=false)
 
C4ViewportWindowGetWindow ()
 
bool UpdateOutputSize (int32_t new_width=0, int32_t new_height=0)
 
bool ViewPositionByScrollBars ()
 
bool ScrollBarsByViewPosition ()
 

Public Attributes

int32_t ViewWdt
 
int32_t ViewHgt
 
float BorderLeft
 
float BorderTop
 
float BorderRight
 
float BorderBottom
 
int32_t DrawX
 
int32_t DrawY
 
C4TargetFacet last_game_draw_cgo
 
C4TargetFacet last_gui_draw_cgo
 
bool fIsNoOwnerViewport
 

Protected Member Functions

void DrawPlayerStartup (C4TargetFacet &cgo)
 
void Draw (C4TargetFacet &cgo, bool fDrawGame, bool fDrawOverlay)
 
void DrawOverlay (C4TargetFacet &cgo, const ZoomData &GameZoom)
 
void DrawMenu (C4TargetFacet &cgo)
 
void DrawPlayerInfo (C4TargetFacet &cgo)
 
void InitZoom ()
 
void BlitOutput ()
 
void AdjustZoomAndPosition ()
 

Protected Attributes

float Zoom
 
float ZoomTarget
 
float ZoomLimitMin
 
float ZoomLimitMax
 
int32_t ViewportOpenFrame
 
int32_t Player
 
bool PlayerLock
 
int32_t OutX
 
int32_t OutY
 
bool ResetMenuPositions
 
C4ViewportNext
 
std::unique_ptr< C4ViewportWindowpWindow
 
std::unique_ptr< C4FoWRegionpFoW
 

Friends

class C4MouseControl
 
class C4ViewportWindow
 
class C4ViewportList
 
class C4GraphicsSystem
 
class C4ConsoleQtViewportView
 

Detailed Description

Definition at line 29 of file C4Viewport.h.

Constructor & Destructor Documentation

C4Viewport::C4Viewport ( )

Definition at line 89 of file C4Viewport.cpp.

References BorderBottom, BorderLeft, BorderRight, BorderTop, DrawX, DrawY, fIsNoOwnerViewport, Next, OutX, OutY, Player, PlayerLock, ResetMenuPositions, ViewHgt, ViewportOpenFrame, ViewWdt, Zoom, ZoomLimitMax, ZoomLimitMin, and ZoomTarget.

90 {
91  Player = 0;
92  viewX = viewY = 0;
93  targetViewX = targetViewY = 0;
94  ViewWdt = ViewHgt = 0;
96  OutX = OutY = ViewWdt = ViewHgt = 0;
97  DrawX = DrawY = 0;
98  Zoom = 1.0;
99  ZoomTarget = 0.0;
100  ViewportOpenFrame = 0;
101  ZoomLimitMin = ZoomLimitMax = 0; // no limit
102  Next = nullptr;
103  PlayerLock = true;
104  ResetMenuPositions = false;
105  viewOffsX = viewOffsY = 0;
106  fIsNoOwnerViewport = false;
107 }
int32_t OutX
Definition: C4Viewport.h:107
int32_t OutY
Definition: C4Viewport.h:107
int32_t DrawY
Definition: C4Viewport.h:39
int32_t DrawX
Definition: C4Viewport.h:39
bool PlayerLock
Definition: C4Viewport.h:106
int32_t ViewHgt
Definition: C4Viewport.h:36
int32_t ViewWdt
Definition: C4Viewport.h:36
bool fIsNoOwnerViewport
Definition: C4Viewport.h:43
bool ResetMenuPositions
Definition: C4Viewport.h:108
float Zoom
Definition: C4Viewport.h:101
C4Viewport * Next
Definition: C4Viewport.h:109
float BorderBottom
Definition: C4Viewport.h:38
float ZoomTarget
Definition: C4Viewport.h:102
float BorderTop
Definition: C4Viewport.h:38
int32_t ViewportOpenFrame
Definition: C4Viewport.h:104
int32_t Player
Definition: C4Viewport.h:105
float ZoomLimitMax
Definition: C4Viewport.h:103
float BorderRight
Definition: C4Viewport.h:38
float BorderLeft
Definition: C4Viewport.h:38
float ZoomLimitMin
Definition: C4Viewport.h:103
C4Viewport::~C4Viewport ( )

Definition at line 109 of file C4Viewport.cpp.

References DisableFoW(), and pWindow.

110 {
111  DisableFoW();
112  if (pWindow) { delete pWindow->pSurface; pWindow->Clear(); }
113 }
void DisableFoW()
Definition: C4Viewport.cpp:690
std::unique_ptr< C4ViewportWindow > pWindow
Definition: C4Viewport.h:110

Here is the call graph for this function:

Member Function Documentation

void C4Viewport::AdjustPosition ( bool  immediate = false)

Definition at line 544 of file C4Viewport.cpp.

References C4PVM_Scrolling, C4ViewportScrollBorder, Clamp(), Config, C4Config::Controls, fIsNoOwnerViewport, fixtof(), C4Config::General, C4PlayerList::Get(), C4Landscape::GetHeight(), C4Landscape::GetWidth(), C4MouseControl::InitCentered, Landscape, C4ConfigControls::MouseAutoScroll, MouseControl, C4Player::MouseControl, Player, PlayerLock, Players, C4ConfigGeneral::ScrollSmooth, ScrollView(), SetViewX(), SetViewY(), ValidPlr(), ViewHgt, C4Player::ViewMode, ViewWdt, C4Player::ViewX, C4Player::ViewY, C4MouseControl::VpX, C4MouseControl::VpY, Zoom, and ZoomTarget.

Referenced by AdjustZoomAndPosition(), and C4Player::SetViewMode().

545 {
546  if (ViewWdt == 0 || ViewHgt == 0)
547  {
548  // zero-sized viewport, possibly minimized editor window
549  // don't do anything then
550  return;
551  }
552 
553  assert(Zoom>0);
554  assert(ZoomTarget>0);
555 
556  float ViewportScrollBorder = fIsNoOwnerViewport ? 0 : float(C4ViewportScrollBorder);
557  C4Player *pPlr = ::Players.Get(Player);
558 
559  // View position
560  if (PlayerLock && ValidPlr(Player))
561  {
562  float scrollRange, extraBoundsX, extraBoundsY;
563 
564  scrollRange = extraBoundsX = extraBoundsY = 0;
565 
566  // target view position (landscape coordinates)
567  float targetCenterViewX = fixtof(pPlr->ViewX);
568  float targetCenterViewY = fixtof(pPlr->ViewY);
569 
570  if (pPlr->ViewMode == C4PVM_Scrolling)
571  {
572  extraBoundsX = extraBoundsY = ViewportScrollBorder;
573  }
574  else
575  {
576  scrollRange = std::min(ViewWdt/(10*Zoom),ViewHgt/(10*Zoom));
577 
578  // if view is close to border, allow scrolling
579  if (targetCenterViewX < ViewportScrollBorder) extraBoundsX = std::min<float>(ViewportScrollBorder - targetCenterViewX, ViewportScrollBorder);
580  else if (targetCenterViewX >= ::Landscape.GetWidth() - ViewportScrollBorder) extraBoundsX = std::min<float>(targetCenterViewX - ::Landscape.GetWidth(), 0) + ViewportScrollBorder;
581  if (targetCenterViewY < ViewportScrollBorder) extraBoundsY = std::min<float>(ViewportScrollBorder - targetCenterViewY, ViewportScrollBorder);
582  else if (targetCenterViewY >= ::Landscape.GetHeight() - ViewportScrollBorder) extraBoundsY = std::min<float>(targetCenterViewY - ::Landscape.GetHeight(), 0) + ViewportScrollBorder;
583  }
584 
585  extraBoundsX = std::max(extraBoundsX, (ViewWdt/Zoom - ::Landscape.GetWidth())/2 + 1);
586  extraBoundsY = std::max(extraBoundsY, (ViewHgt/Zoom - ::Landscape.GetHeight())/2 + 1);
587 
588  // add mouse auto scroll
590  {
591  float strength = Config.Controls.MouseAutoScroll/100.0f;
592  targetCenterViewX += strength*(::MouseControl.VpX - ViewWdt/2.0f)/Zoom;
593  targetCenterViewY += strength*(::MouseControl.VpY - ViewHgt/2.0f)/Zoom;
594  }
595 
596  // scroll range
597  if (!immediate)
598  {
599  targetCenterViewX = Clamp(targetCenterViewX, targetCenterViewX - scrollRange, targetCenterViewX + scrollRange);
600  targetCenterViewY = Clamp(targetCenterViewY, targetCenterViewY - scrollRange, targetCenterViewY + scrollRange);
601  }
602  // bounds
603  targetCenterViewX = Clamp(targetCenterViewX, ViewWdt/Zoom/2 - extraBoundsX, ::Landscape.GetWidth() - ViewWdt/Zoom/2 + extraBoundsX);
604  targetCenterViewY = Clamp(targetCenterViewY, ViewHgt/Zoom/2 - extraBoundsY, ::Landscape.GetHeight() - ViewHgt/Zoom/2 + extraBoundsY);
605 
606  targetViewX = targetCenterViewX - ViewWdt/Zoom/2 + viewOffsX;
607  targetViewY = targetCenterViewY - ViewHgt/Zoom/2 + viewOffsY;
608 
609  if (immediate)
610  {
611  // immediate scroll
612  SetViewX(targetViewX);
613  SetViewY(targetViewY);
614  }
615  else
616  {
617  // smooth scroll
618  int32_t smooth = Clamp<int32_t>(Config.General.ScrollSmooth, 1, 50);
619  ScrollView((targetViewX - viewX) / smooth, (targetViewY - viewY) / smooth);
620  }
621  }
622 
623  UpdateBordersX();
624  UpdateBordersY();
625 
626  // NO_OWNER can't scroll
627  if (fIsNoOwnerViewport) { viewOffsX=0; viewOffsY=0; }
628 }
int32_t MouseAutoScroll
Definition: C4Config.h:230
const int32_t C4PVM_Scrolling
Definition: C4Player.h:33
int32_t MouseControl
Definition: C4Player.h:92
C4Config Config
Definition: C4Config.cpp:833
int32_t ViewMode
Definition: C4Player.h:105
C4ConfigGeneral General
Definition: C4Config.h:251
bool PlayerLock
Definition: C4Viewport.h:106
const int C4ViewportScrollBorder
Definition: C4Constants.h:65
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
int32_t ViewHgt
Definition: C4Viewport.h:36
C4Player * Get(int iPlayer) const
int32_t ViewWdt
Definition: C4Viewport.h:36
bool fIsNoOwnerViewport
Definition: C4Viewport.h:43
C4Landscape Landscape
void ScrollView(float byX, float byY)
Definition: C4Viewport.cpp:734
C4PlayerList Players
void SetViewX(float x)
Definition: C4Viewport.cpp:740
void SetViewY(float y)
Definition: C4Viewport.cpp:759
float Zoom
Definition: C4Viewport.h:101
int32_t GetHeight() const
C4Real ViewY
Definition: C4Player.h:106
C4ConfigControls Controls
Definition: C4Config.h:259
int32_t ValidPlr(int32_t plr)
float fixtof(const C4Fixed &x)
Definition: C4Real.h:257
float ZoomTarget
Definition: C4Viewport.h:102
int32_t Player
Definition: C4Viewport.h:105
int32_t ScrollSmooth
Definition: C4Config.h:49
int32_t GetWidth() const
C4Real ViewX
Definition: C4Player.h:106

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::AdjustZoomAndPosition ( )
protected

Definition at line 502 of file C4Viewport.cpp.

References AdjustPosition(), C4GFX_ZoomStep, CalculateZoom(), ViewHgt, ViewWdt, Zoom, and ZoomTarget.

Referenced by Execute().

503 {
504  // Move zoom towards target zoom
505  if (ZoomTarget < 0.000001f) CalculateZoom();
506  // Change Zoom
507 
508  if (Zoom != ZoomTarget)
509  {
510  float DeltaZoom = Zoom / ZoomTarget;
511  if (DeltaZoom<1) DeltaZoom = 1 / DeltaZoom;
512 
513  // Minimal Zoom change factor
514  static const float Z0 = pow(C4GFX_ZoomStep, 1.0f / 8.0f);
515 
516  // We change zoom based on (logarithmic) distance of current zoom
517  // to target zoom. The greater the distance the more we adjust the
518  // zoom in one frame. There is a minimal zoom change Z0 to make sure
519  // we reach ZoomTarget in finite time.
520  float ZoomAdjustFactor = Z0 * pow(DeltaZoom, 1.0f / 8.0f);
521 
522  if (Zoom == 0)
523  Zoom = ZoomTarget;
524  else
525  {
526  // Remember old viewport center
527  float view_mid_x = this->viewX + float(this->ViewWdt) / Zoom / 2.0f;
528  float view_mid_y = this->viewY + float(this->ViewHgt) / Zoom / 2.0f;
529 
530  if (Zoom < ZoomTarget)
531  Zoom = std::min(Zoom * ZoomAdjustFactor, ZoomTarget);
532  if (Zoom > ZoomTarget)
533  Zoom = std::max(Zoom / ZoomAdjustFactor, ZoomTarget);
534 
535  // Restore new viewport center
536  this->viewX = view_mid_x - float(this->ViewWdt) / Zoom / 2.0f;
537  this->viewY = view_mid_y - float(this->ViewHgt) / Zoom / 2.0f;
538  }
539  }
540  // Adjust position
541  AdjustPosition(false);
542 }
void CalculateZoom()
Definition: C4Viewport.cpp:408
int32_t ViewHgt
Definition: C4Viewport.h:36
int32_t ViewWdt
Definition: C4Viewport.h:36
void AdjustPosition(bool immediate=false)
Definition: C4Viewport.cpp:544
float Zoom
Definition: C4Viewport.h:101
const float C4GFX_ZoomStep
float ZoomTarget
Definition: C4Viewport.h:102

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::BlitOutput ( )
protected

Definition at line 369 of file C4Viewport.cpp.

References DrawX, DrawY, C4Rect::Hgt, OutX, OutY, pWindow, ViewHgt, ViewWdt, C4Rect::Wdt, C4Rect::x, and C4Rect::y.

Referenced by Execute().

370 {
371  if (pWindow)
372  {
373  C4Rect rtSrc,rtDst;
374  rtSrc.x = DrawX; rtSrc.y = DrawY; rtSrc.Wdt = ViewWdt; rtSrc.Hgt = ViewHgt;
375  rtDst.x = OutX; rtDst.y = OutY; rtDst.Wdt = ViewWdt; rtDst.Hgt = ViewHgt;
376  pWindow->pSurface->PageFlip(&rtSrc, &rtDst);
377  }
378 }
int32_t OutX
Definition: C4Viewport.h:107
int32_t OutY
Definition: C4Viewport.h:107
int32_t DrawY
Definition: C4Viewport.h:39
int32_t DrawX
Definition: C4Viewport.h:39
Definition: C4Rect.h:27
int32_t ViewHgt
Definition: C4Viewport.h:36
int32_t Wdt
Definition: C4Rect.h:30
int32_t ViewWdt
Definition: C4Viewport.h:36
int32_t y
Definition: C4Rect.h:30
int32_t x
Definition: C4Rect.h:30
std::unique_ptr< C4ViewportWindow > pWindow
Definition: C4Viewport.h:110
int32_t Hgt
Definition: C4Rect.h:30

Here is the caller graph for this function:

void C4Viewport::CalculateZoom ( )

Definition at line 408 of file C4Viewport.cpp.

References C4Game::FrameCounter, Game, C4PlayerList::Get(), C4Landscape::GetHeight(), C4Landscape::GetWidth(), InitZoom(), Landscape, Player, Players, SetZoomLimits(), ViewHgt, ViewportOpenFrame, ViewWdt, and C4Player::ZoomLimitsToViewport().

Referenced by AdjustZoomAndPosition(), and SetOutputSize().

409 {
410  // Zoom is only initialized by player or global setting during viewport creation time, because after that
411  // the player may have changed to another preferred zoom.
412  // However, viewports may change multiple times during startup (because of NO_OWNER viewport being deleted
413  // and possible other player joins). So check by frame counter. Zoom changes done in paused mode on the
414  // player init frame will be lost, but that should not be a problem.
416  InitZoom();
417 
418  C4Player *plr = Players.Get(Player);
419  if (plr)
420  plr->ZoomLimitsToViewport(this);
421  else
422  SetZoomLimits(0.8*std::min<float>(float(ViewWdt)/::Landscape.GetWidth(),float(ViewHgt)/::Landscape.GetHeight()), 8);
423 
424 }
void InitZoom()
Definition: C4Viewport.cpp:426
C4Game Game
Definition: C4Globals.cpp:52
void ZoomLimitsToViewport(C4Viewport *vp)
Definition: C4Player.cpp:1858
int32_t ViewHgt
Definition: C4Viewport.h:36
C4Player * Get(int iPlayer) const
int32_t FrameCounter
Definition: C4Game.h:128
void SetZoomLimits(float to_min_zoom, float to_max_zoom)
Definition: C4Viewport.cpp:459
int32_t ViewWdt
Definition: C4Viewport.h:36
C4Landscape Landscape
C4PlayerList Players
int32_t GetHeight() const
int32_t ViewportOpenFrame
Definition: C4Viewport.h:104
int32_t Player
Definition: C4Viewport.h:105
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::CenterPosition ( )

Definition at line 630 of file C4Viewport.cpp.

References C4Landscape::GetHeight(), C4Landscape::GetWidth(), Landscape, SetViewX(), SetViewY(), ViewHgt, ViewWdt, and Zoom.

Referenced by C4ViewportList::CreateViewport().

631 {
632  // center viewport position on map
633  // set center position
636 }
int32_t ViewHgt
Definition: C4Viewport.h:36
int32_t ViewWdt
Definition: C4Viewport.h:36
C4Landscape Landscape
void SetViewX(float x)
Definition: C4Viewport.cpp:740
void SetViewY(float y)
Definition: C4Viewport.cpp:759
float Zoom
Definition: C4Viewport.h:101
int32_t GetHeight() const
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::ChangeZoom ( float  by_factor)

Definition at line 440 of file C4Viewport.cpp.

References ZoomLimitMax, ZoomLimitMin, and ZoomTarget.

Referenced by SetZoomLimits().

441 {
442  ZoomTarget *= by_factor;
445 }
float ZoomTarget
Definition: C4Viewport.h:102
float ZoomLimitMax
Definition: C4Viewport.h:103
float ZoomLimitMin
Definition: C4Viewport.h:103

Here is the caller graph for this function:

void C4Viewport::ClearPointers ( C4Object pObj)

Definition at line 803 of file C4Viewport.cpp.

804 {
805 
806 }
void C4Viewport::DisableFoW ( )

Definition at line 690 of file C4Viewport.cpp.

References pFoW.

Referenced by EnableFoW(), and ~C4Viewport().

691 {
692  pFoW.reset();
693 }
std::unique_ptr< C4FoWRegion > pFoW
Definition: C4Viewport.h:111

Here is the caller graph for this function:

void C4Viewport::Draw ( C4TargetFacet cgo,
bool  fDrawGame,
bool  fDrawOverlay 
)
protected

Definition at line 200 of file C4Viewport.cpp.

References Application, C4Draw::BlitSurfaceTile(), BorderBottom, BorderLeft, BorderRight, BorderTop, C4D_Foreground, C4Game::C4S, C4ST_STARTNEW, C4ST_STOP, Console, C4PathFinder::Draw(), C4Sky::Draw(), C4PXSSystem::Draw(), C4Landscape::Draw(), C4EditCursor::Draw(), C4GameMessageList::Draw(), C4ObjectList::Draw(), C4Draw::DrawBoxDw(), C4Game::DrawCrewOverheadText(), C4ParticleSystem::DrawGlobalParticles(), C4ObjectList::DrawIfCategory(), DrawOverlay(), C4Network2::DrawStatus(), DrawX, DrawY, C4Console::EditCursor, C4GraphicsResource::fctBackground, C4Player::fFogOfWar, C4SHead::Film, C4GameObjects::ForeObjects, Game, C4PlayerList::Get(), GetGUIZoom(), C4Landscape::GetSky(), GetViewX(), GetViewY(), GraphicsResource, GraphicsSystem, C4Scenario::Head, C4Rect::Hgt, C4Facet::Hgt, C4Application::isEditor, Landscape, last_game_draw_cgo, last_gui_draw_cgo, Messages, Network, C4Draw::NoPrimaryClipper(), Objects, Particles, C4Game::PathFinder, pDraw, pFoW, Player, Players, PXS, C4FoWRegion::Render(), C4SHead::Replay, C4Game::ScriptGuiRoot, C4TargetFacet::Set(), C4Draw::SetFoW(), C4Draw::SetPrimaryClipper(), C4Draw::SetZoom(), C4GraphicsSystem::ShowLights, C4GraphicsSystem::ShowNetstatus, C4GraphicsSystem::ShowPathfinder, C4Facet::Surface, C4TargetFacet::TargetX, C4TargetFacet::TargetY, C4FoWRegion::Update(), ViewHgt, ViewWdt, C4Rect::Wdt, C4Facet::Wdt, C4Rect::x, ZoomData::X, C4Facet::X, C4Rect::y, ZoomData::Y, C4Facet::Y, ZoomData::Zoom, Zoom, and C4TargetFacet::Zoom.

Referenced by C4GraphicsSystem::DoSaveScreenshot(), and Execute().

201 {
202 #ifdef USE_CONSOLE
203  // No drawing in console mode
204  return;
205 #endif
206  C4TargetFacet cgo; cgo.Set(cgo0);
207  ZoomData GameZoom;
208  GameZoom.X = cgo.X; GameZoom.Y = cgo.Y;
209  GameZoom.Zoom = cgo.Zoom;
210 
211  // Draw landscape borders
216 
217  // Compute non-bordered viewport area
218  cgo.X += BorderLeft; cgo.Y += BorderTop; cgo.Wdt -= (BorderLeft + BorderRight) / cgo.Zoom; cgo.Hgt -= (BorderTop + BorderBottom) / cgo.Zoom;
219  cgo.TargetX += BorderLeft / Zoom; cgo.TargetY += BorderTop / Zoom;
220 
221  // Apply Zoom
222  GameZoom.X = cgo.X; GameZoom.Y = cgo.Y;
223  pDraw->SetZoom(GameZoom);
224  // Set clipper to integer bounds around floating point viewport region
226  const C4Rect& clipRectInt(clipRect);
227  pDraw->SetPrimaryClipper(clipRectInt.x, clipRectInt.y, clipRectInt.x + clipRectInt.Wdt - 1, clipRectInt.y + clipRectInt.Hgt - 1);
228 
229  last_game_draw_cgo = cgo;
230 
231  if (fDrawGame)
232  {
233  // --- activate FoW here ---
234 
235  // Render FoW only if active for player
236  C4Player *pPlr = ::Players.Get(Player);
237  C4FoWRegion* pFoW = nullptr;
238  if (pPlr && pPlr->fFogOfWar) pFoW = this->pFoW.get();
239 
240  // Update FoW
241  if (pFoW)
242  {
243  // Viewport region in landscape coordinates
244  const FLOAT_RECT vpRect = { cgo.TargetX, cgo.TargetX + cgo.Wdt, cgo.TargetY, cgo.TargetY + cgo.Hgt };
245  // Region in which the light is calculated
246  // At the moment, just choose integer coordinates to surround the viewport
247  const C4Rect lightRect(vpRect);
248  if (!lightRect.Wdt || !lightRect.Hgt)
249  {
250  // Do not bother initializing FoW on empty region; would cause errors in drawing proc
251  pFoW = nullptr;
252  }
253  else
254  {
255  pFoW->Update(lightRect, vpRect);
256 
257  if (!pFoW->Render())
258  {
259  // If FoW init fails, do not set it for further drawing
260  pFoW = nullptr;
261  }
262  }
263  }
264 
265  pDraw->SetFoW(pFoW);
266 
267  C4ST_STARTNEW(SkyStat, "C4Viewport::Draw: Sky")
268  ::Landscape.GetSky().Draw(cgo);
269  C4ST_STOP(SkyStat)
270 
271  ::Objects.Draw(cgo, Player, -2147483647 - 1 /* INT32_MIN */, 0);
272 
273  // Draw Landscape
274  C4ST_STARTNEW(LandStat, "C4Viewport::Draw: Landscape")
275  ::Landscape.Draw(cgo, pFoW);
276  C4ST_STOP(LandStat)
277 
278  // draw PXS (unclipped!)
279  C4ST_STARTNEW(PXSStat, "C4Viewport::Draw: PXS")
280  ::PXS.Draw(cgo);
281  C4ST_STOP(PXSStat)
282 
283  // Draw objects which are behind the particle plane.
284  const int particlePlane = 900;
285  C4ST_STARTNEW(ObjStat, "C4Viewport::Draw: Objects (1)")
286  ::Objects.Draw(cgo, Player, 1, particlePlane);
287  C4ST_STOP(ObjStat)
288 
289  // Draw global dynamic particles on a specific Plane
290  // to enable scripters to put objects both behind and in front of particles.
292  ::Particles.DrawGlobalParticles(cgo);
293  C4ST_STOP(PartStat)
294 
295  // Now the remaining objects in front of the particles (e.g. GUI elements)
296  C4ST_STARTNEW(Obj2Stat, "C4Viewport::Draw: Objects (2)")
297  ::Objects.Draw(cgo, Player, particlePlane + 1, 2147483647 /* INT32_MAX */);
298  C4ST_STOP(Obj2Stat)
299 
300  // Draw everything else without FoW
301  pDraw->SetFoW(nullptr);
302  }
303  else
304  {
305  pDraw->DrawBoxDw(cgo.Surface, cgo.X, cgo.Y, cgo.X + cgo.Wdt, cgo.Y + cgo.Hgt, 0xff000000);
306  }
307 
308  // Draw PathFinder
310 
311  // Draw overlay
312  if (!Game.C4S.Head.Film || !Game.C4S.Head.Replay) Game.DrawCrewOverheadText(cgo, Player);
313 
314  // Lights overlay
315  if (::GraphicsSystem.ShowLights && pFoW) pFoW->Render(&cgo);
316 
317  if (fDrawOverlay)
318  {
319  // Determine zoom of overlay
320  float fGUIZoom = GetGUIZoom();
321  // now restore complete cgo range for overlay drawing
322  pDraw->SetZoom(DrawX,DrawY, fGUIZoom);
324  C4TargetFacet gui_cgo;
325  gui_cgo.Set(cgo0);
326 
327  gui_cgo.X = DrawX; gui_cgo.Y = DrawY; gui_cgo.Zoom = fGUIZoom;
328  gui_cgo.Wdt = int(float(ViewWdt)/fGUIZoom); gui_cgo.Hgt = int(float(ViewHgt)/fGUIZoom);
329  gui_cgo.TargetX = GetViewX(); gui_cgo.TargetY = GetViewY();
330 
331  last_gui_draw_cgo = gui_cgo;
332 
333  // draw custom GUI objects
334  ::Objects.ForeObjects.DrawIfCategory(gui_cgo, Player, C4D_Foreground, false);
335 
336  // Draw overlay
337  C4ST_STARTNEW(OvrStat, "C4Viewport::Draw: Overlay")
338 
339  if (Application.isEditor) ::Console.EditCursor.Draw(cgo);
340 
341  // Game messages
343  pDraw->SetZoom(0, 0, 1.0);
344  ::Messages.Draw(gui_cgo, cgo, Player);
345  C4ST_STOP(MsgStat)
346 
347  // ingame menus
348  C4ST_STARTNEW(GuiWindowStat, "C4Viewport::DrawOverlay: Menus")
349  pDraw->SetZoom(0, 0, 1.0);
350  ::Game.ScriptGuiRoot->DrawAll(gui_cgo, Player);
351  C4ST_STOP(GuiWindowStat)
352 
353  DrawOverlay(gui_cgo, GameZoom);
354 
355  // Netstats
356  if (::GraphicsSystem.ShowNetstatus)
357  ::Network.DrawStatus(gui_cgo);
358 
359  C4ST_STOP(OvrStat)
360 
361  }
362 
363  // Remove zoom n clippers
364  pDraw->SetZoom(0, 0, 1.0);
365  pDraw->NoPrimaryClipper();
366 
367 }
void Draw(C4TargetFacet &cgo, bool fDrawGame, bool fDrawOverlay)
Definition: C4Viewport.cpp:200
void SetFoW(const C4FoWRegion *fow)
Definition: C4Draw.h:193
float Y
Definition: C4Facet.h:118
float Zoom
Definition: C4Facet.h:165
C4Console Console
Definition: C4Globals.cpp:45
int32_t DrawY
Definition: C4Viewport.h:39
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4ParticleSystem Particles
int32_t DrawX
Definition: C4Viewport.h:39
bool Replay
Definition: C4Scenario.h:72
float Y
Definition: C4Draw.h:71
Definition: C4Rect.h:27
void Update(C4Rect r, const FLOAT_RECT &vp)
C4GraphicsResource GraphicsResource
void Draw(C4TargetFacet &cgo)
C4TargetFacet last_gui_draw_cgo
Definition: C4Viewport.h:41
int32_t ViewHgt
Definition: C4Viewport.h:36
std::unique_ptr< C4FoWRegion > pFoW
Definition: C4Viewport.h:111
void DrawOverlay(C4TargetFacet &cgo, const ZoomData &GameZoom)
Definition: C4Viewport.cpp:115
void DrawIfCategory(C4TargetFacet &cgo, int iPlayer, uint32_t dwCat, bool fInvert)
C4Player * Get(int iPlayer) const
bool BlitSurfaceTile(C4Surface *sfcSurface, C4Surface *sfcTarget, float iToX, float iToY, float iToWdt, float iToHgt, float iOffsetX, float iOffsetY, C4ShaderCall *shader_call)
Definition: C4Draw.cpp:535
C4Network2 Network
Definition: C4Globals.cpp:53
int32_t ViewWdt
Definition: C4Viewport.h:36
C4Landscape Landscape
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
void DrawBoxDw(C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
Definition: C4Draw.cpp:846
void SetZoom(float zoomValue)
Definition: C4Viewport.cpp:495
void Set(const C4Facet &cpy)
Definition: C4Facet.h:182
C4PlayerList Players
#define C4ST_STOP(StatName)
Definition: C4Stat.h:153
C4Draw * pDraw
Definition: C4Draw.cpp:42
C4PXSSystem PXS
Definition: C4PXS.cpp:525
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:217
float Zoom
Definition: C4Viewport.h:101
C4TargetFacet last_game_draw_cgo
Definition: C4Viewport.h:41
float TargetX
Definition: C4Facet.h:165
#define C4ST_STARTNEW(StatName, strName)
Definition: C4Stat.h:150
float GetViewY()
Definition: C4Viewport.h:75
float BorderBottom
Definition: C4Viewport.h:38
float Hgt
Definition: C4Facet.h:118
C4PathFinder PathFinder
Definition: C4Game.h:84
C4ObjectList ForeObjects
Definition: C4GameObjects.h:44
float GetGUIZoom() const
Definition: C4Viewport.h:47
float X
Definition: C4Draw.h:71
C4SHead Head
Definition: C4Scenario.h:230
bool fFogOfWar
Definition: C4Player.h:111
C4GameMessageList Messages
float BorderTop
Definition: C4Viewport.h:38
C4Surface * Surface
Definition: C4Facet.h:117
float TargetY
Definition: C4Facet.h:165
float GetViewX()
Definition: C4Viewport.h:73
int32_t Player
Definition: C4Viewport.h:105
bool Render(const C4TargetFacet *pOnScreen=nullptr)
float Wdt
Definition: C4Facet.h:118
void SetZoom(float X, float Y, float Zoom)
Definition: C4Draw.cpp:779
float X
Definition: C4Facet.h:118
float Zoom
Definition: C4Draw.h:70
C4Application Application
Definition: C4Globals.cpp:44
const int32_t C4D_Foreground
Definition: C4Def.h:53
float BorderRight
Definition: C4Viewport.h:38
int32_t Film
Definition: C4Scenario.h:73
void DrawCrewOverheadText(C4TargetFacet &cgo, int32_t iPlayer)
Definition: C4Game.cpp:1532
C4GameObjects Objects
Definition: C4Globals.cpp:48
float BorderLeft
Definition: C4Viewport.h:38

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::DrawMenu ( C4TargetFacet cgo)
protected

Definition at line 143 of file C4Viewport.cpp.

References ACenter, C4Draw::ActivateBlitModulation(), C4Player::Cursor, C4Draw::DeactivateBlitModulation(), C4Menu::Draw(), C4Player::Eliminated, C4GraphicsResource::FontRegular, FormatString(), FullScreen, C4PlayerList::Get(), C4Player::GetName(), GraphicsResource, C4Facet::Hgt, C4Menu::IsActive(), C4MouseControl::IsDragging(), C4MouseControl::IsViewport(), LoadResStr(), C4Player::Menu, C4Object::Menu, MouseControl, pDraw, Player, Players, C4FullScreen::pMenu, C4Menu::ResetLocation(), ResetMenuPositions, C4TargetFacet::Set(), C4Draw::SetZoom(), C4Facet::Surface, C4Player::Surrendered, C4TargetFacet::TargetX, C4TargetFacet::TargetY, C4Draw::TextOut(), C4Facet::Wdt, C4Facet::X, C4Facet::Y, and C4TargetFacet::Zoom.

Referenced by DrawOverlay().

144 {
145  // Get player
146  C4Player *pPlr = ::Players.Get(Player);
147 
148  // for menus, cgo is using GUI-syntax: TargetX/Y marks the drawing offset; x/y/Wdt/Hgt marks the offset rect
149  C4TargetFacet cgo; cgo.Set(cgo0);
150  cgo.X = 0; cgo.Y = 0;
151  cgo.Wdt = cgo0.Wdt * cgo0.Zoom; cgo.Hgt = cgo0.Hgt * cgo0.Zoom;
152  cgo.TargetX = float(cgo0.X); cgo.TargetY = float(cgo0.Y);
153  cgo.Zoom = 1;
154  pDraw->SetZoom(cgo.X, cgo.Y, cgo.Zoom);
155 
156  // Player eliminated
157  if (pPlr && pPlr->Eliminated)
158  {
159  pDraw->TextOut(FormatString(LoadResStr(pPlr->Surrendered ? "IDS_PLR_SURRENDERED" : "IDS_PLR_ELIMINATED"),pPlr->GetName()).getData(),
160  ::GraphicsResource.FontRegular, 1.0, cgo.Surface,cgo.TargetX+cgo.Wdt/2,cgo.TargetY+2*cgo.Hgt/3,0xfaFF0000,ACenter);
161  return;
162  }
163 
164  // Player cursor object menu
165  if (pPlr && pPlr->Cursor && pPlr->Cursor->Menu)
166  {
168  // if mouse is dragging, make it transparent to easy construction site drag+drop
169  bool fDragging=false;
171  {
172  fDragging = true;
173  pDraw->ActivateBlitModulation(0x4fffffff);
174  }
175  // draw menu
176  pPlr->Cursor->Menu->Draw(cgo);
177  // reset modulation for dragging
178  if (fDragging) pDraw->DeactivateBlitModulation();
179  }
180  // Player menu
181  if (pPlr && pPlr->Menu.IsActive())
182  {
184  pPlr->Menu.Draw(cgo);
185  }
186  // Fullscreen menu
188  {
190  FullScreen.pMenu->Draw(cgo);
191  }
192 
193  // Flag done
194  ResetMenuPositions=false;
195 
196  // restore Zoom
197  pDraw->SetZoom(cgo0.X, cgo0.Y, cgo0.Zoom);
198 }
void ResetLocation()
Definition: C4Menu.h:195
float Y
Definition: C4Facet.h:118
C4ObjectPtr Cursor
Definition: C4Player.h:130
float Zoom
Definition: C4Facet.h:165
C4MainMenu * pMenu
Definition: C4FullScreen.h:30
C4MainMenu Menu
Definition: C4Player.h:103
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:567
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
C4GraphicsResource GraphicsResource
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4Player * Get(int iPlayer) const
class C4ObjectMenu * Menu
Definition: C4Object.h:140
void Draw(C4TargetFacet &cgo) override
Definition: C4Menu.cpp:775
const int ACenter
Definition: C4Surface.h:41
bool IsViewport(C4Viewport *pViewport)
bool ResetMenuPositions
Definition: C4Viewport.h:108
void Set(const C4Facet &cpy)
Definition: C4Facet.h:182
C4PlayerList Players
C4Draw * pDraw
Definition: C4Draw.cpp:42
int32_t Surrendered
Definition: C4Player.h:84
int32_t Eliminated
Definition: C4Player.h:83
bool IsActive()
Definition: C4Menu.cpp:480
float TargetX
Definition: C4Facet.h:165
const char * GetName() const
Definition: C4Player.h:151
float Hgt
Definition: C4Facet.h:118
void DeactivateBlitModulation()
Definition: C4Draw.h:189
void ActivateBlitModulation(DWORD dwWithClr)
Definition: C4Draw.h:188
C4Surface * Surface
Definition: C4Facet.h:117
float TargetY
Definition: C4Facet.h:165
int32_t Player
Definition: C4Viewport.h:105
float Wdt
Definition: C4Facet.h:118
void SetZoom(float X, float Y, float Zoom)
Definition: C4Draw.cpp:779
float X
Definition: C4Facet.h:118
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::DrawOverlay ( C4TargetFacet cgo,
const ZoomData GameZoom 
)
protected

Definition at line 115 of file C4Viewport.cpp.

References C4Game::C4S, C4ST_STARTNEW, C4ST_STOP, C4MouseControl::Draw(), DrawMenu(), DrawPlayerInfo(), C4SHead::Film, Game, C4Scenario::Head, C4MouseControl::IsViewport(), MouseControl, pGUI, pWindow, C4GUI::Screen::RenderMouse(), and C4SHead::Replay.

Referenced by Draw().

116 {
117  if (!Game.C4S.Head.Film || !Game.C4S.Head.Replay)
118  {
119  // Player info
120  C4ST_STARTNEW(PInfoStat, "C4Viewport::DrawOverlay: Player Info")
121  DrawPlayerInfo(cgo);
122  C4ST_STOP(PInfoStat)
123  C4ST_STARTNEW(MenuStat, "C4Viewport::DrawOverlay: Menu")
124  DrawMenu(cgo);
125  C4ST_STOP(MenuStat)
126  }
127 
128  // Control overlays (if not film/replay)
129  if (!Game.C4S.Head.Film || !Game.C4S.Head.Replay)
130  {
131  // Mouse control
132  if (::MouseControl.IsViewport(this))
133  {
134  C4ST_STARTNEW(MouseStat, "C4Viewport::DrawOverlay: Mouse")
135  ::MouseControl.Draw(cgo, GameZoom);
136  // Draw GUI-mouse in EM if active
137  if (pWindow) ::pGUI->RenderMouse(cgo);
138  C4ST_STOP(MouseStat)
139  }
140  }
141 }
void Draw(C4TargetFacet &cgo, bool fDrawGame, bool fDrawOverlay)
Definition: C4Viewport.cpp:200
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
bool Replay
Definition: C4Scenario.h:72
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
void DrawOverlay(C4TargetFacet &cgo, const ZoomData &GameZoom)
Definition: C4Viewport.cpp:115
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
bool IsViewport(C4Viewport *pViewport)
void RenderMouse(C4TargetFacet &cgo)
Definition: C4Gui.cpp:739
#define C4ST_STOP(StatName)
Definition: C4Stat.h:153
void DrawPlayerInfo(C4TargetFacet &cgo)
Definition: C4Viewport.cpp:650
void DrawMenu(C4TargetFacet &cgo)
Definition: C4Viewport.cpp:143
#define C4ST_STARTNEW(StatName, strName)
Definition: C4Stat.h:150
std::unique_ptr< C4ViewportWindow > pWindow
Definition: C4Viewport.h:110
C4SHead Head
Definition: C4Scenario.h:230
int32_t Film
Definition: C4Scenario.h:73

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::DrawPlayerInfo ( C4TargetFacet cgo)
protected

Definition at line 650 of file C4Viewport.cpp.

References DrawPlayerStartup(), Player, and ValidPlr().

Referenced by DrawOverlay().

651 {
652  C4Facet ccgo;
653  if (!ValidPlr(Player)) return;
654  // Controls
655  DrawPlayerStartup(cgo);
656 }
int32_t ValidPlr(int32_t plr)
void DrawPlayerStartup(C4TargetFacet &cgo)
Definition: C4Viewport.cpp:709
int32_t Player
Definition: C4Viewport.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::DrawPlayerStartup ( C4TargetFacet cgo)
protected

Definition at line 709 of file C4Viewport.cpp.

References ACenter, C4Player::ColorDw, C4Player::ControlSet, C4Facet::Draw(), DrawMessageOffset, C4GraphicsResource::FontRegular, C4PlayerList::Get(), C4Player::GetName(), C4PlayerControlAssignmentSet::GetPicture(), GfxR, GraphicsResource, C4Facet::Hgt, C4Player::LocalControl, pDraw, Player, Players, C4Player::ShowStartup, C4Facet::Surface, C4Draw::TextOut(), C4Facet::Wdt, C4Facet::X, and C4Facet::Y.

Referenced by DrawPlayerInfo().

710 {
711  C4Player *pPlr;
712  if (!(pPlr = ::Players.Get(Player))) return;
713  if (!pPlr->LocalControl || !pPlr->ShowStartup) return;
714  int32_t iNameHgtOff=0;
715 
716  // Control
717  // unnecessary with the current control sets
718  if (pPlr && pPlr->ControlSet)
719  {
720  C4Facet controlset_facet = pPlr->ControlSet->GetPicture();
721  if (controlset_facet.Wdt) controlset_facet.Draw(cgo.Surface,
722  cgo.X+(cgo.Wdt-controlset_facet.Wdt)/2,
723  cgo.Y+cgo.Hgt * 2/3 + DrawMessageOffset,
724  0,0);
725  iNameHgtOff=GfxR->fctKeyboard.Hgt;
726  }
727 
728  // Name
730  cgo.X+cgo.Wdt/2,cgo.Y+cgo.Hgt*2/3+iNameHgtOff + DrawMessageOffset,
731  pPlr->ColorDw | 0xff000000, ACenter);
732 }
float Y
Definition: C4Facet.h:118
#define GfxR
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:567
bool ShowStartup
Definition: C4Player.h:109
C4GraphicsResource GraphicsResource
uint32_t ColorDw
Definition: C4Player.h:89
C4Player * Get(int iPlayer) const
class C4PlayerControlAssignmentSet * ControlSet
Definition: C4Player.h:90
const int ACenter
Definition: C4Surface.h:41
C4PlayerList Players
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
Definition: C4Facet.cpp:154
C4Draw * pDraw
Definition: C4Draw.cpp:42
const char * GetName() const
Definition: C4Player.h:151
float Hgt
Definition: C4Facet.h:118
C4Surface * Surface
Definition: C4Facet.h:117
int32_t Player
Definition: C4Viewport.h:105
float Wdt
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
bool LocalControl
Definition: C4Player.h:99
int32_t DrawMessageOffset

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::DropFile ( const char *  fileName,
float  x,
float  y 
)

Definition at line 47 of file C4Viewport.cpp.

References C4Game::DropFile(), Game, GetViewX(), GetViewY(), and Zoom.

Referenced by ViewportWinProc().

48 {
49  Game.DropFile(fileName, GetViewX()+x/Zoom, GetViewY()+y/Zoom);
50 }
C4Game Game
Definition: C4Globals.cpp:52
float Zoom
Definition: C4Viewport.h:101
float GetViewY()
Definition: C4Viewport.h:75
bool DropFile(const char *szFilename, float iX, float iY)
Definition: C4Game.cpp:1373
float GetViewX()
Definition: C4Viewport.h:73

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::EnableFoW ( )

Definition at line 695 of file C4Viewport.cpp.

References DisableFoW(), C4PlayerList::Get(), C4Landscape::GetFoW(), C4Landscape::HasFoW(), Landscape, NO_OWNER, pFoW, Player, and Players.

Referenced by Init().

696 {
697  if (::Landscape.HasFoW() && Player != NO_OWNER)
698  {
699  pFoW = std::make_unique<C4FoWRegion>(::Landscape.GetFoW(), ::Players.Get(Player));
700  }
701  else
702  {
703  DisableFoW();
704  }
705 }
bool HasFoW() const
class C4FoW * GetFoW()
std::unique_ptr< C4FoWRegion > pFoW
Definition: C4Viewport.h:111
C4Player * Get(int iPlayer) const
C4Landscape Landscape
C4PlayerList Players
void DisableFoW()
Definition: C4Viewport.cpp:690
const int NO_OWNER
Definition: C4Constants.h:137
int32_t Player
Definition: C4Viewport.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::Execute ( )

Definition at line 380 of file C4Viewport.cpp.

References AdjustZoomAndPosition(), Application, BlitOutput(), C4Game::C4S, C4Network2::Clients, C4Game::DebugMode, Draw(), DrawX, DrawY, FullScreen, Game, GameScript, C4PlayerInfoList::GetJoinIssuedPlayerCount(), C4Network2ClientList::GetLocal(), C4Value::getPropList(), GetViewX(), GetViewY(), C4Application::isEditor, C4Network2::isEnabled(), C4Network2Client::isObserver(), C4Scenario::Landscape, Network, NO_OWNER, pDraw, Player, C4Game::PlayerInfos, C4Draw::PrepareRendering(), C4Window::pSurface, C4ScriptUniform::Push(), pWindow, C4GameScriptHost::ScenPropList, C4Draw::scriptUniform, C4SLandscape::Secret, C4TargetFacet::Set(), ViewHgt, ViewWdt, and Zoom.

Referenced by C4ViewportWindow::PerformUpdate(), and ViewportWinProc().

381 {
382  // Adjust position
384  // Current graphics output
385  C4TargetFacet cgo;
386  C4Surface *target = pWindow ? pWindow->pSurface : FullScreen.pSurface;
387  cgo.Set(target,DrawX,DrawY,float(ViewWdt)/Zoom,float(ViewHgt)/Zoom,GetViewX(),GetViewY(),Zoom);
388  pDraw->PrepareRendering(target);
389  // Load script uniforms from Global.Uniforms
390  auto uniform_pop = pDraw->scriptUniform.Push(::GameScript.ScenPropList.getPropList());
391  // Do not spoil game contents on owner-less viewport
392  bool draw_game = true;
393  if (Player == NO_OWNER)
394  if (!::Application.isEditor && !::Game.DebugMode)
396  if (::Game.PlayerInfos.GetJoinIssuedPlayerCount() > 0) // free scrolling allowed if the scenario was started explicitely without players to inspect the landscape
397  if (Game.C4S.Landscape.Secret)
398  draw_game = false;
399  // Draw
400  Draw(cgo, draw_game, true);
401  // Blit output
402  BlitOutput();
403 }
void Draw(C4TargetFacet &cgo, bool fDrawGame, bool fDrawOverlay)
Definition: C4Viewport.cpp:200
bool isObserver() const
int32_t DrawY
Definition: C4Viewport.h:39
C4Game Game
Definition: C4Globals.cpp:52
C4GameScriptHost GameScript
C4ScriptUniform scriptUniform
Definition: C4Draw.h:100
C4Scenario C4S
Definition: C4Game.h:74
int32_t DrawX
Definition: C4Viewport.h:39
C4Surface * pSurface
Definition: C4Window.h:274
C4SLandscape Landscape
Definition: C4Scenario.h:234
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
void BlitOutput()
Definition: C4Viewport.cpp:369
int32_t ViewHgt
Definition: C4Viewport.h:36
virtual bool PrepareRendering(C4Surface *sfcToSurface)=0
C4Network2 Network
Definition: C4Globals.cpp:53
int32_t GetJoinIssuedPlayerCount() const
int32_t ViewWdt
Definition: C4Viewport.h:36
C4Value ScenPropList
Definition: C4ScriptHost.h:163
void Set(const C4Facet &cpy)
Definition: C4Facet.h:182
const int NO_OWNER
Definition: C4Constants.h:137
C4Draw * pDraw
Definition: C4Draw.cpp:42
bool isEnabled() const
Definition: C4Network2.h:203
float Zoom
Definition: C4Viewport.h:101
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
float GetViewY()
Definition: C4Viewport.h:75
void AdjustZoomAndPosition()
Definition: C4Viewport.cpp:502
std::unique_ptr< C4ViewportWindow > pWindow
Definition: C4Viewport.h:110
C4Network2Client * GetLocal() const
float GetViewX()
Definition: C4Viewport.h:73
int32_t Player
Definition: C4Viewport.h:105
C4Application Application
Definition: C4Globals.cpp:44
std::unique_ptr< Popper > Push(C4PropList *proplist)
Definition: C4Shader.cpp:755
bool DebugMode
Definition: C4Game.h:144
C4PropList * getPropList() const
Definition: C4Value.h:116

Here is the call graph for this function:

Here is the caller graph for this function:

float C4Viewport::GetGUIZoom ( ) const
inline

Definition at line 47 of file C4Viewport.h.

Referenced by Draw(), C4MouseControl::Move(), and C4ScriptGuiWindow::OnMouseIn().

47 { return Clamp<float>(float(ViewWdt)/1280,0.5f,1.0f); }
int32_t ViewWdt
Definition: C4Viewport.h:36

Here is the caller graph for this function:

C4Viewport* C4Viewport::GetNext ( )
inline

Definition at line 66 of file C4Viewport.h.

References Next.

Referenced by C4Menu::GetViewport().

66 { return Next; }
C4Viewport * Next
Definition: C4Viewport.h:109

Here is the caller graph for this function:

C4Rect C4Viewport::GetOutputRect ( )
inline

Definition at line 64 of file C4Viewport.h.

References OutX, and OutY.

Referenced by C4GUI::Dialog::ApplyElementOffset(), C4GUI::Dialog::ApplyInvElementOffset(), C4GUI::Screen::MouseInput(), and C4MouseControl::Move().

64 { return C4Rect(OutX, OutY, ViewWdt, ViewHgt); }
int32_t OutX
Definition: C4Viewport.h:107
int32_t OutY
Definition: C4Viewport.h:107
Definition: C4Rect.h:27
int32_t ViewHgt
Definition: C4Viewport.h:36
int32_t ViewWdt
Definition: C4Viewport.h:36

Here is the caller graph for this function:

int32_t C4Viewport::GetPlayer ( )
inline

Definition at line 67 of file C4Viewport.h.

References Player.

Referenced by C4MainMenu::DoRefillInternal().

67 { return Player; }
int32_t Player
Definition: C4Viewport.h:105

Here is the caller graph for this function:

bool C4Viewport::GetPlayerLock ( )
inline

Definition at line 62 of file C4Viewport.h.

References PlayerLock.

62 { return PlayerLock; }
bool PlayerLock
Definition: C4Viewport.h:106
float C4Viewport::GetViewCenterX ( )
inline

Return x-position of the center of viewport in landscape coordinates

Definition at line 77 of file C4Viewport.h.

References Zoom.

77 { return viewX + ViewWdt/Zoom/2; }
int32_t ViewWdt
Definition: C4Viewport.h:36
float Zoom
Definition: C4Viewport.h:101
float C4Viewport::GetViewCenterY ( )
inline

Return y-position of the center of viewport in landscape coordinates

Definition at line 79 of file C4Viewport.h.

References Zoom.

79 { return viewY + ViewHgt/Zoom/2; }
int32_t ViewHgt
Definition: C4Viewport.h:36
float Zoom
Definition: C4Viewport.h:101
float C4Viewport::GetViewX ( )
inline

Return x-position of upper left corner of viewport in landscape coordinates

Definition at line 73 of file C4Viewport.h.

Referenced by C4Object::ActivateMenu(), Draw(), DropFile(), Execute(), C4MouseControl::Move(), ViewportWinProc(), and WindowToGameX().

73 { return viewX; }

Here is the caller graph for this function:

float C4Viewport::GetViewY ( )
inline

Return y-position of upper left corner of viewport in landscape coordinates

Definition at line 75 of file C4Viewport.h.

Referenced by C4Object::ActivateMenu(), Draw(), DropFile(), Execute(), C4MouseControl::Move(), ViewportWinProc(), and WindowToGameY().

75 { return viewY; }

Here is the caller graph for this function:

C4ViewportWindow* C4Viewport::GetWindow ( )
inline

Definition at line 123 of file C4Viewport.h.

123 {return pWindow.get();}
std::unique_ptr< C4ViewportWindow > pWindow
Definition: C4Viewport.h:110
float C4Viewport::GetZoom ( )
inline

Definition at line 45 of file C4Viewport.h.

References Zoom.

Referenced by C4Object::ActivateMenu(), and C4ViewportWindow::EditCursorMove().

45 { return Zoom; }
float Zoom
Definition: C4Viewport.h:101

Here is the caller graph for this function:

float C4Viewport::GetZoom ( ) const
inline

Definition at line 121 of file C4Viewport.h.

References Zoom.

121 { return Zoom; }
float Zoom
Definition: C4Viewport.h:101
float C4Viewport::GetZoomByViewRange ( int32_t  size_x,
int32_t  size_y 
) const

Definition at line 467 of file C4Viewport.cpp.

References ViewHgt, and ViewWdt.

Referenced by C4Player::ZoomLimitsToViewport(), and C4Player::ZoomToViewport().

468 {
469  // set zoom such that both size_x and size_y are guarantueed to fit into the viewport range
470  // determine whether zoom is to be calculated by x or by y
471  bool zoom_by_y = false;
472  if (size_x && size_y)
473  {
474  zoom_by_y = (size_y * ViewWdt > size_x * ViewHgt);
475  }
476  else if (size_y)
477  {
478  // no x size passed - zoom by y
479  zoom_by_y = true;
480  }
481  else
482  {
483  // 0/0 size passed - zoom to default
484  if (!size_x)
485  size_x = C4VP_DefViewRangeX * 2;
486  zoom_by_y = false;
487  }
488  // zoom calculation
489  if (zoom_by_y)
490  return float(ViewHgt) / size_y;
491  else
492  return float(ViewWdt) / size_x;
493 }
int32_t ViewHgt
Definition: C4Viewport.h:36
int32_t ViewWdt
Definition: C4Viewport.h:36

Here is the caller graph for this function:

float C4Viewport::GetZoomLimitMax ( ) const
inline

Definition at line 57 of file C4Viewport.h.

References ZoomLimitMax.

57 { return ZoomLimitMax; }
float ZoomLimitMax
Definition: C4Viewport.h:103
float C4Viewport::GetZoomLimitMin ( ) const
inline

Definition at line 56 of file C4Viewport.h.

References ZoomLimitMin.

56 { return ZoomLimitMin; }
float ZoomLimitMin
Definition: C4Viewport.h:103
float C4Viewport::GetZoomTarget ( ) const
inline

Definition at line 58 of file C4Viewport.h.

References ZoomTarget.

Referenced by C4Player::ZoomToViewport().

58 { return ZoomTarget; }
float ZoomTarget
Definition: C4Viewport.h:102

Here is the caller graph for this function:

bool C4Viewport::Init ( int32_t  iPlayer,
bool  fSetTempOnly 
)

Definition at line 658 of file C4Viewport.cpp.

References Application, EnableFoW(), fIsNoOwnerViewport, C4GraphicsSystem::FlashMessage(), C4Game::FrameCounter, Game, GraphicsSystem, C4Application::isEditor, NO_OWNER, Player, pWindow, TogglePlayerLock(), UpdateOutputSize(), ValidPlr(), and ViewportOpenFrame.

Referenced by C4ViewportList::CreateViewport(), C4MainMenu::MenuCommand(), NextPlayer(), and C4FullScreen::ViewportCheck().

659 {
660  // Fullscreen viewport initialization
661  // Set Player
662  if (!ValidPlr(iPlayer)) iPlayer = NO_OWNER;
663  Player=iPlayer;
665  if (!fSetTempOnly) fIsNoOwnerViewport = (iPlayer == NO_OWNER);
666  if (Application.isEditor)
667  {
668  // Console viewport initialization
669  // Create window
670  pWindow = std::make_unique<C4ViewportWindow>(this);
671  if (!pWindow->Init(Player))
672  return false;
674  // Disable player lock on unowned viewports
676  // Don't call Execute right away since it is not yet guaranteed that
677  // the Player has set this as its Viewport, and the drawing routines rely
678  // on that.
679  }
680  else
681  {
682  // Owned viewport: clear any flash message explaining observer menu
683  if (ValidPlr(iPlayer)) ::GraphicsSystem.FlashMessage("");
684  }
685 
686  EnableFoW();
687  return true;
688 }
C4Game Game
Definition: C4Globals.cpp:52
bool UpdateOutputSize(int32_t new_width=0, int32_t new_height=0)
Definition: C4Viewport.cpp:52
int32_t FrameCounter
Definition: C4Game.h:128
void EnableFoW()
Definition: C4Viewport.cpp:695
bool fIsNoOwnerViewport
Definition: C4Viewport.h:43
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
const int NO_OWNER
Definition: C4Constants.h:137
bool TogglePlayerLock()
Definition: C4Console.cpp:710
void FlashMessage(const char *szMessage)
int32_t ValidPlr(int32_t plr)
std::unique_ptr< C4ViewportWindow > pWindow
Definition: C4Viewport.h:110
int32_t ViewportOpenFrame
Definition: C4Viewport.h:104
int32_t Player
Definition: C4Viewport.h:105
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::InitZoom ( )
protected

Definition at line 426 of file C4Viewport.cpp.

References C4PlayerList::Get(), C4Landscape::GetWidth(), Landscape, Player, Players, ViewWdt, Zoom, ZoomTarget, and C4Player::ZoomToViewport().

Referenced by CalculateZoom().

427 {
428  C4Player *plr = Players.Get(Player);
429  if (plr)
430  {
431  plr->ZoomToViewport(this, true);
432  }
433  else
434  {
435  ZoomTarget = std::max<float>(float(ViewWdt)/::Landscape.GetWidth(), 1.0f);
436  Zoom = ZoomTarget;
437  }
438 }
void ZoomToViewport(C4Viewport *vp, bool direct, bool no_increase=false, bool no_decrease=false)
Definition: C4Player.cpp:1842
C4Player * Get(int iPlayer) const
int32_t ViewWdt
Definition: C4Viewport.h:36
C4Landscape Landscape
C4PlayerList Players
float Zoom
Definition: C4Viewport.h:101
float ZoomTarget
Definition: C4Viewport.h:102
int32_t Player
Definition: C4Viewport.h:105
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Viewport::IsViewportMenu ( class C4Menu pMenu)

Definition at line 822 of file C4Viewport.cpp.

References C4Player::Cursor, C4Player::Eliminated, FullScreen, C4PlayerList::Get(), C4Menu::IsActive(), C4Player::Menu, C4Object::Menu, Player, Players, and C4FullScreen::pMenu.

823 {
824  // check all associated menus
825  // Get player
826  C4Player *pPlr = ::Players.Get(Player);
827  // Player eliminated: No menu
828  if (pPlr && pPlr->Eliminated) return false;
829  // Player cursor object menu
830  if (pPlr && pPlr->Cursor && pPlr->Cursor->Menu == pMenu) return true;
831  // Player menu
832  if (pPlr && pPlr->Menu.IsActive() && &(pPlr->Menu) == pMenu) return true;
833  // Fullscreen menu (if active, only one viewport can exist)
834  if (FullScreen.pMenu && FullScreen.pMenu->IsActive() && FullScreen.pMenu == pMenu) return true;
835  // no match
836  return false;
837 }
C4ObjectPtr Cursor
Definition: C4Player.h:130
C4MainMenu * pMenu
Definition: C4FullScreen.h:30
C4MainMenu Menu
Definition: C4Player.h:103
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
C4Player * Get(int iPlayer) const
class C4ObjectMenu * Menu
Definition: C4Object.h:140
C4PlayerList Players
int32_t Eliminated
Definition: C4Player.h:83
bool IsActive()
Definition: C4Menu.cpp:480
int32_t Player
Definition: C4Viewport.h:105

Here is the call graph for this function:

void C4Viewport::NextPlayer ( )

Definition at line 808 of file C4Viewport.cpp.

References C4Game::C4S, C4SHead::Film, C4PlayerList::First, Game, C4PlayerList::Get(), C4Scenario::Head, Init(), C4Player::Next, NO_OWNER, C4Player::Number, Player, Players, and C4SHead::Replay.

Referenced by C4ViewportList::ViewportNextPlayer().

809 {
810  C4Player *pPlr; int32_t iPlr;
811  if (!(pPlr = ::Players.Get(Player)))
812  {
813  if (!(pPlr = ::Players.First)) return;
814  }
815  else if (!(pPlr = pPlr->Next))
816  if (Game.C4S.Head.Film && Game.C4S.Head.Replay)
817  pPlr = ::Players.First; // cycle to first in film mode only; in network obs mode allow NO_OWNER-view
818  if (pPlr) iPlr = pPlr->Number; else iPlr = NO_OWNER;
819  if (iPlr != Player) Init(iPlr, true);
820 }
C4Game Game
Definition: C4Globals.cpp:52
int32_t Number
Definition: C4Player.h:86
C4Scenario C4S
Definition: C4Game.h:74
bool Replay
Definition: C4Scenario.h:72
C4Player * First
Definition: C4PlayerList.h:31
C4Player * Get(int iPlayer) const
C4PlayerList Players
const int NO_OWNER
Definition: C4Constants.h:137
bool Init(int32_t iPlayer, bool fSetTempOnly)
Definition: C4Viewport.cpp:658
C4Player * Next
Definition: C4Player.h:142
C4SHead Head
Definition: C4Scenario.h:230
int32_t Player
Definition: C4Viewport.h:105
int32_t Film
Definition: C4Scenario.h:73

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Viewport::ScrollBarsByViewPosition ( )

Definition at line 709 of file C4Console.cpp.

Referenced by UpdateOutputSize(), and ViewportWinProc().

709 {return false;}

Here is the caller graph for this function:

void C4Viewport::ScrollView ( float  byX,
float  byY 
)

Scroll the viewport by x,y

Definition at line 734 of file C4Viewport.cpp.

References SetViewX(), and SetViewY().

Referenced by AdjustPosition(), C4ViewportList::FreeScroll(), C4MouseControl::ScrollView(), SetOutputSize(), UpdateOutputSize(), and ViewportWinProc().

735 {
736  SetViewX(viewX + byX);
737  SetViewY(viewY + byY);
738 }
void SetViewX(float x)
Definition: C4Viewport.cpp:740
void SetViewY(float y)
Definition: C4Viewport.cpp:759

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::SetOutputSize ( int32_t  iDrawX,
int32_t  iDrawY,
int32_t  iOutX,
int32_t  iOutY,
int32_t  iOutWdt,
int32_t  iOutHgt 
)

Definition at line 778 of file C4Viewport.cpp.

References CalculateZoom(), DrawX, DrawY, C4PlayerList::Get(), MouseControl, C4Player::MouseControl, OutX, OutY, pGUI, Player, Players, ResetMenuPositions, ScrollView(), C4GUI::Screen::SetPreferredDlgRect(), C4MouseControl::UpdateClip(), ViewHgt, and ViewWdt.

Referenced by C4GraphicsSystem::DoSaveScreenshot(), and C4ViewportList::RecalculateViewports().

779 {
780  int32_t deltaWidth = ViewWdt-iOutWdt;
781  int32_t deltaHeight = ViewHgt-iOutHgt;
782  // update output parameters
783  DrawX=iDrawX; DrawY=iDrawY;
784  OutX=iOutX; OutY=iOutY;
785  ViewWdt=iOutWdt; ViewHgt=iOutHgt;
786  // update view position: Remain centered at previous position
787  // scrolling the view must be done after setting the new view width and height
788  ScrollView(deltaWidth/2, deltaHeight/2);
789  CalculateZoom();
790  // Reset menus
791  ResetMenuPositions=true;
792  // player uses mouse control? then clip the cursor
793  C4Player *pPlr;
794  if ((pPlr=::Players.Get(Player)))
795  if (pPlr->MouseControl)
796  {
798  // and inform GUI
799  ::pGUI->SetPreferredDlgRect(C4Rect(iOutX, iOutY, iOutWdt, iOutHgt));
800  }
801 }
int32_t OutX
Definition: C4Viewport.h:107
int32_t MouseControl
Definition: C4Player.h:92
int32_t OutY
Definition: C4Viewport.h:107
int32_t DrawY
Definition: C4Viewport.h:39
void CalculateZoom()
Definition: C4Viewport.cpp:408
int32_t DrawX
Definition: C4Viewport.h:39
Definition: C4Rect.h:27
void SetPreferredDlgRect(const C4Rect &rtNewPref)
Definition: C4Gui.h:2648
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
int32_t ViewHgt
Definition: C4Viewport.h:36
C4Player * Get(int iPlayer) const
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
int32_t ViewWdt
Definition: C4Viewport.h:36
bool ResetMenuPositions
Definition: C4Viewport.h:108
void ScrollView(float byX, float byY)
Definition: C4Viewport.cpp:734
C4PlayerList Players
int32_t Player
Definition: C4Viewport.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::SetViewOffset ( int32_t  x,
int32_t  y 
)
inline

Set the view offset of the normal viewport center. Used by C4Script function SetViewOffset.

Definition at line 91 of file C4Viewport.h.

91 { viewOffsX = x; viewOffsY = y; }
void C4Viewport::SetViewX ( float  x)

Set the view position.

Definition at line 740 of file C4Viewport.cpp.

References Clamp(), fIsNoOwnerViewport, C4Landscape::GetWidth(), Landscape, ViewWdt, and Zoom.

Referenced by AdjustPosition(), CenterPosition(), ScrollView(), and ViewportWinProc().

741 {
742  viewX = x;
743 
744  if (fIsNoOwnerViewport)
745  {
746  if(::Landscape.GetWidth() < ViewWdt / Zoom)
747  {
748  viewX = ::Landscape.GetWidth()/2 - ViewWdt / Zoom / 2;
749  }
750  else
751  {
752  viewX = Clamp(x, 0.0f, ::Landscape.GetWidth() - ViewWdt / Zoom);
753  }
754  }
755 
756  UpdateBordersX();
757 }
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
int32_t ViewWdt
Definition: C4Viewport.h:36
bool fIsNoOwnerViewport
Definition: C4Viewport.h:43
C4Landscape Landscape
float Zoom
Definition: C4Viewport.h:101
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::SetViewY ( float  y)

Definition at line 759 of file C4Viewport.cpp.

References Clamp(), fIsNoOwnerViewport, C4Landscape::GetHeight(), Landscape, ViewHgt, and Zoom.

Referenced by AdjustPosition(), CenterPosition(), ScrollView(), and ViewportWinProc().

760 {
761  viewY = y;
762 
763  if (fIsNoOwnerViewport)
764  {
765  if(::Landscape.GetHeight() < ViewHgt / Zoom)
766  {
767  viewY = ::Landscape.GetHeight()/2 - ViewHgt / Zoom / 2;
768  }
769  else
770  {
771  viewY = Clamp(y, 0.0f, ::Landscape.GetHeight() - ViewHgt / Zoom);
772  }
773  }
774 
775  UpdateBordersY();
776 }
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
int32_t ViewHgt
Definition: C4Viewport.h:36
bool fIsNoOwnerViewport
Definition: C4Viewport.h:43
C4Landscape Landscape
float Zoom
Definition: C4Viewport.h:101
int32_t GetHeight() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Viewport::SetZoom ( float  zoomValue)

Definition at line 495 of file C4Viewport.cpp.

References Zoom, and ZoomTarget.

Referenced by C4Player::ZoomToViewport().

496 {
497  Zoom = zoomValue;
498  // also set target to prevent zoom from changing back
499  ZoomTarget = zoomValue;
500 }
float Zoom
Definition: C4Viewport.h:101
float ZoomTarget
Definition: C4Viewport.h:102

Here is the caller graph for this function:

void C4Viewport::SetZoom ( float  to_zoom,
bool  direct = false 
)

Definition at line 447 of file C4Viewport.cpp.

References Application, C4Application::isEditor, NO_OWNER, Player, Zoom, ZoomLimitMax, ZoomLimitMin, and ZoomTarget.

448 {
449  ZoomTarget = to_value;
450  if (Player != NO_OWNER || !::Application.isEditor)
451  {
454  }
455  // direct: Set zoom without scrolling to it
456  if (direct) Zoom = ZoomTarget;
457 }
const int NO_OWNER
Definition: C4Constants.h:137
float Zoom
Definition: C4Viewport.h:101
float ZoomTarget
Definition: C4Viewport.h:102
int32_t Player
Definition: C4Viewport.h:105
float ZoomLimitMax
Definition: C4Viewport.h:103
C4Application Application
Definition: C4Globals.cpp:44
float ZoomLimitMin
Definition: C4Viewport.h:103
void C4Viewport::SetZoomLimits ( float  to_min_zoom,
float  to_max_zoom 
)

Definition at line 459 of file C4Viewport.cpp.

References ChangeZoom(), ZoomLimitMax, and ZoomLimitMin.

Referenced by CalculateZoom(), and C4Player::ZoomLimitsToViewport().

460 {
461  ZoomLimitMin = to_min_zoom;
462  ZoomLimitMax = to_max_zoom;
464  ChangeZoom(1); // Constrains zoom to limit.
465 }
void ChangeZoom(float by_factor)
Definition: C4Viewport.cpp:440
float ZoomLimitMax
Definition: C4Viewport.h:103
float ZoomLimitMin
Definition: C4Viewport.h:103

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Viewport::TogglePlayerLock ( )

Definition at line 710 of file C4Console.cpp.

Referenced by Init(), and ViewportWinProc().

710 {return false;}

Here is the caller graph for this function:

bool C4Viewport::UpdateOutputSize ( int32_t  new_width = 0,
int32_t  new_height = 0 
)

Definition at line 52 of file C4Viewport.cpp.

References C4PlayerList::Get(), C4Rect::Hgt, OutX, OutY, Player, Players, pWindow, ResetMenuPositions, ScrollBarsByViewPosition(), ScrollView(), ViewHgt, ViewWdt, C4Rect::Wdt, C4Rect::x, C4Rect::y, and C4Player::ZoomLimitsToViewport().

Referenced by Init(), C4ViewportWindow::PerformUpdate(), and ViewportWinProc().

53 {
54  if (!pWindow) return false;
55  // Output size
56  C4Rect rect;
57  if (new_width)
58  {
59  rect.x = rect.y = 0;
60  rect.Wdt = new_width;
61  rect.Hgt = new_height;
62  }
63  else
64  {
65 #if defined(WITH_QT_EDITOR)
66  // Never query the window - size is always passed from Qt.
67  return false;
68 #else
69  if (!pWindow->GetSize(&rect)) return false;
70 #endif
71  }
72  OutX=rect.x; OutY=rect.y;
73  ViewWdt=rect.Wdt; ViewHgt=rect.Hgt;
74  ScrollView(0,0);
75  // Scroll bars
77  // Reset menus
78  ResetMenuPositions=true;
79  // update internal GL size
80  if (pWindow && pWindow->pSurface)
81  pWindow->pSurface->UpdateSize(ViewWdt, ViewHgt);
82  // Update zoom limits based on new size
83  C4Player *plr = ::Players.Get(Player);
84  if (plr) plr->ZoomLimitsToViewport(this);
85  // Done
86  return true;
87 }
int32_t OutX
Definition: C4Viewport.h:107
int32_t OutY
Definition: C4Viewport.h:107
void ZoomLimitsToViewport(C4Viewport *vp)
Definition: C4Player.cpp:1858
Definition: C4Rect.h:27
int32_t ViewHgt
Definition: C4Viewport.h:36
int32_t Wdt
Definition: C4Rect.h:30
C4Player * Get(int iPlayer) const
int32_t ViewWdt
Definition: C4Viewport.h:36
int32_t y
Definition: C4Rect.h:30
bool ResetMenuPositions
Definition: C4Viewport.h:108
void ScrollView(float byX, float byY)
Definition: C4Viewport.cpp:734
C4PlayerList Players
int32_t x
Definition: C4Rect.h:30
bool ScrollBarsByViewPosition()
Definition: C4Console.cpp:709
std::unique_ptr< C4ViewportWindow > pWindow
Definition: C4Viewport.h:110
int32_t Hgt
Definition: C4Rect.h:30
int32_t Player
Definition: C4Viewport.h:105

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Viewport::ViewPositionByScrollBars ( )
float C4Viewport::WindowToGameX ( int32_t  win_x)
inline

Definition at line 82 of file C4Viewport.h.

References GetViewX(), and Zoom.

Referenced by C4ViewportWindow::EditCursorMove().

82 { return GetViewX() + float(win_x) / Zoom; }
float Zoom
Definition: C4Viewport.h:101
float GetViewX()
Definition: C4Viewport.h:73

Here is the call graph for this function:

Here is the caller graph for this function:

float C4Viewport::WindowToGameY ( int32_t  win_y)
inline

Definition at line 83 of file C4Viewport.h.

References GetViewY(), and Zoom.

Referenced by C4ViewportWindow::EditCursorMove().

83 { return GetViewY() + float(win_y) / Zoom; }
float Zoom
Definition: C4Viewport.h:101
float GetViewY()
Definition: C4Viewport.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4ConsoleQtViewportView
friend

Definition at line 138 of file C4Viewport.h.

friend class C4GraphicsSystem
friend

Definition at line 137 of file C4Viewport.h.

friend class C4MouseControl
friend

Definition at line 31 of file C4Viewport.h.

friend class C4ViewportList
friend

Definition at line 136 of file C4Viewport.h.

friend class C4ViewportWindow
friend

Definition at line 135 of file C4Viewport.h.

Member Data Documentation

float C4Viewport::BorderBottom

Definition at line 38 of file C4Viewport.h.

Referenced by C4Viewport(), C4GraphicsSystem::DoSaveScreenshot(), and Draw().

float C4Viewport::BorderLeft

Definition at line 38 of file C4Viewport.h.

Referenced by C4Viewport(), C4GraphicsSystem::DoSaveScreenshot(), and Draw().

float C4Viewport::BorderRight

Definition at line 38 of file C4Viewport.h.

Referenced by C4Viewport(), C4GraphicsSystem::DoSaveScreenshot(), and Draw().

float C4Viewport::BorderTop

Definition at line 38 of file C4Viewport.h.

Referenced by C4Viewport(), C4GraphicsSystem::DoSaveScreenshot(), and Draw().

int32_t C4Viewport::DrawX

Definition at line 39 of file C4Viewport.h.

Referenced by BlitOutput(), C4Viewport(), Draw(), Execute(), SetOutputSize(), and ViewportWinProc().

int32_t C4Viewport::DrawY

Definition at line 39 of file C4Viewport.h.

Referenced by BlitOutput(), C4Viewport(), Draw(), Execute(), SetOutputSize(), and ViewportWinProc().

bool C4Viewport::fIsNoOwnerViewport
C4TargetFacet C4Viewport::last_game_draw_cgo

Definition at line 41 of file C4Viewport.h.

Referenced by Draw(), and C4MouseControl::Move().

C4TargetFacet C4Viewport::last_gui_draw_cgo

Definition at line 41 of file C4Viewport.h.

Referenced by Draw(), and C4MouseControl::Move().

int32_t C4Viewport::OutX
protected
int32_t C4Viewport::OutY
protected
std::unique_ptr<C4FoWRegion> C4Viewport::pFoW
protected

Definition at line 111 of file C4Viewport.h.

Referenced by DisableFoW(), Draw(), and EnableFoW().

bool C4Viewport::PlayerLock
protected

Definition at line 106 of file C4Viewport.h.

Referenced by AdjustPosition(), C4Viewport(), and GetPlayerLock().

std::unique_ptr<C4ViewportWindow> C4Viewport::pWindow
protected
bool C4Viewport::ResetMenuPositions
protected

Definition at line 108 of file C4Viewport.h.

Referenced by C4Viewport(), DrawMenu(), SetOutputSize(), and UpdateOutputSize().

int32_t C4Viewport::ViewportOpenFrame
protected

Definition at line 104 of file C4Viewport.h.

Referenced by C4Viewport(), CalculateZoom(), and Init().

float C4Viewport::ZoomLimitMax
protected

Definition at line 103 of file C4Viewport.h.

Referenced by C4Viewport(), ChangeZoom(), GetZoomLimitMax(), SetZoom(), and SetZoomLimits().

float C4Viewport::ZoomLimitMin
protected

Definition at line 103 of file C4Viewport.h.

Referenced by C4Viewport(), ChangeZoom(), GetZoomLimitMin(), SetZoom(), and SetZoomLimits().

float C4Viewport::ZoomTarget
protected

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