2 Copyright 1995-2003, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
9 #include <exec/memory.h>
10 #include <utility/tagitem.h>
11 #include <intuition/screens.h>
12 #include <intuition/intuition.h>
13 #include <intuition/imageclass.h>
14 #include <intuition/windecorclass.h>
15 #include <intuition/scrdecorclass.h>
16 #include <intuition/gadgetclass.h>
17 #include <graphics/modeid.h>
18 #include <graphics/videocontrol.h>
19 #include <graphics/displayinfo.h>
20 #include <prefs/screenmode.h>
21 #include <proto/exec.h>
22 #include <proto/graphics.h>
23 #include <proto/layers.h>
24 #include <proto/utility.h>
25 #include <proto/intuition.h>
28 #include <proto/cybergraphics.h>
29 #include <cybergraphx/cybergraphics.h>
31 #include "intuition_intern.h"
32 #include "intuition_customize.h"
33 #include "intuition_extend.h"
34 #include "inputhandler.h"
35 #include "inputhandler_support.h"
36 #include "inputhandler_actions.h"
39 #ifndef DEBUG_OpenScreen
40 #define DEBUG_OpenScreen 0
46 #include <aros/debug.h>
48 struct OpenScreenActionMsg
50 struct IntuiActionMsg msg
;
51 struct IntScreen
*Screen
;
52 struct NewScreen
*NewScreen
;
56 static VOID
int_openscreen(struct OpenScreenActionMsg
*msg
,
57 struct IntuitionBase
*IntuitionBase
);
60 extern const ULONG defaultdricolors
[DRIPEN_NUMDRIPENS
];
62 //FIXME: NUMDRIPENS == DRIPEN_NUMDRIPENS ???
63 extern const ULONG defaultdricolors
[NUMDRIPENS
];
68 static const char THIS_FILE
[] = __FILE__
;
73 #define DEBUG_OBTAINPEN(x) x;
75 /******* graphics.library/ObtainPen **********************************************
78 * ObtainPen -- Obtain a free palette entry for use by your program. (V39)
82 * n = ObtainPen( cm, n, r, g, b, flags)
83 * d0 a0 d0 d1 d2 d3 d4
85 * LONG ObtainPen(struct ColorMap *,ULONG,ULONG,ULONG,ULONG,ULONG);
88 * Attempt to allocate an entry in the colormap for use by the application.
89 * If successful, you should ReleasePen() this entry after you have finished
92 * Applications needing exclusive use of a color register (say for color
93 * cycling) will typically call this function with n=-1. Applications needing
94 * only the shared use of a color will typically use ObtainBestPenA() instead.
95 * Other uses of this function are rare.
98 * cm = A pointer to a color map created by GetColorMap().
99 * n = The index of the desired entry, or -1 if any one is acceptable
100 * rgb = The RGB values (32 bit left justified fractions) to set the new
102 * flags= PEN_EXCLUSIVE - tells the system that you want exclusive
103 * (non-shared) use of this pen value. Default is shared access.
105 * PEN_NO_SETCOLOR - tells the system to not change the rgb values
106 * for the selected pen. Really only makes sense for exclusive pens.
111 * n = The allocated pen. -1 will be returned if there is no pen available
117 * When you allocate a palette entry in non-exclusive mode, you
118 * should not change it (via SetRGB32), because other programs on the
119 * same screen may be using it. With PEN_EXCLUSIVE mode, you can
120 * change the returned entry at will.
122 * To avoid visual artifacts, you should not free up a palette
123 * entry until you are sure that your application is not displaying
124 * any pixels in that color at the time you free it. Otherwise, another
125 * task could allocate and set that color index, thus changing the colors
128 * Generally, for shared access, you should use ObtainBestPenA()
129 * instead, since it will not allocate a new color if there is one
130 * "close enough" to the one you want already.
131 * If there is no Palextra attached to the colormap, then this
132 * routine will always fail.
135 * GetColorMap() ReleasePen() AttachPalExtra() ObtainBestPenA()
137 *********************************************************************************/
139 LONG
MyObtainPen(struct ColorMap
*cm
,
145 struct IntuitionBase
*IntuitionBase
)
147 // struct Library *SysBase = (struct Library *)GfxBase->ExecBase;
148 struct PaletteExtra
*pe
=cm
->PalExtra
;
151 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen(cm 0x%lx n %ld r 0x%08lx g 0x%08lx b 0x%08lx flags %ld)\n",cm
,n
,r
,g
,b
,flags
);)
153 DEBUG_OBTAINPEN(dprintf("LIB_ObtainSemaphore: NestCount 0x%lx,QueueCount 0x%lx,Owner %s\n",
154 pe
->pe_Semaphore
.ss_NestCount
,
155 pe
->pe_Semaphore
.ss_QueueCount
,
156 ((ULONG
) pe
->pe_Semaphore
.ss_Owner
> 1) ? pe
->pe_Semaphore
.ss_Owner
->tc_Node
.ln_Name
: "Shared\n"));
158 ObtainSemaphore(&pe
->pe_Semaphore
);
160 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: obtained the semaphore\n"));
162 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_NFree 0x%lx\n",
165 if (pe
->pe_NFree
!= 0)
171 refcnt
= (UWORD
*)pe
->pe_RefCnt
;
172 alloclist
= (char *)pe
->pe_AllocList
;
174 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_RefCnt 0x%lx\n",
177 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_AllocList 0x%lx\n",
181 // if not allocatable, fail
182 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_SharableColors 0x%lx\n",
183 pe
->pe_SharableColors
));
184 if (pe
->pe_SharableColors
>= n
)
191 // decrement avail count
193 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_NFree 0x%lx\n",
196 if (pe
->pe_NFree
!= 0)
201 j
= pe
->pe_FirstFree
;
203 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_FirstFree 0x%lx\n",
208 // we don't need to walk through the list
210 pe
->pe_FirstFree
= alloclist
[n
];
212 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: pe_FirstFree = alloclist[%ld] 0x%lx\n",
219 while(alloclist
[j
] != n
)
221 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: alloclist[%ld] %ld != %ld\n",
225 // j -> next = n -> next
226 alloclist
[j
] = alloclist
[n
];
232 if ((flags
& PENF_EXCLUSIVE
) == 0)
234 // not exclusive, so add it to shared list
236 alloclist
[n
]=pe
->pe_FirstShared
;
237 pe
->pe_FirstShared
=n
;
242 DEBUG_OBTAINPEN(dprintf("(index already allocated)");)
247 DEBUG_OBTAINPEN(dprintf("(not allocatable,sharable=%ld)",pe
->pe_SharableColors
);)
252 // decrement avail count
253 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: decrement avail cnt\n"));
255 alloc
= pe
->pe_FirstFree
;
257 // FirstFree = alloc->next
258 pe
->pe_FirstFree
= alloclist
[alloc
];
263 if ((flags
& PENF_EXCLUSIVE
) == 0)
265 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: add shared list\n"));
266 // not exclusive, so add it to shared list
268 alloclist
[alloc
]=pe
->pe_FirstShared
;
269 pe
->pe_FirstShared
=alloc
;
277 if ((flags
& PENF_NO_SETCOLOR
) == 0)
279 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: set color\n"));
280 SetRGB32(pe
->pe_ViewPort
,i
,r
,g
,b
);
285 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen: release it\n"));
286 ReleaseSemaphore(&pe
->pe_Semaphore
);
288 DEBUG_OBTAINPEN(dprintf("LIB_ObtainPen(cm 0x%lx n %ld r 0x%08lx g 0x%08lx b 0x%08lx flags %ld) -> retvalue %lx\n",cm
,n
,r
,g
,b
,flags
,retvalue
);)
295 #define ObtainPen(cm,n,r,g,b,flags) MyObtainPen(cm,n,r,g,b,flags,IntuitionBase)
298 /* Default colors for the new screen */
300 const ULONG coltab
[] =
302 (16L << 16) + 0, /* 16 colors, loaded at index 0 */
304 /* X11 color names */
305 0xB3B3B3B3, 0xB3B3B3B3, 0xB3B3B3B3, /* Grey70 */
306 0x00000000, 0x00000000, 0x00000000, /* Black */
307 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, /* White */
308 0x66666666, 0x88888888, 0xBBBBBBBB, /* AMIGA Blue */
310 0x00000000, 0x00000000, 0xFFFFFFFF, /* Blue */
311 0x00000000, 0xFFFFFFFF, 0x00000000, /* Green */
312 0xFFFFFFFF, 0x00000000, 0x00000000, /* Red */
313 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, /* Cyan */
315 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, /* Magenta */
316 0xEEEEEEEE, 0x82828282, 0xEEEEEEEE, /* Violet */
317 0xA5A5A5A5, 0x2A2A2A2A, 0x2A2A2A2A, /* Brown */
318 0xFFFFFFFF, 0xE4E4E4E4, 0xC4C4C4C4, /* Bisque */
320 0xE6E6E6E6, 0xE6E6E6E6, 0xFAFAFAFA, /* Lavender */
321 0x00000000, 0x00000000, 0x80808080, /* Navy */
322 0xF0F0F0F0, 0xE6E6E6E6, 0x8C8C8C8C, /* Khaki */
323 0xA0A0A0A0, 0x52525252, 0x2D2D2D2D, /* Sienna */
327 /*****************************************************************************
331 AROS_LH1(struct Screen
*, OpenScreen
,
334 AROS_LHA(struct NewScreen
*, newScreen
, A0
),
337 struct IntuitionBase
*, IntuitionBase
, 33, Intuition
)
356 29-10-95 digulla automatically created from
357 intuition_lib.fd and clib/intuition_protos.h
359 *****************************************************************************/
362 AROS_LIBBASE_EXT_DECL(struct IntuitionBase
*,IntuitionBase
)
365 struct TagItem
*tag
, *tagList
;
366 struct IntScreen
*screen
;
368 struct Hook
*layer_info_hook
= NULL
;
369 struct ColorSpec
*colors
= NULL
;
370 ULONG
*errorPtr
; /* Store error at user specified location */
371 UWORD
*customdripens
= NULL
;
372 ULONG
*colors32
= NULL
;
374 BOOL ok
= TRUE
, rp_inited
= FALSE
, li_inited
= FALSE
, sharepens
= FALSE
;
376 BOOL windowlock
= FALSE
;
378 struct Rectangle
*dclip
= NULL
;
379 LONG overscan
= OSCAN_TEXT
;
380 DisplayInfoHandle displayinfo
;
381 struct DimensionInfo dimensions
;
382 struct MonitorInfo monitor
;
384 ULONG allocbitmapflags
= BMF_DISPLAYABLE
;
386 BOOL frontbm_set
= FALSE
;
387 struct BitMap
*old_front_bm
= NULL
;
391 BOOL workbench
= FALSE
;
392 struct TagItem modetags
[] =
394 { BIDTAG_Depth
, 0UL },
395 { BIDTAG_DesiredWidth
, 0UL },
396 { BIDTAG_DesiredHeight
, 0UL },
399 ULONG modeid
= INVALID_ID
;
401 ASSERT_VALID_PTR_ROMOK(newScreen
);
403 #define COPY(x) screen->Screen.x = ns.x
404 #define SetError(x) if (errorPtr != NULL) *errorPtr = x;
406 D(bug("OpenScreen (%p = { Left=%d Top=%d Width=%d Height=%d Depth=%d })\n"
408 , newScreen
->LeftEdge
416 if (IntuitionBase
->FirstScreen
)
417 old_front_bm
= IntuitionBase
->FirstScreen
->RastPort
.BitMap
;
420 FireScreenNotifyMessage((IPTR
) newScreen
, SNOTIFY_BEFORE_OPENSCREEN
, IntuitionBase
);
424 if (newScreen
->Type
& NS_EXTENDED
)
426 tagList
= ((struct ExtNewScreen
*)newScreen
)->Extension
;
433 DEBUG_OPENSCREEN(dprintf("OpenScreen: Left %d Top %d Width %d Height %d Depth %d Tags 0x%lx\n",
434 ns
.LeftEdge
, ns
.TopEdge
, ns
.Width
, ns
.Height
, ns
.Depth
, tagList
));
437 if (!CyberGfxBase
) CyberGfxBase
= OpenLibrary("cybergraphics.library",0);
438 if (!CyberGfxBase
) return NULL
;
440 if (!LocaleBase
) LocaleBase
= OpenLibrary("locale.library",0);
441 if (!LocaleBase
) return NULL
;
444 #ifdef USEGETIPREFS //needs INTUITION_THEME_ENCHANCEMENT!
445 if (!GetPrivIBase(IntuitionBase
)->IPrefsLoaded
&& FindPort(SKINMANAGERPORTNAME
))
447 /* let's init prefs before 1st OpenScreen that needs them*/
448 int_SkinAction(SKA_GetIPrefs
,0,0,IntuitionBase
);
452 screen
= AllocMem(sizeof (struct IntScreen
), MEMF_ANY
| MEMF_CLEAR
);
454 DEBUG_OPENSCREEN(dprintf("OpenScreen: screen 0x%lx\n", screen
));
456 /* Do this really early to be able to report errors */
457 errorPtr
= (ULONG
*)GetTagData((Tag
)SA_ErrorCode
, (ULONG
)NULL
, (struct TagItem
*)tagList
);
459 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_ErrorCode 0x%lx\n",errorPtr
));
463 FireScreenNotifyMessage((IPTR
) NULL
, SNOTIFY_AFTER_OPENSCREEN
, IntuitionBase
);
464 SetError(OSERR_NOMEM
);
470 if (GetTagData(SA_LikeWorkbench
, FALSE
, tagList
))
473 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_LikeWorkbench\n"));
475 ns
.Width
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_Width
;
476 ns
.Height
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_Height
;
477 ns
.Depth
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_Depth
;
478 modeid
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_DisplayID
;
480 if (GetPrivIBase(IntuitionBase
)->ScreenModePrefs
.smp_Control
& SMF_AUTOSCROLL
)
482 /* need to mark autoscroll */
483 ns
.Type
|= AUTOSCROLL
;
486 sharepens
= TRUE
; /* not sure */
489 while((tag
= NextTagItem ((const struct TagItem
**)&tagList
)))
492 DEBUG_OPENSCREEN(dprintf("OpenScreen: Tag 0x%08lx Data 0x%08lx\n",
493 tag
->ti_Tag
, tag
->ti_Data
));
498 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Left %ld\n",tag
->ti_Data
));
499 ns
.LeftEdge
= tag
->ti_Data
;
503 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Top %ld\n",tag
->ti_Data
));
504 ns
.TopEdge
= tag
->ti_Data
;
508 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Width %ld\n",tag
->ti_Data
));
509 ns
.Width
= tag
->ti_Data
;
513 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Height %ld\n",tag
->ti_Data
));
514 ns
.Height
= tag
->ti_Data
;
518 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Depth %ld\n",tag
->ti_Data
));
519 ns
.Depth
= tag
->ti_Data
;
523 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_DetailPen %ld\n",tag
->ti_Data
));
524 ns
.DetailPen
= tag
->ti_Data
;
528 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_BlockPen %ld\n",tag
->ti_Data
));
529 ns
.BlockPen
= tag
->ti_Data
;
533 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Type 0x%lx\n",tag
->ti_Data
));
534 ns
.Type
&= ~SCREENTYPE
;
535 ns
.Type
|= tag
->ti_Data
;
539 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Title <%s>\n",tag
->ti_Data
));
540 ns
.DefaultTitle
= (UBYTE
*)tag
->ti_Data
;
544 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Font 0x%lx\n",tag
->ti_Data
));
545 ns
.Font
= (struct TextAttr
*)tag
->ti_Data
;
549 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Colors32 0x%lx\n",tag
->ti_Data
));
550 colors32
= (ULONG
*)tag
->ti_Data
;
554 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Colors 0x%lx\n",tag
->ti_Data
));
555 colors
= (struct ColorSpec
*)tag
->ti_Data
;
559 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_SysFont 0x%lx\n",tag
->ti_Data
));
560 sysfont
= (WORD
)tag
->ti_Data
;
564 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_BitMap 0x%lx\n",tag
->ti_Data
));
567 ns
.Type
|= CUSTOMBITMAP
;
568 ns
.CustomBitMap
= (struct BitMap
*)tag
->ti_Data
;
572 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_BitMap==NULL specified, custom bitmap use disabled\n"));
576 /* Name of this public screen. */
578 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_PubName <%s>\n",tag
->ti_Data
));
581 screen
->pubScrNode
= AllocMem(sizeof(struct PubScreenNode
), MEMF_CLEAR
);
590 if (strcmp((char *)tag
->ti_Data
, "Workbench") == 0)
592 #warning This would still not be safe, if a normal app tried to open its own screen with SA_PubName=Workbench
593 if (GetPrivIBase(IntuitionBase
)->WorkBench
)
595 UnlockPubScreenList();
597 FireScreenNotifyMessage((IPTR
) NULL
, SNOTIFY_AFTER_OPENSCREEN
, IntuitionBase
);
605 old
= LockPubScreen((STRPTR
)tag
->ti_Data
);
609 UnlockPubScreen(NULL
, old
);
610 SetError(OSERR_PUBNOTUNIQUE
);
611 UnlockPubScreenList();
612 FireScreenNotifyMessage((IPTR
) NULL
, SNOTIFY_AFTER_OPENSCREEN
, IntuitionBase
);
618 UnlockPubScreenList();
621 screen
->pubScrNode
= AllocMem(sizeof(struct PubScreenNode
), MEMF_CLEAR
);
623 DEBUG_OPENSCREEN(dprintf("OpenScreen: pubScrNode 0x%lx\n",screen
->pubScrNode
));
625 if (screen
->pubScrNode
== NULL
)
627 SetError(OSERR_NOMEM
);
628 FireScreenNotifyMessage((IPTR
) NULL
, SNOTIFY_AFTER_OPENSCREEN
, IntuitionBase
);
633 if ((ns
.Type
& SCREENTYPE
) == CUSTOMSCREEN
)
635 ns
.Type
&= ~SCREENTYPE
;
636 ns
.Type
|= PUBLICSCREEN
;
639 screen
->pubScrNode
->psn_Node
.ln_Name
= AllocVec(MAXPUBSCREENNAME
+ 1,
642 if (screen
->pubScrNode
->psn_Node
.ln_Name
== NULL
)
644 SetError(OSERR_NOMEM
);
645 FreeMem(screen
->pubScrNode
, sizeof(struct PubScreenNode
));
646 FireScreenNotifyMessage((IPTR
) NULL
, SNOTIFY_AFTER_OPENSCREEN
, IntuitionBase
);
651 /* Always open public screens in private mode. */
652 screen
->pubScrNode
->psn_Flags
|= PSNF_PRIVATE
;
653 strcpy(screen
->pubScrNode
->psn_Node
.ln_Name
, (STRPTR
)tag
->ti_Data
);
656 /* Signal bit number to use when signalling public screen
659 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_PubSig 0x%lx\n",tag
->ti_Data
));
660 if (screen
->pubScrNode
== NULL
)
662 FireScreenNotifyMessage((IPTR
) NULL
, SNOTIFY_AFTER_OPENSCREEN
, IntuitionBase
);
666 /* If no PubTask is set, we set the calling task as default */
667 if (screen
->pubScrNode
->psn_SigTask
== NULL
)
668 screen
->pubScrNode
->psn_SigTask
= FindTask(NULL
);
670 screen
->pubScrNode
->psn_SigBit
= (UBYTE
)tag
->ti_Data
;
673 /* Task that should be signalled when the public screen loses
674 its last visitor window. */
676 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_PubTask 0x%lx\n",tag
->ti_Data
));
677 if (screen
->pubScrNode
== NULL
)
679 FireScreenNotifyMessage((IPTR
) NULL
, SNOTIFY_AFTER_OPENSCREEN
, IntuitionBase
);
682 screen
->pubScrNode
->psn_SigTask
= (struct Task
*)tag
->ti_Data
;
686 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_BackFill Hook 0x%lx\n",tag
->ti_Data
));
687 layer_info_hook
= (struct Hook
*)tag
->ti_Data
;
691 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Quiet 0x%lx\n",tag
->ti_Data
));
694 ns
.Type
|= SCREENQUIET
;
698 ns
.Type
&= ~SCREENQUIET
;
703 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_ShowTitle 0x%lx\n",tag
->ti_Data
));
706 ns
.Type
|= SHOWTITLE
;
710 ns
.Type
&= ~SHOWTITLE
;
715 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Pens 0x%lx\n",tag
->ti_Data
));
716 customdripens
= (UWORD
*)tag
->ti_Data
;
720 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_DisplayID 0x%lx\n",tag
->ti_Data
));
721 //if (modeid == INVALID_ID)
722 modeid
= tag
->ti_Data
;
726 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_SharePens 0x%lx\n",tag
->ti_Data
));
727 sharepens
= tag
->ti_Data
? TRUE
: FALSE
;
730 ns
.Type
|= PENSHARED
;
734 ns
.Type
&= ~PENSHARED
;
740 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Interleaved 0x%lx\n",tag
->ti_Data
));
743 allocbitmapflags
|= BMF_INTERLEAVED
;
747 allocbitmapflags
&= ~BMF_INTERLEAVED
;
753 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Behind 0x%lx\n",tag
->ti_Data
));
756 ns
.Type
|= SCREENBEHIND
;
760 ns
.Type
&= ~SCREENBEHIND
;
765 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_DClip 0x%lx\n",tag
->ti_Data
));
766 dclip
= (struct Rectangle
*)tag
->ti_Data
;
770 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_OverScan 0x%lx\n",tag
->ti_Data
));
771 overscan
= tag
->ti_Data
;
774 case SA_LikeWorkbench
:
782 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_AutoScroll 0x%lx\n",tag
->ti_Data
));
783 ns
.Type
|= AUTOSCROLL
;
787 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_FullPalette 0x%lx\n",tag
->ti_Data
));
790 case SA_ColorMapEntries
:
791 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_ColorMapEntries 0x%lx\n",tag
->ti_Data
));
795 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Parent 0x%lx\n",tag
->ti_Data
));
799 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Draggable 0x%lx\n",tag
->ti_Data
));
803 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_Exclusive 0x%lx\n",tag
->ti_Data
));
806 case SA_VideoControl
:
807 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_VideoControl 0x%lx\n",tag
->ti_Data
));
811 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_FrontChild 0x%lx\n",tag
->ti_Data
));
815 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_BackChild 0x%lx\n",tag
->ti_Data
));
819 DEBUG_OPENSCREEN(dprintf("OpenScreen: SA_MinimizeISG 0x%lx\n",tag
->ti_Data
));
822 #warning TODO: Missing SA_ Tags
824 DEBUG_OPENSCREEN(dprintf("OpenScreen: unknown tag 0x%lx data 0x%lx\n",
829 } /* switch (tag->ti_Tag) */
831 } /* while ((tag = NextTagItem (&tagList))) */
835 DEBUG_OPENSCREEN(dprintf("OpenScreen: Left %d Top %d Width %d Height %d Depth %d Tags 0x%lx\n",
836 ns
.LeftEdge
, ns
.TopEdge
, ns
.Width
, ns
.Height
, ns
.Depth
, tagList
));
838 /* First Init the RastPort then get the BitPlanes!! */
840 modetags
[0].ti_Data
= ns
.Depth
;
841 if (ns
.Width
!= STDSCREENWIDTH
)
843 modetags
[1].ti_Data
= ns
.Width
;
847 modetags
[1].ti_Tag
= TAG_IGNORE
;
850 if (ns
.Height
!= STDSCREENHEIGHT
)
852 modetags
[2].ti_Data
= ns
.Height
;
856 modetags
[2].ti_Tag
= TAG_IGNORE
;
860 // if default HIRES_KEY or HIRESLACE_KEY is passed, make sure we find a replacement
863 if (INVALID_ID
!= modeid
)
865 if (FindDisplayInfo(modeid
) == NULL
)
872 struct TagItem bestmodetags
[] =
874 { CYBRBIDTG_Depth
, 0UL },
875 { CYBRBIDTG_NominalWidth
, 0UL },
876 { CYBRBIDTG_NominalHeight
, 0UL },
880 bestmodetags
[0].ti_Data
= 8;
881 bestmodetags
[1].ti_Data
= ns
.Width
;
882 bestmodetags
[2].ti_Data
= ns
.Height
;
884 DEBUG_OPENSCREEN(dprintf("resetting native mode id !!\n");)
885 DEBUG_OPENSCREEN(dprintf("ns.Width %ld ns.Height %ld ns.Depth %ld !!\n",
886 (LONG
) ns
.Width
, (LONG
) ns
.Height
, (LONG
) ns
.Depth
);)
889 modeid
= BestCModeIDTagList(bestmodetags
);
891 DEBUG_OPENSCREEN(dprintf("BestCModeIDTagList returned %ld\n",modeid
);)
903 if (INVALID_ID
== modeid
)
905 modeid
= BestModeIDA(modetags
);
906 if (INVALID_ID
== modeid
)
908 DEBUG_OPENSCREEN(dprintf("!!! OpenScreen(): Could not find valid modeid !!!\n");)
909 FireScreenNotifyMessage((IPTR
) NULL
, SNOTIFY_AFTER_OPENSCREEN
, IntuitionBase
);
915 DEBUG_OPENSCREEN(dprintf("OpenScreen: ModeID 0x%08lx\n", modeid
));
919 InitRastPort(&screen
->Screen
.RastPort
);
924 if ((displayinfo
= FindDisplayInfo(modeid
)) != NULL
&&
925 GetDisplayInfoData(displayinfo
, &dimensions
, sizeof(dimensions
), DTAG_DIMS
, modeid
) &&
926 GetDisplayInfoData(displayinfo
, &monitor
, sizeof(monitor
), DTAG_MNTR
, modeid
))
930 screen
->Monitor
= monitor
.Mspc
;
937 dclip
= &dimensions
.StdOScan
;
941 dclip
= &dimensions
.MaxOScan
;
945 dclip
= &dimensions
.VideoOScan
;
949 dclip
= &dimensions
.TxtOScan
;
954 if (ns
.Width
== STDSCREENWIDTH
)
955 ns
.Width
= dclip
->MaxX
- dclip
->MinX
+ 1;
957 if (ns
.Height
== STDSCREENHEIGHT
)
958 ns
.Height
= dclip
->MaxY
- dclip
->MinY
+ 1;
960 DEBUG_OPENSCREEN(dprintf("OpenScreen: Monitor 0x%lx Width %ld Height %ld\n",
961 screen
->Monitor
, ns
.Width
, ns
.Height
));
963 if (ns
.Type
& CUSTOMBITMAP
)
965 struct BitMap
*custombm
;
967 custombm
= ns
.CustomBitMap
;
969 if (IsCyberModeID(modeid
) && custombm
)
971 int pixfmt
= GetCyberIDAttr(CYBRIDATTR_PIXFMT
,modeid
);
973 if(GetCyberMapAttr(custombm
,CYBRMATTR_PIXFMT
) != pixfmt
)
975 // incompatible formats !
982 screen
->Screen
.RastPort
.BitMap
= custombm
;
983 ns
.Depth
= GetBitMapAttr(ns
.CustomBitMap
,BMA_DEPTH
);
984 DEBUG_OPENSCREEN(dprintf("OpenScreen: CustomBitmap Depth %ld\n",
989 ns
.CustomBitMap
= NULL
;
990 ns
.Type
&= ~CUSTOMBITMAP
;
995 screen
->Screen
.RastPort
.BitMap
= NULL
;
999 if(screen
->Screen
.RastPort
.BitMap
== NULL
)
1004 Depth
= (dimensions
.MaxDepth
> 8) ? dimensions
.MaxDepth
: ns
.Depth
;
1009 pixfmt
= PIXFMT_RGB15
;
1012 pixfmt
= PIXFMT_RGB16
;
1015 pixfmt
= PIXFMT_BGR24
;
1018 pixfmt
= PIXFMT_ARGB32
;
1021 pixfmt
= PIXFMT_LUT8
;
1025 if (IsCyberModeID(modeid
))
1027 pixfmt
= GetCyberIDAttr(CYBRIDATTR_PIXFMT
,modeid
);
1031 allocbitmapflags
|= (BMF_SPECIALFMT
|BMF_CLEAR
);
1033 screen
->Screen
.RastPort
.BitMap
= AllocBitMap(ns
.Width
,
1036 allocbitmapflags
| (pixfmt
<< 24),
1039 screen
->AllocatedBitmap
= screen
->Screen
.RastPort
.BitMap
;
1041 memcpy(&screen
->Screen
.BitMap
,screen
->Screen
.RastPort
.BitMap
,sizeof(struct BitMap
));
1044 DEBUG_OPENSCREEN(dprintf("OpenScreen: BitMap 0x%lx\n",
1045 screen
->Screen
.RastPort
.BitMap
));
1049 DEBUG_OPENSCREEN(dprintf("OpenScreen: no displayinfo\n"));
1052 if ((displayinfo
= FindDisplayInfo(modeid
)) != NULL
&&
1053 GetDisplayInfoData(displayinfo
, (UBYTE
*)&dimensions
, sizeof(dimensions
), DTAG_DIMS
, modeid
) &&
1054 GetDisplayInfoData(displayinfo
, (UBYTE
*)&monitor
, sizeof(monitor
), DTAG_MNTR
, modeid
))
1056 screen
->Monitor
= monitor
.Mspc
;
1062 case OSCAN_STANDARD
:
1063 dclip
= &dimensions
.StdOScan
;
1067 dclip
= &dimensions
.MaxOScan
;
1071 dclip
= &dimensions
.VideoOScan
;
1075 dclip
= &dimensions
.TxtOScan
;
1080 if (ns
.Width
== STDSCREENWIDTH
)
1081 ns
.Width
= dclip
->MaxX
- dclip
->MinX
+ 1;
1083 if (ns
.Height
== STDSCREENHEIGHT
)
1084 ns
.Height
= dclip
->MaxY
- dclip
->MinY
+ 1;
1088 if ((success
= InitRastPort (&screen
->Screen
.RastPort
)))
1093 screen
->Screen
.RastPort
.BitMap
= screen
->AllocatedBitmap
= AllocScreenBitMap(modeid
);
1096 D(bug("got bitmap\n"));
1098 /* Init screen's viewport */
1099 InitVPort(&screen
->Screen
.ViewPort
);
1101 /* Allocate a RasInfo struct in which we have a pointer
1102 to the struct BitMap, into which the driver can
1103 store its stuff. (Eg. pointer to a BitMap HIDD object)
1105 screen
->Screen
.ViewPort
.RasInfo
= AllocMem(sizeof(struct RasInfo
), MEMF_ANY
| MEMF_CLEAR
);
1107 DEBUG_OPENSCREEN(dprintf("OpenScreen: RasInfo 0x%lx\n",
1108 screen
->Screen
.ViewPort
.RasInfo
));
1111 (screen
->Screen
.RastPort
.BitMap
== NULL
) ||
1112 (screen
->Screen
.ViewPort
.RasInfo
== NULL
))
1118 /* Store pointer to bitmap, so we can get hold of it
1119 from withing LoadRGBxx() functions
1121 D(bug("got allocated stuff\n"));
1122 screen
->Screen
.ViewPort
.RasInfo
->BitMap
= screen
->Screen
.RastPort
.BitMap
;
1128 /* Read depth from the bitmap to avoid AttachPalExtra/ObtainPen getting
1129 * confused if cgx decided to allocate a higher depth bitmap than what
1132 ns
.Depth
= GetBitMapAttr(screen
->Screen
.RastPort
.BitMap
,BMA_DEPTH
);
1134 numcolors
= (ns
.Depth
<= 8) ? (1L << ns
.Depth
) : 256;
1136 /* Get a color map structure. Sufficient colors?? */
1138 DEBUG_OPENSCREEN(dprintf("OpenScreen: Colormap Entries %ld\n",
1141 if ((screen
->Screen
.ViewPort
.ColorMap
= GetColorMap(numcolors
< 32 ? 32 : numcolors
)) != NULL
)
1144 #ifndef __MORPHOS__ /* Use VideoControl for MorphOS */
1145 screen
->Screen
.ViewPort
.ColorMap
->VPModeID
= modeid
;
1148 if (0 == AttachPalExtra(screen
->Screen
.ViewPort
.ColorMap
,
1149 &screen
->Screen
.ViewPort
))
1156 refcnt
=(UWORD
*) screen
->Screen
.ViewPort
.ColorMap
->PalExtra
->pe_RefCnt
;
1157 alloclist
= (UBYTE
*)(refcnt
+ screen
->Screen
.ViewPort
.ColorMap
->Count
);
1159 DEBUG_OPENSCREEN(dprintf("OpenScreen: PalExtra alloclist 0x%lx Count %ld\n",alloclist
,screen
->Screen
.ViewPort
.ColorMap
->Count
));
1161 while(i
< screen
->Screen
.ViewPort
.ColorMap
->Count
)
1163 // initialize alloc list to -1,0,1,2,3,4
1165 DEBUG_OPENSCREEN(dprintf("OpenScreen: alloclist[%ld]=%ld\n",
1181 DEBUG_OPENSCREEN(dprintf("OpenScreen: ColorMap 0x%lx\n",
1182 screen
->Screen
.ViewPort
.ColorMap
));
1187 screen
->ModeID
= modeid
;
1191 struct ViewPortExtra
*vpe
= GfxNew(VIEWPORT_EXTRA_TYPE
);
1193 DEBUG_OPENSCREEN(dprintf("OpenScreen: ViewPortExtra 0x%lx\n", vpe
));
1199 struct TagItem tags
[6];
1201 memcpy(&vpe
->DisplayClip
, dclip
,sizeof(struct Rectangle
));
1203 screen
->Screen
.ViewPort
.DWidth
= dclip
->MaxX
- dclip
->MinX
+ 1;//ns.Width; /* or from dclip ? */
1204 screen
->Screen
.ViewPort
.DHeight
= dclip
->MaxY
- dclip
->MinY
+ 1;//ns.Height;
1206 tags
[0].ti_Tag
= VTAG_ATTACH_CM_SET
;
1207 tags
[0].ti_Data
= (IPTR
)&screen
->Screen
.ViewPort
;
1208 tags
[1].ti_Tag
= VTAG_VIEWPORTEXTRA_SET
;
1209 tags
[1].ti_Data
= (IPTR
)vpe
;
1210 tags
[2].ti_Tag
= VTAG_NORMAL_DISP_SET
;
1211 tags
[2].ti_Data
= (IPTR
)displayinfo
;
1212 tags
[3].ti_Tag
= VTAG_VPMODEID_SET
;
1213 tags
[3].ti_Data
= modeid
;
1214 tags
[4].ti_Tag
= VTAG_END_CM
;
1215 tags
[5].ti_Tag
= TAG_END
;
1217 if (VideoControl(screen
->Screen
.ViewPort
.ColorMap
, tags
) == 0)
1219 DEBUG_OPENSCREEN(dprintf("OpenScreen: VideoControl ok\n"));
1224 DEBUG_OPENSCREEN(dprintf("OpenScreen: VideoControl failed\n"));
1228 // added 2002-03-10, pre iprefs openscreen has all first 4 colours black (cyfm)
1229 // removed 2002-26-12, I now set the pens on start (zapek)
1231 if ((p
= GetPrivIBase(IntuitionBase
)->Colors
))
1235 DEBUG_OPENSCREEN(dprintf("OpenScreen: Intuition Color32 Table 0x%lx\n",p
);)
1237 Sum
= p
[0].red
+ p
[0].green
+ p
[0].blue
;
1238 Sum
+= p
[1].red
+ p
[1].green
+ p
[1].blue
;
1239 Sum
+= p
[2].red
+ p
[2].green
+ p
[2].blue
;
1240 Sum
+= p
[3].red
+ p
[3].green
+ p
[3].blue
;
1245 DEBUG_OPENSCREEN(dprintf("OpenScreen: All 4 first colours black, reset !!\n");)
1247 for (i
= 0; i
< COLORTABLEENTRIES
; i
++)
1249 DEBUG_OPENSCREEN(dprintf("OpenScreen: Current Color32[%ld] R 0x%lx G 0x%lx B 0x%lx\n",
1251 p
[i
].red
, p
[i
].green
, p
[i
].blue
));
1253 p
[0].red
= 0xAAAAAAAA;
1254 p
[0].green
= 0xAAAAAAAA;
1255 p
[0].blue
= 0xAAAAAAAA;
1257 p
[1].red
= 0x00000000;
1258 p
[1].green
= 0x00000000;
1259 p
[1].blue
= 0x00000000;
1261 p
[2].red
= 0xFFFFFFFF;
1262 p
[2].green
= 0xFFFFFFFF;
1263 p
[2].blue
= 0xFFFFFFFF;
1265 p
[3].red
= 0x55555555;
1266 p
[3].green
= 0x77777777;
1267 p
[3].blue
= 0xAAAAAAAA;
1278 // struct Color32 *p;
1282 DEBUG_OPENSCREEN(dprintf("OpenScreen: Load Colors\n"));
1284 D(bug("Loading colors\n"));
1286 /* First load default colors for the screen */
1287 LoadRGB32(&screen
->Screen
.ViewPort
, (ULONG
*)coltab
);
1289 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set first 4 colors\n"));
1291 #warning "FIXME: backport: #if'ed out"
1293 p
= GetPrivIBase(IntuitionBase
)->Colors
;
1294 for (k
= 0; k
< 4 && k
< numcolors
; ++k
)
1296 DEBUG_OPENSCREEN(dprintf("OpenScreen: SetRGB32 Viewport 0x%lx Index %ld R 0x%lx G 0x%lx B 0x%lx\n",
1297 screen
->Screen
.ViewPort
,
1298 k
, p
[k
].red
, p
[k
].green
, p
[k
].blue
));
1299 SetRGB32(&screen
->Screen
.ViewPort
, k
, p
[k
].red
, p
[k
].green
, p
[k
].blue
);
1304 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set last 4 colors\n"));
1306 #warning Isn`t that only set for FullPalette ?
1307 for (k
= 0; k
< 4; ++k
)
1309 DEBUG_OPENSCREEN(dprintf("OpenScreen: SetRGB32 Viewport 0x%lx Index %ld R 0x%lx G 0x%lx B 0x%lx\n",
1310 screen
->Screen
.ViewPort
,
1311 numcolors
- k
- 1, p
[k
+4].red
, p
[k
+4].green
, p
[k
+4].blue
));
1314 ObtainPen(screen
->Screen
.ViewPort
.ColorMap
,
1321 SetRGB32(&screen
->Screen
.ViewPort
, numcolors
- k
- 1, p
[k
+4].red
, p
[k
+4].green
, p
[k
+4].blue
);
1327 DEBUG_OPENSCREEN(dprintf("OpenScreen: Obtain Mousepointer colors\n"));
1329 /* Allocate pens for the mouse pointer */
1330 q
= &GetPrivIBase(IntuitionBase
)->ActivePreferences
->color17
;
1331 for (k
= 0; k
< 3; ++k
, ++q
)
1333 DEBUG_OPENSCREEN(dprintf("OpenScreen: ColorMap 0x%lx Pen %ld R 0x%lx G 0x%lx B 0x%lx\n",
1334 screen
->Screen
.ViewPort
.ColorMap
,
1336 (*q
>> 8) * 0x11111111,
1337 ((*q
>> 4) & 0xf) * 0x11111111,
1338 (*q
& 0xf) * 0x11111111));
1339 if (k
+ 17 < numcolors
)
1341 ObtainPen(screen
->Screen
.ViewPort
.ColorMap
,
1343 (*q
>> 8) * 0x11111111,
1344 ((*q
>> 4) & 0xf) * 0x11111111,
1345 (*q
& 0xf) * 0x11111111,
1350 /* Can't be allocated, but can still be set. */
1351 SetRGB32(&screen
->Screen
.ViewPort
,
1353 (*q
>> 8) * 0x11111111,
1354 ((*q
>> 4) & 0xf) * 0x11111111,
1355 (*q
& 0xf) * 0x11111111);
1359 if (colors
) /* if SA_Colors tag exists */
1361 DEBUG_OPENSCREEN(dprintf("OpenScreen: set SA_Colors 0x%lx\n",colors
));
1362 for(; colors
->ColorIndex
!= (WORD
)~0; colors
++)
1364 DEBUG_OPENSCREEN(dprintf("OpenScreen: SetRGB4 Viewport 0x%lx Index %ld R 0x%lx G 0x%lx B 0x%lx\n",
1365 screen
->Screen
.ViewPort
,
1370 SetRGB4(&screen
->Screen
.ViewPort
,
1378 if (colors32
) /* if SA_Colors32 tag exists */
1380 DEBUG_OPENSCREEN(dprintf("OpenScreen: LoadRGB32 colors32 0x%lx\n",colors32
));
1381 LoadRGB32(&screen
->Screen
.ViewPort
, (const ULONG
*)colors32
);
1384 D(bug("Loaded colors\n"));
1395 //intui68k filters this
1396 screen
->Screen
.Flags
= (ns
.Type
& ~NS_EXTENDED
);
1398 /* Temporary hack */
1399 if (ns
.Width
>= 500 || ns
.Height
>= 300)
1400 screen
->Screen
.Flags
|= SCREENHIRES
;
1403 /* Mark the bitmap of the screen as an AROS-displayed BitMap */
1404 screen
->Screen
.RastPort
.BitMap
->Flags
|= BMF_AROS_HIDD
;
1408 Copy the data from the rastport's bitmap
1409 to the screen's bitmap structure
1411 screen
->Screen
.BitMap
= *screen
->Screen
.RastPort
.BitMap
;
1414 screen
->Screen
.WBorTop
= 2;
1415 screen
->Screen
.WBorLeft
= 4;
1416 screen
->Screen
.WBorRight
= 4;
1417 screen
->Screen
.WBorBottom
= 2;
1419 screen
->Screen
.WBorTop
= 3; /* Amiga default is 2 */
1420 screen
->Screen
.WBorLeft
= 4;
1421 screen
->Screen
.WBorRight
= 4;
1422 screen
->Screen
.WBorBottom
= 2; /* Amiga default is 2 */
1425 screen
->Screen
.Title
= ns
.DefaultTitle
;
1428 DEBUG_OPENSCREEN(dprintf("OpenScreen: init layers\n"));
1429 InitLayers(&screen
->Screen
.LayerInfo
);
1433 /* Root layer now installed automatically by first call
1434 to CreateLayerTagList */
1436 #ifdef CreateLayerTagList
1438 struct TagItem tags
[4] =
1440 {LA_Visible
, FALSE
},
1441 {LA_Priority
, ROOTPRIORITY
},
1446 CreateLayerTagList(&screen
->Screen
.LayerInfo
,
1447 screen
->Screen
.RastPort
.BitMap
,
1448 screen
->Screen
.LeftEdge
,
1449 screen
->Screen
.TopEdge
,
1450 screen
->Screen
.LeftEdge
+ screen
->Screen
.Width
- 1,
1451 screen
->Screen
.TopEdge
+ screen
->Screen
.Height
- 1,
1455 DEBUG_OPENSCREEN(dprintf("OpenScreen: rootLayer 0x%lx\n",screen
->rootLayer
));
1460 if (NULL
!= layer_info_hook
)
1462 DEBUG_OPENSCREEN(dprintf("OpenScreen: instal layerinfohook\n"));
1463 InstallLayerInfoHook(&screen
->Screen
.LayerInfo
, layer_info_hook
);
1465 D(bug("layers intited screen\n"));
1467 screen
->DInfo
.dri
.dri_Version
= DRI_VERSION
;
1468 screen
->DInfo
.dri
.dri_NumPens
= NUMDRIPENS
;
1469 screen
->DInfo
.dri
.dri_Pens
= screen
->Pens
;
1470 /* dri_Depth is 8 on hi/true color screens like in AmigaOS with picasso96/cybergraphx */
1471 screen
->DInfo
.dri
.dri_Depth
= (ns
.Depth
<= 8) ? ns
.Depth
: 8;
1472 #warning These are probably monitor dependent
1473 screen
->DInfo
.dri
.dri_Resolution
.X
= 44;
1474 screen
->DInfo
.dri
.dri_Resolution
.Y
= 44;
1475 screen
->DInfo
.dri
.dri_Flags
= 0;
1476 screen
->DInfo
.dri_Screen
= &screen
->Screen
;
1477 InitSemaphore(&screen
->DInfo
.dri_WinDecorSem
);
1478 InitSemaphore(&screen
->DInfo
.dri_ScrDecorSem
);
1480 /* SA_SysFont overrides SA_Font! */
1482 DEBUG_OPENSCREEN(dprintf("OpenScreen: SysFont = %d, ns.Font = %p\n", sysfont
, ns
.Font
));
1486 /* Is handled below */
1487 DEBUG_OPENSCREEN(dprintf("OpenScreen: skip SysFont for now\n"));
1489 else if (sysfont
== 1)
1492 /* Use safe OpenFont here - Piru
1494 screen
->DInfo
.dri
.dri_Font
= SafeReopenFont(IntuitionBase
, &GetPrivIBase(IntuitionBase
)->ScreenFont
);
1497 #warning: Really hacky way of re-opening ScreenFont
1500 screen
->DInfo
.dri
.dri_Font
= GetPrivIBase(IntuitionBase
)->ScreenFont
;
1501 screen
->DInfo
.dri
.dri_Font
->tf_Accessors
++;
1505 screen
->SpecialFlags
|= SF_SysFont
;
1507 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set ScreenFont\n"));
1512 screen
->DInfo
.dri
.dri_Font
= OpenFont(ns
.Font
);
1513 DEBUG_OPENSCREEN(dprintf("OpenScreen: custom font 0x%lx\n",screen
->DInfo
.dri
.dri_Font
));
1516 if (!screen
->DInfo
.dri
.dri_Font
)
1518 /* GfxBase->DefaultFont is *not* always topaz 8. It
1519 can be set with the Font prefs program!! */
1522 /* Use safe OpenFont.. - Piru
1524 screen
->DInfo
.dri
.dri_Font
= SafeReopenFont(IntuitionBase
, &GfxBase
->DefaultFont
);
1527 #warning: Really hacky way of re-opening system default font
1530 screen
->DInfo
.dri
.dri_Font
= GfxBase
->DefaultFont
;
1531 screen
->DInfo
.dri
.dri_Font
->tf_Accessors
++;
1536 if (!screen
->DInfo
.dri
.dri_Font
) ok
= FALSE
;
1542 /* set default values for pens */
1543 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set Default Pens\n"));
1545 CopyMem(ns
.Depth
== 1 ? GetPrivIBase(IntuitionBase
)->DriPens2
1546 : ns
.Depth
== 4 ? GetPrivIBase(IntuitionBase
)->DriPens4
1547 : GetPrivIBase(IntuitionBase
)->DriPens8
,
1549 sizeof(screen
->Pens
));
1553 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set NewLook\n"));
1554 screen
->DInfo
.dri
.dri_Flags
|= DRIF_NEWLOOK
;
1562 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set Custom Pens\n"));
1564 screen
->Pens
[DETAILPEN
] = screen
->Screen
.DetailPen
;
1565 screen
->Pens
[BLOCKPEN
] = screen
->Screen
.BlockPen
;
1567 for(i
= 0; (i
< NUMDRIPENS
) && (customdripens
[i
] != (UWORD
)~0); i
++)
1569 DEBUG_OPENSCREEN(dprintf("OpenScreen: Pen[%ld] %ld\n",i
,screen
->Pens
[i
]));
1570 screen
->Pens
[i
] = customdripens
[i
];
1576 * Let`s do some broken software validation of the pens
1577 * so we may not run into a black desktop.
1580 DEBUG_OPENSCREEN(dprintf("OpenScreen: Check Default Pens if the make sense\n"));
1581 if (screen
->Screen
.DetailPen
== screen
->Screen
.BlockPen
)
1583 DEBUG_OPENSCREEN(dprintf("OpenScreen: DetailPen==BlockPen..correct\n"));
1584 screen
->Screen
.DetailPen
= 0;
1585 screen
->Screen
.BlockPen
= 1;
1588 if (screen
->Screen
.BlockPen
== 0)
1590 DEBUG_OPENSCREEN(dprintf("OpenScreen: BlockPen==0..correct\n"));
1591 screen
->Screen
.BlockPen
= screen
->Screen
.DetailPen
;
1592 screen
->Screen
.DetailPen
= 0;
1595 screen
->Pens
[DETAILPEN
] = screen
->Screen
.DetailPen
;
1596 screen
->Pens
[BLOCKPEN
] = screen
->Screen
.BlockPen
;
1599 /* Allocate shared/exclusive colors */
1602 BYTE color_alloced
[256];
1606 for(i
= 0; i
< 256; i
++)
1608 color_alloced
[i
] = FALSE
;
1611 /* Mouse pointer colors */
1613 color_alloced
[17] = TRUE
;
1614 color_alloced
[18] = TRUE
;
1615 color_alloced
[19] = TRUE
;
1617 /* The Pens in the DrawInfo must be allocated as shared */
1619 DEBUG_OPENSCREEN(dprintf("OpenScreen: ObtainPen DrawInfo Pens as shared\n"));
1621 for(i
= 0; i
< NUMDRIPENS
; i
++)
1623 int pen
= screen
->Pens
[i
];
1625 if (!color_alloced
[pen
])
1627 DEBUG_OPENSCREEN(dprintf("OpenScreen: ObtainPen ColorMap 0x%lx Pen %ld\n",
1628 screen
->Screen
.ViewPort
.ColorMap
,
1631 ObtainPen(screen
->Screen
.ViewPort
.ColorMap
,
1637 color_alloced
[pen
] = TRUE
;
1640 DEBUG_OPENSCREEN(dprintf("OpenScreen: done\n"));
1642 /* If SA_SharePens is FALSE then allocate the rest of the colors
1643 in the colormap as exclusive */
1647 DEBUG_OPENSCREEN(dprintf("OpenScreen: ObtainPen the remaining Pens as exclusive\n"));
1649 for(i
= 0; i
< numcolors
; i
++)
1651 if (!color_alloced
[i
])
1653 DEBUG_OPENSCREEN(dprintf("OpenScreen: ObtainPen ColorMap 0x%lx Pen %ld\n",
1654 screen
->Screen
.ViewPort
.ColorMap
,
1656 ObtainPen(screen
->Screen
.ViewPort
.ColorMap
,
1661 PENF_EXCLUSIVE
| PENF_NO_SETCOLOR
);
1665 } /* if (!sharepens) */
1673 if (!SetFrontBitMap(screen
->Screen
.RastPort
.BitMap
, TRUE
))
1685 screen
->DInfo
.dri_Screen
= &screen
->Screen
; //useful sometimes ;)
1687 realdepth
= GetBitMapAttr( screen
->Screen
.RastPort
.BitMap
, BMA_DEPTH
);
1690 screen
->DInfo
.dri_Flags
|= DRIF_DIRECTCOLOR
;
1694 screen
->DInfo
.dri_Flags
&= ~DRIF_DIRECTCOLOR
;
1697 if (!(screen
->DInfo
.dri_Colors
= AllocMem(4 * DRIPEN_NUMDRIPENS
,MEMF_PUBLIC
)))
1702 CopyMem(&defaultdricolors
,screen
->DInfo
.dri_Colors
,sizeof (defaultdricolors
));
1703 memset(((UBYTE
*) screen
->DInfo
.dri_Colors
) + sizeof(defaultdricolors
), 0, 4 * DRIPEN_NUMDRIPENS
- sizeof(defaultdricolors
));
1708 if ((screen
->DInfo
.dri_Customize
= AllocMem(sizeof (struct IntuitionCustomize
),MEMF_PUBLIC
|MEMF_CLEAR
)))
1710 struct IntuitionCustomize
*ic
;
1711 ic
= screen
->DInfo
.dri_Customize
;
1712 screen
->DInfo
.dri_Flags
|= DRIF_SKINSSUPPORT
;
1713 /* This initializes CustomizePrefs structure */
1715 int_SkinAction(SKA_LoadSkin
,(ULONG
*)&screen
->DInfo
,(struct Screen
*)screen
,IntuitionBase
);
1726 struct windowclassprefs
*wcprefs
;
1728 wcprefs
= (struct windowclassprefs
*)int_GetCustomPrefs(TYPE_WINDOWCLASS
,&screen
->DInfo
,IntuitionBase
);
1729 if (wcprefs
->flags
& WINDOWCLASS_PREFS_1TO1FRAMES
)
1731 screen
->Screen
.WBorLeft
= screen
->Screen
.WBorTop
;
1732 screen
->Screen
.WBorRight
= screen
->Screen
.WBorTop
;
1733 screen
->Screen
.WBorBottom
= screen
->Screen
.WBorTop
;
1736 screen
->Screen
.WBorTop
+= wcprefs
->titlebarincrement
;
1738 int_FreeCustomPrefs(TYPE_WINDOWCLASS
,&screen
->DInfo
,IntuitionBase
);
1745 struct TagItem windecor_tags
[] =
1747 {WDA_DrawInfo
, (IPTR
)&screen
->DInfo
},
1748 {WDA_Screen
, (IPTR
)screen
},
1752 screen
->DInfo
.dri_WinDecorObj
= NewObjectA(NULL
, WINDECORCLASS
, windecor_tags
);
1753 if (!screen
->DInfo
.dri_WinDecorObj
)
1761 struct TagItem scrdecor_tags
[] =
1763 {SDA_DrawInfo
, (IPTR
)&screen
->DInfo
},
1764 {SDA_Screen
, (IPTR
)screen
},
1768 screen
->DInfo
.dri_ScrDecorObj
= NewObjectA(NULL
, SCRDECORCLASS
, scrdecor_tags
);
1769 if (!screen
->DInfo
.dri_ScrDecorObj
)
1777 struct TagItem sysi_tags
[] =
1779 {SYSIA_Which
, MENUCHECK
},
1780 {SYSIA_DrawInfo
, (IPTR
)&screen
->DInfo
},
1784 screen
->DInfo
.dri
.dri_CheckMark
= NewObjectA(NULL
, "sysiclass", sysi_tags
);
1785 DEBUG_OPENSCREEN(dprintf("OpenScreen: CheckMark 0x%lx\n",
1786 screen
->DInfo
.dri_CheckMark
));
1788 sysi_tags
[0].ti_Data
= AMIGAKEY
;
1790 screen
->DInfo
.dri
.dri_AmigaKey
= NewObjectA(NULL
, "sysiclass", sysi_tags
);
1791 DEBUG_OPENSCREEN(dprintf("OpenScreen: AmigaKey 0x%lx\n",
1792 screen
->DInfo
.dri
.dri_AmigaKey
));
1794 sysi_tags
[0].ti_Data
= SUBMENUIMAGE
;
1795 screen
->DInfo
.dri_Customize
->submenu
= NewObjectA(NULL
, "sysiclass", sysi_tags
);
1796 sysi_tags
[0].ti_Data
= MENUTOGGLEIMAGE
;
1797 screen
->DInfo
.dri_Customize
->menutoggle
= NewObjectA(NULL
, "sysiclass", sysi_tags
);
1798 if (!screen
->DInfo
.dri_Customize
->submenu
||
1799 !screen
->DInfo
.dri_Customize
->menutoggle
) ok
= FALSE
;
1802 if (!screen
->DInfo
.dri
.dri_CheckMark
|| !screen
->DInfo
.dri
.dri_AmigaKey
) ok
= FALSE
;
1807 SetFont(&screen
->Screen
.RastPort
, screen
->DInfo
.dri
.dri_Font
);
1809 AskFont(&screen
->Screen
.RastPort
, (struct TextAttr
*) &screen
->textattr
);
1811 screen
->Screen
.Font
= (struct TextAttr
*) &screen
->textattr
;
1813 DEBUG_OPENSCREEN(dprintf("OpenScreen: Font %s/%d\n",
1814 screen
->textattr
.tta_Name
, screen
->textattr
.tta_YSize
));
1817 screen
->Screen
.BarVBorder
= 1;
1818 screen
->Screen
.BarHBorder
= 5;
1819 screen
->Screen
.MenuVBorder
= 2;
1820 screen
->Screen
.MenuHBorder
= 4;
1822 screen
->Screen
.BarVBorder
= 1; /* on the Amiga it is (usually?) 1 */
1823 screen
->Screen
.BarHBorder
= 5;
1824 screen
->Screen
.MenuVBorder
= 2; /* on the Amiga it is (usually?) 2 */
1825 screen
->Screen
.MenuHBorder
= 4;
1828 screen
->Screen
.BarHeight
= screen
->DInfo
.dri
.dri_Font
->tf_YSize
+ screen
->Screen
.WBorTop
-2 +
1829 screen
->Screen
.BarVBorder
* 2; /* real layer will be 1 pixel higher! */
1831 screen
->Screen
.BarHeight
= screen
->DInfo
.dri
.dri_Font
->tf_YSize
+
1832 screen
->Screen
.BarVBorder
* 2; /* real layer will be 1 pixel higher! */
1836 #define SDEPTH_HEIGHT (screen->Screen.BarHeight + 1)
1840 #define IA_Screen (IA_Dummy + 0x1f) /* OS v44 includes!*/
1842 struct TagItem sdepth_tags
[] =
1846 #if SQUARE_WIN_GADGETS
1847 {GA_Width
, SDEPTH_HEIGHT
},
1849 {GA_Height
, SDEPTH_HEIGHT
},
1850 {GA_SysGadget
, TRUE
},
1851 {GA_SysGType
, GTYP_SDEPTH
},
1852 {GA_RelVerify
, TRUE
},
1858 if (!(screen
->Screen
.Flags
& SCREENQUIET
))
1860 im
= CreateStdSysImage(SDEPTHIMAGE
, SDEPTH_HEIGHT
, &screen
->Screen
,
1861 (struct DrawInfo
*)&screen
->DInfo
, IntuitionBase
);
1864 sdepth_tags
[0].ti_Data
= (IPTR
)im
;
1866 screen
->depthgadget
= NewObjectA(NULL
, BUTTONGCLASS
, sdepth_tags
);
1868 DEBUG_OPENSCREEN(dprintf("OpenScreen: DepthGadget 0x%lx\n",
1869 screen
->depthgadget
));
1871 screen
->Screen
.FirstGadget
= (struct Gadget
*)screen
->depthgadget
;
1872 if (screen
->Screen
.FirstGadget
)
1874 struct IntDrawInfo
*dri
= &screen
->DInfo
;
1875 struct sdpLayoutScreenGadgets msg
;
1877 screen
->Screen
.FirstGadget
->GadgetType
|= GTYP_SCRGADGET
;
1879 msg
.MethodID
= SDM_LAYOUT_SCREENGADGETS
;
1880 msg
.sdp_Layer
= screen
->Screen
.BarLayer
;
1881 msg
.sdp_Gadgets
= screen
->Screen
.FirstGadget
;
1882 msg
.sdp_Flags
= SDF_LSG_INITIAL
| SDF_LSG_MULTIPLE
;
1884 LOCKSHARED_SCRDECOR(dri
);
1885 DoMethodA(dri
->dri_ScrDecorObj
, (Msg
)&msg
);
1886 UNLOCK_SCRDECOR(dri
);
1889 struct TagItem gadtags
[] =
1896 GetAttr(GA_Width
, screen
->depthgadget
, &width
);
1898 gadtags
[0].ti_Data
= -width
+ 1;
1899 SetAttrsA(screen
->depthgadget
, gadtags
);
1905 if (im
) DisposeObject(im
);
1915 for (i
= 0;i
<= screen
->DInfo
.dri
.dri_NumPens
; i
++)
1917 DEBUG_OPENSCREEN(dprintf("OpenScreen: dri_Pen[%ld] = %ld\n",i
,screen
->DInfo
.dri
.dri_Pens
[i
]));
1922 #ifdef USEWINDOWLOCK
1923 /* let's wait for user to finish window drag/size actions to avoid
1924 deadlocks and not break user's input */
1925 ObtainSemaphore(&GetPrivIBase(IntuitionBase
)->WindowLock
);
1930 int_CalcSkinInfo(&screen
->Screen
,IntuitionBase
);
1931 int_InitTitlebarBuffer(screen
,IntuitionBase
);
1933 D(bug("callling SetRast()\n"));
1935 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set background color Pen %ld\n",screen
->Pens
[BACKGROUNDPEN
]));
1936 /* Set screen to background color */
1937 SetRast(&screen
->Screen
.RastPort
, screen
->Pens
[BACKGROUNDPEN
]);
1939 D(bug("SetRast() called\n"));
1941 DEBUG_OPENSCREEN(dprintf("OpenScreen: Creating screen bar\n"));
1946 if (GetPrivIBase(IntuitionBase
)->IControlPrefs
.ic_Flags
& ICF_NOWBTITLEBAR
) screen
->SpecialFlags
|= SF_InvisibleBar
;
1947 if (GetPrivIBase(IntuitionBase
)->IControlPrefs
.ic_Flags
& ICF_DISAPPEARINGTITLEBAR
) screen
->SpecialFlags
|= SF_AppearingBar
;
1951 //jDc: ALL screens MUST have BarLayer!
1952 CreateScreenBar(&screen
->Screen
, IntuitionBase
);
1954 if (!screen
->Screen
.BarLayer
) ok
= FALSE
;
1957 ** jDc: better modify the screen list in sync with inputhandler, this for example allows us to scan the list
1958 ** without any locks when we are on input.device context
1962 struct OpenScreenActionMsg msg
;
1963 struct List
*list
= LockPubScreenList();
1965 msg
.Screen
= screen
;
1966 msg
.NewScreen
= &ns
;
1969 DoSyncAction((APTR
)int_openscreen
,&msg
.msg
,IntuitionBase
);
1971 UnlockPubScreenList();
1978 GetAttr(POINTERA_SharedPointer
, GetPrivIBase(IntuitionBase
)->DefaultPointer
, (IPTR
*)&screen
->Pointer
);
1979 ObtainSharedPointer(screen
->Pointer
, IntuitionBase
);
1980 DEBUG_OPENSCREEN(dprintf("OpenScreen: Sprite DefaultPtr 0x%lx\n",&screen
->Pointer
));
1986 ok
= MakeScreen(&screen
->Screen
) == 0;
1987 DEBUG_OPENSCREEN(dprintf("OpenScreen: MakeScreen %s\n", ok
? "ok" : "failed"));
1992 ok
= RethinkDisplay() == 0;
1993 DEBUG_OPENSCREEN(dprintf("OpenScreen: RethinkDisplay %s\n", ok
? "ok" : "failed"));
2000 FireMenuMessage(MMCODE_STARTCLOCK
,NULL
,NULL
,IntuitionBase
);
2004 #ifdef USEWINDOWLOCK
2005 if (windowlock
) ReleaseSemaphore(&GetPrivIBase(IntuitionBase
)->WindowLock
);
2013 if (NULL
!= old_front_bm
)
2014 SetFrontBitMap(old_front_bm
, FALSE
);
2020 DEBUG_OPENSCREEN(dprintf("OpenScreen: Get ThinLayerInfo\n"));
2021 ThinLayerInfo(&screen
->Screen
.LayerInfo
);
2024 if (screen
->Screen
.ViewPort
.ColorMap
)
2027 struct TagItem tags
[2];
2029 tags
[0].ti_Tag
= VTAG_ATTACH_CM_GET
;
2030 tags
[0].ti_Data
= 0;
2031 tags
[1].ti_Tag
= VTAG_END_CM
;
2033 if (VideoControl(screen
->Screen
.ViewPort
.ColorMap
, tags
) == 0 &&
2036 GfxFree((APTR
)tags
[0].ti_Data
);
2040 FreeColorMap(screen
->Screen
.ViewPort
.ColorMap
);
2043 if (screen
->Screen
.BarLayer
)
2045 DEBUG_OPENSCREEN(dprintf("OpenScreen: KillScreenBar\n"));
2046 KillScreenBar(&screen
->Screen
, IntuitionBase
);
2049 if (screen
->DInfo
.dri_ScrDecorObj
)
2051 DEBUG_OPENSCREEN(dprintf("OpenScreen: Dispose ScrDecor Object\n"));
2052 DisposeObject(screen
->DInfo
.dri_ScrDecorObj
);
2055 if (screen
->DInfo
.dri_WinDecorObj
)
2057 DEBUG_OPENSCREEN(dprintf("OpenScreen: Dispose WinDecor Object\n"));
2058 DisposeObject(screen
->DInfo
.dri_WinDecorObj
);
2061 DisposeObject(screen
->DInfo
.dri_Customize
->submenu
);
2062 DisposeObject(screen
->DInfo
.dri_Customize
->menutoggle
);
2063 if (screen
->DInfo
.dri_Customize
) FreeMem(screen
->DInfo
.dri_Customize
,sizeof (struct IntuitionCustomize
));
2064 if (screen
->DInfo
.dri_Colors
) FreeMem(screen
->DInfo
.dri_Colors
,4 * DRIPEN_NUMDRIPENS
);
2066 if (screen
->DInfo
.dri
.dri_AmigaKey
)
2068 DEBUG_OPENSCREEN(dprintf("OpenScreen: Dispose AmigaKey Object\n"));
2069 DisposeObject(screen
->DInfo
.dri
.dri_AmigaKey
);
2071 if (screen
->DInfo
.dri
.dri_CheckMark
)
2073 DEBUG_OPENSCREEN(dprintf("OpenScreen: Dispose CheckMark Object\n"));
2074 DisposeObject(screen
->DInfo
.dri
.dri_CheckMark
);
2077 if (screen
->DInfo
.dri
.dri_Font
)
2079 DEBUG_OPENSCREEN(dprintf("OpenScreen: Close Font\n"));
2080 CloseFont(screen
->DInfo
.dri
.dri_Font
);
2083 if (screen
->AllocatedBitmap
&& !(ns
.Type
& CUSTOMBITMAP
))
2085 DEBUG_OPENSCREEN(dprintf("OpenScreen: Free BitMap\n"));
2086 FreeBitMap(screen
->AllocatedBitmap
);
2089 if (screen
->Screen
.ViewPort
.RasInfo
)
2091 DEBUG_OPENSCREEN(dprintf("OpenScreen: Free RasInfo\n"));
2092 FreeMem(screen
->Screen
.ViewPort
.RasInfo
, sizeof (struct RasInfo
));
2097 DEBUG_OPENSCREEN(dprintf("OpenScreen: Trash Rastport\n"));
2098 DeinitRastPort(&screen
->Screen
.RastPort
);
2101 DEBUG_OPENSCREEN(dprintf("OpenScreen: Free Screen\n"));
2102 FreeMem (screen
, sizeof (struct IntScreen
));
2108 DEBUG_OPENSCREEN(dprintf("OpenScreen: return 0x%lx\n", screen
));
2110 FireScreenNotifyMessage((IPTR
) screen
, SNOTIFY_AFTER_OPENSCREEN
, IntuitionBase
);
2112 ReturnPtr ("OpenScreen", struct Screen
*, (struct Screen
*)screen
);
2118 static VOID
int_openscreen(struct OpenScreenActionMsg
*msg
,
2119 struct IntuitionBase
*IntuitionBase
)
2122 struct IntScreen
*screen
= msg
->Screen
;
2123 struct NewScreen
*ns
= msg
->NewScreen
;
2124 struct List
*list
= msg
->List
;
2126 DEBUG_OPENSCREEN(dprintf("OpenScreen: Checking for pubScrNode (0x%lx)\n",screen
->pubScrNode
));
2128 /* If this is a public screen, we link it into the intuition global
2129 public screen list */
2130 if (screen
->pubScrNode
!= NULL
)
2132 /* Set the pointer to ourselves */
2133 GetPrivScreen(screen
)->pubScrNode
->psn_Screen
= &screen
->Screen
;
2135 DEBUG_OPENSCREEN(dprintf("OpenScreen: Add Screen to PubList\n"));
2136 AddTail(list
, (struct Node
*)GetPrivScreen(screen
)->pubScrNode
);
2139 lock
= LockIBase((ULONG
)NULL
);
2140 if (ns
->Type
& SCREENBEHIND
)
2142 struct Screen
**ptr
= &IntuitionBase
->FirstScreen
;
2144 DEBUG_OPENSCREEN(dprintf("OpenScreen: Sort Behind\n"));
2146 IntuitionBase
->ActiveScreen
= &screen
->Screen
;
2148 ptr
= &(*ptr
)->NextScreen
;
2149 *ptr
= &screen
->Screen
;
2153 screen
->Screen
.NextScreen
= IntuitionBase
->FirstScreen
;
2154 IntuitionBase
->FirstScreen
=
2155 IntuitionBase
->ActiveScreen
= &screen
->Screen
;
2156 DEBUG_OPENSCREEN(dprintf("OpenScreen: Set as ActiveScreen\n"));
2159 /* set the default pub screen */
2160 if (GetPrivIBase(IntuitionBase
)->IControlPrefs
.ic_Flags
& ICF_DEFPUBSCREEN
)
2162 if ((IntuitionBase
->FirstScreen
== &screen
->Screen
) && screen
->pubScrNode
&& (screen
->Screen
.Flags
& (PUBLICSCREEN
| WBENCHSCREEN
)))
2164 GetPrivIBase(IntuitionBase
)->DefaultPubScreen
= &screen
->Screen
;
2170 D(bug("set active screen\n"));
2172 AddResourceToList(screen
, RESOURCE_SCREEN
, IntuitionBase
);