1 /*
2     XorGramana Copyright 2009 James W. Morris, james@jwm-art.net
3 
4     This file is part of XorGramana.
5 
6     XorGramana is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10 
11     XorGramana is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with XorGramana.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef _GFX_H
20 #define _GFX_H
21 
22 #include <SDL.h>
23 #include "defs.h"
24 #include "types.h"
25 #include "icons.h"
26 
27 /* Please don't make this any smaller */
28 #define GFX_MIN_WIDTH   800
29 #define GFX_MIN_HEIGHT  600
30 
31 struct gfx_mode
32 {
33     SDL_Rect **modes;
34     int mode;
35     SDL_Rect* m;
36     int def;
37     int last;
38 };
39 
40 /*  this window implimentation is very simple, and no clipping      *
41  *  takes place. all windows write to the main SDL_Surface (screen) *
42  *  and they are only used for positioning text (albeit text        *
43  *  represented by the very same icons). most of the code has been  *
44  *  written for the textual layout of the level menu etc, and       *
45  *  to provide various information during game play. the game code  *
46  *  won't use the text abstraction (but will make use of window     *
47  *  coordinates for positioning, etc.)                              */
48 
49 enum NEW_WIN_FLAGS
50 {
51     GFX_DEF=        0x00,   /*  default, use exact coords passed    */
52     GFX_CENTER_X=   0x01,   /*  horizontally center window          */
53     GFX_CENTER_Y=   0x02,   /*  vertically center window            */
54     GFX_ALIGN_R=    0x04,   /*  align window right                  */
55     GFX_ALIGN_B=    0x08,   /*  align window bottom                 */
56     GFX_BLK_ALIGN_X=0x10,   /*  any of above, snap to horiz blocks  */
57     GFX_BLK_ALIGN_Y=0x20    /*  any of above, snap to vert blocks   */
58 };
59 
60 /*  note: the block align enumerations will mess up centering when  *
61  *  the size of the window is only marginally smaller than the      *
62  *  screen.                                                         */
63 
64 struct gfx_win
65 {
66     /*  window coords (pixels)              */
67     int win_tlx;
68     int win_tly;
69     int win_brx;
70     int win_bry;
71     int win_w;
72     int win_h;
73     /*  window cursor pos                   */
74     int win_cx;
75     int win_cy;
76     /*  block/icon dimensions               */
77     int icon_width;
78     int icon_height;
79     /*  block/icon display system pixel     *
80      *  coords within window                */
81     int blk_tlx;
82     int blk_tly;
83     int blk_brx;
84     int blk_bry;
85     /*  block cursor pos                    */
86     su_t blk_cx;
87     su_t blk_cy;
88     su_t blk_count_x;
89     su_t blk_count_y;
90     bool half_size;
91     SDL_Surface** icons;
92 };
93 
94 extern SDL_Surface *screen;
95 extern struct gfx_mode kermode;
96 extern struct gfx_win* scr_win;  /* default window (border)*/
97 extern struct gfx_win* main_win; /* main window (within border)*/
98 extern struct gfx_win* cur_win;
99 
100 void gfx_start();
101 void gfx_end();
102 
103 void scr_win_border();
104 
105 void gfx_inc_mode();
106 void gfx_dec_mode();
107 
108 /*--------------------------------------------------*
109  *  these functions ignore window structures        */
110 
111 void overlay_image(SDL_Surface* image, SDL_Surface *overlay, int x, int y);
112 
113 void draw_image(SDL_Surface *image, int x, int y);
114 
115 /*  lifted from SDL manual, used by icon scaling    */
116 Uint32 getpixel(SDL_Surface *surface, int x, int y);
117 void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
118 
119 /*--------------------------------------------------*
120  *  window related functions follow:                */
121 
122 /*  note: dimensions of image used as block size, but in    *
123  *  xorgramana these are same dimensions (or half ;-)       */
124 void gfx_win_draw_image(SDL_Surface *image, int blk_x, int blk_y);
125 
126 struct gfx_win*
127 gfx_new_win(int flags,
128             int tlx, int tly,int brx, int bry,
129             int blk_width,int blk_height);
130 
131 /*  set window to operate on                        */
132 void gfx_set_win(struct gfx_win* win);
133 
134 /*  change icon sizes to display for current window */
135 void gfx_win_half_size();
136 void gfx_win_full_size();
137 
138 /*  move the cursor to location block x,y           */
139 su_t gfx_mv_cur(su_t blk_x, su_t blk_y);
140 
141 /*  guess   */
142 int gfx_printf(const char* format, ...);
143 
144 void delay(unsigned int flimit);
145 
146 void gfx_message(const char* format, ...);
147 void gfx_box(int tlx,int tly,int brx,int bry,bool solid);
148 #endif
149