1 
2 /*
3  *  Diverse Bristol audio routines.
4  *  Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
5  *
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License as published by
9  *   the Free Software Foundation; either version 3 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This program 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 
22 /*
23  * Render a brightonBitmap into an area.
24  */
25 #include "brightoninternals.h"
26 
27 int
destroyPic(brightonDevice * dev)28 destroyPic(brightonDevice *dev)
29 {
30 	printf("destroyPic()\n");
31 
32 	if (dev->image)
33 		brightonFreeBitmap(dev->bwin, dev->image);
34 
35 	dev->image = NULL;
36 
37 	return(0);
38 }
39 
40 static int
displayPic(brightonDevice * dev)41 displayPic(brightonDevice *dev)
42 {
43 	brightonIResource *panel;
44 
45 /*printf("displayPic\n"); */
46 	/*
47 	 * We should render any text we desire into the bmap, and then have it
48 	 * painted
49 	 */
50 	if (dev->bwin->app->resources[dev->panel].flags & BRIGHTON_WITHDRAWN)
51 		return(0);
52 
53 	panel = &dev->bwin->app->resources[dev->panel];
54 
55 	brightonDevUndraw(dev->bwin, dev->bwin->dlayer,
56 		dev->x + dev->bwin->app->resources[dev->panel].sx,
57 		dev->y + dev->bwin->app->resources[dev->panel].sy,
58 		dev->width, dev->height);
59 
60 	/*
61 	 * Only draw fixed number of steps.
62 	 */
63 	brightonStretch(dev->bwin, dev->image,
64 		dev->bwin->dlayer,
65 		dev->x + dev->bwin->app->resources[dev->panel].sx,
66 		dev->y + dev->bwin->app->resources[dev->panel].sy,
67 		dev->width, dev->height,
68 		dev->position);
69 
70 	brightonFinalRender(dev->bwin,
71 		dev->x + dev->bwin->app->resources[dev->panel].sx,
72 		dev->y + dev->bwin->app->resources[dev->panel].sy,
73 		dev->width, dev->height);
74 
75 	return(0);
76 }
77 
78 static int
configure(brightonDevice * dev,brightonEvent * event)79 configure(brightonDevice *dev, brightonEvent *event)
80 {
81 	/*printf("configurePic(%i)\n", event->command); */
82 
83 	if (event->command == -1)
84 		return(-1);
85 
86 	if (event->command == BRIGHTON_RESIZE)
87 	{
88 		dev->originx = event->x;
89 		dev->originy = event->y;
90 
91 		dev->x = event->x;
92 		dev->y = event->y;
93 		dev->width = event->w;
94 		dev->height = event->h;
95 
96 		displayPic(dev);
97 
98 		return(0);
99 	}
100 
101 	if (event->command == BRIGHTON_PARAMCHANGE)
102 	{
103 		/*
104 		 * This will be used to configure different background images
105 		 */
106 		if ((event->type == BRIGHTON_MEM) && (event->m != 0))
107 		{
108 			if (dev->image)
109 				brightonFreeBitmap(dev->bwin, dev->image);
110 
111 			dev->image = brightonReadImage(dev->bwin, event->m);
112 
113 			displayPic(dev);
114 		}
115 	}
116 
117 	return(0);
118 }
119 
120 int *
createPic(brightonWindow * bwin,brightonDevice * dev,int index,char * bitmap)121 createPic(brightonWindow *bwin, brightonDevice *dev, int index, char *bitmap)
122 {
123 	/*printf("createPic(%s)\n", bitmap); */
124 
125 	dev->destroy = destroyPic;
126 	dev->configure = configure;
127 	dev->bwin = bwin;
128 
129 	if (bitmap != 0)
130 	{
131 		if (dev->image)
132 			brightonFreeBitmap(bwin, dev->image);
133 		dev->image = brightonReadImage(bwin, bitmap);
134 	}
135 
136 	/*
137 	 * These will force an update when we first display ourselves.
138 	 */
139 	dev->value = 0;
140 	dev->lastvalue = -1;
141 	dev->lastposition = -1;
142 
143 	return(0);
144 }
145 
146