|
|
| version 1.2, 2004/07/15 14:24:33 | version 1.3, 2004/07/27 17:07:50 |
|---|---|
| Line 45 drawmng_create(void *parent, int width, | Line 45 drawmng_create(void *parent, int width, |
| GTKDRAWMNG_HDL hdl = NULL; | GTKDRAWMNG_HDL hdl = NULL; |
| GtkWidget *parent_window; | GtkWidget *parent_window; |
| GdkVisual *visual; | GdkVisual *visual; |
| int bitcolor; | pixmap_format_t fmt; |
| int bytes_per_pixel; | int bytes_per_pixel; |
| int padding; | |
| if (parent == NULL) | if (parent == NULL) |
| return NULL; | return NULL; |
| parent_window = GTK_WIDGET(parent); | parent_window = GTK_WIDGET(parent); |
| gtk_widget_realize(parent_window); | |
| hdl = (GTKDRAWMNG_HDL)_MALLOC(sizeof(_GTKDRAWMNG_HDL), "drawmng hdl"); | hdl = (GTKDRAWMNG_HDL)_MALLOC(sizeof(_GTKDRAWMNG_HDL), "drawmng hdl"); |
| if (hdl == NULL) | if (hdl == NULL) |
| Line 65 drawmng_create(void *parent, int width, | Line 67 drawmng_create(void *parent, int width, |
| gtk_widget_set_size_request(GTK_WIDGET(hdl->drawarea), width, height); | gtk_widget_set_size_request(GTK_WIDGET(hdl->drawarea), width, height); |
| visual = gtk_widget_get_visual(hdl->drawarea); | visual = gtk_widget_get_visual(hdl->drawarea); |
| bitcolor = gtkdrawmng_getbpp(hdl->drawarea, parent_window); | if (!gtkdrawmng_getformat(hdl->drawarea, parent_window, &fmt)) |
| if (bitcolor == 0) | |
| goto destroy; | goto destroy; |
| bytes_per_pixel = bitcolor / 8; | |
| if (bitcolor == 16) { | switch (fmt.bits_per_pixel) { |
| #if defined(SUPPORT_32BPP) | |
| case 32: | |
| break; | |
| #endif | |
| #if defined(SUPPORT_24BPP) | |
| case 24: | |
| break; | |
| #endif | |
| #if defined(SUPPORT_16BPP) | |
| case 16: | |
| case 15: | |
| drawmng_make16mask(&hdl->d.pal16mask, visual->blue_mask, | drawmng_make16mask(&hdl->d.pal16mask, visual->blue_mask, |
| visual->red_mask, visual->green_mask); | visual->red_mask, visual->green_mask); |
| break; | |
| #endif | |
| #if defined(SUPPORT_8BPP) | |
| case 8: | |
| break; | |
| #endif | |
| default: | |
| goto destroy; | |
| } | } |
| bytes_per_pixel = fmt.bits_per_pixel / 8; | |
| hdl->d.dest.x = hdl->d.dest.x = 0; | hdl->d.dest.x = hdl->d.dest.x = 0; |
| hdl->d.src.left = hdl->d.src.top = 0; | hdl->d.src.left = hdl->d.src.top = 0; |
| hdl->d.src.right = width; | hdl->d.src.right = width; |
| hdl->d.src.bottom = height; | hdl->d.src.bottom = height; |
| hdl->d.lpitch = hdl->d.src.right * bytes_per_pixel; | hdl->d.lpitch = hdl->d.src.right * bytes_per_pixel; |
| if (hdl->d.lpitch % 4) { | padding = hdl->d.lpitch % (fmt.scanline_pad / 8); |
| hdl->d.src.right += (hdl->d.lpitch % 4) / bytes_per_pixel; | if (padding > 0) { |
| hdl->d.src.right += padding / bytes_per_pixel; | |
| hdl->d.lpitch = hdl->d.src.right * bytes_per_pixel; | hdl->d.lpitch = hdl->d.src.right * bytes_per_pixel; |
| } | } |
| Line 95 drawmng_create(void *parent, int width, | Line 117 drawmng_create(void *parent, int width, |
| hdl->d.vram.height = hdl->d.src.bottom; | hdl->d.vram.height = hdl->d.src.bottom; |
| hdl->d.vram.xalign = bytes_per_pixel; | hdl->d.vram.xalign = bytes_per_pixel; |
| hdl->d.vram.yalign = hdl->d.lpitch; | hdl->d.vram.yalign = hdl->d.lpitch; |
| hdl->d.vram.bpp = bitcolor; | hdl->d.vram.bpp = fmt.bits_per_pixel; |
| /* pixmap */ | /* pixmap */ |
| hdl->backsurf = gdk_pixmap_new(parent_window->window, | hdl->backsurf = gdk_pixmap_new(parent_window->window, |
| Line 107 drawmng_create(void *parent, int width, | Line 129 drawmng_create(void *parent, int width, |
| destroy: | destroy: |
| if (hdl) { | if (hdl) { |
| GtkWidget *da = hdl->drawarea; | |
| drawmng_release((DRAWMNG_HDL)hdl); | drawmng_release((DRAWMNG_HDL)hdl); |
| if (hdl->drawarea) { | if (da) { |
| gtk_widget_unref(hdl->drawarea); | gtk_widget_unref(da); |
| } | } |
| } | } |
| return NULL; | return NULL; |
| Line 236 drawmng_get_widget_handle(DRAWMNG_HDL dh | Line 259 drawmng_get_widget_handle(DRAWMNG_HDL dh |
| return hdl->drawarea; | return hdl->drawarea; |
| } | } |
| int | BOOL |
| gtkdrawmng_getbpp(GtkWidget *w, GtkWidget *parent_window) | gtkdrawmng_getformat(GtkWidget *w, GtkWidget *pw, pixmap_format_t *fmtp) |
| { | { |
| GdkVisual *visual; | GdkVisual *visual; |
| int bitcolor; | |
| visual = gtk_widget_get_visual(w); | visual = gtk_widget_get_visual(w); |
| switch (visual->type) { | switch (visual->type) { |
| case GDK_VISUAL_TRUE_COLOR: | case GDK_VISUAL_TRUE_COLOR: |
| case GDK_VISUAL_PSEUDO_COLOR: | case GDK_VISUAL_PSEUDO_COLOR: |
| case GDK_VISUAL_DIRECT_COLOR: | case GDK_VISUAL_DIRECT_COLOR: |
| if (visual->depth >= 8) { | break; |
| break; | |
| } | |
| /* FALLTHROUGH */ | |
| default: | default: |
| fprintf(stderr, "No support visual class.\n"); | fprintf(stderr, "No support visual class.\n"); |
| return 0; | return FALSE; |
| } | } |
| if (visual->depth == 32) { | switch (visual->depth) { |
| bitcolor = 32; | #if defined(SUPPORT_32BPP) |
| } else if (visual->depth == 24) { | case 32: |
| if (is_32bpp(parent_window->window)) { | #endif |
| bitcolor = 32; | #if defined(SUPPORT_24BPP) |
| } else { | case 24: |
| bitcolor = 24; | #endif |
| #if defined(SUPPORT_16BPP) | |
| case 16: | |
| case 15: | |
| #endif | |
| #if defined(SUPPORT_8BPP) | |
| case 8: | |
| #endif | |
| break; | |
| default: | |
| if (visual->depth < 8) { | |
| fprintf(stderr, "Too few allocable color.\n"); | |
| } | } |
| } else if (visual->depth == 15 || visual->depth == 16) { | |
| bitcolor = 16; | |
| } else if (visual->depth == 8) { | |
| bitcolor = 8; | |
| } else if (visual->depth < 8) { | |
| fprintf(stderr, "Too few allocable color.\n"); | |
| return 0; | |
| } else { | |
| fprintf(stderr, "No support depth.\n"); | fprintf(stderr, "No support depth.\n"); |
| return 0; | return FALSE; |
| } | } |
| return bitcolor; | return gdk_window_get_pixmap_format(pw->window, visual, fmtp); |
| } | } |