1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Loads all standard graphics from Graphics.ocg */
19 
20 #ifndef INC_C4GraphicsResource
21 #define INC_C4GraphicsResource
22 
23 #include "c4group/C4GroupSet.h"
24 #include "graphics/C4Surface.h"
25 #include "graphics/C4FacetEx.h"
26 #include "gui/C4Gui.h"
27 #include "player/C4Achievement.h"
28 
29 class C4GraphicsResource
30 {
31 private:
32 	bool fInitialized;
33 public:
34 	C4GraphicsResource();
35 	~C4GraphicsResource();
36 protected:
37 	C4Surface sfcControl, sfcClonkSkins;
38 	C4Surface sfcCaption, sfcButton, sfcButtonD;
39 	C4Surface sfcScroll, sfcContext;
40 	int32_t idSfcCaption{0}, idSfcButton{0}, idSfcButtonD{0}, idSfcScroll{0}, idSfcContext{0}, idSfcClonkSkins;
41 	int32_t idSfcControl; // id of source group of control surface
42 	// ID of last group in main group set that was already registered into the Files-set
43 	// used to avoid doubled entries by subsequent calls to RegisterMainGroups
44 	int32_t idRegisteredMainGroupSetFiles;
45 public:
46 	C4GroupSet Files;
47 	float ProgressStart, ProgressIncrement;
48 	C4FacetID fctPlayer;
49 	C4FacetID fctFlag;
50 	C4FacetID fctCrew;
51 	C4FacetID fctWealth;
52 	C4FacetID fctRank;
53 	int32_t iNumRanks;
54 	C4FacetID fctFire;
55 	C4FacetID fctBackground;
56 	C4FacetID fctCaptain;
57 	C4FacetID fctMouseCursor;
58 	C4FacetID fctSelectMark;
59 	C4FacetID fctOptions;
60 	C4FacetID fctMenu;
61 	C4FacetID fctUpperBoard;
62 	C4FacetID fctLogo;
63 	C4FacetID fctConstruction;
64 	C4FacetID fctEnergy;
65 	C4FacetID fctArrow;
66 	C4FacetID fctExit;
67 	C4FacetID fctHand;
68 	C4FacetID fctGamepad;
69 	C4FacetID fctBuild;
70 	C4Facet fctClonkSkin;
71 	C4Facet fctKeyboard;
72 	C4Facet fctMouse;
73 	C4Facet fctCommand;
74 	C4Facet fctKey;
75 	C4Facet fctOKCancel;
76 	C4FacetID fctTransformKnob;
77 	C4FacetID fctCrewClr; // ColorByOwner-surface of fctCrew
78 	C4FacetID fctFlagClr; // ColorByOwner-surface of fctFlag
79 	C4FacetID fctPlayerClr; // ColorByOwner-surface of fctPlayer
80 
81 	C4GUI::DynBarFacet barCaption, barButton, barButtonD;
82 	C4FacetID fctButtonHighlight;
83 	C4FacetID fctButtonHighlightRound;
84 	C4FacetID fctIcons, fctIconsEx;
85 	C4FacetID fctControllerIcons;
86 	C4FacetID fctSubmenu;
87 	C4FacetID fctCheckbox;
88 	C4FacetID fctBigArrows;
89 	C4FacetID fctProgressBar;
90 	C4GUI::ScrollBarFacets sfctScroll;
91 	C4Facet fctContext;
92 
93 	// fonts
94 	CStdFont &CaptionFont; // small, bold font
95 	CStdFont &TitleFont;   // large, bold font
96 	CStdFont &TextFont;    // font for normal text
97 	CStdFont &MiniFont;    // tiny font (logfont)
98 	CStdFont &TooltipFont; // same as BookFont
99 	CStdFont FontTiny;     // used for logs
100 	CStdFont FontRegular;  // normal font - just refed from graphics system
101 	CStdFont FontCaption;  // used for title bars
102 	CStdFont FontTitle;    // huge font for titles
103 	CStdFont FontTooltip;  // normal, non-shadowed font (same as BookFont)
104 
105 	// achievement graphics
106 	C4AchievementGraphics Achievements;
107 public:
108 	CStdFont &GetFontByHeight(int32_t iHgt, float *pfZoom=nullptr); // get optimal font for given control size
109 	void Default();
110 	void Clear();
111 	bool InitFonts();
112 	void ClearFonts(); // clear fonts ()
113 	bool Init();
114 
IsInitialized()115 	bool IsInitialized() { return fInitialized; } // return whether any gfx are loaded (so dlgs can be shown)
116 
117 	bool RegisterGlobalGraphics(); // register global Graphics.ocg into own group set
118 	bool RegisterMainGroups();     // register new groups of Game.GroupSet into own group set
119 	void CloseFiles();             // free group set
120 
121 	bool ReloadResolutionDependantFiles(); // reload any files that depend on the current resolution
122 
123 protected:
124 	bool LoadFile(C4FacetID& fct, const char *szName, C4GroupSet &rGfxSet, int32_t iWdt, int32_t iHgt, bool fNoWarnIfNotFound, int iFlags);
125 	bool LoadFile(C4Surface& sfc, const char *szName, C4GroupSet &rGfxSet, int32_t &ridCurrSfc, int iFlags);
126 	bool FindLoadRes(C4Group *pSecondFile, const char *szName);
127 	bool LoadCursorGfx();
128 
129 	friend class C4StartupGraphics;
130 };
131 
132 extern C4GraphicsResource GraphicsResource;
133 #define GfxR (&(::GraphicsResource))
134 #endif
135