26#include <Objectively/String.h>
31#define _Class _WindowController
42 release(this->debugViewController);
43 release(this->renderer);
44 release(this->viewController);
49#pragma mark - WindowController
62 SDL_GetMouseState(&point.x, &point.y);
83 if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) {
84 point =
MakePoint(event->button.x, event->button.y);
85 }
else if (event->type == SDL_MOUSEMOTION) {
86 point =
MakePoint(event->motion.x, event->motion.y);
87 }
else if (event->type == SDL_MOUSEWHEEL) {
88 SDL_GetMouseState(&point.x, &point.y);
150 .name = event->user.code,
151 .sender = event->user.data1,
152 .data = event->user.data2
156 if (event->type == SDL_WINDOWEVENT) {
157 switch (event->window.event) {
158 case SDL_WINDOWEVENT_EXPOSED:
159 $(self,
setWindow, SDL_GL_GetCurrentWindow());
164 case SDL_WINDOWEVENT_CLOSE:
176 switch (event->type) {
177 case SDL_MOUSEMOTION:
181 MVC_LogMessage(SDL_LOG_PRIORITY_DEBUG,
"%d -> %s\n", event->type, desc->chars);
189 if (event->type == SDL_KEYUP) {
190 if (event->key.keysym.sym == SDLK_d) {
191 if (event->key.keysym.mod & KMOD_CTRL) {
245 release(self->
theme);
273 if (viewController) {
296 const Uint32 flags = SDL_GetWindowFlags(self->
window);
297 assert(flags & SDL_WINDOW_OPENGL);
299 SDL_SetWindowData(self->
window,
"windowController", self);
300 assert(SDL_GetWindowData(self->
window,
"windowController") == self);
349 return SDL_GetWindowData(window,
"windowController");
352#pragma mark - Class lifecycle
359 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
361 ((WindowControllerInterface *) clazz->interface)->debug =
debug;
362 ((WindowControllerInterface *) clazz->interface)->eventTarget =
eventTarget;
364 ((WindowControllerInterface *) clazz->interface)->initWithWindow =
initWithWindow;
365 ((WindowControllerInterface *) clazz->interface)->
render =
render;
366 ((WindowControllerInterface *) clazz->interface)->respondToEvent =
respondToEvent;
367 ((WindowControllerInterface *) clazz->interface)->setRenderer =
setRenderer;
368 ((WindowControllerInterface *) clazz->interface)->setSoundStage =
setSoundStage;
369 ((WindowControllerInterface *) clazz->interface)->setTheme =
setTheme;
370 ((WindowControllerInterface *) clazz->interface)->setViewController =
setViewController;
371 ((WindowControllerInterface *) clazz->interface)->setWindow =
setWindow;
372 ((WindowControllerInterface *) clazz->interface)->toggleDebugger =
toggleDebugger;
373 ((WindowControllerInterface *) clazz->interface)->windowController =
windowController;
385 clazz = _initialize(&(
const ClassDef) {
386 .name =
"WindowController",
387 .superclass = _Object(),
390 .interfaceSize =
sizeof(WindowControllerInterface),
static String * description(const Object *self)
View logging facilities via SDL_Log.
#define MVC_LogMessage(priority, fmt,...)
Uint32 MVC_NOTIFICATION_EVENT
#define MakePoint(x, y)
Creates an SDL_Point with the given coordinates.
static void dealloc(Object *self)
static void initialize(Class *clazz)
A WindowController manages a ViewController and its descendants within an SDL_Window.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
The DebugViewController type.
void debug(DebugViewController *self, const View *view, Renderer *renderer)
Debugs the given View.
ViewController viewController
The superclass.
void renderDeviceDidReset(Font *self)
This method should be invoked when the render context is invalidated.
The Renderer is responsible for rasterizing the View hierarchy of a WindowController.
void endFrame(Renderer *self)
void renderDeviceWillReset(Renderer *self)
This method is invoked when the render device will become reset.
void beginFrame(Renderer *self)
Sets up OpenGL state.
Theme * theme(SDL_Window *window)
A ViewController manages a View and its descendants.
View * view
The main view.
void loadView(ViewController *self)
Loads this ViewController's View.
void loadViewIfNeeded(ViewController *self)
Loads this ViewController's View if it is not already loaded.
void viewWillAppear(ViewController *self)
This method is invoked before this ViewController's View is added to the View hierarchy.
void viewDidDisappear(ViewController *self)
This method is invoked after this ViewController's View is removed to the View hierarchy.
void viewWillDisappear(ViewController *self)
This method is invoked before this ViewController's View is removed from the View hierarchy.
void handleNotification(ViewController *self, const Notification *notification)
Handles a broadcast notification.
void viewDidAppear(ViewController *self)
This method is invoked after this ViewController's View is added to the View hierarchy.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
void updateBindings(View *self)
Updates data bindings, prompting the appropriate layout changes.
void applyThemeIfNeeded(View *self, const Theme *theme)
Recursively applies the Theme to this View and its subviews.
void invalidateStyle(View *self)
Invalidates the computed Style for this View and its descendants.
View * hitTest(const View *self, const SDL_Point *point)
Performs a hit test against this View and its descendants for the given point.
View * firstResponder(SDL_Window *window)
void addClassName(View *self, const char *className)
Adds the given class name to this View.
void * draw(View *self, Renderer *renderer)
Draws this View.
void respondToEvent(View *self, const SDL_Event *event)
Responds to the specified event.
void layoutIfNeeded(View *self)
Recursively updates the layout of this View and its subviews.
void moveToWindow(View *self, SDL_Window *window)
Moves this View to the View hierarchy of the given window.
void render(View *self, Renderer *renderer)
Renders this View using the given renderer.
void removeClassName(View *self, const char *className)
Removes the given class name to this View.
A WindowController manages a ViewController and its descendants within an SDL_Window.
ViewController * viewController
The ViewController.
void toggleDebugger(WindowController *self)
Toggles the debugger tools.
void setWindow(WindowController *self, SDL_Window *window)
Sets this WindowController's window.
WindowController * windowController(SDL_Window *window)
void setRenderer(WindowController *self, Renderer *renderer)
Sets this WindowController's Renderer.
Class * _WindowController(void)
The WindowController archetype.
SDL_Window * window
The window.
WindowController * initWithWindow(WindowController *self, SDL_Window *window)
Initializes this WindowController with the given window.
Renderer * renderer
The Renderer.
View * eventTarget(const WindowController *self, const SDL_Event *event)
void setSoundStage(WindowController *self, SoundStage *soundStage)
Sets this WindowController's SoundStage.
DebugViewController * debugViewController
The DebugViewController.
void render(WindowController *self)
Renders the ViewController's View.
SoundStage * soundStage
The SoundStage.
void setViewController(WindowController *self, ViewController *viewController)
Sets this WindowController's ViewController.
void setTheme(WindowController *self, Theme *theme)
Sets this WindowController's Theme.