home *** CD-ROM | disk | FTP | other *** search
- /* GadTools layout toolkit
- **
- ** Copyright © 1993-1995 by Olaf `Olsen' Barthel
- ** Freely distributable.
- */
-
- #include "gtlayout_global.h"
- /*
- #undef DB
- #define DB(x) x
- */
- #ifdef DO_CLONING
- VOID __regargs
- LTP_CloneScreen(struct LayoutHandle *Handle,LONG Width,LONG Height)
- {
- struct ColorSpec *ColourSpec = NULL;
- struct ColourRecord *ColourRecord = NULL;
- struct CloneExtra *Extra = Handle -> CloneExtra;
- LONG AllocationSize;
- UWORD i,j,*Pens = Handle -> CloneExtra -> ScreenPens,NumColours;
- struct Screen *Screen;
- ULONG DisplayID = GetVPModeID(&Handle -> Screen -> ViewPort);
- UWORD EndPen = (UWORD)~0;
-
- if(Handle -> ExactClone)
- NumColours = Handle -> Screen -> ViewPort . ColorMap -> Count;
- else
- {
- NumColours = Extra -> TotalPens;
-
- DisplayID &= ~(HAM | EXTRA_HALFBRITE);
- }
-
- Height += Handle -> Screen -> BarHeight + 1;
-
- if(Width < Extra -> MinWidth)
- Width = Extra -> MinWidth;
-
- if(Height < Extra -> MinHeight)
- Height = Extra -> MinHeight;
-
- if(Handle -> SimpleClone)
- Pens = &EndPen;
- else
- {
- if(V39)
- {
- if(!(ColourRecord = (struct ColourRecord *)LTP_Alloc(Handle,AllocationSize = sizeof(struct ColourRecord) + sizeof(struct ColourTriplet) * NumColours)))
- {
- Handle -> Failed = TRUE;
-
- DB(kprintf("no colours\n"));
-
- return;
- }
- else
- {
- ColourRecord -> NumColours = NumColours;
-
- if(Handle -> ExactClone)
- GetRGB32(Handle -> Screen -> ViewPort . ColorMap,0,NumColours,(ULONG *)ColourRecord -> Triplets);
- else
- {
- for(i = 0 ; i < NumColours ; i++)
- GetRGB32(Handle -> Screen -> ViewPort . ColorMap,Extra -> Pens[i],1,(ULONG *)&ColourRecord -> Triplets[i]);
- }
- }
- }
- else
- {
- if(!(ColourSpec = (struct ColorSpec *)LTP_Alloc(Handle,AllocationSize = sizeof(struct ColorSpec) * (NumColours + 1))))
- {
- Handle -> Failed = TRUE;
-
- DB(kprintf("no colours either\n"));
-
- return;
- }
- else
- {
- UWORD RGB,Which;
-
- for(i = 0 ; i < NumColours ; i++)
- {
- if(Handle -> ExactClone)
- Which = i;
- else
- Which = Extra -> Pens[i];
-
- RGB = GetRGB4(Handle -> Screen -> ViewPort . ColorMap,Which);
-
- ColourSpec[i] . ColorIndex = i;
- ColourSpec[i] . Red = (RGB >> 8) & 0xF;
- ColourSpec[i] . Green = (RGB >> 4) & 0xF;
- ColourSpec[i] . Blue = (RGB ) & 0xF;
- }
-
- ColourSpec[i] . ColorIndex = -1;
- }
- }
-
- if(Handle -> ExactClone)
- {
- for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
- Pens[i] = Extra -> Pens[i];
- }
- else
- {
- for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
- {
- for(j = 0 ; j < NumColours ; j++)
- {
- if(Extra -> Pens[j] == Handle -> DrawInfo -> dri_Pens[i])
- {
- Pens[i] = j;
-
- break;
- }
- }
- }
- }
-
- Pens[i] = (UWORD)~0;
- }
-
- DB(kprintf("Calling openscreen\n"));
-
- if(Screen = OpenScreenTags(NULL,
- SA_Width, Width,
- SA_Height, Height,
- SA_Overscan, OSCAN_TEXT,
- SA_AutoScroll, TRUE,
- SA_DisplayID, DisplayID,
- SA_Behind, TRUE,
- SA_Depth, Handle -> SimpleClone ? 2 : Extra -> Depth,
- SA_Colors, ColourSpec,
- SA_Colors32, ColourRecord,
- SA_Pens, Pens,
- SA_Font, Handle -> TextAttr,
- SA_Title, Handle -> Screen -> DefaultTitle,
- SA_SharePens, TRUE,
- SA_Interleaved, TRUE,
-
- Handle -> SimpleClone ? TAG_IGNORE : SA_BackFill, &Handle -> BackfillHook,
- Handle -> SimpleClone ? TAG_IGNORE : SA_BlockPen, Pens[SHADOWPEN],
- Handle -> SimpleClone ? TAG_IGNORE : SA_DetailPen, Pens[BACKGROUNDPEN],
- TAG_DONE))
- {
- struct DrawInfo *DrawInfo;
-
- DB(kprintf("getting drawinfo\n"));
-
- if(DrawInfo = GetScreenDrawInfo(Screen))
- {
- APTR VisualInfo;
-
- DB(kprintf("getting visualinfo\n"));
-
- if(VisualInfo = GetVisualInfoA(Screen,NULL))
- {
- UnlockPubScreen(NULL,Handle -> PubScreen);
-
- FreeScreenDrawInfo(Handle -> Screen,Handle -> DrawInfo);
-
- FreeVisualInfo(Handle -> VisualInfo);
-
- Handle -> PubScreen = NULL;
- Handle -> Screen = Screen;
- Handle -> DrawInfo = DrawInfo;
- Handle -> VisualInfo = VisualInfo;
- Handle -> TextPen = Handle -> DrawInfo -> dri_Pens[TEXTPEN];
- Handle -> BackgroundPen = Handle -> DrawInfo -> dri_Pens[BACKGROUNDPEN];
- Handle -> ShinePen = Handle -> DrawInfo -> dri_Pens[SHINEPEN];
- Handle -> ShadowPen = Handle -> DrawInfo -> dri_Pens[SHADOWPEN];
- Handle -> AspectX = Handle -> DrawInfo -> dri_Resolution . X;
- Handle -> AspectY = Handle -> DrawInfo -> dri_Resolution . Y;
-
- if(Handle -> SimpleClone)
- Handle -> MaxPen = 0;
- else
- Handle -> MaxPen = Extra -> TotalPens - 1;
-
- Extra -> Screen = Screen;
-
- LTP_Free(Handle,ColourRecord,AllocationSize);
- LTP_Free(Handle,ColourSpec,AllocationSize);
-
- DB(kprintf("fertig\n"));
-
- return;
- }
-
- FreeScreenDrawInfo(Screen,DrawInfo);
- }
-
- CloseScreen(Screen);
- }
-
- LTP_Free(Handle,ColourRecord,AllocationSize);
- LTP_Free(Handle,ColourSpec,AllocationSize);
-
- Handle -> Failed = TRUE;
-
- DB(kprintf("fehlschlag\n"));
- }
-
- BOOLEAN __regargs
- LTP_PrepareCloning(struct LayoutHandle *Handle)
- {
- DB(kprintf("prepare cloning\n"));
-
- if(Handle -> CloneExtra)
- return(TRUE);
- else
- {
- struct DimensionInfo DimensionInfo;
-
- DB(kprintf("getting dimensions\n"));
-
- if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,GetVPModeID(&Handle -> Screen -> ViewPort)))
- {
- DB(kprintf("getting cloneextra\n"));
-
- if(Handle -> CloneExtra = (struct CloneExtra *)LTP_Alloc(Handle,sizeof(struct CloneExtra) + (sizeof(LONG) + sizeof(UWORD)) * Handle -> DrawInfo -> dri_NumPens + sizeof(UWORD)))
- {
- UWORD i,j,TotalPens = 0;
- LONG *Pens;
- BOOLEAN NotFound;
-
- Handle -> CloneExtra -> Pens = (LONG *)(Handle -> CloneExtra + 1);
- Handle -> CloneExtra -> ScreenPens = (UWORD *)(&Handle -> CloneExtra -> Pens[Handle -> DrawInfo -> dri_NumPens]);
- Handle -> CloneExtra -> MinWidth = DimensionInfo . MinRasterWidth;
- Handle -> CloneExtra -> MinHeight = DimensionInfo . MinRasterHeight;
- Handle -> CloneExtra -> MaxWidth = DimensionInfo . MaxRasterWidth;
- Handle -> CloneExtra -> MaxHeight = DimensionInfo . MaxRasterHeight;
-
- Handle -> CloneExtra -> Bounds . Left = 0;
- Handle -> CloneExtra -> Bounds . Top = 0;
- Handle -> CloneExtra -> Bounds . Width = DimensionInfo . MaxRasterWidth;
- Handle -> CloneExtra -> Bounds . Height = DimensionInfo . MaxRasterHeight;
-
- Pens = Handle -> CloneExtra -> Pens;
-
- if(Handle -> ExactClone)
- {
- for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
- Pens[i] = Handle -> DrawInfo -> dri_Pens[i];
-
- TotalPens = Handle -> DrawInfo -> dri_NumPens;
-
- Handle -> CloneExtra -> Depth = Handle -> DrawInfo -> dri_Depth;
- }
- else
- {
- for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
- {
- for(j = 0,NotFound = TRUE ; NotFound && j < TotalPens ; j++)
- {
- if(Pens[j] == Handle -> DrawInfo -> dri_Pens[i])
- NotFound = FALSE;
- }
-
- if(NotFound)
- Pens[TotalPens++] = Handle -> DrawInfo -> dri_Pens[i];
- }
-
- for(i = 0 ; i < DimensionInfo . MaxDepth ; i++)
- {
- if(TotalPens <= (1L << i))
- {
- Handle -> CloneExtra -> Depth = i;
-
- break;
- }
- }
- }
-
- DB(kprintf("totalpens=%ld depth=%ld\n",TotalPens,Handle -> CloneExtra -> Depth));
-
- if((Handle -> CloneExtra -> TotalPens = TotalPens) && Handle -> CloneExtra -> Depth)
- {
- DB(kprintf("setting up glyphs\n"));
-
- if(LTP_GlyphSetup(Handle,Handle -> InitialTextAttr))
- {
- Handle -> Failed = Handle -> Rescaled = FALSE;
-
- LTP_ResetGroups(Handle -> TopGroup);
- /*
- if(!V39 && (Handle -> RPort . TxFlags & FPF_PROPORTIONAL))
- {
- LTP_Rescale(Handle,FALSE,FALSE);
-
- Handle -> Rescaled = FALSE;
- }
- */
- DB(kprintf("fertig\n\n"));
-
- return(TRUE);
- }
- }
- else
- {
- LTP_Free(Handle,Handle -> CloneExtra,sizeof(struct CloneExtra) + sizeof(LONG) * Handle -> DrawInfo -> dri_NumPens);
-
- Handle -> CloneExtra = NULL;
- }
- }
- }
- }
-
- DB(kprintf("fehlschlag\n\n"));
-
- return(FALSE);
- }
- #endif
-