Changeset 2055
- Timestamp:
- 11/25/07 15:11:58 (5 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 16 edited
-
caca/caca.c (modified) (8 diffs)
-
caca/caca_internals.h (modified) (1 diff)
-
caca/driver_cocoa.m (modified) (1 diff)
-
caca/driver_conio.c (modified) (1 diff)
-
caca/driver_gl.c (modified) (1 diff)
-
caca/driver_ncurses.c (modified) (1 diff)
-
caca/driver_raw.c (modified) (1 diff)
-
caca/driver_slang.c (modified) (1 diff)
-
caca/driver_vga.c (modified) (1 diff)
-
caca/driver_win32.c (modified) (1 diff)
-
caca/driver_x11.c (modified) (1 diff)
-
caca/graphics.c (modified) (1 diff)
-
cucul/cucul.c (modified) (11 diffs)
-
cucul/cucul.h (modified) (1 diff)
-
cucul/cucul_internals.h (modified) (2 diffs)
-
msvc/libcucul.def (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/caca.c
r1462 r2055 43 43 #endif 44 44 45 static int caca_can_resize(caca_display_t *); 45 46 static int caca_select_driver(caca_display_t *); 46 47 #if defined(USE_PLUGINS) … … 62 63 * \return The caca graphical context or NULL if an error occurred. 63 64 */ 64 caca_display_t * caca_create_display(cucul_canvas_t * cv)65 caca_display_t * caca_create_display(cucul_canvas_t *cv) 65 66 { 66 67 caca_display_t *dp = malloc(sizeof(caca_display_t)); … … 69 70 { 70 71 seterrno(ENOMEM); 72 return NULL; 73 } 74 75 if(cucul_manage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp)) 76 { 77 free(dp); 78 seterrno(EBUSY); 71 79 return NULL; 72 80 } … … 83 91 dlclose(dp->plugin); 84 92 #endif 93 cucul_unmanage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp); 85 94 free(dp); 86 95 seterrno(ENODEV); … … 94 103 dlclose(dp->plugin); 95 104 #endif 105 cucul_unmanage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp); 96 106 free(dp); 97 107 seterrno(ENODEV); 98 108 return NULL; 99 109 } 100 101 /* Attached! */102 dp->cv->refcount++;103 110 104 111 /* Graphics stuff */ … … 128 135 /* Resize events */ 129 136 dp->resize.resized = 0; 137 dp->resize.allow = 0; 130 138 131 139 return dp; … … 150 158 dlclose(dp->plugin); 151 159 #endif 152 dp->cv->refcount--;160 cucul_unmanage_canvas(dp->cv, (int (*)(void *))caca_can_resize, (void *)dp); 153 161 free(dp); 154 162 … … 159 167 * XXX: The following functions are local. 160 168 */ 169 170 static int caca_can_resize(caca_display_t *dp) 171 { 172 return dp->resize.allow; 173 } 161 174 162 175 static int caca_select_driver(caca_display_t *dp) -
libcaca/trunk/caca/caca_internals.h
r2049 r2055 142 142 { 143 143 int resized; /* A resize event was requested */ 144 int allow; /* The display driver allows resizing */ 144 145 unsigned w, h; /* Requested width and height */ 145 146 } resize; -
libcaca/trunk/caca/driver_cocoa.m
r2040 r2055 835 835 836 836 unsigned int width = dp->cv->width, height = dp->cv->height; 837 __cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); 837 dp->resize.allow = 1; 838 cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); 839 dp->resize.allow = 0; 838 840 839 841 // first create a full cocoa app if the host has no bundle -
libcaca/trunk/caca/driver_conio.c
r2049 r2055 59 59 /* FIXME */ 60 60 # endif 61 __cucul_set_canvas_size(dp->cv, dp->drv.p->ti.screenwidth, 62 dp->drv.p->ti.screenheight); 61 dp->resize.allow = 1; 62 cucul_set_canvas_size(dp->cv, dp->drv.p->ti.screenwidth, 63 dp->drv.p->ti.screenheight); 64 dp->resize.allow = 0; 65 63 66 return 0; 64 67 } -
libcaca/trunk/caca/driver_gl.c
r2049 r2055 103 103 #endif 104 104 105 __cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); 105 dp->resize.allow = 1; 106 cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); 107 dp->resize.allow = 0; 106 108 107 109 /* Load a libcucul internal font */ -
libcaca/trunk/caca/driver_ncurses.c
r2049 r2055 302 302 } 303 303 304 __cucul_set_canvas_size(dp->cv, COLS, LINES); 304 dp->resize.allow = 1; 305 cucul_set_canvas_size(dp->cv, COLS, LINES); 306 dp->resize.allow = 0; 305 307 306 308 return 0; -
libcaca/trunk/caca/driver_raw.c
r2049 r2055 41 41 #endif 42 42 43 __cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24); 43 dp->resize.allow = 1; 44 cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24); 45 dp->resize.allow = 0; 44 46 45 47 return 0; -
libcaca/trunk/caca/driver_slang.c
r2049 r2055 171 171 #endif 172 172 173 __cucul_set_canvas_size(dp->cv, SLtt_Screen_Cols, SLtt_Screen_Rows); 173 dp->resize.allow = 1; 174 cucul_set_canvas_size(dp->cv, SLtt_Screen_Cols, SLtt_Screen_Rows); 175 dp->resize.allow = 0; 174 176 175 177 return 0; -
libcaca/trunk/caca/driver_vga.c
r2049 r2055 77 77 78 78 /* We don't have much choice */ 79 __cucul_set_canvas_size(dp->cv, 80, 25); 79 dp->resize.allow = 1; 80 cucul_set_canvas_size(dp->cv, 80, 25); 81 dp->resize.allow = 0; 80 82 81 83 return 0; -
libcaca/trunk/caca/driver_win32.c
r2049 r2055 127 127 return -1; 128 128 129 __cucul_set_canvas_size(dp->cv, 130 csbi.srWindow.Right - csbi.srWindow.Left + 1, 131 csbi.srWindow.Bottom - csbi.srWindow.Top + 1); 129 dp->resize.allow = 1; 130 cucul_set_canvas_size(dp->cv, 131 csbi.srWindow.Right - csbi.srWindow.Left + 1, 132 csbi.srWindow.Bottom - csbi.srWindow.Top + 1); 133 dp->resize.allow = 0; 132 134 133 135 SetConsoleMode(dp->drv.p->screen, 0); -
libcaca/trunk/caca/driver_x11.c
r2049 r2055 89 89 #endif 90 90 91 __cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); 91 dp->resize.allow = 1; 92 cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 32); 93 dp->resize.allow = 0; 92 94 93 95 dp->drv.p->dpy = XOpenDisplay(NULL); -
libcaca/trunk/caca/graphics.c
r2043 r2055 239 239 /* Tell libcucul we changed size */ 240 240 if(dp->resize.w != dp->cv->width || dp->resize.h != dp->cv->height) 241 __cucul_set_canvas_size(dp->cv, dp->resize.w, dp->resize.h); 241 { 242 dp->resize.allow = 1; 243 cucul_set_canvas_size(dp->cv, dp->resize.w, dp->resize.h); 244 dp->resize.allow = 0; 245 } 242 246 } 243 247 -
libcaca/trunk/cucul/cucul.c
r2043 r2055 35 35 #include "cucul_internals.h" 36 36 37 static int cucul_resize(cucul_canvas_t *, unsigned int, unsigned int); 38 37 39 /** \brief Initialise a \e libcucul canvas. 38 40 * … … 61 63 cv->refcount = 0; 62 64 cv->autoinc = 0; 65 cv->resize_callback = NULL; 66 cv->resize_data = NULL; 63 67 64 68 cv->frame = 0; … … 82 86 cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT); 83 87 84 if( __cucul_set_canvas_size(cv, width, height) < 0)88 if(cucul_resize(cv, width, height) < 0) 85 89 { 86 90 int saved_errno = geterrno(); … … 99 103 } 100 104 105 /** \brief Manage a canvas. 106 * 107 * Lock a canvas to prevent it from being resized. If non-NULL, 108 * the \e callback function pointer will be called upon each 109 * \e cucul_set_canvas_size call and if the returned value is zero, the 110 * canvas resize request will be denied. 111 * 112 * This function is only useful for display drivers such as the \e libcaca 113 * library. 114 * 115 * If an error occurs, -1 is returned and \b errno is set accordingly: 116 * - \c EBUSY The canvas is already being managed. 117 * 118 * \param cv A libcucul canvas. 119 * \param callback An optional callback function pointer. 120 * \param p The argument to be passed to \e callback. 121 * \return 0 in case of success, -1 if an error occurred. 122 */ 123 int cucul_manage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p) 124 { 125 if(cv->refcount) 126 { 127 seterrno(EBUSY); 128 return -1; 129 } 130 131 cv->refcount = 1; 132 133 return 0; 134 } 135 136 /** \brief Unmanage a canvas. 137 * 138 * Unlock a canvas previously locked by cucul_manage_canvas(). For safety 139 * reasons, the callback and callback data arguments must be the same as for 140 * the cucul_manage_canvas() call. 141 * 142 * This function is only useful for display drivers such as the \e libcaca 143 * library. 144 * 145 * If an error occurs, -1 is returned and \b errno is set accordingly: 146 * - \c EINVAL The canvas is not managed, or the callback arguments do 147 * not match. 148 * 149 * \param cv A libcucul canvas. 150 * \param callback The \e callback argument previously passed to 151 cucul_manage_canvas(). 152 * \param p The \e p argument previously passed to cucul_manage_canvas(). 153 * \return 0 in case of success, -1 if an error occurred. 154 */ 155 int cucul_unmanage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p) 156 { 157 if(!cv->refcount 158 || cv->resize_callback != callback || cv->resize_data != p) 159 { 160 seterrno(EINVAL); 161 return -1; 162 } 163 164 cv->refcount = 0; 165 166 return 0; 167 } 168 101 169 /** \brief Resize a canvas. 102 170 * … … 124 192 * happens, the canvas handle becomes invalid and should not be used. 125 193 * 126 * \param cv A libcucul canvas 127 * \param width The desired canvas width 128 * \param height The desired canvas height 194 * \param cv A libcucul canvas. 195 * \param width The desired canvas width. 196 * \param height The desired canvas height. 129 197 * \return 0 in case of success, -1 if an error occurred. 130 198 */ … … 132 200 unsigned int height) 133 201 { 134 if(cv->refcount) 202 if(cv->refcount && cv->resize_callback 203 && !cv->resize_callback(cv->resize_data)) 135 204 { 136 205 seterrno(EBUSY); … … 138 207 } 139 208 140 return __cucul_set_canvas_size(cv, width, height);209 return cucul_resize(cv, width, height); 141 210 } 142 211 … … 147 216 * This function never fails. 148 217 * 149 * \param cv A libcucul canvas 218 * \param cv A libcucul canvas. 150 219 * \return The canvas width. 151 220 */ … … 161 230 * This function never fails. 162 231 * 163 * \param cv A libcucul canvas 232 * \param cv A libcucul canvas. 164 233 * \return The canvas height. 165 234 */ … … 178 247 * - \c EBUSY The canvas is in use by a display driver and cannot be freed. 179 248 * 180 * \param cv A libcucul canvas 249 * \param cv A libcucul canvas. 181 250 * \return 0 in case of success, -1 if an error occurred. 182 251 */ … … 232 301 */ 233 302 234 int __cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width, 235 unsigned int height) 303 int cucul_resize(cucul_canvas_t *cv, unsigned int width, unsigned int height) 236 304 { 237 305 unsigned int x, y, f, old_width, old_height, new_size, old_size; -
libcaca/trunk/cucul/cucul.h
r2043 r2055 85 85 * @{ */ 86 86 __extern cucul_canvas_t * cucul_create_canvas(unsigned int, unsigned int); 87 __extern int cucul_manage_canvas(cucul_canvas_t *, int (*)(void *), void *); 88 __extern int cucul_unmanage_canvas(cucul_canvas_t *, int (*)(void *), void *); 87 89 __extern int cucul_set_canvas_size(cucul_canvas_t *, unsigned int, 88 90 unsigned int); -
libcaca/trunk/cucul/cucul_internals.h
r2040 r2055 44 44 struct cucul_frame *frames; 45 45 46 /* Canvas management */ 46 47 unsigned int refcount; 47 48 unsigned int autoinc; 49 int (*resize_callback)(void *); 50 void *resize_data; 48 51 49 52 /* Shortcut to the active frame information */ … … 61 64 }; 62 65 63 /* Canvas functions */64 extern int __cucul_set_canvas_size(cucul_canvas_t *,65 unsigned int, unsigned int);66 67 66 /* Colour functions */ 68 67 extern uint16_t _cucul_attr_to_rgb12fg(uint32_t); -
libcaca/trunk/msvc/libcucul.def
r2040 r2055 1 LIBRARY "libcucul"2 3 EXPORTS4 __cucul_set_canvas_size ; Private symbol used by libcaca
Note: See TracChangeset
for help on using the changeset viewer.
