2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
9 /*********************************************************************************************/
14 #include "earthmap_small_image.c"
15 #include "timezones_small_image.c"
17 /*********************************************************************************************/
19 #define DOUBLE_ARROWS 1
21 #define CONTINENT_RED 18
22 #define CONTINENT_GREEN 114
23 #define CONTINENT_BLUE 58
26 #define OCEAN_GREEN 18
27 #define OCEAN_BLUE 114
29 #define SELECTED_INTENSITY_INC 80
35 /*********************************************************************************************/
37 #define NUM_TIMEZONES 36
39 static struct timezone
45 timezone_table
[NUM_TIMEZONES
] =
47 { 0, 0 }, /* Z : 0:00 */
48 { 1, 1 * 60 }, /* A : + 1:00 */
49 { 2, 2 * 60 }, /* B : + 2:00 */
50 { 3, 3 * 60 }, /* C : + 3:00 */
51 { 4, 3 * 60 + 30 }, /* C*: + 3:30 */
52 { 5, 4 * 60 }, /* D : + 4:00 */
53 { 6, 4 * 60 + 30 }, /* D*: + 4:30 */
54 { 7, 5 * 60 }, /* E : + 5:00 */
55 { 8, 5 * 60 + 30 }, /* E*: + 5:30 */
56 { 9, 6 * 60 }, /* F : + 6:00 */
57 { 10, 6 * 60 + 30 }, /* F*: + 6:30 */
58 { 11, 7 * 60 }, /* G : + 7:00 */
59 { 12, 8 * 60 }, /* H : + 8:00 */
60 { 13, 9 * 60 }, /* I : + 9:00 */
61 { 14, 9 * 60 + 30 }, /* I*: + 9:30 */
62 { 15, 10 * 60 }, /* K : + 10:00 */
63 { 16, 10 * 60 + 30 }, /* K*: + 10:30 */
64 { 17, 11 * 60 }, /* L : + 11:00 */
65 { 18, 11 * 60 + 30 }, /* L*: + 11:30 */
66 { 19, 12 * 60 }, /* M : + 12:00 */
67 { 20, 13 * 60 }, /* M*: + 13:00 */
68 { 35, -12 * 60 }, /* Y : - 12:00 */
69 { 34, -11 * 60 }, /* X : - 11:00 */
70 { 33, -10 * 60 }, /* W : - 10:00 */
71 { 32, -9 * 60 - 30 }, /* V*: - 9:30 */
72 { 31, -9 * 60 }, /* V : - 9:00 */
73 { 30, -8 * 60 - 30 }, /* U*: - 8:30 */
74 { 29, -8 * 60 }, /* U : - 8:00 */
75 { 28, -7 * 60 }, /* T : - 7:00 */
76 { 27, -6 * 60 }, /* S : - 6:00 */
77 { 26, -5 * 60 }, /* R : - 5:00 */
78 { 25, -4 * 60 }, /* Q : - 4:00 */
79 { 24, -3 * 60 - 30 }, /* P*: - 3:30 */
80 { 23, -3 * 60 }, /* P : - 3:00 */
81 { 22, -2 * 60 }, /* O : - 2:00 */
82 { 21, -1 * 60 }, /* N : - 1:00 */
86 /*********************************************************************************************/
88 static struct Gadget
*gadlist
, *textgad
, *gad
;
89 static WORD minwidth
, minheight
;
90 static WORD domleft
, domtop
, domwidth
, domheight
;
91 static WORD active_timezone
;
92 static BOOL init_done
;
94 static UBYTE timezones_chunky
[TIMEZONES_SMALL_WIDTH
* TIMEZONES_SMALL_HEIGHT
];
95 static UBYTE earthmap_chunky
[EARTHMAP_SMALL_WIDTH
* EARTHMAP_SMALL_HEIGHT
];
96 static UBYTE
*earthmap_chunky_remapped
;
98 static ULONG earthmap_coltab
[256];
99 static WORD remaptable
[256];
100 static UBYTE timezone_text
[256];
101 static WORD pen2index
[NUM_TIMEZONES
];
103 static BOOL pens_alloced
, page_active
;
105 /*********************************************************************************************/
107 #if EARTHMAP_SMALL_PACKED || TIMEZONES_SMALL_PACKED
109 static UBYTE
*unpack_byterun1(UBYTE
*source
, UBYTE
*dest
, LONG unpackedsize
)
116 c
= (BYTE
)(*source
++);
122 if (--unpackedsize
<= 0) return source
;
133 if (--unpackedsize
<= 0) return source
;
142 /*********************************************************************************************/
144 static LONG
timezone_init(void)
150 earthmap_chunky_remapped
= AllocVec(EARTHMAP_SMALL_WIDTH
* EARTHMAP_SMALL_HEIGHT
, MEMF_PUBLIC
);
151 if (!earthmap_chunky_remapped
) return FALSE
;
154 #if EARTHMAP_SMALL_PACKED
155 unpack_byterun1(earthmap_small_data
, earthmap_chunky
, EARTHMAP_SMALL_WIDTH
* EARTHMAP_SMALL_HEIGHT
);
157 #if TIMEZONES_SMALL_PACKED
158 unpack_byterun1(timezones_small_data
, timezones_chunky
, TIMEZONES_SMALL_WIDTH
* TIMEZONES_SMALL_HEIGHT
);
162 for(i
= 0; i
< EARTHMAP_SMALL_COLORS
; i
++)
164 static struct TagItem obp_tags
[] =
166 {OBP_Precision
, PRECISION_IMAGE
},
167 {OBP_FailIfBad
, FALSE
},
170 ULONG rgb
= earthmap_small_pal
[i
];
171 ULONG r
= (rgb
& 0xFF0000) >> 16;
172 ULONG g
= (rgb
& 0x00FF00) >> 8;
173 ULONG b
= (rgb
& 0x0000FF);
174 ULONG a
= (r
+ g
+ b
) / 3;
176 r
= (a
* OCEAN_RED
+ (255 - a
) * CONTINENT_RED
) / 255;
177 g
= (a
* OCEAN_GREEN
+ (255 - a
) * CONTINENT_GREEN
) / 255;
178 b
= (a
* OCEAN_BLUE
+ (255 - a
) * CONTINENT_BLUE
) / 255;
180 rgb
= (r
<< 16) + (g
<< 8) + b
;
182 earthmap_coltab
[i
] = rgb
;
186 remaptable
[i
] = ObtainBestPenA(scr
->ViewPort
.ColorMap
,
193 r
+= SELECTED_INTENSITY_INC
; if (r
> 255) r
= 255;
194 g
+= SELECTED_INTENSITY_INC
; if (g
> 255) g
= 255;
195 b
+= SELECTED_INTENSITY_INC
; if (b
> 255) b
= 255;
197 rgb
= (r
<< 16) + (g
<< 8) + b
;
199 earthmap_coltab
[128 + i
] = rgb
;
203 remaptable
[128 + i
] = ObtainBestPenA(scr
->ViewPort
.ColorMap
,
212 if (!truecolor
) pens_alloced
= TRUE
;
214 /* For each timezone find out, with which pen (index) it is
215 represented in the timezones image */
217 for(i
= 0; i
< NUM_TIMEZONES
; i
++)
219 WORD id
= timezone_table
[i
].id
;
221 ULONG r
= ((id
& 0x30) >> 4) * 64;
222 ULONG g
= ((id
& 0x0C) >> 2) * 64;
223 ULONG b
= ((id
& 0x03) ) * 64;
224 ULONG rgb
= (r
<< 16) + (g
<< 8) + b
;
226 timezone_table
[i
].pen
= -1;
227 for(i2
= 0; i2
< TIMEZONES_SMALL_COLORS
; i2
++)
229 if (timezones_small_pal
[i2
] == rgb
)
231 timezone_table
[i
].pen
= i2
;
244 /*********************************************************************************************/
246 static void ClearEarthmapSelection(void)
250 for(l
= 0; l
< EARTHMAP_SMALL_WIDTH
* EARTHMAP_SMALL_HEIGHT
; l
++)
252 earthmap_chunky
[l
] &= 127;
256 /*********************************************************************************************/
258 static void SetEarthmapSelection(UBYTE timezonespen
)
262 for(l
= 0; l
< EARTHMAP_SMALL_WIDTH
* EARTHMAP_SMALL_HEIGHT
; l
++)
264 if (timezones_chunky
[l
] == timezonespen
) earthmap_chunky
[l
] |= 128;
268 /*********************************************************************************************/
270 static void RepaintEarthmap(void)
277 minoffset
= timezone_table
[active_timezone
].minoffset
;
278 if (minoffset
< 0) minoffset
= -minoffset
;
282 WriteLUTPixelArray(earthmap_chunky
,
285 EARTHMAP_SMALL_WIDTH
,
290 EARTHMAP_SMALL_WIDTH
,
291 EARTHMAP_SMALL_HEIGHT
,
298 for(l
= 0; l
< EARTHMAP_SMALL_WIDTH
* EARTHMAP_SMALL_HEIGHT
; l
++)
300 earthmap_chunky_remapped
[l
] = remaptable
[earthmap_chunky
[l
]];
303 WriteChunkyPixels(win
->RPort
,
306 domleft
+ 1 + EARTHMAP_SMALL_WIDTH
- 1,
307 domtop
+ 1 + EARTHMAP_SMALL_HEIGHT
- 1,
308 earthmap_chunky_remapped
,
309 EARTHMAP_SMALL_WIDTH
);
314 fmt
= MSG(MSG_TIMEZONE_1HOUR
);
316 else if (minoffset
% 60)
318 fmt
= MSG(MSG_TIMEZONE_HOURSMINS
);
322 fmt
= MSG(MSG_TIMEZONE_HOURS
);
325 sprintf(timezone_text
, fmt
, minoffset
/ 60, minoffset
% 60);
327 GT_SetGadgetAttrs(textgad
, win
, NULL
, GTTX_Text
, (IPTR
)timezone_text
,
330 } /* if (page_active) */
333 /*********************************************************************************************/
335 static void scroll_timezone(WORD delta
)
337 active_timezone
+= delta
;
339 if (active_timezone
< 0)
341 active_timezone
= NUM_TIMEZONES
- 1;
343 else if (active_timezone
>= NUM_TIMEZONES
)
348 ClearEarthmapSelection();
349 SetEarthmapSelection(timezone_table
[active_timezone
].pen
);
353 /*********************************************************************************************/
355 static LONG
timezone_input(struct IntuiMessage
*msg
)
359 if ((msg
->Class
== IDCMP_MOUSEBUTTONS
) && (msg
->Code
== SELECTDOWN
))
361 WORD x
= msg
->MouseX
- (domleft
+ 1);
362 WORD y
= msg
->MouseY
- (domtop
+ 1);
366 (x
<= domwidth
- 2) &&
367 (y
<= domheight
- 2))
375 timezonepen
= timezones_chunky
[y
* TIMEZONES_SMALL_WIDTH
+ x
];
376 timezonergb
= timezones_small_pal
[timezonepen
];
377 timezoneid
= (timezonergb
& 0xC00000) >> (16 + 2);
378 timezoneid
+= (timezonergb
& 0x00C000) >> (8 + 4);
379 timezoneid
+= (timezonergb
& 0x0000C0) >> (0 + 6);
381 if ((timezoneid
>= 0) && (timezoneid
< NUM_TIMEZONES
))
383 active_timezone
= pen2index
[timezoneid
];
385 /* AmigaOS seems to have the sign the other way round, therefore the "-" */
387 localeprefs
.lp_GMTOffset
= -timezone_table
[active_timezone
].minoffset
;
389 ClearEarthmapSelection();
390 SetEarthmapSelection(timezonepen
);
398 else if ((msg
->Class
== IDCMP_RAWKEY
))
414 else if ((msg
->Class
== IDCMP_GADGETUP
))
416 struct Gadget
*gad
= (struct Gadget
*)msg
->IAddress
;
418 switch(gad
->GadgetID
)
435 /*********************************************************************************************/
437 static void timezone_cleanup(void)
441 if (earthmap_chunky_remapped
)
443 FreeVec(earthmap_chunky_remapped
);
444 earthmap_chunky_remapped
= NULL
;
449 for(i
= 0; i
< EARTHMAP_SMALL_COLORS
; i
++)
451 if (remaptable
[i
] != -1) ReleasePen(scr
->ViewPort
.ColorMap
, remaptable
[i
]);
452 if (remaptable
[128 + i
] != -1) ReleasePen(scr
->ViewPort
.ColorMap
, remaptable
[128 + i
]);
454 pens_alloced
= FALSE
;
457 if (gadlist
) FreeGadgets(gadlist
);
461 /*********************************************************************************************/
463 static LONG
timezone_makegadgets(void)
468 w
= dri
->dri_Font
->tf_XSize
+ 8;
470 gad
= CreateContext(&gadlist
);
472 ng
.ng_LeftEdge
= domleft
;
473 ng
.ng_TopEdge
= domtop
+ EARTHMAP_SMALL_HEIGHT
+ 2 + SPACE_Y
;
475 ng
.ng_Height
= dri
->dri_Font
->tf_YSize
+ BUTTON_EXTRAHEIGHT
;
476 ng
.ng_GadgetText
= "<";
478 ng
.ng_GadgetID
= GAD_DEC
;
480 ng
.ng_VisualInfo
= vi
;
482 gad
= CreateGadgetA(BUTTON_KIND
, gad
, &ng
, NULL
);
485 ng
.ng_LeftEdge
= domleft
+ domwidth
- w
- w
;
487 gad
= CreateGadgetA(BUTTON_KIND
, gad
, &ng
, NULL
);
490 ng
.ng_LeftEdge
= domleft
+ domwidth
- w
;
491 ng
.ng_GadgetText
= ">";
492 ng
.ng_GadgetID
= GAD_INC
;
494 gad
= CreateGadgetA(BUTTON_KIND
, gad
, &ng
, NULL
);
497 ng
.ng_LeftEdge
= domleft
+ w
;
499 gad
= CreateGadgetA(BUTTON_KIND
, gad
, &ng
, NULL
);
504 ng
.ng_LeftEdge
= domleft
+ w
* 2 + SPACE_X
;
505 ng
.ng_Width
= domwidth
- w
* 4 - SPACE_X
* 2;
507 ng
.ng_LeftEdge
= domleft
+ w
+ SPACE_X
;
508 ng
.ng_Width
= domwidth
- w
* 2 - SPACE_X
* 2;
510 ng
.ng_GadgetID
= GAD_TEXT
;
511 ng
.ng_GadgetText
= NULL
;
513 gad
= textgad
= CreateGadget(TEXT_KIND
, gad
, &ng
, GTTX_Border
, TRUE
,
514 GTTX_Clipped
, TRUE
,
515 GTTX_Text
, (IPTR
)"hello" ,
516 GTTX_Justification
, GTJ_CENTER
,
518 return gad
? TRUE
: FALSE
;
521 /*********************************************************************************************/
523 static void timezone_prefs_changed(void)
527 for(i
= 0; i
< NUM_TIMEZONES
; i
++)
529 /* AmigaOS seems to have the sign the other way round, therefore the "-" */
531 if (-localeprefs
.lp_GMTOffset
== timezone_table
[i
].minoffset
)
540 ClearEarthmapSelection();
541 SetEarthmapSelection(timezone_table
[active_timezone
].pen
);
547 /*********************************************************************************************/
549 static void DrawEarthmapFrame(void)
551 SetDrMd(win
->RPort
, JAM1
);
553 SetAPen(win
->RPort
, dri
->dri_Pens
[SHADOWPEN
]);
555 RectFill(win
->RPort
, domleft
,
557 domleft
+ domwidth
- 2,
560 RectFill(win
->RPort
, domleft
,
563 domtop
+ EARTHMAP_SMALL_HEIGHT
+ 2 - 1);
565 SetAPen(win
->RPort
, dri
->dri_Pens
[SHINEPEN
]);
567 RectFill(win
->RPort
, domleft
+ domwidth
- 1,
569 domleft
+ domwidth
- 1,
570 domtop
+ EARTHMAP_SMALL_HEIGHT
+ 2 - 1);
572 RectFill(win
->RPort
, domleft
+ 1,
573 domtop
+ EARTHMAP_SMALL_HEIGHT
+ 2 - 1,
574 domleft
+ domwidth
- 2,
575 domtop
+ EARTHMAP_SMALL_HEIGHT
+ 2 - 1);
578 /*********************************************************************************************/
580 LONG
page_timezone_handler(LONG cmd
, IPTR param
)
587 retval
= timezone_init();
591 minwidth
= EARTHMAP_SMALL_WIDTH
+ 2;
592 minheight
= EARTHMAP_SMALL_HEIGHT
+ 2 + dri
->dri_Font
->tf_YSize
+ BUTTON_EXTRAHEIGHT
+ SPACE_Y
;
595 case PAGECMD_GETMINWIDTH
:
599 case PAGECMD_GETMINHEIGHT
:
603 case PAGECMD_SETDOMLEFT
:
607 case PAGECMD_SETDOMTOP
:
611 case PAGECMD_SETDOMWIDTH
:
612 /* domwidth = param; */
614 domleft
+= (param
- minwidth
) /2;
617 case PAGECMD_SETDOMHEIGHT
:
618 /* domheight = param; */
619 domheight
= minheight
;
620 domtop
+= (param
- minheight
) / 2;
623 case PAGECMD_MAKEGADGETS
:
624 retval
= timezone_makegadgets();
627 case PAGECMD_ADDGADGETS
:
632 AddGList(win
, gadlist
, -1, -1, NULL
);
633 GT_RefreshWindow(win
, NULL
);
634 RefreshGList(gadlist
, win
, NULL
, -1);
636 ClearEarthmapSelection();
637 SetEarthmapSelection(timezone_table
[active_timezone
].pen
);
645 case PAGECMD_REMGADGETS
:
648 if (gadlist
) RemoveGList(win
, gadlist
, -1);
654 case PAGECMD_REFRESH
:
659 case PAGECMD_HANDLEINPUT
:
660 retval
= timezone_input((struct IntuiMessage
*)param
);
663 case PAGECMD_PREFS_CHANGED
:
664 timezone_prefs_changed();
667 case PAGECMD_CLEANUP
: