2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
9 /*********************************************************************************************/
14 #include <aros/debug.h>
15 #include <aros/macros.h>
16 #include <datatypes/pictureclass.h>
17 #include <prefs/prefhdr.h>
18 #include <prefs/pointer.h>
20 #include <intuition/iprefs.h>
21 #include <proto/datatypes.h>
23 /*********************************************************************************************/
25 static void InstallBitMap(struct BitMap
*bm
, UWORD which
, UWORD x
, UWORD y
, UWORD size
, UWORD ysize
)
27 struct IPointerPrefs ip
;
32 ip
.BytesPerRow
= bm
->BytesPerRow
;
37 SetIPrefs(&ip
, sizeof(struct IPointerPrefs
), IPREFS_TYPE_POINTER
);
40 static void InstallPointer(struct PointerPrefs
*pp
, UWORD which
)
44 struct RGBTable
*colors
= (struct RGBTable
*)&pp
[1];
46 UWORD width
= AROS_BE2WORD(pp
->pp_Width
);
47 UWORD height
= AROS_BE2WORD(pp
->pp_Height
);
48 UWORD depth
= AROS_BE2WORD(pp
->pp_Depth
);
49 UWORD ncols
= (1 << depth
) - 1;
50 ULONG ic_size
= (1 << depth
) * sizeof(struct ColorSpec
);
52 UWORD x
= AROS_BE2WORD(pp
->pp_X
);
53 UWORD y
= AROS_BE2WORD(pp
->pp_Y
);
54 UWORD size
= AROS_BE2WORD(pp
->pp_Size
);
55 UWORD ysize
= AROS_BE2WORD(pp
->pp_YSize
);
57 InitBitMap(&bm
, depth
, width
, height
);
59 D(bug("[PointerPrefs] Which: %d\n", which
));
60 D(bug("[PointerPrefs] Bitmap: %dx%dx%d\n", width
, height
, depth
));
61 D(bug("[PointerPrefs] Size: %d\n", size
));
62 D(bug("[PointerPrefs] YSize: %d\n", ysize
));
63 D(bug("[PointerPrefs] Hotspot: (%d, %d)\n", x
, y
));
65 ic
= AllocMem(ic_size
, MEMF_ANY
);
67 for (i
= 0; i
< ncols
; i
++) {
68 D(bug("[PointerPrefs] Color %u RGB 0x%02X%02X%02X\n", i
, colors
->t_Red
, colors
->t_Green
, colors
->t_Blue
));
69 ic
[i
].ColorIndex
= i
+ 8; /* Pointer colors have numbers 8-10 in the intuition's internal table */
70 ic
[i
].Red
= colors
->t_Red
* 0x0101;
71 ic
[i
].Green
= colors
->t_Green
* 0x0101;
72 ic
[i
].Blue
= colors
->t_Blue
* 0x0101;
75 ic
[ncols
].ColorIndex
= -1; /* Terminator */
77 planes
= (UBYTE
*)colors
;
78 for (i
= 0; i
< depth
; i
++) {
79 bm
.Planes
[i
] = planes
;
80 planes
+= bm
.BytesPerRow
* height
;
83 /* First change palette, then image. It is important in order to get correct colors on
85 SetIPrefs(ic
, ic_size
, IPREFS_TYPE_OLD_PALETTE
);
86 InstallBitMap(&bm
, which
, x
, y
, size
, ysize
);
91 static LONG stopchunks
[] =
97 static void LoadPointerPrefs(STRPTR filename
, WORD which
, WORD installas
, LONG numstopchunks
);
99 static void LoadPointerFile(STRPTR filename
, ULONG which
, UWORD installas
, UWORD x
, UWORD y
)
102 struct BitMap
*bm
= NULL
;
105 D(bug("[PointerPrefs] Load file: %s\n", filename
));
106 o
= NewDTObject(filename
, DTA_GroupID
, GID_PICTURE
, PDTA_Remap
, FALSE
, TAG_DONE
);
107 D(bug("[PointerPrefs] Datatype object: 0x%p\n", o
));
108 /* If datatypes failed, try to load AmigaOS 3.x prefs file */
110 /* Set numstopchunks to 1 because we want to avoid recursion
111 if someone specifies new pointer prefs file as a target */
112 LoadPointerPrefs(filename
, which
, installas
, 1);
116 if (DoDTMethod(o
, NULL
, NULL
, DTM_PROCLAYOUT
, NULL
, TRUE
)) {
117 D(bug("[PointerPrefs] Layout complete\n"));
119 h_which
= AROS_BE2WORD(installas
);
120 GetDTAttrs(o
, PDTA_DestBitMap
, &bm
, TAG_DONE
);
121 D(bug("[PointerPrers] BitMap: 0x%p\n", bm
));
122 D(bug("[PointerPrefs] Which: %d\n", h_which
));
123 D(bug("[PointerPrefs] Size: %dx%d\n", bm
->BytesPerRow
* 8, bm
->Rows
));
124 D(bug("[PointerPrefs] Hotspot: (%d, %d)\n", x
, y
));
125 /* FIXME: What are actually Size and YSize ? */
126 InstallBitMap(bm
, h_which
, x
, y
, 0, 0);
132 static void LoadPointerPrefs(STRPTR filename
, WORD which
, WORD installas
, LONG numstopchunks
)
134 struct IFFHandle
*iff
;
135 struct PointerPrefs
*pp
;
136 struct NewPointerPrefs
*npp
;
138 D(bug("[PointerPrefs] filename=%s\n",filename
));
139 iff
= CreateIFF(filename
, stopchunks
, numstopchunks
);
141 while(ParseIFF(iff
, IFFPARSE_SCAN
) == 0)
143 struct ContextNode
*cn
;
145 cn
= CurrentChunk(iff
);
149 pp
= LoadChunk(iff
, sizeof(struct PointerPrefs
), MEMF_CHIP
);
151 D(bug("[PointerPrefs] Got AmigaOS 3.0 pointer chunk, code is %d\n", AROS_BE2WORD(pp
->pp_Which
)));
152 if ((which
== -1) || (which
== pp
->pp_Which
)) {
153 InstallPointer(pp
, AROS_BE2WORD((installas
== -1) ? pp
->pp_Which
: installas
));
159 npp
= LoadChunk(iff
, sizeof(struct NewPointerPrefs
), MEMF_ANY
);
161 UWORD alpha
= AROS_BE2WORD(npp
->npp_AlphaValue
);
162 UWORD x
= AROS_BE2WORD(npp
->npp_X
);
163 UWORD y
= AROS_BE2WORD(npp
->npp_Y
);
165 D(bug("[PointerPrefs] Got new pointer chunk\n"));
166 D(bug("[PointerPrefs] Which %u, alpha: 0x%04X\n", AROS_BE2WORD(npp
->npp_Which
), alpha
));
167 SetIPrefs(&alpha
, sizeof(alpha
), IPREFS_TYPE_POINTER_ALPHA
);
168 LoadPointerFile(npp
->npp_File
, npp
->npp_WhichInFile
, npp
->npp_Which
, x
, y
);
178 void PointerPrefs_Handler(STRPTR filename
)
180 D(bug("In IPrefs:PointerPrefs_Handler\n"));
181 LoadPointerPrefs(filename
, -1, -1, 2);