Shape2D.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 
34 #ifndef H_DC_SHAPE2D_INCLUDED
35 #define H_DC_SHAPE2D_INCLUDED
36 
37 #include <Dynacoe/Components/Render2D.h>
38 #include <Dynacoe/Image.h>
39 #include <Dynacoe/Color.h>
40 namespace Dynacoe {
41 
46 class Shape2D : public Render2D {
47  public:
48  Shape2D();
49 
55  Color color;
56 
64  void FormRectangle (float width, float height);
65 
74  void FormImage (AssetID image, float forcedWidth = -1.f, float forcedHeight = -1.f);
75 
76 
77 
78 
87  void FormImageFrame (AssetID image, int frame, float forcedWidth = -1.f, float forcedHeight = -1.f);
88 
96  void FormCircle (float radius, int numIterations);
97 
98 
105  void FormTriangles(std::vector<Dynacoe::Vector> & pts);
106 
111  void FormLines (const std::vector<Dynacoe::Vector> & pts);
112 
114 
115  void OnDraw();
116  std::string GetInfo();
117 
118  private:
119  AssetID id;
120  int idFrame;
121  Color realColor;
122  float forcedWidth;
123  float forcedHeight;
124  float currentTexture;
125 
126  void SetFrameActive(const Image::Frame & f);
127  void Initialize();
128 };
129 }
130 
131 
132 
133 #endif
A standard object representing an RGBA color.
Definition: Color.h:47
void FormRectangle(float width, float height)
Forms the aspect into a rectangle.
void FormTriangles(std::vector< Dynacoe::Vector > &pts)
Forms the aspect into a collection of triangle primitives.
void FormCircle(float radius, int numIterations)
Forms the aspect into an estimated circle made of triangles.
Base component to render a 2D object.
Definition: Render2D.h:42
void FormImageFrame(AssetID image, int frame, float forcedWidth=-1.f, float forcedHeight=-1.f)
Forms the aspect into a frame of an image.
A 2D matrix of pixels.
Definition: Image.h:68
Definition: AssetID.h:37
void FormLines(const std::vector< Dynacoe::Vector > &pts)
Forms a collection of line segments.
Assets are referred to by an AssetID. The AssetID uniquely refers to an Asset stored within memory...
Definition: AssetID.h:42
void OnDraw()
Function that is called upon each Draw iteration. Component Draw()s are run before the entity's draw ...
std::string GetInfo()
Returns a string containing human-readable information on the state of the component.
An aspect that can express basic 2D objects, such as images and shapes.
Definition: Shape2D.h:46
void FormImage(AssetID image, float forcedWidth=-1.f, float forcedHeight=-1.f)
Forms the aspect into the shape and visual of an image.