1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design)
5 * Copyright (c) 2017-2021, The LegacyClonk Team and contributors
6 *
7 * Distributed under the terms of the ISC license; see accompanying file
8 * "COPYING" for details.
9 *
10 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11 * See accompanying file "TRADEMARK" for details.
12 *
13 * To redistribute this file separately, substitute the full license texts
14 * for the above references.
15 */
16
17/* Operates viewports, message board and draws the game */
18
19#pragma once
20
21#include <C4FacetEx.h>
22#include <C4MessageBoard.h>
23#include <C4UpperBoard.h>
24#include <C4Shape.h>
25#include <C4Cooldown.h>
26
27#include <memory>
28#include <vector>
29
30class C4Game;
31class C4LoaderScreen;
32extern C4Game Game;
33
34class C4GraphicsSystem
35{
36public:
37 C4GraphicsSystem();
38 ~C4GraphicsSystem();
39 C4MessageBoard MessageBoard;
40 C4UpperBoard UpperBoard;
41 int32_t iRedrawBackground;
42 bool ShowHelp;
43 bool ShowVertices;
44 bool ShowAction;
45 bool ShowCommand;
46 bool ShowEntrance;
47 bool ShowPathfinder;
48 bool ShowNetstatus;
49 bool ShowSolidMask;
50 bool fSetPalette;
51 uint32_t dwGamma[C4MaxGammaRamps * 3]; // gamma ramps
52 bool fSetGamma; // must gamma ramp be reassigned?
53 C4LoaderScreen *pLoaderScreen;
54 // Used to determine if arrow keys are held in FreeScroll()
55 C4Cooldown<std::chrono::milliseconds::rep, std::chrono::milliseconds::period> MostRecentScrolling{std::chrono::milliseconds{100}};
56 void Default();
57 void Clear();
58 bool StartDrawing();
59 void FinishDrawing();
60 void Execute();
61 void FlashMessage(const char *szMessage);
62 void FlashMessageOnOff(const char *strWhat, bool fOn);
63 void DeactivateDebugOutput();
64 void MouseMove(int32_t iButton, int32_t iX, int32_t iY, uint32_t dwKeyParam, class C4Viewport *pVP); // pVP specified for console mode viewports only
65 void SetMouseInGUI(bool fInGUI, bool fByMouse);
66 void SortViewportsByPlayerControl();
67 void ClearPointers(C4Object *pObj);
68 void RecalculateViewports();
69 bool Init();
70 bool InitLoaderScreen(const char *szLoaderSpec);
71 bool SaveScreenshot(bool fSaveAll);
72 bool DoSaveScreenshot(bool fSaveAll, const char *szFilename);
73 bool SetPalette();
74 bool CreateViewport(int32_t iPlayer, bool fSilent);
75 bool CloseViewport(int32_t iPlayer, bool fSilent);
76 int32_t GetAudibility(int32_t iX, int32_t iY, int32_t *iPan, int32_t iAudibilityRadius = 0);
77 int32_t GetViewportCount();
78 C4Viewport *GetViewport(int32_t iPlayer);
79 const std::vector<std::unique_ptr<C4Viewport>> &GetViewports() { return Viewports; }
80 inline void InvalidateBg() { iRedrawBackground = 2; }
81 inline void OverwriteBg() { InvalidateBg(); }
82 void SetGamma(uint32_t dwClr1, uint32_t dwClr2, uint32_t dwClr3, int32_t iRampIndex); // set gamma ramp
83 void ApplyGamma(); // apply gamma ramp to ddraw
84 bool CloseViewport(C4Viewport *cvp);
85
86protected:
87 std::vector<std::unique_ptr<C4Viewport>> Viewports;
88 C4Facet ViewportArea;
89 C4RectList BackgroundAreas; // rectangles covering background without viewports in fullscreen
90 char FlashMessageText[C4MaxTitle + 1];
91 int32_t FlashMessageTime, FlashMessageX, FlashMessageY;
92 void DrawHelp();
93 void DrawFlashMessage();
94 void DrawHoldMessages();
95 void DrawFullscreenBackground();
96 void ClearFullscreenBackground();
97 void MouseMoveToViewport(int32_t iButton, int32_t iX, int32_t iY, uint32_t dwKeyParam);
98
99public:
100 bool ToggleShowSolidMask();
101 bool ToggleShowNetStatus();
102 bool ToggleShowVertices();
103 bool ToggleShowAction();
104 bool ViewportNextPlayer();
105 bool ToggleShowHelp();
106
107 bool FreeScroll(C4Vec2D vScrollBy); // key callback: Scroll ownerless viewport by some offset
108};
109