ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Action.c
Go to the documentation of this file.
1/*
2 * ObjectivelyMVC: Object oriented MVC framework for OpenGL, SDL2 and GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#include <assert.h>
25
26#include "Action.h"
27
28#define _Class _Action
29
30#pragma mark - Action
31
36static Action *initWithEventType(Action *self, SDL_EventType eventType, ActionFunction function, ident sender, ident data) {
37
38 self = (Action *) super(Object, self, init);
39 if (self) {
40 self->eventType = eventType;
41 assert(self->eventType);
42
43 self->function = function;
44 assert(self->function);
45
46 self->sender = sender;
47 self->data = data;
48 }
49
50 return self;
51}
52
53#pragma mark - Class lifecycle
54
58static void initialize(Class *clazz) {
59
60 ((ActionInterface *) clazz->interface)->initWithEventType = initWithEventType;
61}
62
67Class *_Action(void) {
68 static Class *clazz;
69 static Once once;
70
71 do_once(&once, {
72 clazz = _initialize(&(const ClassDef) {
73 .name = "Action",
74 .superclass = _Object(),
75 .instanceSize = sizeof(Action),
76 .interfaceOffset = offsetof(Action, interface),
77 .interfaceSize = sizeof(ActionInterface),
79 });
80 });
81
82 return clazz;
83}
84
85#undef _Class
static void initialize(Class *clazz)
Definition: Action.c:58
Actions bind event-driven behavior to Controls.
void(* ActionFunction)(Control *control, const SDL_Event *event, ident sender, ident data)
The ActionFunction callback.
Definition: Action.h:43
Actions bind event-driven behavior to Controls.
Definition: Action.h:50
Class * _Action(void)
The Action archetype.
Definition: Action.c:67
SDL_EventType eventType
The event type.
Definition: Action.h:71
ident data
The user data.
Definition: Action.h:66
Action * initWithEventType(Action *self, SDL_EventType eventType, ActionFunction function, ident sender, ident data)
Initializes this Action with the given function and data.
Definition: Action.c:36
ActionFunction function
The function.
Definition: Action.h:76
ident sender
The sender.
Definition: Action.h:81
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.