revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / devs / diskimage / ra_gui / images.c
blob9fba92ca9c88aadea2c7b9f0dc6a838c1faeed79
1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 **
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
9 **
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 #include "diskimagegui.h"
28 #include <proto/dos.h>
29 #include <proto/utility.h>
30 #include <proto/intuition.h>
32 extern struct ClassLibrary *PNGBase;
34 #ifndef BITMAP_DisabledSourceFile
35 #define BITMAP_DisabledSourceFile (BITMAP_Dummy + 19)
36 #endif
38 #define PNGObject NewObject(PNGBase->cl_Class, NULL
40 static BPTR FileExists (CONST_STRPTR dir, CONST_STRPTR file, STRPTR path, LONG path_size) {
41 struct Process *proc = (struct Process *)FindTask(NULL);
42 APTR window = proc->pr_WindowPtr;
43 BPTR fh;
44 Strlcpy(path, dir, path_size);
45 AddPart(path, file, path_size);
46 proc->pr_WindowPtr = (APTR)~0;
47 fh = Open(path, MODE_OLDFILE);
48 proc->pr_WindowPtr = window;
49 if (fh) Close(fh);
50 return fh;
53 BOOL FindImage (CONST_STRPTR image, STRPTR path, LONG path_size) {
54 return FileExists("PROGDIR:", image, path, path_size)
55 || FileExists("PROGDIR:Images", image, path, path_size)
56 || FileExists("SYS:Prefs/Presets/Images", image, path, path_size)
57 || FileExists("TBImages:", image, path, path_size);
60 Object *LoadImage (struct Screen *screen, CONST_STRPTR image, BOOL selected, BOOL disabled) {
61 TEXT normal_path[64];
62 TEXT selected_path[64];
63 TEXT disabled_path[64];
64 if (!FindImage(image, normal_path, sizeof(normal_path))) {
65 return NULL;
67 Strlcpy(selected_path, normal_path, sizeof(selected_path));
68 Strlcat(selected_path, "_s", sizeof(selected_path));
69 Strlcpy(disabled_path, normal_path, sizeof(disabled_path));
70 Strlcat(disabled_path, "_g", sizeof(disabled_path));
71 if (PNGBase) {
72 Object *image = PNGObject,
73 BITMAP_Screen, screen,
74 BITMAP_SourceFile, normal_path,
75 selected ? BITMAP_SelectSourceFile : TAG_IGNORE, selected_path,
76 disabled ? BITMAP_DisabledSourceFile : TAG_IGNORE, disabled_path,
77 End;
78 if (image) return image;
80 return BitMapObject,
81 BITMAP_Screen, screen,
82 BITMAP_SourceFile, normal_path,
83 selected ? BITMAP_SelectSourceFile : TAG_IGNORE, selected_path,
84 disabled ? BITMAP_DisabledSourceFile : TAG_IGNORE, disabled_path,
85 BITMAP_Masking, TRUE,
86 End;