corrections to check for existing files.
[AROS-Contrib.git] / dopus / Library / imagery.c
bloba450aee71f8aa0748fb47e522ec61e0dbc2f479e
1 /*
3 Directory Opus 4
4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
31 #define PROTO_DOPUS_H
32 #include <dopus/dopusbase.h>
33 #include "dopuslib.h"
35 extern __chip UWORD pdb_cycletop[];
36 extern __chip UWORD pdb_cyclebot[];
37 extern __chip UWORD pdb_check[];
39 struct Image * __regargs get_image_data(struct DOpusRemember **key,int width,int height,int depth,struct BitMap *bm,struct RastPort *rp)
41 struct Image *image;
42 UWORD *data;
43 short a,words;
45 words=(width+15)/16;
47 if (!(image=DoAllocRemember(key,sizeof(struct Image),MEMF_CLEAR)) ||
48 !(data=DoAllocRemember(key,words*2*height*depth,MEMF_CHIP|MEMF_CLEAR)))
49 return(NULL);
51 InitBitMap(bm,depth,width,height);
52 for (a=0;a<depth;a++) bm->Planes[a]=(PLANEPTR)&data[words*height*a];
53 InitRastPort(rp);
54 rp->BitMap=bm;
56 image->Width=width;
57 image->Height=height;
58 image->Depth=depth;
59 image->ImageData=data;
60 image->PlanePick=(1<<depth)-1;
62 return(image);
65 __inline void drawline(rp,x1,y1,x2,y2)
66 struct RastPort *rp;
67 int x1,y1,x2,y2;
69 Move(rp,x1,y1);
70 Draw(rp,x2,y2);
73 #define drawline(rp,x1,y1,x2,y2) Move(rp,x1,y1);Draw(rp,x2,y2)
75 void __saveds Do3DBox(register struct RastPort *rp __asm("a0"),register int x __asm("d0"),register int y __asm("d1"),register int w __asm("d2"),register int h __asm("d3"),register int tp __asm("d4"),register int bp __asm("d5"))
77 //D(bug("Do3DBox()\n"));
78 SetAPen(rp,tp);
80 drawline(rp,x-2,y-1,x+w,y-1);
81 drawline(rp,x-2,y-1,x-2,y+h);
82 drawline(rp,x-1,y-1,x-1,y+h-1);
84 SetAPen(rp,bp);
86 drawline(rp,x-1,y+h,x+w+1,y+h);
87 Draw(rp,x+w+1,y-1);
89 drawline(rp,x+w,y+h,x+w,y);
92 void __saveds Do3DStringBox(register struct RastPort *rp __asm("a0"),register int x __asm("d0"),register int y __asm("d1"),register int w __asm("d2"),register int h __asm("d3"),register int tp __asm("d4"),register int bp __asm("d5"))
94 //D(bug("Do3DStringBox()\n"));
95 Do3DBox(rp,x-2,y-1,w+4,h+2,tp,bp);
97 SetAPen(rp,bp);
99 drawline(rp,x-2,y-1,x+w+1,y-1);
100 drawline(rp,x-2,y-1,x-2,y+h+1);
101 drawline(rp,x-1,y-1,x-1,y+h-1);
103 SetAPen(rp,tp);
105 drawline(rp,x-1,y+h,x+w+1,y+h);
106 Draw(rp,x+w+1,y-1);
108 drawline(rp,x+w,y+h,x+w,y);
111 void __saveds Do3DCycleBox(register struct RastPort *rp __asm("a0"),register int x __asm("d0"),register int y __asm("d1"),register int w __asm("d2"),register int h __asm("d3"),register int tp __asm("d4"),register int bp __asm("d5"))
113 UBYTE old_drmd;
115 //D(bug("Do3DCycleBox(%lx,%lx)\n",pdb_cycletop,pdb_cyclebot));
116 Do3DBox(rp,x,y,w,h,tp,bp);
118 old_drmd = GetDrMd(rp);
119 SetDrMd(rp,JAM1);
121 SetAPen(rp,bp);
123 if (/*DOpusBase->*/pdb_cycletop)
125 BltTemplate(/*DOpusBase->*/pdb_cycletop,0,2,rp,x+4,y+1,11,6);
127 if (/*DOpusBase->*/pdb_cyclebot)
129 BltTemplate(/*DOpusBase->*/pdb_cyclebot,0,2,rp,x+4,y+1+h-12+7,11,2);
132 drawline(rp,x+4,y+7,x+4,/*y+7+*/y+1+h-12+7/*-12*/);
133 drawline(rp,x+5,y+7,x+5,/*y+7+*/y+1+h-12+7/*-12*/);
134 drawline(rp,x+18,y+1,x+18,y+h-2);
136 SetAPen(rp,tp);
138 drawline(rp,x+19,y+1,x+19,y+h-2);
140 SetDrMd(rp,old_drmd);
143 void __saveds DrawCheckMark(register struct RastPort *rp __asm("a0"),register int x __asm("d0"),register int y __asm("d1"),register int clear __asm("d2"))
145 UBYTE old_apen;
146 UBYTE old_drmd = GetDrMd(rp);
148 D(bug("DrawCheckMark(%lx)\n",pdb_check));
149 SetDrMd(rp,JAM1);
151 if (clear==0)
153 old_apen = GetAPen(rp);
154 SetAPen(rp,GetBPen(rp));
156 if (/*DOpusBase->*/pdb_check)
158 BltTemplate(/*DOpusBase->*/pdb_check,0,2,rp,x,y,13,7);
160 if (clear==0)
162 SetAPen(rp,old_apen);
164 SetDrMd(rp,old_drmd);
167 void __saveds DoDoArrow(register struct RastPort *p __asm("a0"), register int x __asm("d0"), register int y __asm("d1"), register int w __asm("d2"), register int h __asm("d3"), register int fg __asm("d4"), register int bg __asm("d5"), register int d __asm("d6"))
169 int x1,y1,x2,y2,x3,y3,x4,y4,xb;
171 SetAPen(p,bg);
172 xb=x+w;
173 RectFill(p,x,y,xb-1,y+h-1);
174 SetAPen(p,fg);
175 switch (d) {
176 case 0:
177 y1=y+h-2;
178 y3=y+1;
179 goto sameupdown;
181 case 1:
182 y1=y+1;
183 y3=y+h-2;
184 sameupdown:
185 x1=x+2;
186 x2=xb-3;
187 x3=x+(w/2)-1;
188 x4=xb-(w/2);
189 y2=y1;
190 y4=y3;
191 break;
193 case 2:
194 x1=x+1;
195 x3=xb-2;
196 goto sameleftright;
198 default:
199 // case 3:
200 x1=xb-2;
201 x3=x+1;
202 sameleftright:
203 x2=x1;
204 y1=y+1;
205 y2=y+h-2;
206 y3=y+(h/2);
207 if (h%2==0) --y3;
208 x4=x3;
209 y4=y3;
210 break;
212 drawline(p,x1,y1,x3,y3);
213 drawline(p,x2,y2,x4,y4);
216 void __saveds DoDrawRadioButton(register struct RastPort *rp __asm("a0"), register int x __asm("d0"), register int y __asm("d1"), register int w __asm("d2"), register int h __asm("d3"), register int hi __asm("d4"), register int lo __asm("d5"))
218 SetAPen(rp,hi);
219 drawline(rp,x,y-1,x+w-3,y-1);
220 drawline(rp,x-1,y,x,y);
221 drawline(rp,x-2,y+1,x-2,y+h-4);
222 drawline(rp,x-1,y+1,x-1,y+h-4);
223 drawline(rp,x-1,y+h-3,x,y+h-3);
224 SetAPen(rp,lo);
225 drawline(rp,x,y+h-2,x+w-3,y+h-2);
226 drawline(rp,x+w-3,y+h-3,x+w-2,y+h-3);
227 drawline(rp,x+w-1,y+h-4,x+w-1,y+1);
228 drawline(rp,x+w-2,y+h-4,x+w-2,y+1);
229 drawline(rp,x+w-3,y,x+w-2,y);
232 __saveds struct Image *DoGetButtonImage(register int w __asm("d0"), register int h __asm("d1"), register int fg __asm("d2"), register int bg __asm("d3"), register int fpen __asm("d4"), register int bpen __asm("d5"), register struct DOpusRemember **key __asm("a0"))
234 struct Image *image;
235 short a,b,depth;
236 struct BitMap tbm;
237 struct RastPort trp;
239 b=(fg>bg)?fg:bg;
240 if (fpen>b) b=fpen;
241 if (bpen>b) b=bpen;
243 depth=2; w+=4;
244 for (a=0;a<8;a++) if (b&(1<<a)) depth=a+1;
246 if (!(image=get_image_data(key,w,h,depth,&tbm,&trp))) return(NULL);
248 SetAPen(&trp,bpen);
249 RectFill(&trp,0,0,w-1,h-1);
250 DoDrawRadioButton(&trp,2,1,w-4,h,(fpen!=bpen)?bg:fg,(fpen!=bpen)?fg:bg);
251 if (w>10 && h>4 && fpen!=bpen) {
252 SetAPen(&trp,fpen);
253 RectFill(&trp,4,2,w-7,h-3);
254 SetAPen(&trp,bpen);
255 WritePixel(&trp,4,2);
256 WritePixel(&trp,4,h-3);
257 WritePixel(&trp,w-7,2);
258 WritePixel(&trp,w-7,h-3);
261 image->LeftEdge=-2;
262 image->TopEdge=-1;
263 return(image);
266 __saveds struct Image *DoGetCheckImage(register UBYTE fg __asm("d0"), register UBYTE bg __asm("d1"), register int pen __asm("d2"), register struct DOpusRemember **key __asm("a0"))
268 struct Image *image;
269 int a,b,depth;
270 struct BitMap tbm;
271 struct RastPort trp;
273 D(bug("DoGetCheckImage: fg = %ld, bg = %ld\n",fg,bg));
274 b=(fg>bg)?fg:bg;
275 depth=2;
276 for (a=0;a<8;a++) if (b&(1<<a)) depth=a+1;
278 if (!(image=get_image_data(key,13,7,depth,&tbm,&trp))) return(NULL);
280 SetDrMd(&trp,JAM1);
281 SetAPen(&trp,bg);
282 RectFill(&trp,0,0,12,6);
283 if (pen) {
284 SetAPen(&trp,fg);
285 BltTemplate(/*(char *)DOpusBase->*/pdb_check,0,2,&trp,0,0,13,7);
288 image->LeftEdge=7;
289 image->TopEdge=2;
290 return(image);
293 void __saveds DoDo3DFrame(register struct RastPort *rp __asm("a0"), register int x __asm("d0"), register int y __asm("d1"), register int w __asm("d2"), register int h __asm("d3"), register char *title __asm("a1"), register int hi __asm("d4"), register int lo __asm("d5"))
295 char of,ob;
296 int a,l;
298 of=rp->FgPen; ob=rp->BgPen;
299 Do3DBox(rp,x+2,y+1,w-4,h-2,lo,hi);
300 Do3DBox(rp,x+4,y+2,w-8,h-4,hi,lo);
301 SetAPen(rp,of); SetBPen(rp,ob);
302 if (title) {
303 a=strlen(title);
304 x+=((w-(l=(TextLength(rp,title,a))))/2);
305 SetAPen(rp,ob);
306 RectFill(rp,
307 x-rp->Font->tf_XSize/2,y+2-rp->Font->tf_Baseline,
308 x+l+rp->Font->tf_XSize/2,y+2-rp->Font->tf_Baseline+rp->Font->tf_YSize);
309 SetAPen(rp,of);
310 Move(rp,x,y+2); Text(rp,title,a);
314 extern UWORD __chip glass_image1[];
315 extern UWORD __chip glass_image2[];
317 void __saveds DoDoGlassImage(register struct RastPort *rp __asm("a0"), register struct Gadget *gadget __asm("a1"), register int shine __asm("d0"), register int shadow __asm("d1"), register int type __asm("d2"))
319 int x,y;
320 char op,om;
322 om=rp->DrawMode; op=rp->FgPen;
323 SetDrMd(rp,JAM1);
325 if (type==0) {
326 x=gadget->LeftEdge+((gadget->Width-16)/2);
327 y=gadget->TopEdge+((gadget->Height-8)/2);
329 SetAPen(rp,shine);
330 BltTemplate((char *)glass_image2,0,2,rp,x,y,16,8);
331 SetAPen(rp,shadow);
332 BltTemplate((char *)glass_image1,0,2,rp,x,y,16,8);
335 SetAPen(rp,op);
336 SetDrMd(rp,om);