4 #include <exec/types.h>
5 #include <exec/memory.h>
6 #include <exec/execbase.h>
7 #include <libraries/dos.h>
8 #include <libraries/dosextens.h>
9 #include <graphics/gfxmacros.h>
10 #include <graphics/videocontrol.h>
11 #include <graphics/view.h>
12 #include <graphics/gfxbase.h>
13 #include <libraries/gadtools.h>
14 #include <intuition/intuition.h>
15 #include <intuition/intuitionbase.h>
16 #include <intuition/imageclass.h>
17 #include <proto/graphics.h>
18 #include <proto/exec.h>
19 #include <proto/intuition.h>
20 #include <proto/dos.h>
21 #include <proto/gadtools.h>
22 #include <proto/utility.h>
23 #include <clib/macros.h>
26 #include <libraries/reqtools.h>
27 #include <proto/reqtools.h>
30 #include <aros/asmcall.h>
35 /****************************************************************************************/
37 /* Use ColorMap.Count to find out number of palette entried on screen */
40 /****************************************************************************************/
42 UWORD CHIP waitpointer
[] =
45 0x0400,0x07C0,0x0000,0x07C0,0x0100,0x0380,0x0000,0x07E0,
46 0x07C0,0x1FF8,0x1FF0,0x3FEC,0x3FF8,0x7FDE,0x3FF8,0x7FBE,
47 0x7FFC,0xFF7F,0x7EFC,0xFFFF,0x7FFC,0xFFFF,0x3FF8,0x7FFE,
48 0x3FF8,0x7FFE,0x1FF0,0x3FFC,0x07C0,0x1FF8,0x0000,0x07E0,
52 /****************************************************************************************/
54 extern struct Library
*GadToolsBase
;
55 extern struct DosLibrary
*DOSBase
;
56 extern struct IntuitionBase
*IntuitionBase
;
57 extern struct GfxBase
*GfxBase
;
58 extern struct ReqToolsBase
*ReqToolsBase
;
59 #if defined(__AROS__) || defined(__GNUC__)
60 extern struct UtilityBase
*UtilityBase
;
62 extern struct Library
*UtilityBase
;
65 /****************************************************************************************/
67 int ASM SAVEDS
GetVScreenSize (
68 REGPARAM(a0
, struct Screen
*, scr
),
69 REGPARAM(a1
, int *, width
),
70 REGPARAM(a2
, int *, height
))
72 struct ViewPortExtra
*vpe
;
73 struct Rectangle dispclip
, *clip
;
77 struct Screen
*pubscr
;
83 getvpetags
[0] = VTAG_VIEWPORTEXTRA_GET
;
84 getvpetags
[1] = (ULONG
)&vpe
;
85 getvpetags
[2] = TAG_END
;
92 #warning No VideoControl in AROS, yet
94 if (IntuitionBase
->FirstScreen
== scr
&&
95 VideoControl (scr
->ViewPort
.ColorMap
, (struct TagItem
*)getvpetags
) == 0)
97 clip
= &((struct ViewPortExtra
*)getvpetags
[1])->DisplayClip
;
102 QueryOverscan (GetVPModeID (&scr
->ViewPort
), &dispclip
, OSCAN_TEXT
);
112 if ((pubscr
= LockPubScreenByAddr(scr
)))
114 /* Cool, we got a lock on the screen, we don't need to Forbid() */
115 ilock
= LockIBase(0);
119 /* damn it, not a pubscreen, Forbid() as a last resort */
123 isfirst
= (IntuitionBase
->FirstScreen
== scr
);
131 #warning No VideoControl in AROS, yet
134 VideoControl (scr
->ViewPort
.ColorMap
, (struct TagItem
*)getvpetags
) == 0)
136 clip
= &((struct ViewPortExtra
*)getvpetags
[1])->DisplayClip
;
141 QueryOverscan (GetVPModeID (&scr
->ViewPort
), &dispclip
, OSCAN_TEXT
);
148 UnlockPubScreen(NULL
, pubscr
);
157 *width
= clip
->MaxX
- clip
->MinX
+ 1;
158 *height
= ht
= clip
->MaxY
- clip
->MinY
+ 1;
160 if (scr
->Width
< *width
) *width
= scr
->Width
;
161 if (scr
->Height
< *height
) *height
= scr
->Height
;
163 return ((ht
>= 400) ? 4 : 2);
166 /****************************************************************************************/
168 struct Screen
*REGARGS
LockPubScreenByAddr (struct Screen
*scr
)
170 struct List
*pubscreenlist
;
171 struct PubScreenNode
*pubscreennode
;
172 UBYTE pubscreenname
[MAXPUBSCREENNAME
+ 1];
174 pubscreenname
[0] = '\0';
176 pubscreenlist
= LockPubScreenList();
177 pubscreennode
= (struct PubScreenNode
*) pubscreenlist
->lh_Head
;
178 while (pubscreennode
->psn_Node
.ln_Succ
)
180 if (pubscreennode
->psn_Screen
== scr
)
182 strcpy(pubscreenname
, pubscreennode
->psn_Node
.ln_Name
);
185 pubscreennode
= (struct PubScreenNode
*) pubscreennode
->psn_Node
.ln_Succ
;
187 UnlockPubScreenList();
189 /* If we found a matching pubscreen try to lock it (note: can fail) */
190 if (pubscreenname
[0])
192 scr
= LockPubScreen(pubscreenname
);
202 /****************************************************************************************/
206 #define ThisProcess() ( ( APTR ) FindTask( NULL ) )
208 /****************************************************************************************/
210 struct Screen
*REGARGS
GetReqScreen (
211 struct NewWindow
*nw
, struct Window
**prwin
, struct Screen
*scr
, char *pubname
)
213 struct Window
*win
= *prwin
;
214 struct Process
*proc
;
216 if (!pubname
&& !scr
&& !win
)
218 proc
= ThisProcess();
219 if (proc
->pr_Task
.tc_Node
.ln_Type
== NT_PROCESS
) win
= proc
->pr_WindowPtr
;
222 nw
->Type
= CUSTOMSCREEN
;
225 struct Screen
*pubscr
;
227 /* Try to lock the screen as a public screen */
228 if ((pubscr
= LockPubScreenByAddr(scr
)))
231 nw
->Type
= PUBLICSCREEN
;
233 /* FIXME: probably should do something smart if the locking fail.
234 RT_Screen is more than dangerous if you ask me... - Piru */
238 if (win
&& (ULONG
)win
!= ~0) scr
= win
->WScreen
;
241 if (!(scr
= LockPubScreen (pubname
)))
242 if (!(scr
= LockPubScreen (NULL
))) return (NULL
);
244 nw
->Type
= PUBLICSCREEN
;
249 return (nw
->Screen
= scr
);
252 /****************************************************************************************/
255 static int VpDepth (struct ViewPort
*vp
)
257 ULONG modeid
= GetVPModeID (vp
);
260 depth
= vp
->RasInfo
->BitMap
->Depth
;
262 if (modeid
& HAM_KEY
) depth
-= 2;
263 if (modeid
& EXTRAHALFBRITE_KEY
) depth
= 5;
274 /****************************************************************************************/
277 GetVpCM( struct ViewPort
*vp
, APTR
*cmap
)
288 numcols
= vp
->ColorMap
->Count
;
297 depth
= VpDepth (vp
);
298 numcols
= (1 << depth
);
300 if( GfxBase
->LibNode
.lib_Version
>= 39 )
302 if( ( *cmap
= AllocVec( ( numcols
* 3 + 2 ) * 4, MEMF_PUBLIC
| MEMF_CLEAR
) ) )
304 ( ( UWORD
* ) ( *cmap
) )[ 0 ] = numcols
;
309 *cmap
= AllocVec( numcols
* 2, MEMF_PUBLIC
| MEMF_CLEAR
);
314 RefreshVpCM( vp
, *cmap
);
323 /****************************************************************************************/
326 RefreshVpCM( struct ViewPort
*vp
, APTR cmap
)
331 numcols
= vp
->ColorMap
->Count
;
333 int i
, depth
, numcols
;
335 depth
= VpDepth( vp
);
336 numcols
= ( 1 << depth
);
338 if( GfxBase
->LibNode
.lib_Version
>= 39 )
340 GetRGB32( vp
->ColorMap
, 0, numcols
, ( ( ULONG
* ) cmap
) + 1 );
344 for( i
= 0; i
< numcols
; i
++ )
346 ( ( UWORD
* ) cmap
)[ i
] = GetRGB4( vp
->ColorMap
, i
);
351 /****************************************************************************************/
353 void REGARGS
LoadCMap (struct ViewPort
*vp
, APTR cmap
)
355 if (GfxBase
->LibNode
.lib_Version
>= 39) LoadRGB32 (vp
, cmap
);
357 else LoadRGB4 (vp
, cmap
, vp
->ColorMap
->Count
);
359 else LoadRGB4 (vp
, cmap
, (1 << VpDepth (vp
)));
363 /****************************************************************************************/
365 void REGARGS
FreeVpCM (struct ViewPort
*vp
, APTR cmap
, BOOL restore
)
367 if (restore
&& cmap
) LoadCMap (vp
, cmap
);
371 /****************************************************************************************/
373 void REGARGS
InitNewGadget (struct NewGadget
*ng
,
374 int x
, int y
, int w
, int h
, char *s
, UWORD id
)
376 ng
->ng_LeftEdge
= x
; ng
->ng_TopEdge
= y
; ng
->ng_Width
= w
; ng
->ng_Height
= h
;
377 ng
->ng_GadgetText
= s
; ng
->ng_GadgetID
= id
;
380 /****************************************************************************************/
382 struct TextFont
* REGARGS
GetReqFont (struct TextAttr
*attr
,
383 struct TextFont
*deffont
, int *fontheight
, int *fontwidth
, int allowprop
)
388 forcedef
= (rtLockPrefs()->Flags
& RTPRF_DEFAULTFONT
);
391 ft
= OpenFont (attr
);
392 if (!ft
|| forcedef
|| (!allowprop
&& (ft
->tf_Flags
& FPF_PROPORTIONAL
)))
394 if (ft
) CloseFont (ft
);
395 if (deffont
) ft
= deffont
;
396 else ft
= GfxBase
->DefaultFont
;
398 attr
->ta_Name
= ft
->tf_Message
.mn_Node
.ln_Name
;
399 attr
->ta_YSize
= ft
->tf_YSize
;
400 attr
->ta_Style
= ft
->tf_Style
;
401 attr
->ta_Flags
= ft
->tf_Flags
;
402 ft
= OpenFont (attr
);
407 *fontheight
= ft
->tf_YSize
;
408 *fontwidth
= ft
->tf_XSize
;
414 /****************************************************************************************/
416 struct IntuiMessage
*REGARGS
GetWin_GT_Msg (struct Window
*win
,
417 struct Hook
*hook
, APTR req
)
419 struct IntuiMessage
*imsg
, *reqmsg
;
421 while ((imsg
= (struct IntuiMessage
*)GetMsg (win
->UserPort
)))
422 if ((reqmsg
= ProcessWin_Msg (win
, imsg
, hook
, req
))) return (reqmsg
);
427 /****************************************************************************************/
429 struct IntuiMessage
*REGARGS
ProcessWin_Msg (struct Window
*win
,
430 struct IntuiMessage
*imsg
, struct Hook
*hook
, APTR req
)
432 struct IntuiMessage
*reqmsg
;
434 if (imsg
->IDCMPWindow
== win
)
436 reqmsg
= GT_FilterIMsg (imsg
);
437 if (reqmsg
) return (reqmsg
);
438 ReplyMsg ((struct Message
*)imsg
);
442 if (hook
) CallHookPkt (hook
, req
, imsg
);
443 ReplyMsg ((struct Message
*)imsg
);
449 /****************************************************************************************/
451 void REGARGS
Reply_GT_Msg (struct IntuiMessage
*reqmsg
)
453 ReplyMsg ((struct Message
*)GT_PostFilterIMsg (reqmsg
));
456 /****************************************************************************************/
458 void REGARGS
DoScreenToFront (struct Screen
*scr
, int nopop
, int popup
)
464 noscrtofront
= (rtLockPrefs()->Flags
& RTPRF_NOSCRTOFRONT
);
467 if (noscrtofront
) return;
471 rtScreenToFrontSafely (scr
);
475 /****************************************************************************************/
477 void REGARGS
DoCloseWindow (struct Window
*win
, int idcmpshared
)
479 if (idcmpshared
) rtCloseWindowSafely (win
);
480 else CloseWindow (win
);
483 /****************************************************************************************/
488 struct Rectangle bounds
;
493 /****************************************************************************************/
496 AROS_UFH3(void, WinBackFill
,
497 AROS_UFHA(struct Hook
*, hook
, A0
),
498 AROS_UFHA(struct RastPort
*, the_rp
, A2
),
499 AROS_UFHA(struct BackFillMsg
*, msg
, A1
))
503 void SAVEDS ASM
WinBackFill (
504 REGPARAM(a0
, struct Hook
*, hook
),
505 REGPARAM(a2
, struct RastPort
*, the_rp
),
506 REGPARAM(a1
, struct BackFillMsg
*, msg
))
511 memcpy( &rp
, the_rp
, sizeof( rp
) );
513 SetAPen (&rp
, ((UWORD
*)hook
->h_Data
)[BACKGROUNDPEN
]);
514 mySetWriteMask (&rp
, ~0);
515 RectFill (&rp
, msg
->bounds
.MinX
, msg
->bounds
.MinY
,
516 msg
->bounds
.MaxX
, msg
->bounds
.MaxY
);
523 /****************************************************************************************/
527 AROS_UFH3(void, PatternWinBackFill
,
528 AROS_UFHA(struct Hook
*, hook
, A0
),
529 AROS_UFHA(struct RastPort
*, the_rp
, A2
),
530 AROS_UFHA(struct BackFillMsg
*, msg
, A1
))
535 UWORD pattern
[] = {0xAAAA,0x5555};
537 memcpy( &rp
, the_rp
, sizeof( rp
) );
540 SetAPen (&rp
, ((UWORD
*)hook
->h_Data
)[BACKGROUNDPEN
]);
541 SetBPen (&rp
, ((UWORD
*)hook
->h_Data
)[SHINEPEN
]);
544 mySetWriteMask (&rp
, ~0);
546 SetAfPt(&rp
, pattern
, 1);
548 RectFill (&rp
, msg
->bounds
.MinX
, msg
->bounds
.MinY
,
549 msg
->bounds
.MaxX
, msg
->bounds
.MaxY
);
551 SetAfPt(&rp
, NULL
, 0);
558 /****************************************************************************************/
560 void REGARGS
mySetWriteMask (struct RastPort
*rp
, ULONG mask
)
562 if (GfxBase
->LibNode
.lib_Version
>= 39) SetWriteMask (rp
, mask
);
563 else SetWrMsk (rp
, (UBYTE
)mask
);
566 /****************************************************************************************/
568 struct Window
*REGARGS
OpenWindowBF (struct NewWindow
*nw
,
569 struct Hook
*hook
, UWORD
*pens
, ULONG
*maskptr
, WORD
*zoom
,
570 BOOL backfillpattern
)
581 hook
->h_Entry
= (HOOKFUNC
)PatternWinBackFill
;
584 hook
->h_Entry
= (HOOKFUNC
)WinBackFill
;
586 hook
->h_Data
= (void *)pens
;
588 tags
[0] = WA_BackFill
;
589 tags
[1] = (ULONG
)hook
;
591 tags
[3] = (ULONG
)zoom
;
596 if (IntuitionBase
->LibNode
.lib_Version
>= 39)
597 zoom
[0] = zoom
[1] = ~0;
600 zoom
[0] = nw
->LeftEdge
;
601 zoom
[1] = nw
->TopEdge
;
606 tags
[2] = TAG_IGNORE
;
609 if ((win
= OpenWindowTagList (nw
, (struct TagItem
*)tags
)))
612 for (i
= 0; i
<= HIGHLIGHTTEXTPEN
; i
++)
613 if (pens
[i
] > maxpen
) maxpen
= pens
[i
];
616 while (mask
< maxpen
)
622 mySetWriteMask (rp
, mask
);
623 if (maskptr
) *maskptr
= mask
;
630 /****************************************************************************************/
632 int CheckReqPos (int reqpos
, int reqdefnum
, struct NewWindow
*newwin
)
634 struct ReqDefaults
*reqdefs
;
636 if (reqpos
== REQPOS_DEFAULT
)
638 reqdefs
= &rtLockPrefs()->ReqDefaults
[reqdefnum
];
639 reqpos
= reqdefs
->ReqPos
;
641 if (reqpos
<= REQPOS_CENTERSCR
)
643 newwin
->LeftEdge
= 0;
648 newwin
->LeftEdge
= reqdefs
->LeftOffset
;
649 newwin
->TopEdge
= reqdefs
->TopOffset
;
658 /****************************************************************************************/
664 /****************************************************************************************/
666 int REGARGS
StrWidth_noloc (struct IntuiText
*itxt
, UBYTE
*str
)
668 char labstr
[100], *l
;
670 if (!str
) return (0);
672 /* Copy string, remove underscore */
674 while (*str
&& *str
!= '_') *l
++ = *str
++;
676 if (*str
) while ((*l
++ = *++str
)); else *l
= 0;
678 itxt
->IText
= labstr
;
680 return (IntuiTextLength (itxt
));
683 /****************************************************************************************/
685 static int ObjectWidth (struct NewGadget
*ng
, int normalw
, int normalh
)
687 if ((GadToolsBase
->lib_Version
>= 39) && (ng
->ng_TextAttr
->ta_YSize
> normalh
))
688 return (normalw
+ (ng
->ng_TextAttr
->ta_YSize
- normalh
) * 2);
693 /****************************************************************************************/
695 static int ObjectHeight (struct NewGadget
*ng
, int normalh
)
697 if ((GadToolsBase
->lib_Version
>= 39) && (ng
->ng_TextAttr
->ta_YSize
> normalh
))
698 return (ng
->ng_TextAttr
->ta_YSize
);
703 /****************************************************************************************/
705 int CheckBoxWidth (struct NewGadget
*ng
)
707 return (ObjectWidth (ng
, CHECKBOX_WIDTH
, CHECKBOX_HEIGHT
));
710 /****************************************************************************************/
712 int CheckBoxHeight (struct NewGadget
*ng
)
714 return (ObjectHeight (ng
, CHECKBOX_HEIGHT
));
717 /****************************************************************************************/
722 LONG
BottomBorderHeight (struct Screen
*scr
)
724 struct DrawInfo
*dri
;
728 if ((dri
= GetScreenDrawInfo (scr
)))
730 if((obj
= NewObject (NULL
, "sysiclass", SYSIA_DrawInfo
, (IPTR
) dri
,
731 /* Must be SYSISIZE_MEDRES! */
732 SYSIA_Size
, SYSISIZE_MEDRES
,
733 SYSIA_Which
, SIZEIMAGE
,
736 if (!GetAttr (IA_Height
, obj
, (IPTR
*)&h
))
737 h
= 10; // Probably not needed.. Or?
738 DisposeObject( obj
);
740 FreeScreenDrawInfo (scr
, dri
);
745 /****************************************************************************************/