1 /*
2  * Copyright 2010 Vincent Sanders <vince@simtec.co.uk>
3  *
4  * Framebuffer windowing toolkit bitmaped image widget
5  *
6  * This file is part of NetSurf, http://www.netsurf-browser.org/
7  *
8  * NetSurf is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * NetSurf is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <stdbool.h>
22 #include <stdlib.h>
23 
24 #include <libnsfb.h>
25 #include <libnsfb_plot.h>
26 
27 #include "netsurf/browser_window.h"
28 
29 #include "framebuffer/gui.h"
30 #include "framebuffer/fbtk.h"
31 #include "framebuffer/image_data.h"
32 
33 #include "widget.h"
34 
35 static int
fb_redraw_bitmap(fbtk_widget_t * widget,fbtk_callback_info * cbi)36 fb_redraw_bitmap(fbtk_widget_t *widget, fbtk_callback_info *cbi)
37 {
38 	nsfb_bbox_t bbox;
39 	nsfb_bbox_t rect;
40 	nsfb_t *nsfb;
41 
42 	nsfb = fbtk_get_nsfb(widget);
43 
44 	fbtk_get_bbox(widget, &bbox);
45 
46 	rect = bbox;
47 
48 	nsfb_claim(nsfb, &bbox);
49 
50 	/* clear background */
51 	if ((widget->bg & 0xFF000000) != 0) {
52 		/* transparent polygon filling isnt working so fake it */
53 		nsfb_plot_rectangle_fill(nsfb, &bbox, widget->bg);
54 	}
55 
56 	/* plot the image */
57 	nsfb_plot_bitmap(nsfb,
58 			 &rect,
59 			 (nsfb_colour_t *)widget->u.bitmap.bitmap->pixdata,
60 			 widget->u.bitmap.bitmap->width,
61 			 widget->u.bitmap.bitmap->height,
62 			 widget->u.bitmap.bitmap->width,
63 			 !widget->u.bitmap.bitmap->opaque);
64 
65 	nsfb_update(nsfb, &bbox);
66 
67 	return 0;
68 }
69 
70 /* exported function documented in fbtk.h */
71 void
fbtk_set_bitmap(fbtk_widget_t * widget,struct fbtk_bitmap * image)72 fbtk_set_bitmap(fbtk_widget_t *widget, struct fbtk_bitmap *image)
73 {
74 	if ((widget == NULL) || (widget->type != FB_WIDGET_TYPE_BITMAP))
75 		return;
76 
77 	widget->u.bitmap.bitmap = image;
78 
79 	fbtk_request_redraw(widget);
80 }
81 
82 /* exported function documented in fbtk.h */
83 fbtk_widget_t *
fbtk_create_bitmap(fbtk_widget_t * parent,int x,int y,int width,int height,colour c,struct fbtk_bitmap * image)84 fbtk_create_bitmap(fbtk_widget_t *parent,
85 		   int x,
86 		   int y,
87 		   int width,
88 		   int height,
89 		   colour c,
90 		   struct fbtk_bitmap *image)
91 {
92 	fbtk_widget_t *neww;
93 
94 	neww = fbtk_widget_new(parent, FB_WIDGET_TYPE_BITMAP, x, y, width, height);
95 
96 	neww->bg = c;
97 	neww->mapped = true;
98 	neww->u.bitmap.bitmap = image;
99 
100 	fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_bitmap, NULL);
101 
102 	return neww;
103 }
104 
105 /* exported function documented in fbtk.h */
106 fbtk_widget_t *
fbtk_create_button(fbtk_widget_t * parent,int x,int y,int width,int height,colour c,struct fbtk_bitmap * image,fbtk_callback click,void * pw)107 fbtk_create_button(fbtk_widget_t *parent,
108 		   int x,
109 		   int y,
110 		   int width,
111 		   int height,
112 		   colour c,
113 		   struct fbtk_bitmap *image,
114 		   fbtk_callback click,
115 		   void *pw)
116 {
117 	fbtk_widget_t *neww;
118 
119 	neww = fbtk_widget_new(parent, FB_WIDGET_TYPE_BITMAP, x, y, width, height);
120 
121 	neww->bg = c;
122 	neww->mapped = true;
123 	neww->u.bitmap.bitmap = image;
124 
125 	fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_bitmap, NULL);
126 	fbtk_set_handler(neww, FBTK_CBT_CLICK, click, pw);
127 	fbtk_set_handler(neww, FBTK_CBT_POINTERENTER, fbtk_set_ptr, &hand_image);
128 
129 	return neww;
130 }
131 
132 /*
133  * Local Variables:
134  * c-basic-offset:8
135  * End:
136  */
137