use m4_normalize on the output strings to remove trailing spaces/tabs and consolidate...
[AROS.git] / workbench / c / iprefs / pointerprefs.c
blob1213395d4ed0b78e6e6f216a9f4f81545e014d68
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include "global.h"
13 #define DEBUG 0
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;
29 ip.BitMap = bm;
30 ip.XOffset = x;
31 ip.YOffset = y;
32 ip.BytesPerRow = bm->BytesPerRow;
33 ip.Size = size;
34 ip.YSize = ysize;
35 ip.Which = which;
37 SetIPrefs(&ip, sizeof(struct IPointerPrefs), IPREFS_TYPE_POINTER);
40 static void InstallPointer(struct PointerPrefs *pp, UWORD which)
42 struct BitMap bm;
43 struct ColorSpec *ic;
44 struct RGBTable *colors = (struct RGBTable *)&pp[1];
45 UWORD i;
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);
51 UBYTE *planes;
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);
66 if (ic) {
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;
73 colors++;
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
84 truecolor screens */
85 SetIPrefs(ic, ic_size, IPREFS_TYPE_OLD_PALETTE);
86 InstallBitMap(&bm, which, x, y, size, ysize);
87 FreeMem(ic, ic_size);
91 static LONG stopchunks[] =
93 ID_PREF, ID_PNTR,
94 ID_PREF, ID_NPTR
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)
101 Object *o;
102 struct BitMap *bm = NULL;
103 UWORD h_which;
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 */
109 if (!o) {
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);
113 return;
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);
129 DisposeDTObject(o);
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);
140 if (iff) {
141 while(ParseIFF(iff, IFFPARSE_SCAN) == 0)
143 struct ContextNode *cn;
145 cn = CurrentChunk(iff);
147 switch(cn->cn_ID) {
148 case ID_PNTR:
149 pp = LoadChunk(iff, sizeof(struct PointerPrefs), MEMF_CHIP);
150 if (pp) {
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));
155 FreeVec(pp);
157 break;
158 case ID_NPTR:
159 npp = LoadChunk(iff, sizeof(struct NewPointerPrefs), MEMF_ANY);
160 if (npp) {
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);
169 FreeVec(npp);
171 break;
174 KillIFF(iff);
178 void PointerPrefs_Handler(STRPTR filename)
180 D(bug("In IPrefs:PointerPrefs_Handler\n"));
181 LoadPointerPrefs(filename, -1, -1, 2);