summaryrefslogtreecommitdiff
path: root/src/pixmap.h
blob: c00f7b56f5a19914d2c91b3a348d86267c6cf9c3 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 * Copyright (C) 1999-1997, Michael Jennings
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies of the Software, its documentation and marketing & publicity
 * materials, and acknowledgment shall be given in the documentation, materials
 * and software packages that this Software was used.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef _PIXMAP_H
# define _PIXMAP_H

#include <X11/Xatom.h>
#include <Imlib.h>

/************ Macros and Definitions ************/
#ifdef PIXMAP_SUPPORT
# define background_is_image() ((buffer_pixmap) || (images[image_bg].current && images[image_bg].current->iml && images[image_bg].current->iml->im))
# define background_is_trans() (images[image_bg].mode & MODE_TRANS)
# define background_is_viewport() (images[image_bg].mode & MODE_VIEWPORT)
# define background_is_auto() (images[image_bg].mode & MODE_AUTO)
# define background_is_pixmap() (background_is_image() || background_is_trans() || background_is_viewport() || background_is_auto())
# define delete_simage(simg) do { \
                               Imlib_free_pixmap(imlib_id, (simg)->pmap->pixmap); \
                               Imlib_destroy_image(imlib_id, (simg)->iml->im); \
                               (simg)->pmap->pixmap = None; (simg)->iml->im = NULL; \
                             } while (0)
# define CONVERT_SHADE(s) (0xff - (((s) * 0xff) / 100))
# define CONVERT_TINT_RED(t)   (((t) & 0xff0000) >> 16)
# define CONVERT_TINT_GREEN(t) (((t) & 0x00ff00) >> 8)
# define CONVERT_TINT_BLUE(t)  ((t) & 0x0000ff)
#else
# define background_is_image()    NOP
# define background_is_trans()    NOP
# define background_is_viewport() NOP
# define background_is_auto()     NOP
# define delete_simage(simg)      NOP
#endif
#define PIXMAP_EXT NULL
/*   '[', 2*4 + 2*3 digits + 3 delimiters, ']'. -vendu */
#define GEOM_LEN 19

enum {
  image_bg,
  image_up,
  image_down,
  image_left,
  image_right,
  image_sb,
  image_sa,
  image_menu,
  image_submenu,
  image_max
};

/* Image manipulation operations */
#define OP_NONE		0x00
#define OP_TILE		0x01
#define OP_HSCALE	0x02
#define OP_VSCALE	0x04
#define OP_PROPSCALE	0x08
#define OP_SCALE	(OP_HSCALE | OP_VSCALE)

/* Image modes */
#define MODE_SOLID	0x00
#define MODE_IMAGE	0x01
#define MODE_TRANS	0x02
#define MODE_VIEWPORT	0x04
#define MODE_AUTO	0x08
#define MODE_MASK	0x0f
#define ALLOW_SOLID	0x00
#define ALLOW_IMAGE	0x10
#define ALLOW_TRANS	0x20
#define ALLOW_VIEWPORT	0x40
#define ALLOW_AUTO	0x80
#define ALLOW_MASK	0xf0

/* Image states */
#define IMAGE_STATE_CURRENT   (0)
#define IMAGE_STATE_NORMAL    (1)
#define IMAGE_STATE_SELECTED  (2)
#define IMAGE_STATE_CLICKED   (3)

/* Helper macros */
#define FOREACH_IMAGE(x)                  do {unsigned char idx; for (idx = 0; idx < image_max; idx++) { x } } while (0)
#define image_set_mode(which, bit)        do {images[which].mode &= ~(MODE_MASK); images[which].mode |= (bit);} while (0)
#define image_allow_mode(which, bit)      (images[which].mode |= (bit))
#define image_disallow_mode(which, bit)   (images[which].mode &= ~(bit))
#define image_mode_is(which, bit)         (images[which].mode & (bit))
#define image_mode_fallback(which)        do {if (image_mode_is((which), ALLOW_IMAGE)) {image_set_mode((which), MODE_IMAGE);} else {image_set_mode((which), MODE_SOLID);}} while (0)
#define redraw_all_images()               do {render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 0); \
                                              scr_touch(); scrollbar_draw(MODE_MASK); if (image_mode_any(MODE_AUTO)) enl_ipc_sync();} while (0)

/* Elements of an simage to be reset */
#define RESET_NONE		(0UL)
#define RESET_IMLIB_MOD		(1UL << 0)
#define RESET_IMLIB_RMOD	(1UL << 1)
#define RESET_IMLIB_GMOD	(1UL << 2)
#define RESET_IMLIB_BMOD	(1UL << 3)
#define RESET_ALL_TINT		(RESET_IMLIB_RMOD | RESET_IMLIB_GMOD | RESET_IMLIB_BMOD)
#define RESET_ALL_MOD		(RESET_IMLIB_MOD | RESET_IMLIB_RMOD | RESET_IMLIB_GMOD | RESET_IMLIB_BMOD)
#define RESET_IMLIB_BORDER	(1UL << 4)
#define RESET_IMLIB_IM		(1UL << 5)
#define RESET_ALL_IMLIB		(RESET_ALL_MOD | RESET_IMLIB_BORDER | RESET_IMLIB_IM)
#define RESET_PMAP_GEOM		(1UL << 6)
#define RESET_PMAP_PIXMAP	(1UL << 7)
#define RESET_PMAP_MASK		(1UL << 8)
#define RESET_ALL_PMAP		(RESET_PMAP_GEOM | RESET_PMAP_PIXMAP | RESET_PMAP_MASK)
#define RESET_ALL		(RESET_ALL_IMLIB | RESET_ALL_PMAP)

/************ Structures ************/
typedef struct {
  unsigned short op;
  short w, h, x, y;
  Pixmap pixmap;
  Pixmap mask;
} pixmap_t;
typedef struct {
  ImlibBorder *edges;
  unsigned char up;
} bevel_t;
typedef struct {
  ImlibImage *im;
  ImlibBorder *border, *pad;
  bevel_t *bevel;
  ImlibColorModifier *mod, *rmod, *gmod, *bmod;
  short last_w, last_h;
} imlib_t;
typedef struct {
  pixmap_t *pmap;
  imlib_t *iml;
} simage_t;
typedef struct {
  Window win;
  unsigned char mode;
  simage_t *norm, *selected, *clicked, *current;
} image_t;
typedef short renderop_t;

/************ Variables ************/
extern image_t images[image_max];
extern ImlibData *imlib_id;
extern Pixmap desktop_pixmap, viewport_pixmap, buffer_pixmap;
extern Window desktop_window;

/************ Function Prototypes ************/
_XFUNCPROTOBEGIN

extern const char *get_image_type(unsigned short);
extern unsigned char image_mode_any(unsigned char);
extern unsigned short parse_pixmap_ops(char *);
extern unsigned short set_pixmap_scale(const char *, pixmap_t *);
extern unsigned char check_image_ipc(unsigned char);
extern void reset_simage(simage_t *, unsigned long);
extern void paste_simage(simage_t *, unsigned char, Window, unsigned short, unsigned short, unsigned short, unsigned short);
extern void redraw_image(unsigned char);
extern void redraw_images_by_mode(unsigned char);
extern void render_simage(simage_t *, Window, unsigned short, unsigned short, unsigned char, renderop_t);
extern const char *search_path(const char *, const char *, const char *);
extern unsigned short load_image(const char *, short);
extern void free_desktop_pixmap(void);
#ifdef PIXMAP_OFFSET
extern unsigned char need_colormod(imlib_t *);
extern void colormod_trans(Pixmap, imlib_t *, GC, unsigned short, unsigned short);
extern Window get_desktop_window(void);
extern Pixmap get_desktop_pixmap(void);
#endif
extern void shaped_window_apply_mask(Drawable, Pixmap);
extern void set_icon_pixmap(char *, XWMHints *);
#ifdef USE_EFFECTS
extern int fade_in(ImlibImage *, int);
extern int fade_out(ImlibImage *, int);
#endif

_XFUNCPROTOEND

#endif /* _PIXMAP_H */