From fa7048d66d95c434f40b761b8d7673583dd2233d Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Sat, 13 Oct 2012 22:25:10 +0200 Subject: Redraw favicon when it has been changed. Improve the window icon / favicon interface. --- atari/browser_win.c | 86 ++++++++++++++++++++++++++++++++++++----------------- atari/browser_win.h | 3 +- atari/gui.c | 8 +++-- 3 files changed, 66 insertions(+), 31 deletions(-) diff --git a/atari/browser_win.c b/atari/browser_win.c index 3b987bb32..8beb39645 100755 --- a/atari/browser_win.c +++ b/atari/browser_win.c @@ -306,6 +306,59 @@ bool window_widget_has_focus( struct gui_window * gw, enum focus_element_type t, } assert( gw->root != NULL ); return( ( element == gw->root->focus.element && t == gw->root->focus.type) ); +} + +void window_set_icon(struct gui_window *gw, struct bitmap * bmp ) +{ + gw->icon = bmp; + /* redraw window when it is iconyfied: */ + if (gw->icon != NULL) { + short info, dummy; + WindGet(gw->root->handle, WF_ICONIFY, &info, &dummy, &dummy, &dummy); + if (info == 1) { + window_redraw_favicon(gw, NULL); + } + } +} + + +/** + * Redraw the favicon +*/ +void window_redraw_favicon(struct gui_window *gw, GRECT *clip) +{ + GRECT work; + + assert(gw->root); + + WINDOW * bw = gw->root->handle; + + WindClear(bw); + WindGet(bw, WF_WORKXYWH, &work.g_x, &work.g_y, &work.g_w, &work.g_h); + if (clip == NULL) { + clip = &work; + } + + if (gw->icon == NULL) { + OBJECT * tree; + RsrcGaddr( h_gem_rsrc, R_TREE, ICONIFY , &tree); + tree->ob_x = work.g_x; + tree->ob_y = work.g_y; + tree->ob_width = work.g_w; + tree->ob_height = work.g_h; + objc_draw(tree, 0, 8, clip->g_x, clip->g_y, clip->g_w, clip->g_h); + } else { + // TODO: consider the clipping rectangle + struct rect work_clip = { 0,0,work.g_w,work.g_h }; + int xoff=0; + if (work.g_w > work.g_h) { + xoff = ((work.g_w-work.g_h)/2); + work.g_w = work.g_h; + } + plot_set_dimensions( work.g_x+xoff, work.g_y, work.g_w, work.g_h); + plot_clip(&work_clip); + atari_plotters.bitmap(0, 0, work.g_w, work.g_h, gw->icon, 0xffffff, 0); + } } @@ -483,35 +536,12 @@ static void __CDECL evnt_window_iconify( WINDOW *win, short buff[8], void * data } } -/** - * Redraw the favicon -*/ -static void __CDECL evnt_window_icondraw( WINDOW *win, short buff[8], void * data ) -{ - short x,y,w,h; - struct gui_window * gw = (struct gui_window*)data; - WindClear( win); - WindGet( win, WF_WORKXYWH, &x, &y, &w, &h); - if( gw->icon == NULL ) { - OBJECT * tree; - RsrcGaddr( h_gem_rsrc, R_TREE, ICONIFY , &tree ); - tree->ob_x = x; - tree->ob_y = y; - tree->ob_width = w; - tree->ob_height = h; - mt_objc_draw( tree, 0, 8, buff[4], buff[5], buff[6], buff[7], app.aes_global ); - } else { - struct rect clip = { 0,0,w,h }; - int xoff=0; - if (w > h) { - xoff = ((w-h)/2); - w = h; - } - plot_set_dimensions( x+xoff,y,w,h ); - plot_clip(&clip); - atari_plotters.bitmap(0, 0, w, h, gw->icon, 0xffffff, 0); - } +static void __CDECL evnt_window_icondraw(WINDOW *win, short buff[8], void * data) +{ + struct gui_window *gw = (struct gui_window*) data; + GRECT clip = {buff[4], buff[5], buff[6], buff[7]}; + window_redraw_favicon(gw, &clip); } /* perform the actual resize */ diff --git a/atari/browser_win.h b/atari/browser_win.h index 4cf8a26f4..28001baad 100755 --- a/atari/browser_win.h +++ b/atari/browser_win.h @@ -59,7 +59,8 @@ bool window_widget_has_focus( struct gui_window * gw, enum focus_element_type t, bool window_url_widget_has_focus( struct gui_window * gw ); void window_set_url( struct gui_window * gw, const char * text); void window_set_stauts( struct gui_window * gw , char * text ); -void window_set_icon(struct gui_window * gw, struct bitmap * bmp ); +void window_set_icon(struct gui_window * gw, struct bitmap * bmp ); +void window_redraw_favicon(struct gui_window *gw, GRECT *clip); /* -------------------------------------------------------------------------- */ diff --git a/atari/gui.c b/atari/gui.c index 0b76d39ba..a2dac21d3 100755 --- a/atari/gui.c +++ b/atari/gui.c @@ -553,8 +553,12 @@ gui_window_remove_caret(struct gui_window *w) void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) -{ - g->icon = (icon != NULL) ? content_get_bitmap(icon) : NULL; +{ + struct bitmap *bmp_icon; + + bmp_icon = (icon != NULL) ? content_get_bitmap(icon) : NULL; + + window_set_icon(g, bmp_icon); } void -- cgit v1.2.3