canvas size (use cucul_init(0, 0) for the old behaviour).tags/v0.99.beta14
| @@ -37,9 +37,14 @@ static void cucul_read_environment(cucul_t *); | |||||
| * first \e libcucul function to be called in a function. cucul_end() should | * first \e libcucul function to be called in a function. cucul_end() should | ||||
| * be called at the end of the program to free all allocated resources. | * be called at the end of the program to free all allocated resources. | ||||
| * | * | ||||
| * If one of the desired canvas coordinates is zero, a default canvas size | |||||
| * of 80x32 is used instead. | |||||
| * | |||||
| * \param width The desired canvas width | |||||
| * \param height The desired canvas height | |||||
| * \return 0 upon success, a non-zero value if an error occurs. | * \return 0 upon success, a non-zero value if an error occurs. | ||||
| */ | */ | ||||
| cucul_t * cucul_init(void) | |||||
| cucul_t * cucul_init(unsigned int width, unsigned int height) | |||||
| { | { | ||||
| cucul_t *qq = malloc(sizeof(cucul_t)); | cucul_t *qq = malloc(sizeof(cucul_t)); | ||||
| @@ -48,14 +53,18 @@ cucul_t * cucul_init(void) | |||||
| qq->fgcolor = CUCUL_COLOR_LIGHTGRAY; | qq->fgcolor = CUCUL_COLOR_LIGHTGRAY; | ||||
| qq->bgcolor = CUCUL_COLOR_BLACK; | qq->bgcolor = CUCUL_COLOR_BLACK; | ||||
| /* Initialise to a default size. 80x32 is arbitrary but matches AAlib's | |||||
| * default X11 window. When a graphic driver attaches to us, it can set | |||||
| * a different size. */ | |||||
| qq->width = qq->width = 0; | qq->width = qq->width = 0; | ||||
| qq->chars = NULL; | qq->chars = NULL; | ||||
| qq->attr = NULL; | qq->attr = NULL; | ||||
| qq->empty_line = qq->scratch_line = NULL; | qq->empty_line = qq->scratch_line = NULL; | ||||
| _cucul_set_size(qq, 80, 32); | |||||
| /* Initialise to a default size. 80x32 is arbitrary but matches AAlib's | |||||
| * default X11 window. When a graphic driver attaches to us, it can set | |||||
| * a different size. */ | |||||
| if(width && height) | |||||
| _cucul_set_size(qq, width, height); | |||||
| else | |||||
| _cucul_set_size(qq, 80, 32); | |||||
| if(_cucul_init_bitmap()) | if(_cucul_init_bitmap()) | ||||
| { | { | ||||
| @@ -70,14 +79,16 @@ cucul_t * cucul_init(void) | |||||
| * | * | ||||
| * This function sets the canvas width and height, in character cells. | * This function sets the canvas width and height, in character cells. | ||||
| * | * | ||||
| * The contents of the canvas are preserved to the extent of the new | |||||
| * canvas size. Newly allocated character cells at the right and/or at | |||||
| * the bottom of the canvas are filled with spaces. | |||||
| * | |||||
| * It is an error to try to resize the canvas if an output driver has | * It is an error to try to resize the canvas if an output driver has | ||||
| * been attached to the canvas using caca_attach(). You need to remove | * been attached to the canvas using caca_attach(). You need to remove | ||||
| * the output driver using caca_detach() before you can change the | * the output driver using caca_detach() before you can change the | ||||
| * canvas size again. | |||||
| * | |||||
| * However, the caca output driver can cause a canvas resize through | |||||
| * user interaction. See the caca_event() documentation for more about | |||||
| * this. | |||||
| * canvas size again. However, the caca output driver can cause a canvas | |||||
| * resize through user interaction. See the caca_event() documentation | |||||
| * for more about this. | |||||
| * | * | ||||
| * \param width The desired canvas width | * \param width The desired canvas width | ||||
| * \param height The desired canvas height | * \param height The desired canvas height | ||||
| @@ -118,7 +118,7 @@ typedef struct cucul_context cucul_t; | |||||
| * initialisation, system information retrieval and configuration. | * initialisation, system information retrieval and configuration. | ||||
| * | * | ||||
| * @{ */ | * @{ */ | ||||
| cucul_t * cucul_init(void); | |||||
| cucul_t * cucul_init(unsigned int, unsigned int); | |||||
| void cucul_set_size(cucul_t *, unsigned int, unsigned int); | void cucul_set_size(cucul_t *, unsigned int, unsigned int); | ||||
| unsigned int cucul_get_width(cucul_t *); | unsigned int cucul_get_width(cucul_t *); | ||||
| unsigned int cucul_get_height(cucul_t *); | unsigned int cucul_get_height(cucul_t *); | ||||
| @@ -100,7 +100,7 @@ initialize (void) | |||||
| #endif | #endif | ||||
| #ifdef LIBCACA | #ifdef LIBCACA | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(80, 32); | |||||
| if (!qq) | if (!qq) | ||||
| { | { | ||||
| printf ("Failed to initialize libcucul\n"); | printf ("Failed to initialize libcucul\n"); | ||||
| @@ -53,7 +53,7 @@ int main(int argc, char **argv) | |||||
| double frameOffset40[360]; | double frameOffset40[360]; | ||||
| double frameOffset80[360]; | double frameOffset80[360]; | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| if(!qq) | if(!qq) | ||||
| return 1; | return 1; | ||||
| kk = caca_attach(qq); | kk = caca_attach(qq); | ||||
| @@ -42,7 +42,7 @@ int main (int argc, char **argv) | |||||
| struct cucul_bitmap *bitmap; | struct cucul_bitmap *bitmap; | ||||
| int i, x, y, frame = 0, pause = 0; | int i, x, y, frame = 0, pause = 0; | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| if(!qq) | if(!qq) | ||||
| return 1; | return 1; | ||||
| kk = caca_attach(qq); | kk = caca_attach(qq); | ||||
| @@ -45,7 +45,7 @@ int main (int argc, char **argv) | |||||
| struct cucul_bitmap *bitmap; | struct cucul_bitmap *bitmap; | ||||
| int i, x, y, frame = 0, pause = 0; | int i, x, y, frame = 0, pause = 0; | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| if(!qq) | if(!qq) | ||||
| return 1; | return 1; | ||||
| kk = caca_attach(qq); | kk = caca_attach(qq); | ||||
| @@ -88,7 +88,7 @@ int main(int argc, char **argv) | |||||
| int i; | int i; | ||||
| /* Initialise libcucul */ | /* Initialise libcucul */ | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| if(!qq) | if(!qq) | ||||
| { | { | ||||
| fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]); | fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]); | ||||
| @@ -26,7 +26,7 @@ int main(int argc, char **argv) | |||||
| caca_t *kk; | caca_t *kk; | ||||
| int i, j; | int i, j; | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| if(!qq) | if(!qq) | ||||
| return 1; | return 1; | ||||
| @@ -45,7 +45,7 @@ int main(int argc, char **argv) | |||||
| void (*demo)(void) = NULL; | void (*demo)(void) = NULL; | ||||
| int quit = 0; | int quit = 0; | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| if(!qq) | if(!qq) | ||||
| return 1; | return 1; | ||||
| kk = caca_attach(qq); | kk = caca_attach(qq); | ||||
| @@ -39,7 +39,7 @@ int main(void) | |||||
| int neara, dista, nearb, distb, dist; | int neara, dista, nearb, distb, dist; | ||||
| int x, y; | int x, y; | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| kk = caca_attach(qq); | kk = caca_attach(qq); | ||||
| for(x = 0; x < 100; x++) | for(x = 0; x < 100; x++) | ||||
| @@ -30,7 +30,7 @@ int main(int argc, char **argv) | |||||
| int *events; | int *events; | ||||
| int i, h, quit; | int i, h, quit; | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| if(!qq) | if(!qq) | ||||
| return 1; | return 1; | ||||
| kk = caca_attach(qq); | kk = caca_attach(qq); | ||||
| @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) | |||||
| exit(-1); | exit(-1); | ||||
| } | } | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| cucul_set_size(qq, WIDTH, HEIGHT); | cucul_set_size(qq, WIDTH, HEIGHT); | ||||
| for(y = 0; y < 256; y++) | for(y = 0; y < 256; y++) | ||||
| @@ -34,7 +34,7 @@ int main(void) | |||||
| struct cucul_bitmap *left, *right; | struct cucul_bitmap *left, *right; | ||||
| int x; | int x; | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| kk = caca_attach(qq); | kk = caca_attach(qq); | ||||
| for(x = 0; x < 256; x++) | for(x = 0; x < 256; x++) | ||||
| @@ -34,7 +34,7 @@ int main(void) | |||||
| struct cucul_bitmap *bitmap; | struct cucul_bitmap *bitmap; | ||||
| int x, y; | int x, y; | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| kk = caca_attach(qq); | kk = caca_attach(qq); | ||||
| for(y = 0; y < 256; y++) | for(y = 0; y < 256; y++) | ||||
| @@ -33,7 +33,7 @@ int main(int argc, char **argv) | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| if(!qq) | if(!qq) | ||||
| return 1; | return 1; | ||||
| kk = caca_attach(qq); | kk = caca_attach(qq); | ||||
| @@ -29,7 +29,7 @@ int main(void) | |||||
| cucul_t *qq; | cucul_t *qq; | ||||
| caca_t *kk; | caca_t *kk; | ||||
| qq = cucul_init(); | |||||
| qq = cucul_init(0, 0); | |||||
| kk = caca_attach(qq); | kk = caca_attach(qq); | ||||
| cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | ||||