chiark / gitweb /
Initial revision
[ssr] / StraySrc / Glass / !Glass / c / wGraph
1 /*
2  * wGraph.c
3  *
4  * Low-level graphics handling
5  *
6  * © 1994-1998 Straylight
7  */
8
9 /*----- Licensing note ----------------------------------------------------*
10  *
11  * This file is part of Straylight's Glass.
12  *
13  * Glass is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * Glass is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with Glass.  If not, write to the Free Software Foundation,
25  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26  */
27
28 /*----- Header files ------------------------------------------------------*/
29
30 /*
31  * ANSI standard headers
32  */
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 /*
39  * Steel headers
40  */
41
42 #define _STDAPP
43 #define _LOWLVL
44 #include "steel/Steel.h"
45
46 #include "steel/bbc.h"
47 #include "steel/colourtran.h"
48
49 /*
50  * Glass headers
51  */
52
53 #include "gStruct.h"
54 #include "gMenus.h"
55 #include "gIcons.h"
56
57 #include "glass.h"
58 #include "gPrefs.h"
59 #include "window.h"
60 #include "_window.h"
61
62 /*----- Private variables -------------------------------------------------*/
63
64 static int window__dashPos;      /* Current rotating dash position         */
65
66 /*----- Main code ---------------------------------------------------------*/
67
68 /*
69  * void window__colourChange(int col1,int col2)
70  *
71  * Use
72  *  Sets up the current foreground colour so that when plotted over colour
73  *  col1 it looks like col2 and vice-versa.  The effects of plotting over
74  *  other colours is defined to be psychedelically interesting, but not
75  *  pretty.
76  *
77  *  Basically, all it does is suss out what the colours really mean and XOR
78  *  them together.
79  *
80  * Parameters
81  *  int col1,int col2 == the Wimp colour numbers to swap between
82  */
83
84 void window__colourChange(int col1,int col2)
85 {
86   wimp_palettestr pal;
87   int x,y;
88   wimpt_noerr(wimp_readpalette(&pal));
89   wimpt_noerr(colourtran_return_colournumber(pal.c[col1],&x));
90   wimpt_noerr(colourtran_return_colournumber(pal.c[col2],&y));
91   if (os_swiv(XOS_SetColour,3,x^y))
92   {
93     if (wimpt_bpp()==8)
94     {
95       wimpt_noerr(colourtran_colournumbertoGCOL(x^y,&x));
96       bbc_vduq(18,3,x>>2);
97       bbc_vduq(23,17,2,(x & 3)<<6,0,0,0,0,0,0);
98     }
99     else
100       bbc_vduq(18,3,x^y);
101   }
102 }
103
104 /*
105  * void window__setXORColour(glass_windPointer *w,int col)
106  *
107  * Use
108  *  Sets up the current foreground colour so that it appears to be WIMP
109  *  colour col on the specified window background.  Lots of tedious
110  *  ColourTransing to do on this, with no real reward, but at least it will
111  *  look vaguely right in 256 colour modes.
112  *
113  * Parameters
114  *  glass_windPointer *w == the window in which to set the colour
115  *  int col == the colour to set
116  */
117
118 void window__setXORColour(glass_windPointer *w,int col)
119 {
120   int old=w->def->desc.w.colours[3];
121
122   /* --- Make sure the background isn't transparent --- */
123
124   if (old==255)
125     old=1;
126
127   window__colourChange(old,col);
128 }
129
130 /*
131  * void window__makeDashPattern(int ptn)
132  *
133  * Use
134  *  Sets the OS dash pattern to the given pattern (only the lowest byte
135  *  is considered).
136  *
137  * Parameters
138  *  int ptn == the LSB of this word contains the dash pattern as a bit
139  *   pattern
140  */
141
142 void window__makeDashPattern(int ptn)
143 {
144   int byte1,byte2;
145   byte1=242;
146   byte2=8;
147   wimpt_noerr(os_byte(163,&byte1,&byte2)); /* Dot-dash length              */
148   bbc_vduq(23,6,ptn,ptn,ptn,ptn,ptn,ptn,ptn,ptn);
149 }
150
151 /*
152  * void window__setDash(void)
153  *
154  * Use
155  *  Sets the dashed pattern so that it looks as if a 'rotating' box is being
156  *  dragged, like the WIMP's, only better...  The box is set up so that a
157  *  SINGLE exclusive-or plot will move the dash round.
158  */
159
160 #define SECTION(x,i) ((((x)<<(i)) & 0xff00) >> 8)
161
162 void window__setDash(void)
163 {
164   int dash=SECTION(0xFCFCFC,window__dashPos);
165   int newDash;
166   window__dashPos+=2;
167   if (window__dashPos>7)
168     window__dashPos=0;
169   newDash=SECTION(0xFCFCFC,window__dashPos);
170   dash^=newDash;
171   window__makeDashPattern(dash);
172   window__setXORColour(window__dragWind(),window__DRAGCOL);
173 }
174
175 /*
176  * void window__rotate(int by)
177  *
178  * Use
179  *  Rotates the current rotating-dash pattern by a given amount.  This is
180  *  used to rotate the dash box while the box is moving.
181  *
182  * Parameters
183  *  int by == the number of steps to rotate the dash pattern.
184  */
185
186 void window__rotate(int by)
187 {
188   window__dashPos+=by;
189   if (window__dashPos<0)
190     window__dashPos=6;
191   else if (window__dashPos>7)
192     window__dashPos=0;
193   window__makeDashPattern(SECTION(0xFCFCFC,window__dashPos));
194   window__setXORColour(window__dragWind(),window__DRAGCOL);
195 }
196
197 /*
198  * void window__rectangle(int x,int y,int w,int h)
199  *
200  * Use
201  *  Draws a rectangle, using the current dotted line pattern
202  *
203  * Parameters
204  *  int x == the left side of the rectangle
205  *  int y == the right side of the rectangle
206  *  int w == the width of the rectangle (may be <0)
207  *  int h == the height of the rectangle (may be <0)
208  */
209
210 void window__rectangle(int x,int y,int w,int h)
211 {
212   bbc_plot(bbc_DottedBoth+bbc_MoveCursorAbs,x,y);
213   bbc_plot(bbc_DottedBoth+bbc_DrawRelFore,0,h);
214   bbc_plot(bbc_DottedExInit+bbc_DrawRelFore,w,0);
215   bbc_plot(bbc_DottedExInit+bbc_DrawRelFore,0,-h);
216   bbc_plot(bbc_DottedExBoth+bbc_DrawRelFore,-w,0);
217 }