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 #include <stdio.h>
23 #include <math.h>
24 
25 #include "brightonX11.h"
26 #include "brightoninternals.h"
27 
28 /*
29  * This will eventually go into a header file and be placed inside the bwin
30  * structure.
31  */
32 #define BRIGHTON_MENUPOSTED 0x0001
33 typedef struct BrightonMenuCtl {
34 	unsigned int flags;
35 	int origx, origy;
36 	int postx, posty;
37 	int postw, posth;
38 	void *deviceMenu; /* menu entries and source data, etc */
39 	int panel, device;
40 } brightonMenuCtl;
41 
42 brightonMenuCtl menu;
43 
44 int
brightonMenu(brightonWindow * bwin,int x,int y,int w,int h)45 brightonMenu(brightonWindow *bwin, int x, int y, int w, int h)
46 {
47 	int dx, dy, cw, ch = h, color;
48 	brightonBitmap *mlayer = bwin->mlayer;
49 
50 	if (menu.flags && BRIGHTON_MENUPOSTED)
51 	{
52 		brightonInitBitmap(bwin->mlayer, -1);
53 
54 		brightonDoFinalRender(bwin, menu.postx, menu.posty,
55 			menu.postw, menu.posth);
56 
57 		menu.flags &= ~BRIGHTON_MENUPOSTED;
58 
59 		return(-1);
60 	}
61 
62 	menu.origx = x;
63 	menu.origy = y;
64 	menu.postw = w;
65 	menu.posth = h;
66 
67 	/*
68 	 * Do some bounds checking to make sure the menubox even fits the window.
69 	 * The rhodesbass is small and all can be resized.
70 	 */
71 	if (((y + h) >= bwin->height) &&
72 		((y = bwin->height - h - 1) < 0))
73 		return(-1);
74 
75 	if (((x + w) >= bwin->width) &&
76 		((x = bwin->width - w - 1) < 0))
77 		return(-1);
78 
79 	/*
80 	 * Put a box in to represent a menu, just to test the results.
81 	 */
82 	dy = y * mlayer->width;
83 	dx = x;
84 
85 	/*
86 	 * Color of the border should be a parameter and we should consider finding
87 	 * if not inserting it.
88 	 */
89 	if ((color = brightonGetGC(bwin, 0xff00, 0xff00, 0x0000)) < 0)
90 	{
91 		printf("missed color\n");
92 		color = 1;
93 	}
94 
95 	for (; h > 0; h--)
96 	{
97 		for (cw = 0; cw < w; cw++)
98 			mlayer->pixels[dy + dx + cw] = color;
99 
100 		dy += mlayer->width;
101 	}
102 
103 	dy = (y + 1) * mlayer->width;
104 	dx = x + 1;
105 
106 	/*
107 	 * Color of the background should be a parameter and we should consider
108 	 * finding if not inserting it.
109 	 */
110 	if ((color = brightonGetGC(bwin, 0, 0, 0)) < 0)
111 	{
112 		printf("missed color\n");
113 		color = 1;
114 	}
115 
116 	for (h = ch; h > 2; h--)
117 	{
118 		for (cw = 0; cw < (w - 2); cw++)
119 			mlayer->pixels[dy + dx + cw] = color;
120 
121 		dy += mlayer->width;
122 	}
123 
124 	brightonDoFinalRender(bwin, x, y, w, ch);
125 
126 	menu.postx = x;
127 	menu.posty = y;
128 
129 	menu.flags |= BRIGHTON_MENUPOSTED;
130 
131 	return(-1);
132 }
133 
134