ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
ObjectivelyMVC Documentation

Cross-platform object oriented MVC framework for OpenGL, SDL2 and GNU C

ObjectivelyMVC is a cross-platform user interface and interaction framework for SDL2 inspired by Apple's AppKit. It is geared towards building high-quality, modern looking user interfaces within OpenGL video games that are already using SDL2. It is built on Objectively, written in GNU C, and requires gcc or clang.

Features

Cross platform

Wait, gcc or clang? Is this a Linux-only framework? Not at all. ObjectivelyMVC supports Windows XP and later, Apple OS X, and Linux. Support for other Unix derivatives is likely there, but untested. To build ObjectivelyMVC for Windows, you can use either MinGW-w64 (cross-compile or native), or recent Visual Studio 15, which includes Clang.

Object-oriented Model-View-Controller implementation in C

ObjectivelyMVC is built on Objectively, an ultra-lightweight Object-oriented framework for GNU C. ObjectivelyMVC delivers the elegance of OO / MVC without imposing C++ on your project. If you're' using C++ or Objective-C, ObjectivelyMVC is perfectly happy alongside those, too.

A WindowController manages a ViewController and its descendants within an SDL_Window.
WindowController * windowController(SDL_Window *window)
WindowController * initWithWindow(WindowController *self, SDL_Window *window)
Initializes this WindowController with the given window.

Easily embeddable in any SDL2 / OpenGL application

ObjectivelyMVC is purpose-built for video games. Unlike Gtk+, Qt, wxWidgets, FLTK, ..ObjectivelyMVC does not hijack the main loop. ObjectivelyMVC does not create a window, manage an OpenGL context, or originate events. Your game already does that, because it has to. Like your mother, ObjectivelyMVC only asks that you give it a call once in a while. That's it.

...
void respondToEvent(View *self, const SDL_Event *event)
Responds to the specified event.
Definition: Control.c:213
void render(View *self, Renderer *renderer)
Renders this View using the given renderer.
Definition: Control.c:131

Beautiful 4K-ready fonts

ObjectivelyMVC uses SDL_ttf to render TrueType fonts. It also automatically detects High-DPI (Retina, 4K) displays, and scales fonts accordingly. The result is crisp, beautiful vector-based fonts that look native, because they are.

Data *data = $$(Data, dataWithContentsOfFile, "Verdana.ttf");
...
$$(Font, cacheFont, data, "Verdana");
...
Font *verdana = $$(Font, cachedFont, "Verdana", 24, FontStyleRegular); // will render at 48pt on Retina displays
@ FontStyleRegular
Definition: Font.h:47
TrueType fonts.
Definition: Font.h:63
void(* cacheFont)(Data *data, const char *family)
Caches the specified font Data.
Definition: Font.h:136
Font * cachedFont(const char *family, int size, int style)
Resolves the cached Font with the given attributes.
Definition: Font.c:124

Full suite of Views and Controls

ObjectivelyMVC provides a robust set of containers, views and controls. Stack and arrange components with Box, Panel and StackView. Add Buttons, Checkboxes, Selects, Sliders, editable TextViews and more by simply instantiating them. Display tabular data or a thumbnail gallery with TableView and CollectionView. Split complex interfaces into multiple tabs with TabView and TabViewController. Bind Actions to SDL_Event types, or use the specialized delegate callbacks for convenience.

$(button, addActionForEventType, SDL_MOUSEBUTTONUP, my_callback, my_sender, my_data);
void addActionForEventType(Control *self, SDL_EventType eventType, ActionFunction function, ident sender, ident data)
Adds an Action for the given event type to this Control.
Definition: Control.c:264
Select *select = $(alloc(Select), initWithFrame, NULL);
...
select->delegate.didSelectOption = my_callback;
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92
A Control allowing users to select one or more Options.
Definition: Select.h:63
Array * select(const Selector *self, View *view)

Programmatic or JSON-based layout options

ObjectivelyMVC allows you to define your View hierarchy programmatically, via JSON, or using any combination of both. Programmatic layout gives you explicit control over the big picture, while JSON layout allows you to reduce boilerplate and avoid common pitfalls like memory leaks.

{
"class": "Panel",
"style": {
"top": 50,
"left": 50
},
"contentView": {
"subviews": [{
"class": "Input",
"control": {
"class": "Checkbox",
"identifier": "checkbox"
},
"label": {
"text": "This is a checkbox:"
}
}]
}
}

Examples

HelloViewController

An example application that creates a Window, enters its main loop and draws a scene before rendering a simple menu:

Hello

Quetoo

Quetoo is an open source FPS based on idTech2. Quetoo uses ObjectivelyMVC for its in-game user interface:

Quetoo Quetoo Quetoo

Installation

See INSTALL.md for installation and linking instructions.

API documentation

Browse the Class hierarchy to grok the API.