|
|
| version 1.1, 2003/11/16 16:43:45 | version 1.3, 2003/11/28 16:29:57 |
|---|---|
| Line 34 | Line 34 |
| #include "scrnmng.h" | #include "scrnmng.h" |
| #include "gtk/xnp2.h" | #include "gtk/xnp2.h" |
| #include "gtk/gtkdrawmng.h" | |
| typedef struct { | typedef struct { |
| BYTE scrnmode; | BYTE scrnmode; |
| int width; | int width; |
| int height; | int height; |
| int extend; | int extend; |
| int clipping; | int clipping; |
| RGB32 pal16mask; | PAL16MASK pal16mask; |
| BYTE r16b; | |
| BYTE l16r; | RECT_T scrn; |
| BYTE l16g; | RECT_T rect; |
| RECT_T scrn; | int lpitch; |
| RECT_T rect; | int scrw; |
| int scrh; | |
| int scrw; | |
| int scrh; | |
| int lpitch; | |
| /* toolkit depend */ | /* toolkit depend */ |
| GdkImage* surface; | GdkImage *surface; |
| GdkPixmap* backsurf; | GdkPixmap *backsurf; |
| BOOL shared_pixmap; | |
| unsigned long pixel[24]; /* pallete */ | unsigned long pixel[24]; /* pallete */ |
| } DRAWMNG; | } DRAWMNG; |
| Line 145 renewal_client_size(void) | Line 144 renewal_client_size(void) |
| static void | static void |
| clear_out_of_rect(const RECT_T* target, const RECT_T* base) | clear_out_of_rect(const RECT_T* target, const RECT_T* base) |
| { | { |
| GdkDrawable *d = drawarea->window; | |
| GdkGC *gc = drawarea->style->black_gc; | |
| RECT_T rect; | RECT_T rect; |
| rect.left = base->left; | rect.left = base->left; |
| Line 152 clear_out_of_rect(const RECT_T* target, | Line 153 clear_out_of_rect(const RECT_T* target, |
| rect.top = base->top; | rect.top = base->top; |
| rect.bottom = target->top; | rect.bottom = target->top; |
| if (rect.top < rect.bottom) { | if (rect.top < rect.bottom) { |
| gdk_draw_rectangle(drawmng.backsurf, | gdk_draw_rectangle(d, gc, TRUE, |
| drawarea->style->black_gc, TRUE, | |
| rect.left, rect.top, rect.right, rect.bottom); | rect.left, rect.top, rect.right, rect.bottom); |
| } | } |
| rect.top = target->bottom; | rect.top = target->bottom; |
| rect.bottom = base->bottom; | rect.bottom = base->bottom; |
| if (rect.top < rect.bottom) { | if (rect.top < rect.bottom) { |
| gdk_draw_rectangle(drawmng.backsurf, | gdk_draw_rectangle(d, gc, TRUE, |
| drawarea->style->black_gc, TRUE, | |
| rect.left, rect.top, rect.right, rect.bottom); | rect.left, rect.top, rect.right, rect.bottom); |
| } | } |
| Line 170 clear_out_of_rect(const RECT_T* target, | Line 169 clear_out_of_rect(const RECT_T* target, |
| rect.left = base->left; | rect.left = base->left; |
| rect.right = target->left; | rect.right = target->left; |
| if (rect.left < rect.right) { | if (rect.left < rect.right) { |
| gdk_draw_rectangle(drawmng.backsurf, | gdk_draw_rectangle(d, gc, TRUE, |
| drawarea->style->black_gc, TRUE, | |
| rect.left, rect.top, rect.right, rect.bottom); | rect.left, rect.top, rect.right, rect.bottom); |
| } | } |
| rect.left = target->right; | rect.left = target->right; |
| rect.right = base->right; | rect.right = base->right; |
| if (rect.left < rect.right) { | if (rect.left < rect.right) { |
| gdk_draw_rectangle(drawmng.backsurf, | gdk_draw_rectangle(d, gc, TRUE, |
| drawarea->style->black_gc, TRUE, | |
| rect.left, rect.top, rect.right, rect.bottom); | rect.left, rect.top, rect.right, rect.bottom); |
| } | } |
| } | } |
| Line 190 clear_outscreen(void) | Line 187 clear_outscreen(void) |
| RECT_T target; | RECT_T target; |
| RECT_T base; | RECT_T base; |
| base.left = base.top = 0; | |
| base.right = drawmng.scrw; | |
| base.bottom = drawmng.scrh; | |
| target = drawmng.scrn; | target = drawmng.scrn; |
| memset(&base, 0, sizeof(base)); | |
| clear_out_of_rect(&target, &base); | clear_out_of_rect(&target, &base); |
| } | } |
| Line 236 palette_set(void) | Line 235 palette_set(void) |
| } | } |
| } | } |
| static void | |
| make16mask(UINT32 bmask, UINT32 rmask, UINT32 gmask) | |
| { | |
| BYTE sft; | |
| sft = 0; | |
| while ((!(bmask & 0x80)) && (sft < 32)) { | |
| bmask <<= 1; | |
| sft++; | |
| } | |
| drawmng.pal16mask.p.b = (BYTE)bmask; | |
| drawmng.r16b = sft; | |
| sft = 0; | |
| while ((rmask & 0xffffff00) && (sft < 32)) { | |
| rmask >>= 1; | |
| sft++; | |
| } | |
| drawmng.pal16mask.p.r = (BYTE)rmask; | |
| drawmng.l16r = sft; | |
| sft = 0; | |
| while ((gmask & 0xffffff00) && (sft < 32)) { | |
| gmask >>= 1; | |
| sft++; | |
| } | |
| drawmng.pal16mask.p.g = (BYTE)gmask; | |
| drawmng.l16g = sft; | |
| } | |
| void | void |
| scrnmng_initialize(void) | scrnmng_initialize(void) |
| { | { |
| Line 298 scrnmng_create(BYTE mode) | Line 266 scrnmng_create(BYTE mode) |
| scrnmng.flag = SCRNFLAG_HAVEEXTEND; | scrnmng.flag = SCRNFLAG_HAVEEXTEND; |
| visual = gtk_widget_get_visual(drawarea); | visual = gtk_widget_get_visual(drawarea); |
| switch (visual->type) { | bitcolor = gtkdrawmng_getbpp(drawarea, window); |
| case GDK_VISUAL_TRUE_COLOR: | if (bitcolor == 0) { |
| break; | |
| case GDK_VISUAL_PSEUDO_COLOR: | |
| break; | |
| case GDK_VISUAL_DIRECT_COLOR: | |
| if (visual->depth > 8) { | |
| break; | |
| } | |
| /* FALLTHROUGH */ | |
| default: | |
| fprintf(stderr, "No support visual class.\n"); | |
| return 1; | |
| } | |
| if (visual->depth == 32) { | |
| bitcolor = 32; | |
| } else if (visual->depth == 24) { | |
| if (is_32bpp(window->window)) { | |
| bitcolor = 32; | |
| } else { | |
| bitcolor = 24; | |
| } | |
| } else if (visual->depth == 15 || visual->depth == 16) { | |
| bitcolor = 16; | |
| make16mask(visual->blue_mask, visual->red_mask, visual->green_mask); | |
| } else if (visual->depth == 8) { | |
| bitcolor = 8; | |
| palette_init(); | |
| } else if (visual->depth < 8) { | |
| fprintf(stderr, "Too few allocable color.\n"); | |
| return FAILURE; | |
| } else { | |
| fprintf(stderr, "No support depth.\n"); | |
| return FAILURE; | return FAILURE; |
| } else if (bitcolor == 16) { | |
| drawmng_make16mask(&drawmng.pal16mask, visual->blue_mask, visual->red_mask, visual->green_mask); | |
| } else if (bitcolor == 8) { | |
| palette_init(); | |
| } | } |
| drawmng.extend = 1; | drawmng.extend = 1; |
| bytes_per_pixel = bitcolor >> 3; | bytes_per_pixel = bitcolor >> 3; |
| if (!(mode & SCRNMODE_ROTATE)) { | if (!(mode & SCRNMODE_ROTATE)) { |
| rect.right = 640; | rect.right = 641; |
| rect.bottom = 480; | rect.bottom = 480; |
| if (np2oscfg.paddingx) { | |
| rect.right++; | |
| } | |
| lpitch = rect.right * bytes_per_pixel; | lpitch = rect.right * bytes_per_pixel; |
| if (lpitch % 4) { | if (lpitch % 4) { |
| rect.right += (lpitch % 4) / bytes_per_pixel; | rect.right += (lpitch % 4) / bytes_per_pixel; |
| lpitch = rect.right * bytes_per_pixel; | |
| } | } |
| } else { | } else { |
| rect.right = 480; | rect.right = 480; |
| rect.bottom = 640; | rect.bottom = 641; |
| if (np2oscfg.paddingx) { | lpitch = rect.right * bytes_per_pixel; |
| rect.bottom++; | |
| } | |
| } | } |
| lpitch = rect.right * bytes_per_pixel; | |
| height = 480; | height = 480; |
| drawmng.surface = gdk_image_new(GDK_IMAGE_FASTEST, visual, | drawmng.surface = gdk_image_new(GDK_IMAGE_FASTEST, visual, |
| Line 366 scrnmng_create(BYTE mode) | Line 298 scrnmng_create(BYTE mode) |
| g_message("can't create surface."); | g_message("can't create surface."); |
| return FAILURE; | return FAILURE; |
| } | } |
| drawmng.shared_pixmap = use_shared_pixmap; | |
| drawmng.backsurf = NULL; | |
| if (use_shared_pixmap) { | |
| drawmng.backsurf = gdk_pixmap_shpix_new( | |
| drawarea->window, drawmng.surface, | |
| rect.right, rect.bottom, visual->depth); | |
| } | |
| if (drawmng.backsurf == NULL) { | |
| drawmng.shared_pixmap = FALSE; | |
| drawmng.backsurf = gdk_pixmap_new(drawarea->window, | |
| rect.right, rect.bottom, visual->depth); | |
| } | |
| if (drawmng.backsurf == NULL) { | |
| g_message("can't create pixmap."); | |
| return FAILURE; | |
| } | |
| gdk_draw_rectangle(drawmng.backsurf, drawarea->style->black_gc, | |
| TRUE, 0, 0, rect.right, rect.bottom); | |
| } | } |
| scrnmng.bpp = (BYTE)bitcolor; | scrnmng.bpp = (BYTE)bitcolor; |
| drawmng.lpitch = lpitch; | drawmng.lpitch = lpitch; |
| Line 376 scrnmng_create(BYTE mode) | Line 327 scrnmng_create(BYTE mode) |
| drawmng.clipping = 0; | drawmng.clipping = 0; |
| renewal_client_size(); | renewal_client_size(); |
| drawmng.backsurf = gdk_pixmap_new(drawarea->window, | |
| drawmng.scrw, drawmng.scrh, visual->depth); | |
| if (drawmng.backsurf == NULL) { | |
| g_message("can't create pixmap."); | |
| return FAILURE; | |
| } | |
| gdk_draw_rectangle(drawmng.backsurf, drawarea->style->black_gc, TRUE, | |
| 0, 0, drawmng.scrw, drawmng.scrh); | |
| return SUCCESS; | return SUCCESS; |
| } | } |
| Line 407 scrnmng_destroy(void) | Line 349 scrnmng_destroy(void) |
| RGB16 | RGB16 |
| scrnmng_makepal16(RGB32 pal32) | scrnmng_makepal16(RGB32 pal32) |
| { | { |
| RGB32 pal; | |
| pal.d = pal32.d & drawmng.pal16mask.d; | return drawmng_makepal16(&drawmng.pal16mask, pal32); |
| return (RGB16)((pal.p.g << drawmng.l16g) + (pal.p.r << drawmng.l16r) + (pal.p.b >> drawmng.r16b)); | |
| } | } |
| void | void |
| Line 471 void | Line 411 void |
| scrnmng_surfunlock(const SCRNSURF* surf) | scrnmng_surfunlock(const SCRNSURF* surf) |
| { | { |
| X11SCRNSURF *ss = (X11SCRNSURF *)surf; | X11SCRNSURF *ss = (X11SCRNSURF *)surf; |
| GtkWidget *w = drawarea; | GdkDrawable *d = drawarea->window; |
| GdkGC *gc = w->style->fg_gc[GTK_WIDGET_STATE(w)]; | GdkGC *gc = drawarea->style->fg_gc[GTK_WIDGET_STATE(drawarea)]; |
| BYTE *delta = ss->renewal; | BYTE *delta = ss->renewal; |
| RECT_T r; | RECT_T r; |
| gint h, s; | gint h, s; |
| r.left = drawmng.scrn.left; | if (!drawmng.shared_pixmap) { |
| r.top = drawmng.scrn.top; | r.left = drawmng.scrn.left; |
| r.right = drawmng.rect.right; | r.top = drawmng.scrn.top; |
| r.bottom = drawmng.rect.bottom; | r.right = drawmng.rect.right; |
| r.bottom = drawmng.rect.bottom; | |
| if (!(drawmng.scrnmode & SCRNMODE_ROTATE)) { | |
| /* normal */ | |
| for (s = h = 0; h < r.bottom; h++) { | |
| if ((renewal_line[h] != delta[h]) || (s == h)) | |
| continue; | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | |
| 0, s, r.left, r.top + s, r.right, h - s); | |
| s = h + 1; | |
| } | |
| if (s != h) { | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | |
| 0, s, r.left, r.top + s, r.right, h - s); | |
| } | |
| } else if (!(drawmng.scrnmode & SCRNMODE_ROTATEDIR)) { | |
| /* rotate left */ | |
| for (s = h = 0; h < r.right; h++) { | |
| if ((renewal_line[h] != delta[h]) || (s == h)) | |
| continue; | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | |
| s, 0, r.left + s, r.top, h - s, r.bottom); | |
| s = h + 1; | |
| } | |
| if (s != h) { | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | |
| s, 0, r.left + s, r.top, h - s, r.bottom); | |
| } | |
| } else { | |
| /* rotate right */ | |
| for (s = h = 0; h < r.right; h++) { | |
| if ((renewal_line[h] != delta[h]) || (s == h)) | |
| continue; | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | if (!(drawmng.scrnmode & SCRNMODE_ROTATE)) { |
| r.right - h, 0, | /* normal */ |
| drawmng.scrn.right - h, r.top, h - s, r.bottom); | for (s = h = 0; h < r.bottom; h++) { |
| s = h + 1; | if ((renewal_line[h] != delta[h]) || (s == h)) |
| } | continue; |
| if (s != h) { | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, |
| r.right - h, 0, | 0, s, r.left, r.top + s, r.right, h - s); |
| drawmng.scrn.right - h, r.top, h - s, r.bottom); | s = h + 1; |
| } | |
| if (s != h) { | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | |
| 0, s, r.left, r.top + s, r.right, h - s); | |
| } | |
| } else if (!(drawmng.scrnmode & SCRNMODE_ROTATEDIR)) { | |
| /* rotate left */ | |
| for (s = h = 0; h < r.right; h++) { | |
| if ((renewal_line[h] != delta[h]) || (s == h)) | |
| continue; | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | |
| s, 0, r.left + s, r.top, h - s, r.bottom); | |
| s = h + 1; | |
| } | |
| if (s != h) { | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | |
| s, 0, r.left + s, r.top, h - s, r.bottom); | |
| } | |
| } else { | |
| /* rotate right */ | |
| for (s = h = 0; h < r.right; h++) { | |
| if ((renewal_line[h] != delta[h]) || (s == h)) | |
| continue; | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | |
| r.right - h, 0, | |
| drawmng.scrn.right - h, r.top, h - s, r.bottom); | |
| s = h + 1; | |
| } | |
| if (s != h) { | |
| gdk_draw_image(drawmng.backsurf, gc, drawmng.surface, | |
| r.right - h, 0, | |
| drawmng.scrn.right - h, r.top, h - s, r.bottom); | |
| } | |
| } | } |
| } | } |
| scrnmng_update(); | |
| } | |
| void | |
| scrnmng_update(void) | |
| { | |
| GdkDrawable *d = (GdkDrawable *)drawarea->window; | |
| GtkWidget *w = drawarea; | |
| GdkGC *gc = w->style->fg_gc[GTK_WIDGET_STATE(w)]; | |
| if (scrnmng.palchanged) { | if (scrnmng.palchanged) { |
| scrnmng.palchanged = FALSE; | scrnmng.palchanged = FALSE; |
| palette_set(); | palette_set(); |
| Line 550 scrnmng_update(void) | Line 482 scrnmng_update(void) |
| { | { |
| if (scrnmng.allflash) { | if (scrnmng.allflash) { |
| scrnmng.allflash = 0; | scrnmng.allflash = 0; |
| clear_outscreen(); | if (np2oscfg.paddingx || np2oscfg.paddingy) { |
| clear_outscreen(); | |
| } | |
| } | } |
| gdk_draw_pixmap(d, gc, drawmng.backsurf, | gdk_draw_pixmap(d, gc, drawmng.backsurf, |
| 0, 0, 0, 0, drawmng.scrw, drawmng.scrh); | 0, 0, /* src */ |
| drawmng.scrn.left, drawmng.scrn.top, /* dest */ | |
| drawmng.rect.right, drawmng.rect.bottom); /* w/h */ | |
| } | } |
| } | } |