Rose
ImageStore.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <cstdint>
11 #include <map>
12 #include "Color.h"
13 #include "Entypo.h"
14 #include "GraphicsModel.h"
15 #include "Surface.h"
16 #include "Texture.h"
17 
18 namespace rose {
19 
20  enum class ImageId : int {
21  NoImage,
22  Compass,
23  Heart,
24  HeartEmpty,
25  Cancel,
26  Help,
27  Info,
28  Check,
29  Alert,
30  Lock,
31  LockOpen,
32  UpBold,
33  UpOpenBig,
34  DownBold,
35  DownOpenBig,
36  Left,
37  Right,
38  ToEnd,
39  Back,
40  LevelDown,
41  OneDot,
42  TwoDots,
43  ThreeDots,
44  UpDir,
45  DownDir,
46  LeftDir,
47  RightDir,
48  Keyboard,
49  Globe,
50  Network,
51  Rocket,
52  Location,
53  Camera,
54  ScaleNeedleUp,
55  ScaleNeedleDown,
56  ScaleNeedleLeft,
57  ScaleNeedleRight,
58  IconTarget,
59  // ImageIds for Frames
68  RoundCornerTrim,
69  // ImageIds for Centres
78  // Following value must be last.
79  DynamicIdStart,
80  };
81 
86  struct IconImage {
87  ImageId key{};
88  uint32_t code{};
89  color::RGBA color{};
90  };
91 
96  class ImageStore {
97  protected:
99  bool mInitialized{false};
100 
102  int mNextImageId{static_cast<int>(ImageId::DynamicIdStart)};
103 
105  std::map<ImageId,gm::Texture> mImageMap{};
106 
108  void createIcon(gm::Context &context, IconImage iconImage);
109 
111  template<typename Iterator>
112  void createIcons(gm::Context &context, Iterator first, Iterator last) {
113  while (first != last) {
114  createIcon(context, *first);
115  first++;
116  }
117  }
118 
120  void initialize(gm::Context &context);
121 
122  void createSquareCorners(gm::Context &context, int radius, int borderWidth,
123  color::RGBA top, color::RGBA bot,
124  color::RGBA left, color::RGBA right);
125 
126  void createRoundCorners(gm::Context &context, int scale, int radius, int borderWidth,
127  color::RGBA top, color::RGBA bot,
128  color::RGBA left, color::RGBA right);
129 
130  void createCenters(gm::Context &context, int scale, int radius);
131 
132  public:
133 
138  static ImageStore &getStore() {
139  static ImageStore imageStore{};
140  return imageStore;
141  }
142 
150  static ImageStore& getStore(gm::Context &context) {
151  ImageStore& store{getStore()};
152  if (!store.mInitialized) {
153  store.initialize(context);
154  store.mInitialized = true;
155  }
156  return getStore();
157  }
158 
160  ImageId nextImageId() {
161  return static_cast<ImageId>(mNextImageId++);
162  }
163 
165  void setImage(ImageId imageId, gm::Texture &&texture);
166 
168  bool exists(ImageId imageId) {
169  return mImageMap.find(imageId) != mImageMap.end();
170  }
171 
179  Size size(ImageId imageId) {
180  Size size{};
181  auto image = mImageMap.find(imageId);
182  if (image != mImageMap.end()) {
183  size = image->second.getSize();
184  }
185  return size;
186  }
187 
196  int renderCopy(gm::Context& context, ImageId imageId, Rectangle dst) {
197  if (auto image = mImageMap.find(imageId); image != mImageMap.end())
198  return context.renderCopy(image->second, dst);
199  return 0;
200  }
201 
210  int renderCopy(gm::Context& context, ImageId imageId, Rectangle src, Rectangle dst) {
211  if (auto image = mImageMap.find(imageId); image != mImageMap.end())
212  return context.renderCopy(image->second, src, dst);
213  return 0;
214  }
215 
226  int renderCopyEx(gm::Context& context, ImageId imageId, Rectangle src, Rectangle dst, double angle, gm::RenderFlip flip) {
227  if (auto image = mImageMap.find(imageId); image != mImageMap.end())
228  return context.renderCopyEx(image->second, src, dst, angle, flip);
229  return 0;
230  }
231  };
232 }
233 
Sheet of square corners beveled in.
Definition: Constants.h:220
int renderCopyEx(Texture &texture, Rectangle src, Rectangle dst, double angle, RenderFlip renderFlip, std::optional< Position< int >> point=std::nullopt) const
Render with extensions.
Definition: GraphicsModel.cpp:94
Center for the round corners in red hue.
Definition: Constants.h:215
void initialize(gm::Context &context)
Initialize the ImageStore.
Definition: ImageStore.cpp:99
The information required to create an Icon from the Entypo Font.
Definition: ImageStore.h:86
ImageId nextImageId()
Get the next dyname ImageId.
Definition: ImageStore.h:160
int renderCopy(gm::Context &context, ImageId imageId, Rectangle dst)
Render the Texture associated with an Image Id.
Definition: ImageStore.h:196
Red Green Blue Alpha representation of a color.
Definition: Color.h:64
Center for the square corners in theme invert color.
Definition: Constants.h:224
Sheet of square corners notched out.
Definition: Constants.h:221
Center for the round corners in yellow hue.
Definition: Constants.h:218
Center for the square corners in theme base color.
Definition: Constants.h:223
Definition: ImageStore.h:96
Sheet of round corners notched out.
Definition: Constants.h:211
Sheet of round corners beveled in.
Definition: Constants.h:210
void createIcons(gm::Context &context, Iterator first, Iterator last)
Create many Icons using a container of IconImage structures.
Definition: ImageStore.h:112
Sheet of round corners beveled out.
Definition: Constants.h:209
Center for the round corners in theme invert color.
Definition: Constants.h:214
Sheet of round corners notched in.
Definition: Constants.h:212
int renderCopy(const Texture &texture)
Copy a Texture to the current render target using the size of the Texture and the size of the target...
Definition: GraphicsModel.cpp:80
Abstraction of SDL_Texture.
Definition: Texture.h:46
Context
Definition: GraphicsModel.h:76
static ImageStore & getStore(gm::Context &context)
Get access to, and initialize, the Singleton ImageStore.
Definition: ImageStore.h:150
Sheet of square corners beveled out.
Definition: Constants.h:219
Abstraction of the graphics model.
static ImageStore & getStore()
Get access to the Singleton ImageStore.
Definition: ImageStore.h:138
Size size(ImageId imageId)
Get the size of the Texture associated with an ImageId.
Definition: ImageStore.h:179
Center for the round corners in theme base color.
Definition: Constants.h:213
bool exists(ImageId imageId)
Test to see if a Texture is associated with an ImageId.
Definition: ImageStore.h:168
A composite of a Position and a Size.
Definition: Types.h:307
int renderCopy(gm::Context &context, ImageId imageId, Rectangle src, Rectangle dst)
Render the Texture associated with an Image Id.
Definition: ImageStore.h:210
Sheet of square corners notched in.
Definition: Constants.h:222
A size in integer dimensions.
Definition: Types.h:230
int renderCopyEx(gm::Context &context, ImageId imageId, Rectangle src, Rectangle dst, double angle, gm::RenderFlip flip)
Render the Texture associated with an Image Id with with optional rotation and flipping.
Definition: ImageStore.h:226
A Widget manipulator to indicate if and how rendering a texture should be flipped.
Definition: GraphicsModel.h:62
Center for the round corners in green hue.
Definition: Constants.h:216
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
Center for the round corners in blue hue.
Definition: Constants.h:217
This is a list of icon codes for the entypo.ttf font by Daniel Bruce.