libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xpngloader.h
Go to the documentation of this file.
1 /*
2  * 0BSD
3  *
4  * BSD Zero Clause License
5  *
6  * Copyright (c) 2019 Hermann Meyer
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted.
10 
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  *
19  */
20 
21 #pragma once
22 
23 #ifndef XPNGLOADER_H_
24 #define XPNGLOADER_H_
25 
26 #include "xputty.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 
33 /**
34  define some MACROS to read png data from binary stream
35  png's been converted to object files with
36  ld -r -b binary name.png -o name.o
37 */
38 
39 #ifdef __APPLE__
40 
41 #ifdef __cplusplus
42 }
43 #endif
44 
45 #include <mach-o/getsect.h>
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #define EXTLD(NAME) \
52  extern const unsigned char _section$__DATA__ ## NAME [];
53 #define LDVAR(NAME) _section$__DATA__ ## NAME
54 #define LDLEN(NAME) (getsectbyname("__DATA", "__" #NAME)->size)
55 
56 #elif (defined __WIN32__) /* mingw */
57 
58 #define EXTLD(NAME) \
59  extern const unsigned char binary_ ## NAME ## _start[]; \
60  extern const unsigned char binary_ ## NAME ## _end[];
61 #define LDVAR(NAME) \
62  binary_ ## NAME ## _start
63 #define LDLEN(NAME) \
64  ((binary_ ## NAME ## _end) - (binary_ ## NAME ## _start))
65 
66 #else /* gnu/linux ld */
67 
68 #define EXTLD(NAME) \
69  extern const unsigned char _binary_ ## NAME ## _start[]; \
70  extern const unsigned char _binary_ ## NAME ## _end[];
71 #define LDVAR(NAME) \
72  _binary_ ## NAME ## _start
73 #define LDLEN(NAME) \
74  ((_binary_ ## NAME ## _end) - (_binary_ ## NAME ## _start))
75 #endif
76 
77 
78 /*---------------------------------------------------------------------
79 -----------------------------------------------------------------------
80  define needed structs
81 -----------------------------------------------------------------------
82 ----------------------------------------------------------------------*/
83 
84 /**
85  * @brief binary_stream - struct definition to read binary data
86  * into cairo surface
87  * @param *data - pointer to the binary image data
88  * @param position - pointer to the read position
89  */
90 
91 typedef struct {
92  const unsigned char * data;
93  long int position;
95 
96 #include "xresources.h"
97 
98 /**
99  * @brief cairo_image_surface_create_from_stream - read binary data
100  * into cairo surface from stream
101  * @param *name - pointer to the binary image data LDVAR(name)
102  * @return cairo_surface_t - the cairo_image_surface
103  */
104 
105 cairo_surface_t *cairo_image_surface_create_from_stream ( const unsigned char* name);
106 
107 /**
108  * @brief widget_get_png - read png into Widget_t xlib surface
109  * @param *w - pointer to the Widget_t which should use the png
110  * @param *name - pointer to the binary image data LDVAR(name)
111  * @return void
112  */
113 
114 void widget_get_png(Widget_t *w, const unsigned char* name);
115 
116 /**
117  * @brief widget_get_scaled_png - read scaled png into Widget_t xlib surface
118  * @param *w - pointer to the Widget_t which should use the png
119  * @param *name - pointer to the binary image data LDVAR(name)
120  * @return void
121  */
122 
123 
124 void widget_get_scaled_png(Widget_t *w, const unsigned char* name);
125 
126 /**
127  * @brief widget_get_surface_ptr - set pointer to a 2. Widget_t xlib surface
128  * @param *w - pointer to the Widget_t which should use the surface
129  * @param *wid - pointer to the Widget_t which hold the surface
130  * @return void
131  */
132 
134 
135 /**
136  * @brief surface_get_png - read png into Widget_t xlib surface
137  * @param *w - pointer to the Widget_t which should use the png
138  * @param *sf - pointer to the cairo_surface_t which should hold the png
139  * @param *name - pointer to the binary image data LDVAR(name)
140  * @return cairo_surface_t - the cairo_xlib_surface, you need to free it by yourself
141  */
142 
143 cairo_surface_t * surface_get_png(Widget_t *w, cairo_surface_t *sf, const unsigned char* name);
144 
145 /**
146  * @brief widget_set_icon_from_surface - set icon image from cairo surface for Widget_t
147  * those icon will be used in the Window decoration and the toolbar (depending on the Widnow manager)
148  * @param *w - pointer to the Widget_t which should use the icon
149  * @param *image - pointer to the cairo_surface_t to use for the icon
150  * @return void
151  */
152 
153 void widget_set_icon_from_surface(Widget_t *w, Pixmap *icon_, cairo_surface_t *image);
154 
155 /**
156  * @brief widget_set_icon_from_png - set icon image from png binary to Widget_t
157  * those icon will be used in the Window decoration and the toolbar (depending on the Widnow manager)
158  * @param *w - pointer to the Widget_t which should use the icon
159  * @param *name - pointer to the binary image data LDVAR(name)
160  * @return void
161  */
162 
163 void widget_set_icon_from_png(Widget_t *w, Pixmap *icon_, const unsigned char* name);
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif //XPNGLOADER_H_
widget_set_icon_from_surface
void widget_set_icon_from_surface(Widget_t *w, Pixmap *icon_, cairo_surface_t *image)
widget_set_icon_from_surface - set icon image from cairo surface for Widget_t those icon will be used...
Definition: xpngloader.c:98
binary_stream
binary_stream - struct definition to read binary data into cairo surface
Definition: xpngloader.h:91
xputty.h
widget_get_png
void widget_get_png(Widget_t *w, const unsigned char *name)
widget_get_png - read png into Widget_t xlib surface
Definition: xpngloader.c:41
binary_stream::data
const unsigned char * data
Definition: xpngloader.h:92
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
widget_get_scaled_png
void widget_get_scaled_png(Widget_t *w, const unsigned char *name)
widget_get_scaled_png - read scaled png into Widget_t xlib surface
Definition: xpngloader.c:57
widget_get_surface_ptr
void widget_get_surface_ptr(Widget_t *w, Widget_t *wid)
widget_get_surface_ptr - set pointer to a 2. Widget_t xlib surface
Definition: xpngloader.c:78
widget_set_icon_from_png
void widget_set_icon_from_png(Widget_t *w, Pixmap *icon_, const unsigned char *name)
widget_set_icon_from_png - set icon image from png binary to Widget_t those icon will be used in the ...
Definition: xpngloader.c:124
cairo_image_surface_create_from_stream
cairo_surface_t * cairo_image_surface_create_from_stream(const unsigned char *name)
cairo_image_surface_create_from_stream - read binary data into cairo surface from stream
Definition: xpngloader.c:34
binary_stream::position
long int position
Definition: xpngloader.h:93
surface_get_png
cairo_surface_t * surface_get_png(Widget_t *w, cairo_surface_t *sf, const unsigned char *name)
surface_get_png - read png into Widget_t xlib surface
Definition: xpngloader.c:83