summaryrefslogtreecommitdiff
path: root/layer.h
blob: cfdb853a95380a99008b762a99308cab300a7715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
Copyright (c) 2003 Bruno T. C. de Oliveira

LICENSE INFORMATION:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This program 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 General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
Copyright (c) 2002 Bruno T. C. de Oliveira

INFORMA��ES DE LICEN�A:
Este programa � um software de livre distribui��o; voc� pode
redistribu�-lo e/ou modific�-lo sob os termos da GNU General
Public License, conforme publicado pela Free Software Foundation,
pela vers�o 2 da licen�a ou qualquer vers�o posterior.

Este programa � distribu�do na esperan�a de que ele ser� �til
aos seus usu�rios, por�m, SEM QUAISQUER GARANTIAS; sem sequer
a garantia impl�cita de COMERCIABILIDADE ou DE ADEQUA��O A
QUALQUER FINALIDADE ESPEC�FICA. Consulte a GNU General Public
License para obter mais detalhes (uma c�pia acompanha este
programa, armazenada no arquivo COPYING).
*/


#ifndef _btco_aewan_layer_h
#define _btco_aewan_layer_h

#include <stdbool.h>
#include "bores/bores.h"
#include <stdio.h>
#include "aeff.h"

struct _Cell {
   unsigned char ch;   /* character that occupies this cell.
                        * Since a control character may never be in a cell,
                        * aewan uses some characters in the 0-31 range to
                        * represent vt100 line graphics characters and
                        * other special characters. See the chtr.h
                        * file for more details.  */

   unsigned char attr; /* attribute of the character */
};
typedef struct _Cell Cell;

struct _Layer {
   char *name;           /* name of this layer */
   int width, height;    /* width and height of layer, in cells */
   Cell **cells;         /* indexed cells[0][0] to cells[width-1][height-1] */
   bool visible;        /* whether visibility for this layer is enabled */
   bool transp;         /* whether this layer has transparency enabled.
                          * Upon blit and paint operations, transparent
                          * cells will not be drawn. */
};
typedef struct _Layer Layer;

/* A blank cell. */
extern const Cell BLANK_CELL;

/* Creates a new, empty layer with the specified dimensions.
 * Sets the layer name to <layer_name>. Returns a pointer to the newly
 * created layer. */
Layer *layer_create(const char *layer_name, int width, int height);

/* Creates a new layer that is an exact copy of the given layer,
 * except possibly for the name. Returns a pointer to the newly created 
 * layer */
Layer *layer_dup(const char *layer_name, Layer *model);

/* Destroys a layer previously created with layer_create */
void layer_destroy(Layer *layer);

/* Copies part of or the totality of the contents of the source layer onto 
 * the destination layer. The source rectangle for the copy is given
 * by xsrc, ysrc, width and height; the destination rectangle is given
 * by xdst, ydst, width and height. */
void layer_blit(Layer *src, int xsrc, int ysrc, int width, int height,
                Layer *dst, int xdst, int ydst);

/* Paints the given layer on the screen, placing its top-left corner
 * at the given coordinates x0, y0, which may be negative. The clipping
 * rectangle is given by xclip, yclip, wclip and hclip. 
 *
 * Painting code allows custom modification of output through
 * a call to the modify function. If <modify> is not NULL, it
 * will be called for every cell drawn, and it can modify the
 * color.
 * 
 * Please note that this function pays no attention to the layer's
 * 'visible' flag: it draws it regardless. It DOES pay attention
 * to the 'transparent' flag. 
 */
void layer_paint(Layer *layer, int x0, int y0, int xclip, int yclip,
                               int wclip, int hclip,
                        void (*modify)(int x, int y, int *ch, int *attr));

/* Same as layer_paint, but forces opaque rendering, that is, transparent
 * cells will be rendered as white-foreground, black-background spaces. */
void layer_paint_opaque(Layer *layer, int x0, int y0, int xclip, int yclip,
                               int wclip, int hclip,
                        void (*modify)(int x, int y, int *ch, int *attr));

/* Returns whether the given (x, y) coordinates are valid within
 * layer lyr, that is, returns true if and only if 0 <= x <= lyr->width
 * and 0 <= y <= lyr->height */
bool layer_valid_cell(Layer *layer, int x, int y);

/* Performs a vertical mirroring operation on the given layer.
 * The <flipchars> parameter indicates whether characters themselves
 * should be "flipped" to their mirrored counterparts (e.g.
 * change '>' to '<', etc). */
void layer_flip_x(Layer *layer, bool flipchars);

/* Performs a horizontal mirroring operation on the given layer.
 * The <flipchars> parameter indicates whether characters themselves
 * should be "flipped" to their mirrored counterpars (e.g.
 * change '\' to '/' */
void layer_flip_y(Layer *layer, bool flipchars);

/* Writes layer's data to file f */
void layer_save(Layer *lyr, AeFile *f);

/* Attempts to load layer from file f; if loading succeeds, returns
 * a pointer to a dynamically allocated layer that corresponds
 * to the loaded data; if an error occurs, returns NULL. */
Layer *layer_load(AeFile *f);

/* Loads a layer in the OLD binary format */
Layer *layer_load_OLD(FILE *f);

/* Returns whether the given cell is considered transparent or not */
bool is_cell_transp(const Cell* c);

#endif