OpenClonk
C4Viewport Class Reference

#include <C4Viewport.h>

Collaboration diagram for C4Viewport:
[legend]

Public Member Functions

 C4Viewport ()
 
 ~C4Viewport ()
 
float GetZoom ()
 
void SetZoom (float zoom_value)
 
float GetGUIZoom () const
 
void Execute ()
 
void ClearPointers (C4Object *obj)
 
void SetOutputSize (int32_t draw_x, int32_t draw_y, int32_t out_x, int32_t out_y, int32_t out_wdt, int32_t out_hgt)
 
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 for_player, bool set_temporary_only)
 
void DropFile (const char *filename, float x, float y)
 
bool TogglePlayerLock ()
 
bool GetPlayerLock ()
 
void NextPlayer ()
 
C4Rect GetOutputRect ()
 
bool IsViewportMenu (class C4Menu *menu)
 
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 by_x, float by_y)
 
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 draw_game, bool draw_overlay)
 
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::C4Viewport ( )

Definition at line 102 of file C4Viewport.cpp.

103 {
104  Player = 0;
105  viewX = viewY = 0;
106  targetViewX = targetViewY = 0;
107  ViewWdt = ViewHgt = 0;
109  OutX = OutY = ViewWdt = ViewHgt = 0;
110  DrawX = DrawY = 0;
111  Zoom = 1.0;
112  ZoomTarget = 0.0;
113  ViewportOpenFrame = 0;
114  ZoomLimitMin = ZoomLimitMax = 0; // no limit
115  Next = nullptr;
116  PlayerLock = true;
117  ResetMenuPositions = false;
118  viewOffsX = viewOffsY = 0;
119  fIsNoOwnerViewport = false;
120 }
float BorderTop
Definition: C4Viewport.h:39
float Zoom
Definition: C4Viewport.h:104
float ZoomTarget
Definition: C4Viewport.h:105
int32_t ViewWdt
Definition: C4Viewport.h:36
int32_t ViewportOpenFrame
Definition: C4Viewport.h:107
float BorderRight
Definition: C4Viewport.h:39
int32_t OutY
Definition: C4Viewport.h:110
int32_t OutX
Definition: C4Viewport.h:110
int32_t ViewHgt
Definition: C4Viewport.h:37
float BorderLeft
Definition: C4Viewport.h:39
bool ResetMenuPositions
Definition: C4Viewport.h:111
float ZoomLimitMax
Definition: C4Viewport.h:106
float ZoomLimitMin
Definition: C4Viewport.h:106
bool PlayerLock
Definition: C4Viewport.h:109
int32_t DrawY
Definition: C4Viewport.h:41
int32_t Player
Definition: C4Viewport.h:108
int32_t DrawX
Definition: C4Viewport.h:40
C4Viewport * Next
Definition: C4Viewport.h:112
bool fIsNoOwnerViewport
Definition: C4Viewport.h:46
float BorderBottom
Definition: C4Viewport.h:39

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

◆ ~C4Viewport()

C4Viewport::~C4Viewport ( )

Definition at line 122 of file C4Viewport.cpp.

123 {
124  DisableFoW();
125  if (pWindow)
126  {
127  delete pWindow->pSurface;
128  pWindow->Clear();
129  }
130 }
std::unique_ptr< C4ViewportWindow > pWindow
Definition: C4Viewport.h:113
void DisableFoW()
Definition: C4Viewport.cpp:829

References DisableFoW(), and pWindow.

Here is the call graph for this function:

Member Function Documentation

◆ AdjustPosition()

void C4Viewport::AdjustPosition ( bool  immediate = false)

Definition at line 653 of file C4Viewport.cpp.

654 {
655  if (ViewWdt == 0 || ViewHgt == 0)
656  {
657  // zero-sized viewport, possibly minimized editor window
658  // don't do anything then
659  return;
660  }
661 
662  assert(Zoom > 0);
663  assert(ZoomTarget > 0);
664 
665  float ViewportScrollBorder = fIsNoOwnerViewport ? 0 : float(C4ViewportScrollBorder);
667 
668  // View position
669  if (PlayerLock && ValidPlr(Player))
670  {
671  float scrollRange = 0;
672  float extraBoundsX = 0;
673  float extraBoundsY = 0;
674 
675  // target view position (landscape coordinates)
676  float targetCenterViewX = fixtof(player->ViewX);
677  float targetCenterViewY = fixtof(player->ViewY);
678 
679  if (player->ViewMode == C4PVM_Scrolling)
680  {
681  extraBoundsX = extraBoundsY = ViewportScrollBorder;
682  }
683  else
684  {
685  scrollRange = std::min(ViewWdt/(10*Zoom),ViewHgt/(10*Zoom));
686 
687  // if view is close to border, allow scrolling
688  if (targetCenterViewX < ViewportScrollBorder)
689  {
690  extraBoundsX = std::min<float>(ViewportScrollBorder - targetCenterViewX, ViewportScrollBorder);
691  }
692  else if (targetCenterViewX >= ::Landscape.GetWidth() - ViewportScrollBorder)
693  {
694  extraBoundsX = std::min<float>(targetCenterViewX - ::Landscape.GetWidth(), 0) + ViewportScrollBorder;
695  }
696  if (targetCenterViewY < ViewportScrollBorder)
697  {
698  extraBoundsY = std::min<float>(ViewportScrollBorder - targetCenterViewY, ViewportScrollBorder);
699  }
700  else if (targetCenterViewY >= ::Landscape.GetHeight() - ViewportScrollBorder)
701  {
702  extraBoundsY = std::min<float>(targetCenterViewY - ::Landscape.GetHeight(), 0) + ViewportScrollBorder;
703  }
704  }
705 
706  extraBoundsX = std::max(extraBoundsX, (ViewWdt/Zoom - ::Landscape.GetWidth())/2 + 1);
707  extraBoundsY = std::max(extraBoundsY, (ViewHgt/Zoom - ::Landscape.GetHeight())/2 + 1);
708 
709  // add mouse auto scroll
711  {
712  float strength = Config.Controls.MouseAutoScroll/100.0f;
713  targetCenterViewX += strength*(::MouseControl.VpX - ViewWdt/2.0f)/Zoom;
714  targetCenterViewY += strength*(::MouseControl.VpY - ViewHgt/2.0f)/Zoom;
715  }
716 
717  // scroll range
718  if (!immediate)
719  {
720  targetCenterViewX = Clamp(targetCenterViewX, targetCenterViewX - scrollRange, targetCenterViewX + scrollRange);
721  targetCenterViewY = Clamp(targetCenterViewY, targetCenterViewY - scrollRange, targetCenterViewY + scrollRange);
722  }
723  // bounds
724  targetCenterViewX = Clamp(targetCenterViewX, ViewWdt/Zoom/2 - extraBoundsX, ::Landscape.GetWidth() - ViewWdt/Zoom/2 + extraBoundsX);
725  targetCenterViewY = Clamp(targetCenterViewY, ViewHgt/Zoom/2 - extraBoundsY, ::Landscape.GetHeight() - ViewHgt/Zoom/2 + extraBoundsY);
726 
727  targetViewX = targetCenterViewX - ViewWdt/Zoom/2 + viewOffsX;
728  targetViewY = targetCenterViewY - ViewHgt/Zoom/2 + viewOffsY;
729 
730  if (immediate)
731  {
732  // immediate scroll
733  SetViewX(targetViewX);
734  SetViewY(targetViewY);
735  }
736  else
737  {
738  // smooth scroll
739  int32_t smooth = Clamp<int32_t>(Config.General.ScrollSmooth, 1, 50);
740  ScrollView((targetViewX - viewX) / smooth, (targetViewY - viewY) / smooth);
741  }
742  }
743 
744  UpdateBordersX();
745  UpdateBordersY();
746 
747  // NO_OWNER can't scroll
748  if (fIsNoOwnerViewport)
749  {
750  viewOffsX = 0;
751  viewOffsY = 0;
752  }
753 }
C4Config Config
Definition: C4Config.cpp:930
const int C4ViewportScrollBorder
Definition: C4Constants.h:65
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
C4Landscape Landscape
const int32_t C4PVM_Scrolling
Definition: C4Player.h:33
C4PlayerList Players
int32_t ValidPlr(int32_t plr)
float fixtof(const C4Fixed &x)
Definition: C4Real.h:257
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
int32_t MouseAutoScroll
Definition: C4Config.h:234
int32_t ScrollSmooth
Definition: C4Config.h:51
C4ConfigGeneral General
Definition: C4Config.h:255
C4ConfigControls Controls
Definition: C4Config.h:263
int32_t GetWidth() const
int32_t GetHeight() const
C4Player * Get(int iPlayer) const
void SetViewX(float x)
Definition: C4Viewport.cpp:888
void ScrollView(float by_x, float by_y)
Definition: C4Viewport.cpp:882
void SetViewY(float y)
Definition: C4Viewport.cpp:907

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AdjustZoomAndPosition()

void C4Viewport::AdjustZoomAndPosition ( )
protected

Definition at line 599 of file C4Viewport.cpp.

600 {
601  // Move zoom towards target zoom
602  if (ZoomTarget < 0.000001f)
603  {
604  CalculateZoom();
605  }
606  // Change Zoom
607 
608  if (Zoom != ZoomTarget)
609  {
610  float DeltaZoom = Zoom / ZoomTarget;
611  if (DeltaZoom < 1)
612  {
613  DeltaZoom = 1 / DeltaZoom;
614  }
615 
616  // Minimal Zoom change factor
617  static const float Z0 = pow(C4GFX_ZoomStep, 1.0f / 8.0f);
618 
619  // We change zoom based on (logarithmic) distance of current zoom
620  // to target zoom. The greater the distance the more we adjust the
621  // zoom in one frame. There is a minimal zoom change Z0 to make sure
622  // we reach ZoomTarget in finite time.
623  float ZoomAdjustFactor = Z0 * pow(DeltaZoom, 1.0f / 8.0f);
624 
625  if (Zoom == 0)
626  {
627  Zoom = ZoomTarget;
628  }
629  else
630  {
631  // Remember old viewport center
632  float view_mid_x = this->viewX + float(this->ViewWdt) / Zoom / 2.0f;
633  float view_mid_y = this->viewY + float(this->ViewHgt) / Zoom / 2.0f;
634 
635  if (Zoom < ZoomTarget)
636  {
637  Zoom = std::min(Zoom * ZoomAdjustFactor, ZoomTarget);
638  }
639  if (Zoom > ZoomTarget)
640  {
641  Zoom = std::max(Zoom / ZoomAdjustFactor, ZoomTarget);
642  }
643 
644  // Restore new viewport center
645  this->viewX = view_mid_x - float(this->ViewWdt) / Zoom / 2.0f;
646  this->viewY = view_mid_y - float(this->ViewHgt) / Zoom / 2.0f;
647  }
648  }
649  // Adjust position
650  AdjustPosition(false);
651 }
const float C4GFX_ZoomStep
void CalculateZoom()
Definition: C4Viewport.cpp:481
void AdjustPosition(bool immediate=false)
Definition: C4Viewport.cpp:653

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

Referenced by Execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BlitOutput()

void C4Viewport::BlitOutput ( )
protected

Definition at line 432 of file C4Viewport.cpp.

433 {
434  if (pWindow)
435  {
436  C4Rect src, dst;
437  src.x = DrawX; src.y = DrawY; src.Wdt = ViewWdt; src.Hgt = ViewHgt;
438  dst.x = OutX; dst.y = OutY; dst.Wdt = ViewWdt; dst.Hgt = ViewHgt;
439  pWindow->pSurface->PageFlip(&src, &dst);
440  }
441 }
Definition: C4Rect.h:28
int32_t y
Definition: C4Rect.h:30
int32_t Hgt
Definition: C4Rect.h:30
int32_t Wdt
Definition: C4Rect.h:30
int32_t x
Definition: C4Rect.h:30

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

Referenced by Execute().

Here is the caller graph for this function:

◆ CalculateZoom()

void C4Viewport::CalculateZoom ( )

Definition at line 481 of file C4Viewport.cpp.

482 {
483  // Zoom is only initialized by player or global setting during viewport creation time, because after that
484  // the player may have changed to another preferred zoom.
485  // However, viewports may change multiple times during startup (because of NO_OWNER viewport being deleted
486  // and possible other player joins). So check by frame counter. Zoom changes done in paused mode on the
487  // player init frame will be lost, but that should not be a problem.
489  {
490  InitZoom();
491  }
492 
494  if (player)
495  {
496  player->ZoomLimitsToViewport(this);
497  }
498  else
499  {
500  SetZoomLimits(0.8*std::min<float>(float(ViewWdt)/::Landscape.GetWidth(),float(ViewHgt)/::Landscape.GetHeight()), 8);
501  }
502 
503 }
C4Game Game
Definition: C4Globals.cpp:52
int32_t FrameCounter
Definition: C4Game.h:129
void SetZoomLimits(float to_min_zoom, float to_max_zoom)
Definition: C4Viewport.cpp:547
void InitZoom()
Definition: C4Viewport.cpp:505

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

Referenced by AdjustZoomAndPosition(), and SetOutputSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CenterPosition()

void C4Viewport::CenterPosition ( )

Definition at line 755 of file C4Viewport.cpp.

756 {
757  // center viewport position on map
758  // set center position
761 }

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

Referenced by C4ViewportList::CreateViewport().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ChangeZoom()

void C4Viewport::ChangeZoom ( float  by_factor)

Definition at line 519 of file C4Viewport.cpp.

520 {
521  ZoomTarget *= by_factor;
524 }

References ZoomLimitMax, ZoomLimitMin, and ZoomTarget.

Referenced by SetZoomLimits().

Here is the caller graph for this function:

◆ ClearPointers()

void C4Viewport::ClearPointers ( C4Object obj)

Definition at line 957 of file C4Viewport.cpp.

958 {
959 
960 }

◆ DisableFoW()

void C4Viewport::DisableFoW ( )

Definition at line 829 of file C4Viewport.cpp.

830 {
831  pFoW.reset();
832 }
std::unique_ptr< C4FoWRegion > pFoW
Definition: C4Viewport.h:114

References pFoW.

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

Here is the caller graph for this function:

◆ Draw()

void C4Viewport::Draw ( C4TargetFacet cgo,
bool  draw_game,
bool  draw_overlay 
)
protected

Definition at line 235 of file C4Viewport.cpp.

236 {
237 #ifdef USE_CONSOLE
238  // No drawing in console mode
239  return;
240 #endif
241  C4TargetFacet cgo; cgo.Set(cgo0);
242  ZoomData GameZoom;
243  GameZoom.X = cgo.X;
244  GameZoom.Y = cgo.Y;
245  GameZoom.Zoom = cgo.Zoom;
246 
247  // Draw landscape borders
252 
253  // Compute non-bordered viewport area
254  cgo.X += BorderLeft;
255  cgo.Y += BorderTop;
256  cgo.Wdt -= (BorderLeft + BorderRight) / cgo.Zoom;
257  cgo.Hgt -= (BorderTop + BorderBottom) / cgo.Zoom;
258  cgo.TargetX += BorderLeft / Zoom;
259  cgo.TargetY += BorderTop / Zoom;
260 
261  // Apply Zoom
262  GameZoom.X = cgo.X;
263  GameZoom.Y = cgo.Y;
264  pDraw->SetZoom(GameZoom);
265 
266  // Set clipper to integer bounds around floating point viewport region
268  const C4Rect& clipRectInt(clipRect);
269  pDraw->SetPrimaryClipper(clipRectInt.x, clipRectInt.y, clipRectInt.x + clipRectInt.Wdt - 1, clipRectInt.y + clipRectInt.Hgt - 1);
270 
271  last_game_draw_cgo = cgo;
272 
273  if (draw_game)
274  {
275  // --- activate FoW here ---
276 
277  // Render FoW only if active for player
279  C4FoWRegion* FoW = nullptr;
280  if (player && player->fFogOfWar)
281  {
282  FoW = this->pFoW.get();
283  }
284 
285  // Update FoW
286  if (FoW)
287  {
288  // Viewport region in landscape coordinates
289  const FLOAT_RECT vpRect = { cgo.TargetX, cgo.TargetX + cgo.Wdt, cgo.TargetY, cgo.TargetY + cgo.Hgt };
290  // Region in which the light is calculated
291  // At the moment, just choose integer coordinates to surround the viewport
292  const C4Rect lightRect(vpRect);
293  if (!lightRect.Wdt || !lightRect.Hgt)
294  {
295  // Do not bother initializing FoW on empty region; would cause errors in drawing proc
296  FoW = nullptr;
297  }
298  else
299  {
300  FoW->Update(lightRect, vpRect);
301 
302  if (!FoW->Render())
303  {
304  // If FoW init fails, do not set it for further drawing
305  FoW = nullptr;
306  }
307  }
308  }
309 
310  pDraw->SetFoW(FoW);
311 
312  C4ST_STARTNEW(SkyStat, "C4Viewport::Draw: Sky")
313  ::Landscape.GetSky().Draw(cgo);
314  C4ST_STOP(SkyStat)
315 
316  ::Objects.Draw(cgo, Player, -2147483647 - 1 /* INT32_MIN */, 0);
317 
318  // Draw Landscape
319  C4ST_STARTNEW(LandStat, "C4Viewport::Draw: Landscape")
320  ::Landscape.Draw(cgo, FoW);
321  C4ST_STOP(LandStat)
322 
323  // draw PXS (unclipped!)
324  C4ST_STARTNEW(PXSStat, "C4Viewport::Draw: PXS")
325  ::PXS.Draw(cgo);
326  C4ST_STOP(PXSStat)
327 
328  // Draw objects which are behind the particle plane.
329  const int particlePlane = 900;
330  C4ST_STARTNEW(ObjStat, "C4Viewport::Draw: Objects (1)")
331  ::Objects.Draw(cgo, Player, 1, particlePlane);
332  C4ST_STOP(ObjStat)
333 
334  // Draw global dynamic particles on a specific Plane
335  // to enable scripters to put objects both behind and in front of particles.
336  C4ST_STARTNEW(PartStat, "C4Viewport::Draw: Dynamic Particles")
337  ::Particles.DrawGlobalParticles(cgo);
338  C4ST_STOP(PartStat)
339 
340  // Now the remaining objects in front of the particles (e.g. GUI elements)
341  C4ST_STARTNEW(Obj2Stat, "C4Viewport::Draw: Objects (2)")
342  ::Objects.Draw(cgo, Player, particlePlane + 1, 2147483647 /* INT32_MAX */);
343  C4ST_STOP(Obj2Stat)
344 
345  // Draw everything else without FoW
346  pDraw->SetFoW(nullptr);
347  }
348  else
349  {
350  pDraw->DrawBoxDw(cgo.Surface, cgo.X, cgo.Y, cgo.X + cgo.Wdt, cgo.Y + cgo.Hgt, 0xff000000);
351  }
352 
353  // Draw PathFinder
355  {
356  Game.PathFinder.Draw(cgo);
357  }
358 
359  // Draw overlay
360  if (!Game.C4S.Head.Film || !Game.C4S.Head.Replay)
361  {
363  }
364 
365  // Lights overlay
366  if (::GraphicsSystem.ShowLights && pFoW)
367  {
368  pFoW->Render(&cgo);
369  }
370 
371  if (draw_overlay)
372  {
373  // Determine zoom of overlay
374  float gui_zoom = GetGUIZoom();
375  // now restore complete cgo range for overlay drawing
376  pDraw->SetZoom(DrawX, DrawY, gui_zoom);
378  C4TargetFacet gui_cgo;
379  gui_cgo.Set(cgo0);
380 
381  gui_cgo.X = DrawX;
382  gui_cgo.Y = DrawY;
383  gui_cgo.Zoom = gui_zoom;
384  gui_cgo.Wdt = int(float(ViewWdt)/gui_zoom);
385  gui_cgo.Hgt = int(float(ViewHgt)/gui_zoom);
386  gui_cgo.TargetX = GetViewX();
387  gui_cgo.TargetY = GetViewY();
388 
389  last_gui_draw_cgo = gui_cgo;
390 
391  // draw custom GUI objects
393 
394  // Draw overlay
395  C4ST_STARTNEW(OvrStat, "C4Viewport::Draw: Overlay")
396 
397  if (Application.isEditor)
398  {
400  }
401 
402  // Game messages
403  C4ST_STARTNEW(MsgStat, "C4Viewport::DrawOverlay: Messages")
404  pDraw->SetZoom(0, 0, 1.0);
405  ::Messages.Draw(gui_cgo, cgo, Player);
406  C4ST_STOP(MsgStat)
407 
408  // ingame menus
409  C4ST_STARTNEW(GuiWindowStat, "C4Viewport::DrawOverlay: Menus")
410  pDraw->SetZoom(0, 0, 1.0);
411  ::Game.ScriptGuiRoot->DrawAll(gui_cgo, Player);
412  C4ST_STOP(GuiWindowStat)
413 
414  DrawOverlay(gui_cgo, GameZoom);
415 
416  // Netstats
417  if (::GraphicsSystem.ShowNetstatus)
418  {
419  ::Network.DrawStatus(gui_cgo);
420  }
421 
422  C4ST_STOP(OvrStat)
423 
424  }
425 
426  // Remove zoom n clippers
427  pDraw->SetZoom(0, 0, 1.0);
429 
430 }
const int32_t C4D_Foreground
Definition: C4Def.h:53
C4Draw * pDraw
Definition: C4Draw.cpp:42
C4GameMessageList Messages
C4Console Console
Definition: C4Globals.cpp:45
C4Application Application
Definition: C4Globals.cpp:44
C4GameObjects Objects
Definition: C4Globals.cpp:48
C4Network2 Network
Definition: C4Globals.cpp:53
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
C4GraphicsResource GraphicsResource
C4PXSSystem PXS
Definition: C4PXS.cpp:423
C4ParticleSystem Particles
#define C4ST_STOP(StatName)
Definition: C4Stat.h:153
#define C4ST_STARTNEW(StatName, strName)
Definition: C4Stat.h:150
C4EditCursor EditCursor
Definition: C4Console.h:90
void SetFoW(const C4FoWRegion *fow)
Definition: C4Draw.h:193
bool NoPrimaryClipper()
Definition: C4Draw.cpp:237
void DrawBoxDw(C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
Definition: C4Draw.cpp:840
void SetZoom(float X, float Y, float Zoom)
Definition: C4Draw.cpp:773
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:217
bool BlitSurfaceTile(C4Surface *sfcSurface, C4Surface *sfcTarget, float iToX, float iToY, float iToWdt, float iToHgt, float iOffsetX, float iOffsetY, C4ShaderCall *shader_call)
Definition: C4Draw.cpp:529
void Draw(C4TargetFacet &cgo)
C4Surface * Surface
Definition: C4Facet.h:117
float Hgt
Definition: C4Facet.h:118
float Wdt
Definition: C4Facet.h:118
float Y
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
void Update(C4Rect r, const FLOAT_RECT &vp)
bool Render(const C4TargetFacet *pOnScreen=nullptr)
C4Scenario C4S
Definition: C4Game.h:74
void DrawCrewOverheadText(C4TargetFacet &cgo, int32_t player_nr)
Definition: C4Game.cpp:1897
C4PathFinder PathFinder
Definition: C4Game.h:84
C4ObjectList ForeObjects
Definition: C4GameObjects.h:44
void DrawStatus(C4TargetFacet &cgo)
void DrawIfCategory(C4TargetFacet &cgo, int player, uint32_t dwCategory, bool invert)
void Draw(C4TargetFacet &cgo)
bool Replay
Definition: C4Scenario.h:72
int32_t Film
Definition: C4Scenario.h:73
C4SHead Head
Definition: C4Scenario.h:232
float TargetY
Definition: C4Facet.h:165
float TargetX
Definition: C4Facet.h:165
float Zoom
Definition: C4Facet.h:165
void Set(const C4Facet &cpy)
Definition: C4Facet.h:182
C4TargetFacet last_gui_draw_cgo
Definition: C4Viewport.h:44
float GetViewY()
Definition: C4Viewport.h:78
C4TargetFacet last_game_draw_cgo
Definition: C4Viewport.h:43
float GetGUIZoom() const
Definition: C4Viewport.h:50
float GetViewX()
Definition: C4Viewport.h:76
void Draw(C4TargetFacet &cgo, bool draw_game, bool draw_overlay)
Definition: C4Viewport.cpp:235
void DrawOverlay(C4TargetFacet &cgo, const ZoomData &GameZoom)
Definition: C4Viewport.cpp:132
void SetZoom(float zoom_value)
Definition: C4Viewport.cpp:592
float Zoom
Definition: C4Draw.h:70
float X
Definition: C4Draw.h:71
float Y
Definition: C4Draw.h:71

References Application, C4Draw::BlitSurfaceTile(), BorderBottom, BorderLeft, BorderRight, BorderTop, C4D_Foreground, C4Game::C4S, C4ST_STARTNEW, C4ST_STOP, Console, C4EditCursor::Draw(), C4PathFinder::Draw(), C4PXSSystem::Draw(), C4Sky::Draw(), C4Landscape::Draw(), C4ObjectList::Draw(), C4GameMessageList::Draw(), C4Draw::DrawBoxDw(), C4Game::DrawCrewOverheadText(), C4ParticleSystem::DrawGlobalParticles(), C4ObjectList::DrawIfCategory(), DrawOverlay(), C4Network2::DrawStatus(), DrawX, DrawY, C4Console::EditCursor, C4GraphicsResource::fctBackground, C4SHead::Film, C4GameObjects::ForeObjects, Game, C4PlayerList::Get(), GetGUIZoom(), C4Landscape::GetSky(), GetViewX(), GetViewY(), GraphicsResource, GraphicsSystem, C4Scenario::Head, C4Facet::Hgt, C4Rect::Hgt, C4Application::isEditor, Landscape, last_game_draw_cgo, last_gui_draw_cgo, Messages, Network, C4Draw::NoPrimaryClipper(), Objects, Particles, C4Game::PathFinder, pDraw, pFoW, Player, C4ScriptGuiWindowPropertyName::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, C4Facet::Wdt, C4Rect::Wdt, ZoomData::X, C4Facet::X, C4Rect::x, ZoomData::Y, C4Facet::Y, C4Rect::y, Zoom, ZoomData::Zoom, and C4TargetFacet::Zoom.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawMenu()

void C4Viewport::DrawMenu ( C4TargetFacet cgo)
protected

Definition at line 163 of file C4Viewport.cpp.

164 {
165  // Get player
167 
168  // for menus, cgo is using GUI-syntax: TargetX/Y marks the drawing offset; x/y/Wdt/Hgt marks the offset rect
169  C4TargetFacet cgo; cgo.Set(cgo0);
170  cgo.X = 0;
171  cgo.Y = 0;
172  cgo.Wdt = cgo0.Wdt * cgo0.Zoom;
173  cgo.Hgt = cgo0.Hgt * cgo0.Zoom;
174  cgo.TargetX = float(cgo0.X);
175  cgo.TargetY = float(cgo0.Y);
176  cgo.Zoom = 1;
177  pDraw->SetZoom(cgo.X, cgo.Y, cgo.Zoom);
178 
179  // Player eliminated
180  if (player && player->Eliminated)
181  {
182  pDraw->TextOut(FormatString(LoadResStr(player->Surrendered ? "IDS_PLR_SURRENDERED" : "IDS_PLR_ELIMINATED"),player->GetName()).getData(),
183  ::GraphicsResource.FontRegular, 1.0, cgo.Surface,cgo.TargetX+cgo.Wdt/2,cgo.TargetY+2*cgo.Hgt/3,0xfaFF0000,ACenter);
184  return;
185  }
186 
187  // Player cursor object menu
188  if (player && player->Cursor && player->Cursor->Menu)
189  {
190  if (ResetMenuPositions)
191  {
192  player->Cursor->Menu->ResetLocation();
193  }
194  // if mouse is dragging, make it transparent to easy construction site drag+drop
195  bool mouse_dragging = false;
196  if (::MouseControl.IsDragging() && ::MouseControl.IsViewport(this))
197  {
198  mouse_dragging = true;
199  pDraw->ActivateBlitModulation(0x4fffffff);
200  }
201  // draw menu
202  player->Cursor->Menu->Draw(cgo);
203  // reset modulation for dragging
204  if (mouse_dragging)
205  {
207  }
208  }
209  // Player menu
210  if (player && player->Menu.IsActive())
211  {
212  if (ResetMenuPositions)
213  {
214  player->Menu.ResetLocation();
215  }
216  player->Menu.Draw(cgo);
217  }
218  // Fullscreen menu
220  {
221  if (ResetMenuPositions)
222  {
224  }
225  FullScreen.MainMenu->Draw(cgo);
226  }
227 
228  // Flag done
229  ResetMenuPositions = false;
230 
231  // restore Zoom
232  pDraw->SetZoom(cgo0.X, cgo0.Y, cgo0.Zoom);
233 }
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const int ACenter
Definition: C4Surface.h:41
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
void DeactivateBlitModulation()
Definition: C4Draw.h:189
void ActivateBlitModulation(DWORD dwWithClr)
Definition: C4Draw.h:188
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:561
C4MainMenu * MainMenu
Definition: C4FullScreen.h:30
void ResetLocation()
Definition: C4Menu.h:195
void Draw(C4TargetFacet &cgo) override
Definition: C4Menu.cpp:775
bool IsActive()
Definition: C4Menu.cpp:480
bool IsViewport(C4Viewport *pViewport)
const char * getData() const
Definition: StdBuf.h:442

References ACenter, C4Draw::ActivateBlitModulation(), C4Draw::DeactivateBlitModulation(), C4Menu::Draw(), C4GraphicsResource::FontRegular, FormatString(), FullScreen, C4PlayerList::Get(), StdStrBuf::getData(), GraphicsResource, C4Facet::Hgt, C4Menu::IsActive(), C4MouseControl::IsDragging(), C4MouseControl::IsViewport(), LoadResStr(), C4FullScreen::MainMenu, MouseControl, pDraw, Player, C4ScriptGuiWindowPropertyName::player, Players, C4Menu::ResetLocation(), ResetMenuPositions, C4TargetFacet::Set(), C4Draw::SetZoom(), C4Facet::Surface, C4TargetFacet::TargetX, C4TargetFacet::TargetY, C4Draw::TextOut(), C4Facet::Wdt, C4Facet::X, C4Facet::Y, and C4TargetFacet::Zoom.

Referenced by DrawOverlay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawOverlay()

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

Definition at line 132 of file C4Viewport.cpp.

133 {
134  if (!Game.C4S.Head.Film || !Game.C4S.Head.Replay)
135  {
136  // Player info
137  C4ST_STARTNEW(PInfoStat, "C4Viewport::DrawOverlay: Player Info")
138  DrawPlayerInfo(cgo);
139  C4ST_STOP(PInfoStat)
140  C4ST_STARTNEW(MenuStat, "C4Viewport::DrawOverlay: Menu")
141  DrawMenu(cgo);
142  C4ST_STOP(MenuStat)
143  }
144 
145  // Control overlays (if not film/replay)
146  if (!Game.C4S.Head.Film || !Game.C4S.Head.Replay)
147  {
148  // Mouse control
149  if (::MouseControl.IsViewport(this))
150  {
151  C4ST_STARTNEW(MouseStat, "C4Viewport::DrawOverlay: Mouse")
152  ::MouseControl.Draw(cgo, GameZoom);
153  // Draw GUI-mouse in EM if active
154  if (pWindow)
155  {
156  ::pGUI->RenderMouse(cgo);
157  }
158  C4ST_STOP(MouseStat)
159  }
160  }
161 }
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
void RenderMouse(C4TargetFacet &cgo)
Definition: C4Gui.cpp:739
void DrawMenu(C4TargetFacet &cgo)
Definition: C4Viewport.cpp:163
void DrawPlayerInfo(C4TargetFacet &cgo)
Definition: C4Viewport.cpp:775

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawPlayerInfo()

void C4Viewport::DrawPlayerInfo ( C4TargetFacet cgo)
protected

Definition at line 775 of file C4Viewport.cpp.

776 {
777  C4Facet ccgo;
778  if (!ValidPlr(Player))
779  {
780  return;
781  }
782  // Controls
783  DrawPlayerStartup(cgo);
784 }
void DrawPlayerStartup(C4TargetFacet &cgo)
Definition: C4Viewport.cpp:848

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

Referenced by DrawOverlay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawPlayerStartup()

void C4Viewport::DrawPlayerStartup ( C4TargetFacet cgo)
protected

Definition at line 848 of file C4Viewport.cpp.

849 {
850  C4Player *player;
851  if (!(player = ::Players.Get(Player)))
852  {
853  return;
854  }
855  if (!player->LocalControl || !player->ShowStartup)
856  {
857  return;
858  }
859  int32_t name_height_offset = 0;
860 
861  // Control
862  // unnecessary with the current control sets
863  if (player && player->ControlSet)
864  {
865  C4Facet controlset_facet = player->ControlSet->GetPicture();
866  if (controlset_facet.Wdt)
867  {
868  controlset_facet.Draw(cgo.Surface,
869  cgo.X + (cgo.Wdt - controlset_facet.Wdt)/2,
870  cgo.Y + cgo.Hgt * 2/3 + DrawMessageOffset,
871  0, 0);
872  }
873  name_height_offset = GfxR->fctKeyboard.Hgt;
874  }
875 
876  // Name
877  pDraw->TextOut(player->GetName(), ::GraphicsResource.FontRegular, 1.0, cgo.Surface,
878  cgo.X+cgo.Wdt/2, cgo.Y+cgo.Hgt*2/3+name_height_offset + DrawMessageOffset,
879  player->ColorDw | 0xff000000, ACenter);
880 }
#define GfxR
int32_t DrawMessageOffset
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
Definition: C4Facet.cpp:154

References ACenter, C4Facet::Draw(), DrawMessageOffset, C4GraphicsResource::FontRegular, C4PlayerList::Get(), GfxR, GraphicsResource, C4Facet::Hgt, pDraw, Player, C4ScriptGuiWindowPropertyName::player, Players, C4Facet::Surface, C4Draw::TextOut(), C4Facet::Wdt, C4Facet::X, and C4Facet::Y.

Referenced by DrawPlayerInfo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DropFile()

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

Definition at line 47 of file C4Viewport.cpp.

48 {
49  Game.DropFile(filename, GetViewX()+x/Zoom, GetViewY()+y/Zoom);
50 }
bool DropFile(const char *filename, float x, float y)
Definition: C4Game.cpp:1722

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

Here is the call graph for this function:

◆ EnableFoW()

void C4Viewport::EnableFoW ( )

Definition at line 834 of file C4Viewport.cpp.

835 {
836  if (::Landscape.HasFoW() && Player != NO_OWNER)
837  {
838  pFoW = std::make_unique<C4FoWRegion>(::Landscape.GetFoW(), ::Players.Get(Player));
839  }
840  else
841  {
842  DisableFoW();
843  }
844 }
const int NO_OWNER
Definition: C4Constants.h:137
bool HasFoW() const
class C4FoW * GetFoW()

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

Referenced by Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Execute()

void C4Viewport::Execute ( )

Definition at line 443 of file C4Viewport.cpp.

444 {
445  // Adjust position
447  // Current graphics output
448  C4TargetFacet cgo;
449  C4Surface *target = pWindow ? pWindow->pSurface : FullScreen.pSurface;
450  cgo.Set(target,DrawX,DrawY,float(ViewWdt)/Zoom,float(ViewHgt)/Zoom,GetViewX(),GetViewY(),Zoom);
451  pDraw->PrepareRendering(target);
452  // Load script uniforms from Global.Uniforms
453  auto uniform_pop = pDraw->scriptUniform.Push(::GameScript.ScenPropList.getPropList());
454  // Do not spoil game contents on owner-less viewport
455  bool draw_game = true;
456  if (Player == NO_OWNER)
457  {
458  if (!::Application.isEditor && !::Game.DebugMode)
459  {
461  {
462  if (::Game.PlayerInfos.GetJoinIssuedPlayerCount() > 0) // free scrolling allowed if the scenario was started explicitely without players to inspect the landscape
463  {
464  if (Game.C4S.Landscape.Secret)
465  {
466  draw_game = false;
467  }
468  }
469  }
470  }
471  }
472  // Draw
473  Draw(cgo, draw_game, true);
474  // Blit output
475  BlitOutput();
476 }
C4GameScriptHost GameScript
C4ScriptUniform scriptUniform
Definition: C4Draw.h:100
virtual bool PrepareRendering(C4Surface *sfcToSurface)=0
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
bool DebugMode
Definition: C4Game.h:145
C4Value ScenPropList
Definition: C4ScriptHost.h:164
bool isObserver() const
C4Network2Client * GetLocal() const
bool isEnabled() const
Definition: C4Network2.h:203
C4Network2ClientList Clients
Definition: C4Network2.h:116
int32_t GetJoinIssuedPlayerCount() const
C4SLandscape Landscape
Definition: C4Scenario.h:236
std::unique_ptr< Popper > Push(C4PropList *proplist)
Definition: C4Shader.cpp:757
C4PropList * getPropList() const
Definition: C4Value.h:116
void AdjustZoomAndPosition()
Definition: C4Viewport.cpp:599
void BlitOutput()
Definition: C4Viewport.cpp:432
C4Surface * pSurface
Definition: C4Window.h:275

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetGUIZoom()

float C4Viewport::GetGUIZoom ( ) const
inline

Definition at line 50 of file C4Viewport.h.

50 { return Clamp<float>(float(ViewWdt)/1280, 0.5f, 1.0f); }

References ViewWdt.

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

Here is the caller graph for this function:

◆ GetNext()

C4Viewport* C4Viewport::GetNext ( )
inline

Definition at line 69 of file C4Viewport.h.

69 { return Next; }

References Next.

Referenced by C4Menu::GetViewport().

Here is the caller graph for this function:

◆ GetOutputRect()

C4Rect C4Viewport::GetOutputRect ( )
inline

Definition at line 67 of file C4Viewport.h.

67 { return C4Rect(OutX, OutY, ViewWdt, ViewHgt); }

References OutX, OutY, ViewHgt, and ViewWdt.

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

Here is the caller graph for this function:

◆ GetPlayer()

int32_t C4Viewport::GetPlayer ( )
inline

Definition at line 70 of file C4Viewport.h.

70 { return Player; }

References Player.

Referenced by C4MainMenu::DoRefillInternal().

Here is the caller graph for this function:

◆ GetPlayerLock()

bool C4Viewport::GetPlayerLock ( )
inline

Definition at line 65 of file C4Viewport.h.

65 { return PlayerLock; }

References PlayerLock.

◆ GetViewCenterX()

float C4Viewport::GetViewCenterX ( )
inline

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

Definition at line 80 of file C4Viewport.h.

80 { return viewX + ViewWdt/Zoom/2; }

References ViewWdt, and Zoom.

◆ GetViewCenterY()

float C4Viewport::GetViewCenterY ( )
inline

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

Definition at line 82 of file C4Viewport.h.

82 { return viewY + ViewHgt/Zoom/2; }

References ViewHgt, and Zoom.

◆ GetViewX()

float C4Viewport::GetViewX ( )
inline

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

Definition at line 76 of file C4Viewport.h.

76 { return viewX; }

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

Here is the caller graph for this function:

◆ GetViewY()

float C4Viewport::GetViewY ( )
inline

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

Definition at line 78 of file C4Viewport.h.

78 { return viewY; }

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

Here is the caller graph for this function:

◆ GetWindow()

C4ViewportWindow* C4Viewport::GetWindow ( )
inline

Definition at line 126 of file C4Viewport.h.

126 {return pWindow.get();}

References pWindow.

◆ GetZoom() [1/2]

float C4Viewport::GetZoom ( )
inline

Definition at line 48 of file C4Viewport.h.

48 { return Zoom; }

References Zoom.

Referenced by C4ViewportWindow::EditCursorMove().

Here is the caller graph for this function:

◆ GetZoom() [2/2]

float C4Viewport::GetZoom ( ) const
inline

Definition at line 124 of file C4Viewport.h.

124 { return Zoom; }

References Zoom.

◆ GetZoomByViewRange()

float C4Viewport::GetZoomByViewRange ( int32_t  size_x,
int32_t  size_y 
) const

Definition at line 558 of file C4Viewport.cpp.

559 {
560  // set zoom such that both size_x and size_y are guarantueed to fit into the viewport range
561  // determine whether zoom is to be calculated by x or by y
562  bool zoom_by_y = false;
563  if (size_x && size_y)
564  {
565  zoom_by_y = (size_y * ViewWdt > size_x * ViewHgt);
566  }
567  else if (size_y)
568  {
569  // no x size passed - zoom by y
570  zoom_by_y = true;
571  }
572  else
573  {
574  // 0/0 size passed - zoom to default
575  if (!size_x)
576  {
577  size_x = C4VP_DefViewRangeX * 2;
578  }
579  zoom_by_y = false;
580  }
581  // zoom calculation
582  if (zoom_by_y)
583  {
584  return float(ViewHgt) / size_y;
585  }
586  else
587  {
588  return float(ViewWdt) / size_x;
589  }
590 }

References ViewHgt, and ViewWdt.

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

Here is the caller graph for this function:

◆ GetZoomLimitMax()

float C4Viewport::GetZoomLimitMax ( ) const
inline

Definition at line 60 of file C4Viewport.h.

60 { return ZoomLimitMax; }

References ZoomLimitMax.

◆ GetZoomLimitMin()

float C4Viewport::GetZoomLimitMin ( ) const
inline

Definition at line 59 of file C4Viewport.h.

59 { return ZoomLimitMin; }

References ZoomLimitMin.

◆ GetZoomTarget()

float C4Viewport::GetZoomTarget ( ) const
inline

Definition at line 61 of file C4Viewport.h.

61 { return ZoomTarget; }

References ZoomTarget.

◆ Init()

bool C4Viewport::Init ( int32_t  for_player,
bool  set_temporary_only 
)

Definition at line 786 of file C4Viewport.cpp.

787 {
788  // Fullscreen viewport initialization
789  // Set Player
790  if (!ValidPlr(for_player))
791  {
792  for_player = NO_OWNER;
793  }
794  Player = for_player;
796  if (!set_temporary_only) fIsNoOwnerViewport = (for_player == NO_OWNER);
797  if (Application.isEditor)
798  {
799  // Console viewport initialization
800  // Create window
801  pWindow = std::make_unique<C4ViewportWindow>(this);
802  if (!pWindow->Init(Player))
803  {
804  return false;
805  }
807  // Disable player lock on unowned viewports
808  if (!ValidPlr(Player))
809  {
811  }
812  // Don't call Execute right away since it is not yet guaranteed that
813  // the Player has set this as its Viewport, and the drawing routines rely
814  // on that.
815  }
816  else
817  {
818  // Owned viewport: clear any flash message explaining observer menu
819  if (ValidPlr(for_player))
820  {
822  }
823  }
824 
825  EnableFoW();
826  return true;
827 }
void FlashMessage(const char *message)
void EnableFoW()
Definition: C4Viewport.cpp:834
bool UpdateOutputSize(int32_t new_width=0, int32_t new_height=0)
Definition: C4Viewport.cpp:52
bool TogglePlayerLock()
Definition: C4Console.cpp:711

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitZoom()

void C4Viewport::InitZoom ( )
protected

Definition at line 505 of file C4Viewport.cpp.

506 {
508  if (player)
509  {
510  player->ZoomToViewport(this, true);
511  }
512  else
513  {
514  ZoomTarget = std::max<float>(float(ViewWdt)/::Landscape.GetWidth(), 1.0f);
515  Zoom = ZoomTarget;
516  }
517 }

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

Referenced by CalculateZoom().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsViewportMenu()

bool C4Viewport::IsViewportMenu ( class C4Menu menu)

Definition at line 994 of file C4Viewport.cpp.

995 {
996  // check all associated menus
997  // Get player
999  // Player eliminated: No menu
1000  if (player && player->Eliminated)
1001  {
1002  return false;
1003  }
1004  // Player cursor object menu
1005  if (player && player->Cursor && player->Cursor->Menu == menu)
1006  {
1007  return true;
1008  }
1009  // Player menu
1010  if (player && player->Menu.IsActive() && &(player->Menu) == menu)
1011  {
1012  return true;
1013  }
1014  // Fullscreen menu (if active, only one viewport can exist)
1016  {
1017  return true;
1018  }
1019  // no match
1020  return false;
1021 }

References FullScreen, C4PlayerList::Get(), C4Menu::IsActive(), C4FullScreen::MainMenu, Player, C4ScriptGuiWindowPropertyName::player, and Players.

Here is the call graph for this function:

◆ NextPlayer()

void C4Viewport::NextPlayer ( )

Definition at line 962 of file C4Viewport.cpp.

963 {
964  C4Player *player;
965  int32_t player_nr;
966  if (!(player = ::Players.Get(Player)))
967  {
968  if (!(player = ::Players.First))
969  {
970  return;
971  }
972  }
973  else if (!(player = player->Next))
974  {
975  if (Game.C4S.Head.Film && Game.C4S.Head.Replay)
976  {
977  player = ::Players.First; // cycle to first in film mode only; in network obs mode allow NO_OWNER-view
978  }
979  }
980  if (player)
981  {
982  player_nr = player->Number;
983  }
984  else
985  {
986  player_nr = NO_OWNER;
987  }
988  if (player_nr != Player)
989  {
990  Init(player_nr, true);
991  }
992 }
C4Player * First
Definition: C4PlayerList.h:31
bool Init(int32_t for_player, bool set_temporary_only)
Definition: C4Viewport.cpp:786

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

Referenced by C4ViewportList::ViewportNextPlayer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScrollBarsByViewPosition()

bool C4Viewport::ScrollBarsByViewPosition ( )

Definition at line 710 of file C4Console.cpp.

710 {return false;}

Referenced by UpdateOutputSize().

Here is the caller graph for this function:

◆ ScrollView()

void C4Viewport::ScrollView ( float  by_x,
float  by_y 
)

Scroll the viewport by x,y

Definition at line 882 of file C4Viewport.cpp.

883 {
884  SetViewX(viewX + by_x);
885  SetViewY(viewY + by_y);
886 }

References SetViewX(), and SetViewY().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetOutputSize()

void C4Viewport::SetOutputSize ( int32_t  draw_x,
int32_t  draw_y,
int32_t  out_x,
int32_t  out_y,
int32_t  out_wdt,
int32_t  out_hgt 
)

Definition at line 926 of file C4Viewport.cpp.

927 {
928  int32_t deltaWidth = ViewWdt - out_wdt;
929  int32_t deltaHeight = ViewHgt - out_hgt;
930 
931  // update output parameters
932  DrawX = draw_x;
933  DrawY = draw_y;
934  OutX = out_x;
935  OutY = out_y;
936  ViewWdt = out_wdt;
937  ViewHgt = out_hgt;
938  // update view position: Remain centered at previous position
939  // scrolling the view must be done after setting the new view width and height
940  ScrollView(deltaWidth/2, deltaHeight/2);
941  CalculateZoom();
942  // Reset menus
943  ResetMenuPositions = true;
944  // player uses mouse control? then clip the cursor
945  C4Player *player;
946  if ((player = ::Players.Get(Player)))
947  {
948  if (player->MouseControl)
949  {
951  // and inform GUI
952  ::pGUI->SetPreferredDlgRect(C4Rect(out_x, out_y, out_wdt, out_hgt));
953  }
954  }
955 }
void SetPreferredDlgRect(const C4Rect &rtNewPref)
Definition: C4Gui.h:2651

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetViewOffset()

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 94 of file C4Viewport.h.

94 { viewOffsX = x; viewOffsY = y; }

◆ SetViewX()

void C4Viewport::SetViewX ( float  x)

Set the view position.

Definition at line 888 of file C4Viewport.cpp.

889 {
890  viewX = x;
891 
892  if (fIsNoOwnerViewport)
893  {
894  if(::Landscape.GetWidth() < ViewWdt / Zoom)
895  {
896  viewX = ::Landscape.GetWidth()/2 - ViewWdt / Zoom / 2;
897  }
898  else
899  {
900  viewX = Clamp(x, 0.0f, ::Landscape.GetWidth() - ViewWdt / Zoom);
901  }
902  }
903 
904  UpdateBordersX();
905 }

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetViewY()

void C4Viewport::SetViewY ( float  y)

Definition at line 907 of file C4Viewport.cpp.

908 {
909  viewY = y;
910 
911  if (fIsNoOwnerViewport)
912  {
913  if(::Landscape.GetHeight() < ViewHgt / Zoom)
914  {
915  viewY = ::Landscape.GetHeight()/2 - ViewHgt / Zoom / 2;
916  }
917  else
918  {
919  viewY = Clamp(y, 0.0f, ::Landscape.GetHeight() - ViewHgt / Zoom);
920  }
921  }
922 
923  UpdateBordersY();
924 }

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetZoom() [1/2]

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

Definition at line 526 of file C4Viewport.cpp.

527 {
528  ZoomTarget = to_value;
529  if (Player != NO_OWNER || !::Application.isEditor)
530  {
532  {
534  }
536  {
538  }
539  }
540  // direct: Set zoom without scrolling to it
541  if (direct)
542  {
543  Zoom = ZoomTarget;
544  }
545 }

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

◆ SetZoom() [2/2]

void C4Viewport::SetZoom ( float  zoom_value)

Definition at line 592 of file C4Viewport.cpp.

593 {
594  Zoom = zoom_value;
595  // also set target to prevent zoom from changing back
596  ZoomTarget = zoom_value;
597 }

References Zoom, and ZoomTarget.

◆ SetZoomLimits()

void C4Viewport::SetZoomLimits ( float  to_min_zoom,
float  to_max_zoom 
)

Definition at line 547 of file C4Viewport.cpp.

548 {
549  ZoomLimitMin = to_min_zoom;
550  ZoomLimitMax = to_max_zoom;
552  {
554  }
555  ChangeZoom(1); // Constrains zoom to limit.
556 }
void ChangeZoom(float by_factor)
Definition: C4Viewport.cpp:519

References ChangeZoom(), ZoomLimitMax, and ZoomLimitMin.

Referenced by CalculateZoom().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TogglePlayerLock()

bool C4Viewport::TogglePlayerLock ( )

Definition at line 711 of file C4Console.cpp.

711 {return false;}

Referenced by Init().

Here is the caller graph for this function:

◆ UpdateOutputSize()

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

Definition at line 52 of file C4Viewport.cpp.

53 {
54  if (!pWindow)
55  {
56  return false;
57  }
58  // Output size
59  C4Rect rect;
60  if (new_width)
61  {
62  rect.x = rect.y = 0;
63  rect.Wdt = new_width;
64  rect.Hgt = new_height;
65  }
66  else
67  {
68 #if defined(WITH_QT_EDITOR)
69  // Never query the window - size is always passed from Qt.
70  return false;
71 #else
72  if (!pWindow->GetSize(&rect))
73  {
74  return false;
75  }
76 #endif
77  }
78  OutX = rect.x;
79  OutY = rect.y;
80  ViewWdt = rect.Wdt;
81  ViewHgt = rect.Hgt;
82  ScrollView(0,0);
83  // Scroll bars
85  // Reset menus
86  ResetMenuPositions = true;
87  // update internal GL size
88  if (pWindow && pWindow->pSurface)
89  {
90  pWindow->pSurface->UpdateSize(ViewWdt, ViewHgt);
91  }
92  // Update zoom limits based on new size
94  if (player)
95  {
96  player->ZoomLimitsToViewport(this);
97  }
98  // Done
99  return true;
100 }
bool ScrollBarsByViewPosition()
Definition: C4Console.cpp:710

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ViewPositionByScrollBars()

bool C4Viewport::ViewPositionByScrollBars ( )

◆ WindowToGameX()

float C4Viewport::WindowToGameX ( int32_t  win_x)
inline

Definition at line 85 of file C4Viewport.h.

85 { return GetViewX() + float(win_x) / Zoom; }

References GetViewX(), and Zoom.

Referenced by C4ViewportWindow::EditCursorMove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WindowToGameY()

float C4Viewport::WindowToGameY ( int32_t  win_y)
inline

Definition at line 86 of file C4Viewport.h.

86 { return GetViewY() + float(win_y) / Zoom; }

References GetViewY(), and Zoom.

Referenced by C4ViewportWindow::EditCursorMove().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4ConsoleQtViewportView

friend class C4ConsoleQtViewportView
friend

Definition at line 141 of file C4Viewport.h.

◆ C4GraphicsSystem

friend class C4GraphicsSystem
friend

Definition at line 140 of file C4Viewport.h.

◆ C4MouseControl

friend class C4MouseControl
friend

Definition at line 31 of file C4Viewport.h.

◆ C4ViewportList

friend class C4ViewportList
friend

Definition at line 139 of file C4Viewport.h.

◆ C4ViewportWindow

friend class C4ViewportWindow
friend

Definition at line 138 of file C4Viewport.h.

Member Data Documentation

◆ BorderBottom

float C4Viewport::BorderBottom

Definition at line 39 of file C4Viewport.h.

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

◆ BorderLeft

float C4Viewport::BorderLeft

Definition at line 39 of file C4Viewport.h.

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

◆ BorderRight

float C4Viewport::BorderRight

Definition at line 39 of file C4Viewport.h.

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

◆ BorderTop

float C4Viewport::BorderTop

Definition at line 39 of file C4Viewport.h.

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

◆ DrawX

int32_t C4Viewport::DrawX

Definition at line 40 of file C4Viewport.h.

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

◆ DrawY

int32_t C4Viewport::DrawY

Definition at line 41 of file C4Viewport.h.

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

◆ fIsNoOwnerViewport

bool C4Viewport::fIsNoOwnerViewport

◆ last_game_draw_cgo

C4TargetFacet C4Viewport::last_game_draw_cgo

Definition at line 43 of file C4Viewport.h.

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

◆ last_gui_draw_cgo

C4TargetFacet C4Viewport::last_gui_draw_cgo

Definition at line 44 of file C4Viewport.h.

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

◆ Next

◆ OutX

int32_t C4Viewport::OutX
protected

◆ OutY

int32_t C4Viewport::OutY
protected

◆ pFoW

std::unique_ptr<C4FoWRegion> C4Viewport::pFoW
protected

Definition at line 114 of file C4Viewport.h.

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

◆ Player

◆ PlayerLock

bool C4Viewport::PlayerLock
protected

Definition at line 109 of file C4Viewport.h.

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

◆ pWindow

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

◆ ResetMenuPositions

bool C4Viewport::ResetMenuPositions
protected

Definition at line 111 of file C4Viewport.h.

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

◆ ViewHgt

◆ ViewportOpenFrame

int32_t C4Viewport::ViewportOpenFrame
protected

Definition at line 107 of file C4Viewport.h.

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

◆ ViewWdt

◆ Zoom

◆ ZoomLimitMax

float C4Viewport::ZoomLimitMax
protected

Definition at line 106 of file C4Viewport.h.

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

◆ ZoomLimitMin

float C4Viewport::ZoomLimitMin
protected

Definition at line 106 of file C4Viewport.h.

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

◆ ZoomTarget

float C4Viewport::ZoomTarget
protected

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