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

Go to the source code of this file.

Macros

#define _Class   _Button
 

Functions

Class * _Button (void)
 
static void awakeWithDictionary (View *self, const Dictionary *dictionary)
 
static _Bool captureEvent (Control *self, const SDL_Event *event)
 
static void dealloc (Object *self)
 
static Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static ButtoninitWithFrame (Button *self, const SDL_Rect *frame)
 
static ButtoninitWithImage (Button *self, Image *image)
 
static ButtoninitWithTitle (Button *self, const char *title)
 

Macro Definition Documentation

◆ _Class

#define _Class   _Button

Definition at line 29 of file Button.c.

Function Documentation

◆ _Button()

Class * _Button ( void  )

Definition at line 167 of file Button.c.

167 {
168 static Class *clazz;
169 static Once once;
170
171 do_once(&once, {
172 clazz = _initialize(&(const ClassDef) {
173 .name = "Button",
174 .superclass = _Control(),
175 .instanceSize = sizeof(Button),
176 .interfaceOffset = offsetof(Button, interface),
177 .interfaceSize = sizeof(ButtonInterface),
179 });
180 });
181
182 return clazz;
183}
static void initialize(Class *clazz)
Definition: Button.c:149
Buttons are Controls that respond to click events.
Definition: Button.h:42
Class * _Control(void)
The Control archetype.
Definition: Control.c:379

◆ awakeWithDictionary()

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

Definition at line 51 of file Button.c.

51 {
52
53 super(View, self, awakeWithDictionary, dictionary);
54
55 Button *this = (Button *) self;
56
57 const Inlet inlets[] = MakeInlets(
58 MakeInlet("title", InletTypeView, &this->title, NULL)
59 );
60
61 $(self, bind, inlets, dictionary);
62}
@ InletTypeView
Definition: View+JSON.h:139
#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

◆ captureEvent()

static _Bool captureEvent ( Control self,
const SDL_Event *  event 
)
static
See also
Control::captureEvent(Control *, const SDL_Event *)

Definition at line 76 of file Button.c.

76 {
77
78 if (event->type == SDL_MOUSEBUTTONDOWN) {
81 return true;
82 }
83
84 if (event->type == SDL_MOUSEBUTTONUP) {
85 self->state &= ~ControlStateHighlighted;
87 return true;
88 }
89
90 return super(Control, self, captureEvent, event);
91}
@ ControlStateHighlighted
Definition: Control.h:68
Sound * _clack
Definition: SoundStage.c:86
Sound * _click
Definition: SoundStage.c:85
OBJECTIVELYMVC_EXPORT void MVC_PlaySound(const Sound *sound)
Plays the specified Sound through the current SoundStage (if any).
Definition: SoundStage.c:141
Controls are Views which capture events and dispatch Actions.
Definition: Control.h:83
_Bool captureEvent(Control *self, const SDL_Event *event)
Captures a given event, potentially altering the state of this Control.
Definition: Button.c:76
unsigned int state
The bit mask of ControlState.
Definition: Control.h:110

◆ dealloc()

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

Definition at line 36 of file Button.c.

36 {
37
38 Button *this = (Button *) self;
39
40 release(this->image);
41 release(this->title);
42
43 super(Object, self, dealloc);
44}
static void dealloc(Object *self)
Definition: Button.c:36

◆ init()

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

Definition at line 67 of file Button.c.

67 {
68 return (View *) $((Button *) self, initWithFrame, NULL);
69}
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92

◆ initialize()

static void initialize ( Class *  clazz)
static
See also
Class::initialize(Class *)

Definition at line 149 of file Button.c.

149 {
150
151 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
152
153 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
154 ((ViewInterface *) clazz->interface)->init = init;
155
156 ((ControlInterface *) clazz->interface)->captureEvent = captureEvent;
157
158 ((ButtonInterface *) clazz->interface)->initWithFrame = initWithFrame;
159 ((ButtonInterface *) clazz->interface)->initWithImage = initWithImage;
160 ((ButtonInterface *) clazz->interface)->initWithTitle = initWithTitle;
161}
Button * initWithImage(Button *self, Image *image)
Initializes this Button with the sopecified Image.
Definition: Button.c:122
Button * initWithTitle(Button *self, const char *title)
Initializes this Button with the specified title.
Definition: Button.c:135
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.

◆ initWithFrame()

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

Definition at line 99 of file Button.c.

99 {
100
101 self = (Button *) super(Control, self, initWithFrame, frame);
102 if (self) {
103
104 self->image = $(alloc(ImageView), initWithFrame, frame);
105 assert(self->image);
106
107 $((View *) self, addSubview, (View *) self->image);
108
109 self->title = $(alloc(Text), initWithText, NULL, NULL);
110 assert(self->title);
111
112 $((View *) self, addSubview, (View *) self->title);
113 }
114
115 return self;
116}
ImageView * image
The image.
Definition: Button.h:58
ImageViews render an Image in the context of a View hierarchy.
Definition: ImageView.h:43
Label * initWithText(Label *self, const char *text, Font *font)
Initializes this Label with the given text and Font.
Definition: Label.c:96
Text rendered with TrueType fonts.
Definition: Text.h:41
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
Definition: PageView.c:35

◆ initWithImage()

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

Definition at line 122 of file Button.c.

122 {
123
124 self = $(self, initWithFrame, NULL);
125 if (self) {
126 $(self->image, setImage, image);
127 }
128 return self;
129}
void setImage(ImageView *self, Image *image)
Sets the Image for this ImageView.
Definition: ImageView.c:171

◆ initWithTitle()

static Button * initWithTitle ( Button self,
const char *  title 
)
static

Definition at line 135 of file Button.c.

135 {
136
137 self = $(self, initWithFrame, NULL);
138 if (self) {
139 $(self->title, setText, title);
140 }
141 return self;
142}
Text * title
The title.
Definition: Button.h:63
void setText(Text *self, const char *text)
Sets this Text's text.
Definition: Text.c:261