ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Macros | Functions | Variables
ImageView.c File Reference
#include <assert.h>
#include "ImageView.h"

Go to the source code of this file.

Macros

#define _Class   _ImageView
 

Functions

Class * _ImageView (void)
 
static void awakeWithDictionary (View *self, const Dictionary *dictionary)
 
static void dealloc (Object *self)
 
static Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static ImageViewinitWithFrame (ImageView *self, const SDL_Rect *frame)
 
static ImageViewinitWithImage (ImageView *self, Image *image)
 
static void render (View *self, Renderer *renderer)
 
static void renderDeviceWillReset (View *self)
 
static void setImage (ImageView *self, Image *image)
 
static void setImageWithResource (ImageView *self, const Resource *resource)
 
static void setImageWithResourceName (ImageView *self, const char *name)
 
static void setImageWithSurface (ImageView *self, SDL_Surface *surface)
 

Variables

const EnumName GLBlendNames []
 

Macro Definition Documentation

◆ _Class

#define _Class   _ImageView

Definition at line 43 of file ImageView.c.

Function Documentation

◆ _ImageView()

Class * _ImageView ( void  )

Definition at line 261 of file ImageView.c.

261 {
262 static Class *clazz;
263 static Once once;
264
265 do_once(&once, {
266 clazz = _initialize(&(const ClassDef) {
267 .name = "ImageView",
268 .superclass = _View(),
269 .instanceSize = sizeof(ImageView),
270 .interfaceOffset = offsetof(ImageView, interface),
271 .interfaceSize = sizeof(ImageViewInterface),
273 });
274 });
275
276 return clazz;
277}
static void initialize(Class *clazz)
Definition: ImageView.c:240
ImageViews render an Image in the context of a View hierarchy.
Definition: ImageView.h:43
Class * _View(void)
The View archetype.
Definition: View.c:1769

◆ awakeWithDictionary()

static void awakeWithDictionary ( View self,
const Dictionary *  dictionary 
)
static
See also
View::awakeWithDictionary(View *, const Dictionary *)

Definition at line 68 of file ImageView.c.

68 {
69
70 super(View, self, awakeWithDictionary, dictionary);
71
72 ImageView *this = (ImageView *) self;
73
74 const Inlet inlets[] = MakeInlets(
75 MakeInlet("blend.src", InletTypeEnum, &this->blend.src, (ident) GLBlendNames),
76 MakeInlet("blend.dst", InletTypeEnum, &this->blend.dst, (ident) GLBlendNames),
77 MakeInlet("color", InletTypeColor, &this->color, NULL),
78 MakeInlet("image", InletTypeImage, &this->image, NULL)
79 );
80
81 $(self, bind, inlets, dictionary);
82}
const EnumName GLBlendNames[]
Definition: ImageView.c:28
@ InletTypeImage
Definition: View+JSON.h:90
@ InletTypeEnum
Definition: View+JSON.h:75
@ InletTypeColor
Definition: View+JSON.h:62
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
Definition: View+JSON.h:221
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Definition: View+JSON.h:216
Inlets enable inbound data binding of View attributes through JSON.
Definition: View+JSON.h:155
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133
_Bool bind(View *self, const Inlet *inlets, const Dictionary *dictionary)
Performs data binding for the Inlets described in dictionary.
void awakeWithDictionary(View *self, const Dictionary *dictionary)
Wakes this View with the specified Dictionary.
Definition: Box.c:50

◆ dealloc()

static void dealloc ( Object *  self)
static
See also
Object::dealloc(Object *)

Definition at line 50 of file ImageView.c.

50 {
51
52 ImageView *this = (ImageView *) self;
53
54 release(this->image);
55
56 if (this->texture) {
57 glDeleteTextures(1, &this->texture);
58 }
59
60 super(Object, self, dealloc);
61}
static void dealloc(Object *self)
Definition: ImageView.c:50

◆ init()

static View * init ( View self)
static
See also
View::init(View *)

Definition at line 87 of file ImageView.c.

87 {
88 return (View *) $((ImageView *) self, initWithImage, NULL);
89}
Button * initWithImage(Button *self, Image *image)
Initializes this Button with the sopecified Image.
Definition: Button.c:122

◆ initialize()

static void initialize ( Class *  clazz)
static

see Class::initialize(Class *)

Definition at line 240 of file ImageView.c.

240 {
241
242 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
243
244 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
245 ((ViewInterface *) clazz->interface)->init = init;
246 ((ViewInterface *) clazz->interface)->render = render;
247 ((ViewInterface *) clazz->interface)->renderDeviceWillReset = renderDeviceWillReset;
248
249 ((ImageViewInterface *) clazz->interface)->initWithFrame = initWithFrame;
250 ((ImageViewInterface *) clazz->interface)->initWithImage = initWithImage;
251 ((ImageViewInterface *) clazz->interface)->setImage = setImage;
252 ((ImageViewInterface *) clazz->interface)->setImageWithResource = setImageWithResource;
253 ((ImageViewInterface *) clazz->interface)->setImageWithResourceName = setImageWithResourceName;
254 ((ImageViewInterface *) clazz->interface)->setImageWithSurface = setImageWithSurface;
255}
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
void setImageWithResource(ImageView *self, const Resource *resource)
Sets the Image for this ImageView with the given Resource.
Definition: ImageView.c:195
void setImage(ImageView *self, Image *image)
Sets the Image for this ImageView.
Definition: ImageView.c:171
void setImageWithSurface(ImageView *self, SDL_Surface *surface)
A convenience method to set this view's Image with a surface.
Definition: ImageView.c:221
void setImageWithResourceName(ImageView *self, const char *name)
Sets the Image for this ImageView with the Resource by the given name.
Definition: ImageView.c:208
void renderDeviceWillReset(Renderer *self)
This method is invoked when the render device will become reset.
Definition: Renderer.c:252
void render(View *self, Renderer *renderer)
Renders this View using the given renderer.
Definition: Control.c:131

◆ initWithFrame()

static ImageView * initWithFrame ( ImageView self,
const SDL_Rect *  frame 
)
static

Definition at line 140 of file ImageView.c.

140 {
141
142 self = (ImageView *) super(View, self, initWithFrame, frame);
143 if (self) {
144 self->blend.src = GL_SRC_ALPHA;
145 self->blend.dst = GL_ONE_MINUS_SRC_ALPHA;
146
147 self->color = Colors.White;
148 }
149
150 return self;
151}
W3C Color constants.
Definition: Colors.h:37
SDL_Color White
Definition: Colors.h:185
GLenum dst
Definition: ImageView.h:60
GLenum src
Definition: ImageView.h:60
SDL_Color color
The drawing color.
Definition: ImageView.h:66
struct ImageView::@0 blend
The blend function.

◆ initWithImage()

static ImageView * initWithImage ( ImageView self,
Image image 
)
static

Definition at line 157 of file ImageView.c.

157 {
158
159 self = (ImageView *) $(self, initWithFrame, NULL);
160 if (self) {
161 $(self, setImage, image);
162 }
163
164 return self;
165}

◆ render()

static void render ( View self,
Renderer renderer 
)
static
See also
ViewInterface::render(View *, Renderer *)

Definition at line 94 of file ImageView.c.

94 {
95
96 super(View, self, render, renderer);
97
98 ImageView *this = (ImageView *) self;
99
100 if (this->texture == 0) {
101 if (this->image) {
102 this->texture = $(renderer, createTexture, this->image->surface);
103 assert(this->texture);
104 }
105 }
106
107 if (this->texture) {
108
109 // TODO: Actually use self->blend
110
111 $(renderer, setDrawColor, &this->color);
112 const SDL_Rect frame = $(self, renderFrame);
113 $(renderer, drawTexture, this->texture, &frame);
114 $(renderer, setDrawColor, &Colors.White);
115 }
116}
GLuint createTexture(const Renderer *self, const SDL_Surface *surface)
Generates and binds to an OpenGL texture object, uploading the given surface.
Definition: Renderer.c:56
void drawTexture(const Renderer *self, GLuint texture, const SDL_Rect *dest)
Draws a textured GL_QUAD in the given rectangle.
Definition: Renderer.c:155
void setDrawColor(Renderer *self, const SDL_Color *color)
Sets the primary color for drawing operations.
Definition: Renderer.c:281
SDL_Rect renderFrame(const View *self)
Definition: View.c:1275

◆ renderDeviceWillReset()

static void renderDeviceWillReset ( View self)
static
See also
View::renderDeviceWillReset(View *)

Definition at line 121 of file ImageView.c.

121 {
122
123 ImageView *this = (ImageView *) self;
124
125 if (this->texture) {
126 glDeleteTextures(1, &this->texture);
127 }
128
129 this->texture = 0;
130
131 super(View, self, renderDeviceWillReset);
132}

◆ setImage()

static void setImage ( ImageView self,
Image image 
)
static

Definition at line 171 of file ImageView.c.

171 {
172
173 release(self->image);
174
175 if (image) {
176 self->image = retain(image);
177
178 const SDL_Size size = $((View *) self, size);
179 const SDL_Size imageSize = $(image, size);
180
181 if (size.w == 0 && size.h == 0) {
182 $((View *) self, resize, &imageSize);
183 }
184 } else {
185 self->image = NULL;
186 }
187
188 self->texture = 0;
189}
SDL_Size size(const Image *self)
Definition: Image.c:181
Image * image
The image.
Definition: ImageView.h:71
GLuint texture
The texture.
Definition: ImageView.h:76
The SDL_Size type.
Definition: Types.h:62
int w
Definition: Types.h:63
int h
Definition: Types.h:63
void resize(View *self, const SDL_Size *size)
Resizes this View to the specified size.
Definition: View.c:1326

◆ setImageWithResource()

static void setImageWithResource ( ImageView self,
const Resource *  resource 
)
static

Definition at line 195 of file ImageView.c.

195 {
196
197 Image *image = $$(Image, imageWithResource, resource);
198
199 $(self, setImage, image);
200
201 release(image);
202}
Image loading.
Definition: Image.h:38
Image * imageWithResource(const Resource *resource)
Instantiates an Image with the specified Resource.
Definition: Image.c:64

◆ setImageWithResourceName()

static void setImageWithResourceName ( ImageView self,
const char *  name 
)
static

Definition at line 208 of file ImageView.c.

208 {
209
210 Resource *resource = $$(Resource, resourceWithName, name);
211
212 $(self, setImageWithResource, resource);
213
214 release(resource);
215}

◆ setImageWithSurface()

static void setImageWithSurface ( ImageView self,
SDL_Surface *  surface 
)
static

Definition at line 221 of file ImageView.c.

221 {
222
223 $(self, setImage, NULL);
224
225 if (surface) {
226 Image *image = $(alloc(Image), initWithSurface, surface);
227 assert(image);
228
229 $(self, setImage, image);
230
231 release(image);
232 }
233}
Image * initWithSurface(Image *self, SDL_Surface *surface)
Initializes this Image with the given surface.
Definition: Image.c:157

Variable Documentation

◆ GLBlendNames

const EnumName GLBlendNames[]
Initial value:
= MakeEnumNames(
MakeEnumName(GL_CONSTANT_ALPHA),
MakeEnumName(GL_CONSTANT_COLOR),
MakeEnumName(GL_DST_ALPHA),
MakeEnumName(GL_DST_COLOR),
MakeEnumName(GL_ONE),
MakeEnumName(GL_ONE_MINUS_DST_ALPHA),
MakeEnumName(GL_ONE_MINUS_DST_COLOR),
MakeEnumName(GL_ONE_MINUS_SRC_ALPHA),
MakeEnumName(GL_ONE_MINUS_SRC_COLOR),
MakeEnumName(GL_SRC_ALPHA),
MakeEnumName(GL_SRC_COLOR),
MakeEnumName(GL_ZERO)
)

Definition at line 28 of file ImageView.c.