Added:
/trunk/include/fake437/display.hpp
/trunk/src/libfake437++/display.cpp
Modified:
/trunk/Makefile.am
/trunk/examples/display.c
/trunk/include/fake437/display.h
/trunk/include/fake437/surface.hpp
/trunk/include/fake437/types.h
/trunk/include/fake437.hpp
/trunk/src/libfake437/display.c
/trunk/src/libfake437++/surface.cpp
=======================================
--- /dev/null
+++ /trunk/include/fake437/display.hpp Fri Jan 1 19:06:33 2010
@@ -0,0 +1,74 @@
+/* libfake437 - a library for the rendering of code page 437 `graphics'
+ * Copyright (C) 2008, 2009, 2010 Jack Kelly <endga...@gmail.com>
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef FAKE437_DISPLAY_HPP
+#define FAKE437_DISPLAY_HPP
+
+namespace fake437 {
+ class DisplayLayer {
+ friend class Display;
+ public:
+ DisplayLayer(int left, int top, int width, int height);
+ /* Does not incrememnt the reference count, so implicit conversion
+ from the result of Display::get_layer etc. doesn't generate
+ spurious f437_display_layer_ref's. */
+ /* Only shares the reference. */
+ DisplayLayer(const DisplayLayer& other);
+ DisplayLayer(F437DisplayLayer* layer);
+ ~DisplayLayer(void);
+ /* Only shares the reference. */
+ DisplayLayer& operator =(const DisplayLayer& other);
+ F437DisplayCell& get_cell(int x, int y);
+ int get_left(void) const;
+ int get_top(void) const;
+ void set_left(int left);
+ void set_top(int top);
+ private:
+ F437DisplayLayer* layer;
+ };
+
+ class Display {
+ public:
+ Display(SDL_Surface* surface, const F437Font* font);
+ ~Display(void);
+
+ void insert_layer(F437DisplayLayer* layer, int n);
+ void insert_layer(DisplayLayer& layer, int n);
+ F437DisplayLayer* get_layer(int n);
+ void remove_layer(int n);
+
+ void swap_layers(int n, int m);
+
+ void push_layer(F437DisplayLayer* layer);
+ void push_layer(DisplayLayer& layer);
+ F437DisplayLayer* peek_layer(void);
+ void pop_layer(void);
+
+ void draw(void);
+
+ SDL_Surface* get_surface(void);
+ int get_width(void) const;
+ int get_height(void) const;
+ private:
+ F437Display *display;
+ /* Disallow copy and assign. */
+ Display(const Display&);
+ void operator =(const Display&);
+ };
+}
+
+#endif
=======================================
--- /dev/null
+++ /trunk/src/libfake437++/display.cpp Fri Jan 1 19:06:33 2010
@@ -0,0 +1,125 @@
+/* libfake437 - a library for the rendering of code page 437 `graphics'
+ * Copyright (C) 2008, 2009, 2010 Jack Kelly <endga...@gmail.com>
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <assert.h>
+#include <SDL.h>
+#include "fake437.h"
+#include "fake437/display.hpp"
+
+namespace fake437 {
+ DisplayLayer::DisplayLayer(int left, int top, int width, int height):
+ layer(f437_display_layer_new(left, top, width, height)) {}
+
+ DisplayLayer::DisplayLayer(const DisplayLayer& other):
+ layer(f437_display_layer_ref(other.layer)) {}
+
+ DisplayLayer::DisplayLayer(F437DisplayLayer* layer):
+ layer(layer) {}
+
+ DisplayLayer::~DisplayLayer(void) {
+ f437_display_layer_unref(layer);
+ }
+
+ DisplayLayer& DisplayLayer::operator =(const DisplayLayer& other) {
+ if (&other == this) return *this;
+ f437_display_layer_unref(this->layer);
+ this->layer = f437_display_layer_ref(other.layer);
+ return *this;
+ }
+
+ F437DisplayCell& DisplayLayer::get_cell(int x, int y) {
+ assert(x >= 0 && x < this->layer->width);
+ assert(y >= 0 && y < this->layer->height);
+ return this->layer->cells[y * this->layer->height + x];
+ }
+
+ int DisplayLayer::get_left(void) const {
+ return this->layer->left;
+ }
+
+ int DisplayLayer::get_top(void) const {
+ return this->layer->top;
+ }
+
+ void DisplayLayer::set_left(int left) {
+ this->layer->left = left;
+ }
+
+ void DisplayLayer::set_top(int top) {
+ this->layer->top = top;
+ }
+
+ Display::Display(SDL_Surface* surface, const F437Font* font):
+ display(f437_display_new(surface, font)) {}
+
+ Display::~Display(void) {
+ f437_display_free(this->display);
+ }
+
+ void Display::insert_layer(F437DisplayLayer* layer, int n) {
+ f437_display_insert_layer(this->display, layer, n);
+ }
+
+ void Display::insert_layer(DisplayLayer& layer, int n) {
+ this->insert_layer(layer.layer, n);
+ }
+
+ F437DisplayLayer* Display::get_layer(int n) {
+ return f437_display_get_layer(this->display, n);
+ }
+
+ void Display::remove_layer(int n) {
+ f437_display_remove_layer(this->display, n);
+ }
+
+ void Display::swap_layers(int n, int m) {
+ f437_display_swap_layers(this->display, n, m);
+ }
+
+ void Display::push_layer(F437DisplayLayer* layer) {
+ f437_display_push_layer(this->display, layer);
+ }
+
+ void Display::push_layer(DisplayLayer& layer) {
+ this->push_layer(layer.layer);
+ }
+
+ F437DisplayLayer* Display::peek_layer(void) {
+ return f437_display_peek_layer(this->display);
+ }
+
+ void Display::pop_layer(void) {
+ f437_display_pop_layer(this->display);
+ }
+
+ void Display::draw(void) {
+ f437_display_draw(this->display);
+ }
+
+ int Display::get_width(void) const {
+ return this->display->surface->width;
+ }
+
+ int Display::get_height(void) const {
+ return this->display->surface->height;
+ }
+
+ SDL_Surface* Display::get_surface(void) {
+ return this->display->surface->surface;
+ }
+}
=======================================
--- /trunk/Makefile.am Mon Dec 28 16:23:21 2009
+++ /trunk/Makefile.am Fri Jan 1 19:06:33 2010
@@ -19,6 +19,7 @@
fake437dir = $(includedir)/fake437
fake437_HEADERS = \
include/fake437/display.h \
+ include/fake437/display.hpp \
include/fake437/primitive.h \
include/fake437/surface.h \
include/fake437/surface.hpp \
@@ -37,7 +38,9 @@
libfake437_la_LDFLAGS = $(SDL_L_FLAGS) -no-undefined -version-info 6:0:0
libfake437_la_LIBADD = -lSDL
-libfake437___la_SOURCES = src/libfake437++/surface.cpp
+libfake437___la_SOURCES = \
+ src/libfake437++/display.cpp \
+ src/libfake437++/surface.cpp
libfake437___la_LDFLAGS = $(SDL_L_FLAGS) -no-undefined -version-info 2:0:0
libfake437___la_LIBADD = libfake437.la
=======================================
--- /trunk/examples/display.c Fri Jan 1 19:05:03 2010
+++ /trunk/examples/display.c Fri Jan 1 19:06:33 2010
@@ -63,8 +63,7 @@
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
SDL_DEFAULT_REPEAT_INTERVAL);
- display = f437_display_new(f437_surface_new
- (screen, f437_get_font(F437_FONT_8x8_THIN)));
+ display = f437_display_new(screen, f437_get_font(F437_FONT_8x8_THIN));
layer = f437_display_layer_new(0, 0, 1024 / 8, 768 / 8);
for (i = 0 ; i < (1024 * 768) / 64 ; i++) {
layer->cells[i].ch = i % 256;
=======================================
--- /trunk/include/fake437/display.h Fri Jan 1 19:05:51 2010
+++ /trunk/include/fake437/display.h Fri Jan 1 19:06:33 2010
@@ -74,23 +74,27 @@
/**
** @deftypefun F437Display* f437_display_new @
- ** (F437Surface* @var{surface})
+ ** (SDL_Surface* @var{surface}, @
+ ** const F437Font* @var{font})
**
** @deftypefunx F437Display* f437_display_try_new @
- ** (F437Surface* @var{surface})
+ ** (SDL_Surface* @var{surface}, @
+ ** const F437Font* @var{font})
**
- ** @deftypefunx F437Surface* f437_display_free @
+ ** @deftypefunx SDL_Surface* f437_display_free @
** (F437Display* @var{display})
**
- ** Create and destroy @code{F437Display}s. The @code{F437Surface*}
+ ** Create and destroy @code{F437Display}s. The @code{SDL_Surface*}
** passed to @code{f437_display_new} will not be owned by the
** display. It will be returned by @code{f437_display_free}.
**
** @end deftypefun
**/
-F437Display* f437_display_new(F437Surface* surface);
-F437Display* f437_display_try_new(F437Surface* surface);
-F437Surface* f437_display_free(F437Display* display);
+F437Display* f437_display_new(SDL_Surface* surface,
+ const F437Font* font);
+F437Display* f437_display_try_new(SDL_Surface* surface,
+ const F437Font* font);
+SDL_Surface* f437_display_free(F437Display* display);
/**
** @deftypefun void f437_display_insert_layer @
=======================================
--- /trunk/include/fake437/surface.hpp Fri Jan 1 19:05:51 2010
+++ /trunk/include/fake437/surface.hpp Fri Jan 1 19:06:33 2010
@@ -40,6 +40,10 @@
const SDL_Color& fg, const SDL_Color& bg);
void put_string(int left, int top, const std::string& string,
F437Color fg, F437Color bg);
+
+ SDL_Surface* get_surface(void);
+ int get_width(void) const;
+ int get_height(void) const;
private:
F437Surface* surface;
/* Disallow copy and assign. */
=======================================
--- /trunk/include/fake437/types.h Fri Jan 1 19:05:51 2010
+++ /trunk/include/fake437/types.h Fri Jan 1 19:06:33 2010
@@ -226,7 +226,10 @@
** as a whole is drawn at a left and top offset relative to the
** top-left corner of the enclosing @code{F437Display}. @var{cells}
** is a @var{width}*@var{height} array of @code{F437DisplayCell}
- ** which is populated with graphical data.
+ ** which is populated with graphical data. Accessing @code{left},
+ ** @code{top} and the contents of @code{cells} is necessary and
+ ** expected, but don't manually change @code{refcount}, @code{width}
+ ** or @code{height}.
**
** @deftypeivar F437DisplayLayer int refcount
** @end deftypeivar
@@ -278,7 +281,7 @@
** @end deftp
**/
typedef struct {
- F437Surface* surface; /* not owned */
+ F437Surface* surface; /* owned */
int size; /* number of layers */
int allocated_size; /* number of layers that can fit before reallocation
*/
F437DisplayLayer** layers; /* owned */
=======================================
--- /trunk/include/fake437.hpp Fri Jan 1 19:05:51 2010
+++ /trunk/include/fake437.hpp Fri Jan 1 19:06:33 2010
@@ -22,5 +22,6 @@
#include <fake437.h>
#include <fake437/surface.hpp>
+#include <fake437/display.hpp>
#endif
=======================================
--- /trunk/src/libfake437/display.c Fri Jan 1 19:05:51 2010
+++ /trunk/src/libfake437/display.c Fri Jan 1 19:06:33 2010
@@ -72,19 +72,21 @@
}
}
-F437Display* f437_display_new(F437Surface* surface) {
- F437Display* result = f437_display_try_new(surface);
+F437Display* f437_display_new(SDL_Surface* surface,
+ const F437Font* font) {
+ F437Display* result = f437_display_try_new(surface, font);
if (result == NULL) abort();
return result;
}
-F437Display* f437_display_try_new(F437Surface* surface) {
+F437Display* f437_display_try_new(SDL_Surface* surface,
+ const F437Font* font) {
F437Display* result;
int i;
assert(surface != NULL);
result = malloc(sizeof(*result));
if (result == NULL) return NULL;
- result->surface = surface;
+ result->surface = f437_surface_new(surface, font);
result->size = 0;
result->allocated_size = INITIAL_SIZE;
result->layers = malloc(sizeof(*result->layers) * INITIAL_SIZE);
@@ -96,11 +98,11 @@
return result;
}
-F437Surface* f437_display_free(F437Display* display) {
- F437Surface* result;
+SDL_Surface* f437_display_free(F437Display* display) {
+ SDL_Surface* result;
int i;
assert(display != NULL);
- result = display->surface;
+ result = f437_surface_free(display->surface);
for (i = 0 ; i < display->size ; i++) {
f437_display_layer_unref(display->layers[i]);
}
=======================================
--- /trunk/src/libfake437++/surface.cpp Fri Jan 1 19:06:06 2010
+++ /trunk/src/libfake437++/surface.cpp Fri Jan 1 19:06:33 2010
@@ -73,4 +73,16 @@
f437_surface_put_string(this->surface, left, top, string.c_str(),
f437_get_color(fg), f437_get_color(bg));
}
-}
+
+ SDL_Surface* Surface::get_surface(void) {
+ return this->surface->surface;
+ }
+
+ int Surface::get_width(void) const {
+ return this->surface->width;
+ }
+
+ int Surface::get_height(void) const {
+ return this->surface->height;
+ }
+}