Exemplo n.º 1
0
struct RastPort *RenderMessage::ObtainDoubleBuffer (ULONG width, ULONG height)
{
  if(BufferRP)
  {
    if(width > BufferWidth || height > BufferHeight)
    {
      WaitBlit();
      FreeBitMap(BufferRP->BitMap);
      BufferWidth = MAX(BufferWidth, width);
      BufferHeight = MAX(BufferHeight, height);
      BufferRP->BitMap = AllocBitMap(BufferWidth, BufferHeight, GetBitMapAttr(RPort->BitMap, BMA_DEPTH), BMF_MINPLANES, RPort->BitMap);
    }
  }
  else
  {
    BufferRP = new (std::nothrow) struct RastPort[1];
    if (!BufferRP) return NULL;

    InitRastPort(BufferRP);
    BufferRP->BitMap = AllocBitMap(width, height, GetBitMapAttr(RPort->BitMap, BMA_DEPTH), BMF_MINPLANES, RPort->BitMap);
    BufferWidth = width;
    BufferHeight = height;
  }
  return(BufferRP->BitMap ? BufferRP : NULL);
}
Exemplo n.º 2
0
LONG MyTextLength (struct TextFont* font, STRPTR string, LONG count)
{
  struct RastPort rp;
  InitRastPort(&rp);
  SetFont(&rp,font);
  return TextLength32(&rp, string, count);
}
Exemplo n.º 3
0
IPTR Levelmeter__MUIM_Setup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
{
    struct Levelmeter_DATA *data = INST_DATA(cl, obj);
    //struct RastPort 	       rp;
    IPTR    	    	       retval;

    retval = DoSuperMethodA(cl, obj, (Msg)msg);
    if (retval)
    {
#if 0
        InitRastPort(&rp);
        SetFont(&rp,_font(obj));

        DeinitRastPort(&rp);
#endif
        data->levelbgpen = ObtainBestPen(_screen(obj)->ViewPort.ColorMap,
                                         0x4b4b4b4b,
                                         0x39393939,
                                         0x93939393,
                                         OBP_FailIfBad, FALSE,
                                         OBP_Precision, PRECISION_GUI,
                                         TAG_DONE);
    }

    return retval;
}
Exemplo n.º 4
0
LONG MyTextFit(struct TextFont *font, char *text, long length, long width, long direction)
{
  struct RastPort rp;
  struct TextExtent te;
  InitRastPort(&rp);
  SetFont(&rp,font);
  return TextFit(&rp, text, length, &te, NULL, direction, width, 10000);
}
Exemplo n.º 5
0
struct RastPort *ScratchRast_New(int Width, int Height, char Planes)
{
struct RastPort *This;
int loop;

/* Planes must be < 8, since we steal the topmost entry for our Mask */

if(Planes > 7)
	return(NULL); /* Zo zorry. */

Width = ROUNDUP(Width,32);

if(This=AllocMem(sizeof(struct RastPort), MEMF_CLEAR))
	{
	InitRastPort(This);
	This->RP_User=(void *)Width; /* cope with it. */
	if(This->BitMap = AllocMem(sizeof(struct BitMap), MEMF_CLEAR))
		{
		InitBitMap(This->BitMap, Planes, Width, Height);
		for(loop = 0; loop < Planes; loop++)
			{
			if(!(This->BitMap->Planes[loop] = AllocRaster(Width, Height)))
				{
				break;
				} /* if */
			} /* for */
		if(loop == Planes)
			{
			This->BitMap->Planes[7] = AllocRaster(Width, Height);
			} /* if */
		if(loop != Planes) /* aborted early */
			{
			for(loop = 0; loop < Planes; loop++)
				{
				if(This->BitMap->Planes[loop])
					{
					FreeRaster(This->BitMap->Planes[loop], Width, Height);
					This->BitMap->Planes[loop] = NULL;
					} /* if */
				} /* for */
			} /* if */
		else /* Success! Rice */
			{
			return(This);
			} /* else */
		FreeMem(This->BitMap, sizeof(struct BitMap));
		} /* if */
	FreeMem(This, sizeof(struct RastPort));
	} /* if */

return(NULL);
} /* ScratchRast_New() */
Exemplo n.º 6
0
/**************************************************************************
 MUIM_AskMinMax
**************************************************************************/
IPTR Numericbutton__MUIM_AskMinMax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
{
    struct Numericbutton_DATA *data = INST_DATA(cl, obj);

    DoSuperMethodA(cl, obj, (Msg)msg);

    if (data->needs_to_recalculate_sizes)
    {
        struct RastPort rp;
        LONG min, max, val, width;

        InitRastPort(&rp);
        SetFont(&rp,_font(obj));

        width = 0;

        longget(obj, MUIA_Numeric_Min, &min);
        longget(obj, MUIA_Numeric_Max, &max);

        /* Determine the width of the knob */
        for (val=min; val<=max; val++)
        {
            LONG nw;
            char *buf;

            buf = (char*)DoMethod(obj, MUIM_Numeric_Stringify, val);
            nw  = TextLength(&rp, buf, strlen(buf));

            if (nw > width)
                width = nw;
        }

        data->max_text_width = width;
        data->text_height    = _font(obj)->tf_YSize;

        data->needs_to_recalculate_sizes = FALSE;
    }

    msg->MinMaxInfo->MinWidth  += data->max_text_width;
    msg->MinMaxInfo->MinHeight += data->text_height;
    msg->MinMaxInfo->DefWidth  += data->max_text_width;
    msg->MinMaxInfo->DefHeight += data->text_height;
    msg->MinMaxInfo->MaxWidth  += data->max_text_width;
    msg->MinMaxInfo->MaxHeight += data->text_height;

    return TRUE;
}
Exemplo n.º 7
0
IPTR Register__MUIM_Setup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
{
    struct Register_DATA *data = INST_DATA(cl, obj);
    WORD    	    i, h = 0;

    if (!DoSuperMethodA(cl, obj, (Msg)msg))
    {
        return FALSE;
    }

    _font(obj) = zune_font_get(obj, MUIV_Font_Title);
    data->fonth = _font(obj)->tf_YSize;
    data->fontb = _font(obj)->tf_Baseline;

    h = 0;

    i = data->fonth + REGISTERTAB_EXTRA_HEIGHT;
    h = (i > h) ? i : h;

    data->tab_height = h;
    data->ty = data->fontb + 1 + (data->tab_height - data->fonth) / 2;

    /*      D(bug("Register_Setup : data->height=%d\n", data->tab_height)); */

    for(i = 0; i < data->numitems; i++)
    {
        data->items[i].textlen = strlen(data->items[i].text);
    }

    data->total_hspacing = (data->columns + 1) * INTERTAB - 2;
    /*      D(bug("Register_AskMinMax : data->total_hspacing = %d\n", data->total_hspacing)); */

    data->min_width = data->total_hspacing * 3;
    data->def_width = data->total_hspacing;

    if (!(muiGlobalInfo(obj)->mgi_Prefs->register_truncate_titles))
    {
        struct RastPort temprp;
        int i;
        WORD textpixmax;

        InitRastPort(&temprp);
        SetFont(&temprp, _font(obj));

        textpixmax = 0;
        for(i = 0; i < data->numitems; i++)
        {
            WORD textpix = TextLength(&temprp, data->items[i].text, data->items[i].textlen);
            textpixmax = MAX(textpix, textpixmax);
        }
        data->def_width += (textpixmax + TEXTSPACING + 1) * data->numitems;
        data->def_width = MAX(data->min_width, data->def_width);

        DeinitRastPort(&temprp);
    }

    SetHardCoord(obj,data);
    muiAreaData(obj)->mad_Flags     	|= (MADF_INNERLEFT | MADF_INNERTOP | MADF_INNERRIGHT | MADF_INNERBOTTOM);

    DoMethod(_win(obj), MUIM_Window_AddEventHandler, (IPTR)&data->ehn);

    return TRUE;
}
Exemplo n.º 8
0
// Get the maximum size of a button in the bank
short buttons_get_max_size(Buttons *buttons,unsigned short *max_width,unsigned short *max_height)
{
	Cfg_Button *button;
	struct TagItem dim_tags[3];
	struct RastPort rp;
	short count,image_count;

	// Initialise
	*max_width=0;
	*max_height=0;

	// Initialise tags
	dim_tags[0].ti_Tag=IM_Width;
	dim_tags[1].ti_Tag=IM_Height;
	dim_tags[2].ti_Tag=TAG_DONE;

	// Initialise rastport
	if (buttons->window) rp=*buttons->window->RPort;
	else
	{
		InitRastPort(&rp);
		if (buttons->font) SetFont(&rp,buttons->font);
		else SetFont(&rp,GUI->screen_pointer->RastPort.Font);
	}

	// Start with font height for text buttons
	if (!(buttons->bank->window.flags&BTNWF_GFX))
		*max_height=rp.TxHeight;

	// Go through buttons
	for (button=(Cfg_Button *)buttons->bank->buttons.lh_Head,count=0,image_count=0;
		button->node.ln_Succ;
		button=(Cfg_Button *)button->node.ln_Succ,count++)
	{
		Cfg_ButtonFunction *func;

		// Go through all functions looking for images/text
		for (func=(Cfg_ButtonFunction *)button->function_list.mlh_Head;
			func->node.ln_Succ;
			func=(Cfg_ButtonFunction *)func->node.ln_Succ)
		{
			// Graphical buton?
			if (button->button.flags&BUTNF_GRAPHIC)
			{
				// Clear size tags
				dim_tags[0].ti_Data=0;
				dim_tags[1].ti_Data=0;

				// Valid image?
				if (func->image)
				{
					// Get size of this image
					GetImageAttrs(func->image,dim_tags);
					++image_count;
				}

				// Otherwise, use unknown image size
				else
				if (func->function.func_type==FTYPE_LEFT_BUTTON)
				{
					dim_tags[0].ti_Data=16;
					dim_tags[1].ti_Data=16;
				}

				// If this image is the biggest so far, store size
				if (dim_tags[0].ti_Data>*max_width)
					*max_width=dim_tags[0].ti_Data;
				if (dim_tags[1].ti_Data>*max_height)
					*max_height=dim_tags[1].ti_Data;
			}

			// Text button
			else
			if (func->label)
			{
				short width;

				// Get width
				width=TextLength(&rp,func->label,strlen(func->label));

				// Maximum width?
				if (width>*max_width) *max_width=width;
			}
		}
	}

	// Want borders?
	if (!(buttons->bank->window.flags&BTNWF_BORDERLESS))
	{
		short xextra,yextra;

		// Graphical?
		if (buttons->bank->window.flags&BTNWF_GFX)
		{
			// Not much space for toolbars
			if (buttons->flags&BUTTONF_TOOLBAR)
			{
				xextra=2;
				yextra=2;
			}

			// Normal bank
			else
			{
				xextra=8;
				yextra=8;
			}
		}

		// Text
		else
		{
			xextra=4;  // <-- was 2
			yextra=4;
		}

		// Add on space around image
		*max_width+=xextra;
		*max_height+=yextra;
	}

	// Minimum
	else
	{
		if (*max_width<4) *max_width=4;
		if (*max_height<4) *max_height=4;
/*
		// Take off some size for graphical toolbar
		if (buttons->bank->window.flags&BTNWF_GFX &&
			buttons->flags&BUTTONF_TOOLBAR) *max_height-=4;
*/
	}

	// Graphical?
	if (buttons->bank->window.flags&BTNWF_GFX)
	{
		// If no images, use big size
		if (image_count==0)
		{
			*max_width=96;
			*max_height=16;
		}
	}

	return count;
}
Exemplo n.º 9
0
void ami_init_mouse_pointers(void)
{
	int i;
	struct RastPort mouseptr;
	struct DiskObject *dobj;
	uint32 format = IDFMT_BITMAPPED;
	int32 mousexpt=0,mouseypt=0;

	InitRastPort(&mouseptr);

	for(i=0;i<=AMI_LASTPOINTER;i++)
	{
		BPTR ptrfile = 0;
		mouseptrbm[i] = NULL;
		mouseptrobj[i] = NULL;
		char ptrfname[1024];

#ifdef __amigaos4__
		if(nsoption_bool(truecolour_mouse_pointers))
		{
			ami_get_theme_filename((char *)&ptrfname,ptrs32[i], false);
			if(dobj = GetIconTags(ptrfname,ICONGETA_UseFriendBitMap,TRUE,TAG_DONE))
			{
				if(IconControl(dobj, ICONCTRLA_GetImageDataFormat, &format, TAG_DONE))
				{
					if(IDFMT_DIRECTMAPPED == format)
					{
						int32 width = 0, height = 0;
						uint8* data = 0;
						IconControl(dobj,
							ICONCTRLA_GetWidth, &width,
							ICONCTRLA_GetHeight, &height,
							ICONCTRLA_GetImageData1, &data,
							TAG_DONE);

						if (width > 0 && width <= 64 && height > 0 && height <= 64 && data)
						{
							STRPTR tooltype;

							if(tooltype = FindToolType(dobj->do_ToolTypes, "XOFFSET"))
								mousexpt = atoi(tooltype);

							if(tooltype = FindToolType(dobj->do_ToolTypes, "YOFFSET"))
								mouseypt = atoi(tooltype);

							if (mousexpt < 0 || mousexpt >= width)
								mousexpt = 0;
							if (mouseypt < 0 || mouseypt >= height)
								mouseypt = 0;

							static uint8 dummyPlane[64 * 64 / 8];
                   			static struct BitMap dummyBitMap = { 64 / 8, 64, 0, 2, 0, { dummyPlane, dummyPlane, 0, 0, 0, 0, 0, 0 }, };

							mouseptrobj[i] = NewObject(NULL, "pointerclass",
												POINTERA_BitMap, &dummyBitMap,
												POINTERA_XOffset, -mousexpt,
												POINTERA_YOffset, -mouseypt,
												POINTERA_WordWidth, (width + 15) / 16,
												POINTERA_XResolution, POINTERXRESN_SCREENRES,
												POINTERA_YResolution, POINTERYRESN_SCREENRESASPECT,
												POINTERA_ImageData, data,
												POINTERA_Width, width,
												POINTERA_Height, height,
												TAG_DONE);
						}
					}
				}
			}
		}
#endif

		if(!mouseptrobj[i])
		{
			ami_get_theme_filename(ptrfname,ptrs[i], false);
			if(ptrfile = Open(ptrfname,MODE_OLDFILE))
			{
				int mx,my;
				UBYTE *pprefsbuf = AllocVec(1061,MEMF_PRIVATE | MEMF_CLEAR);
				Read(ptrfile,pprefsbuf,1061);

				mouseptrbm[i]=AllocVec(sizeof(struct BitMap),MEMF_PRIVATE | MEMF_CLEAR);
				InitBitMap(mouseptrbm[i],2,32,32);
				mouseptrbm[i]->Planes[0] = AllocRaster(32,32);
				mouseptrbm[i]->Planes[1] = AllocRaster(32,32);
				mouseptr.BitMap = mouseptrbm[i];

				for(my=0;my<32;my++)
				{
					for(mx=0;mx<32;mx++)
					{
						SetAPen(&mouseptr,pprefsbuf[(my*(33))+mx]-'0');
						WritePixel(&mouseptr,mx,my);
					}
				}

				mousexpt = ((pprefsbuf[1056]-'0')*10)+(pprefsbuf[1057]-'0');
				mouseypt = ((pprefsbuf[1059]-'0')*10)+(pprefsbuf[1060]-'0');

				mouseptrobj[i] = NewObject(NULL,"pointerclass",
					POINTERA_BitMap,mouseptrbm[i],
					POINTERA_WordWidth,2,
					POINTERA_XOffset,-mousexpt,
					POINTERA_YOffset,-mouseypt,
					POINTERA_XResolution,POINTERXRESN_SCREENRES,
					POINTERA_YResolution,POINTERYRESN_SCREENRESASPECT,
					TAG_DONE);

				FreeVec(pprefsbuf);
				Close(ptrfile);
			}

		}

	} // for
}
Exemplo n.º 10
0
/*************
 * DESCRIPTION:   Loads a image with the datatypes.
 * INPUT:         filename    name of picture to load
 * OUTPUT:        FALSE if failed
 *************/
BOOL IMAGE::LoadAsDatatype(char *filename)
{
    struct Library *PictureDTBase;
    BOOL pic24bit;             // TRUE for new 24bit picture.datatype (V43)
    Object *obj;
    struct BitMapHeader *bmhd;
    struct BitMap *bitmap, *tempbitmap;
    int x,y;
    SMALL_COLOR *c;
    UBYTE *colreg, *buffer;
    int color;
    ULONG modeid;
    struct DisplayInfo dispinfo;
    UBYTE r,g,b;
    struct RastPort rp, temprp;
    struct gpBlitPixelArray arg;

    DataTypesBase = OpenLibrary((unsigned char*)"datatypes.library", 39);
    if(!DataTypesBase)
        return FALSE;

    // try to open the 24bit picture datatype
    PictureDTBase = OpenLibrary("datatypes/picture.datatype", 43L);
    if(PictureDTBase)
    {
        // we only need the picture.datatype to test the version, therefore
        // close it now
        CloseLibrary(PictureDTBase);

        pic24bit = TRUE;
    }
    else
        pic24bit = FALSE;

    if(!pic24bit)
    {
        // no 24bit version available
        // get the picture object
        obj = NewDTObject(filename,
                          DTA_SourceType,   DTST_FILE,
                          DTA_GroupID,      GID_PICTURE,
                          PDTA_Remap,       FALSE,
                          TAG_DONE);
        if(!obj)
        {
            CloseLibrary(DataTypesBase);
            return FALSE;
        }
    }
    else
    {
        // get the picture object
        obj = NewDTObject(filename,
                          DTA_SourceType,   DTST_FILE,
                          DTA_GroupID,      GID_PICTURE,
                          PDTA_Remap,       FALSE,
                          PDTA_DestMode,    MODE_V43,
                          TAG_DONE);
        if(!obj)
        {
            CloseLibrary(DataTypesBase);
            return FALSE;
        }
    }

    // get the bitmap header
    if(GetDTAttrs(obj,
                  PDTA_ColorRegisters, &colreg,
                  PDTA_BitMap, &bitmap,
                  PDTA_ModeID, &modeid,
                  PDTA_BitMapHeader, &bmhd,
                  TAG_DONE) != 4)
    {
        DisposeDTObject(obj);
        CloseLibrary(DataTypesBase);
        return FALSE;
    }

    if(!bmhd || !bitmap)
    {
        DisposeDTObject(obj);
        CloseLibrary(DataTypesBase);
        return FALSE;
    }

    width = bmhd->bmh_Width;
    height = bmhd->bmh_Height;

    if(!GetDisplayInfoData(NULL, (UBYTE*)&dispinfo, sizeof(struct DisplayInfo), DTAG_DISP, modeid))
    {
        DisposeDTObject(obj);
        CloseLibrary(DataTypesBase);
        return FALSE;
    }

    colormap = (SMALL_COLOR*)malloc(sizeof(SMALL_COLOR)*width*height);
    if(!colormap)
    {
        DisposeDTObject(obj);
        CloseLibrary(DataTypesBase);
        return FALSE;
    }

    c = colormap;

    if((bmhd->bmh_Depth > 8) && pic24bit)
    {
        // true color picture
        buffer = (UBYTE*)AllocVec(3*width, MEMF_PUBLIC);
        if(!buffer)
        {
            DisposeDTObject(obj);
            CloseLibrary(DataTypesBase);
            return FALSE;
        }

        for(y=0; y<height; y++)
        {
            arg.MethodID = DTM_READPIXELARRAY;
            arg.PixelArray = buffer;
            arg.PixelArrayMode = RECTFMT_RGB;
            arg.PixelArrayMod = 3*width;
            arg.LeftEdge = 0;
            arg.TopEdge = y;
            arg.Width = width;
            arg.Height = 1;
#ifdef __PPC__
            ppc_DoMethodA(obj, (Msg)&arg);
#else
            DoMethodA(obj, (Msg)&arg);
#endif
            for(x=0; x<width; x++)
            {
                c->r = buffer[x*3];
                c->g = buffer[x*3+1];
                c->b = buffer[x*3+2];
                c++;
            }
        }
        FreeVec(buffer);
    }
    else
    {
        // normal picture

        // planar to chunky conversion
        InitRastPort(&rp);
        rp.BitMap = bitmap;

        tempbitmap = AllocBitMap(width, 1, bmhd->bmh_Depth, BMF_CLEAR, NULL);
        if(!tempbitmap)
        {
            DisposeDTObject(obj);
            CloseLibrary(DataTypesBase);
            return FALSE;
        }

        InitRastPort(&temprp);
        temprp.BitMap = tempbitmap;

        buffer = (UBYTE*)AllocVec((width+15)&(~15), MEMF_PUBLIC);
        if(!buffer)
        {
            FreeBitMap(tempbitmap);
            DisposeDTObject(obj);
            CloseLibrary(DataTypesBase);
            return FALSE;
        }

        if(dispinfo.PropertyFlags & DIPF_IS_HAM)
        {
            // Simulate HAM mode
            if(bmhd->bmh_Depth == 8)
            {
                // Super HAM
                for(y=0; y<height; y++)
                {
                    r = g = b = 0;
                    ReadPixelLine8(&rp, 0, y, width, buffer, &temprp);
                    for(x=0; x<width; x++)
                    {
                        color = buffer[x];
                        switch(color & 0xc0)
                        {
                        case 0x00:  // Take it from color registers
                            color *= 3;
                            r = colreg[color];
                            g = colreg[color+1];
                            b = colreg[color+2];
                            break;
                        case 0x40:  // modify blue
                            b = color << 2;
                            break;
                        case 0x80:  // modify red
                            r = color << 2;
                            break;
                        case 0xc0:  // modify green
                            g = color << 2;
                            break;
                        }
                        c->r = r;
                        c->g = g;
                        c->b = b;
                        c++;
                    }
                }
            }
            else
            {
                // Normal HAM
                for(y=0; y<height; y++)
                {
                    r = g = b = 0;
                    ReadPixelLine8(&rp, 0, y, width, buffer, &temprp);
                    for(x=0; x<width; x++)
                    {
                        color = buffer[x];
                        switch(color & 0x30)
                        {
                        case 0x00:  // Take it from color registers
                            color *= 3;
                            r = colreg[color];
                            g = colreg[color+1];
                            b = colreg[color+2];
                            break;
                        case 0x40:  // modify blue
                            b = color << 4;
                            break;
                        case 0x80:  // modify red
                            r = color << 4;
                            break;
                        case 0xc0:  // modify green
                            g = color << 4;
                            break;
                        }
                        c->r = r;
                        c->g = g;
                        c->b = b;
                        c++;
                    }
                }
            }
        }
        else
        {
            for(y=0; y<height; y++)
            {
                ReadPixelLine8(&rp, 0, y, width, buffer, &temprp);
                for(x=0; x<width; x++)
                {
                    color = buffer[x];
                    color *= 3;
                    c->r = colreg[color];
                    c->g = colreg[color+1];
                    c->b = colreg[color+2];
                    c++;
                }
            }
        }
        FreeVec(buffer);
        FreeBitMap(tempbitmap);
    }

    DisposeDTObject(obj);
    CloseLibrary(DataTypesBase);
    return TRUE;
}
Exemplo n.º 11
0
APTR ReadBitMapA(struct BitMap *bm, UWORD displayID, PALETTE palette,
        int *ptr_pixelformat, int *ptr_width, int *ptr_height, TAGLIST tags)
{
        APTR array = NULL;

        if (bm)
        {
                BOOL success;
                
                int sourcex, sourcey, sourcewidth, sourceheight, destwidth, destheight; 
                int width, height, flags, depth, iscyber, bmapformat, pixelformat;
                int bufsize;
                APTR scaleengine = NULL;
                struct RastPort rp, temprp;
        
                sourcex = GetTagData(GGFX_SourceX, 0, tags);
                sourcey = GetTagData(GGFX_SourceY, 0, tags);

                GetBitMapInfo(bm, displayID,
                        BMAPATTR_Width, &width,
                        BMAPATTR_Height, &height,
                        BMAPATTR_Depth, &depth,
                        BMAPATTR_Flags, &flags,
                        BMAPATTR_CyberGFX, &iscyber,
                        BMAPATTR_BitMapFormat, &bmapformat,
                        BMAPATTR_PixelFormat, &pixelformat,
                        TAG_DONE);

                sourcewidth = GetTagData(GGFX_SourceWidth, width, tags);
                sourceheight = GetTagData(GGFX_SourceHeight, height, tags);
                destwidth = GetTagData(GGFX_DestWidth, width, tags);
                destheight = GetTagData(GGFX_DestHeight, height, tags);


                success = TRUE;


                //      insert bitmap into rastport, create temp rastport

                InitRastPort(&rp);
                rp.BitMap = bm;
                TurboCopyMem(&rp, &temprp, sizeof(struct RastPort));
                temprp.Layer = NULL;
                if (!(temprp.BitMap = AllocBitMap(width, 1, depth, flags, bm)))
                {
                        success = FALSE;
                }


                //      create scale engine

                if (success)
                {
                        if (sourcewidth != destwidth || sourceheight != destheight)
                        {
                                if (!(scaleengine = CreateScaleEngine(
                                        sourcewidth, sourceheight,
                                        destwidth, destheight,
                                        RND_RMHandler, MemHandler,
                                        RND_PixelFormat, pixelformat,
                                        TAG_DONE)))
                                {
                                        success = FALSE;
                                }
                        }
                }


                //      get buffer

                if (success)
                {
                        if (pixelformat == PIXFMT_0RGB_32)
                        {
                                bufsize = destwidth * destheight * PIXELSIZE(pixelformat);
                        }
                        else
                        {
                                bufsize = ((destwidth+15) & ~15) * destheight;
                        }

                        DB(kprintf("!readbitmap alloc\n"));

                        if (!(array = AllocRenderVec(MemHandler, bufsize)))
                        {
                                success = FALSE;
                        }
                }



                //      convert data
                
                if (success)
                {
                        success = FALSE;

                        if (scaleengine)
                        {

                                //      with scaling

                                switch (bmapformat)
                                {
                                        case PIXFMT_BITMAP_RGB:
                                        {
                                                ULONG *linebuffer;

                                                DB(kprintf("~reading/scaling RGB bitmap\n"));
                                                
                                                if (linebuffer = AllocRenderVec(MemHandler, sourcewidth * 4))
                                                {
                                                        struct Hook readhook;
                                                        struct readrgbdata hookdata;
                
                                                        hookdata.rp = &rp;
                                                        hookdata.sourcex = sourcex;
                                                        hookdata.sourcey = sourcey;
                                                        hookdata.sourcewidth = sourcewidth;
                                                        hookdata.lastline = -1;
        
                                                        readhook.h_Data = &hookdata;
                                                        readhook.h_Entry = HOOKENTRY(readrgb);

                                                        Scale(scaleengine, linebuffer, array,
                                                                RND_SourceWidth, 0,
                                                                RND_LineHook, &readhook,
                                                                TAG_DONE);

                                                        FreeRenderVec(linebuffer);
                                                        success = TRUE;
                                                }
                                                break;
                                        }
                                        case PIXFMT_BITMAP_CLUT:
                                        {
                                                UBYTE *linebuffer;

                                                DB(kprintf("~reading/scaling CLUT bitmap\n"));

                                                if (linebuffer = AllocRenderVec(MemHandler, ((sourcewidth+15) & ~15)))
                                                {
                                                        struct Hook readhook;
                                                        struct readclutdata hookdata;
                
                                                        hookdata.rp = &rp;
                                                        hookdata.temprp = &temprp;
                                                        hookdata.sourcex = sourcex;
                                                        hookdata.sourcey = sourcey;
                                                        hookdata.sourcewidth = sourcewidth;
                                                        hookdata.lastline = -1;
        
                                                        readhook.h_Data = &hookdata;
                                                        readhook.h_Entry = HOOKENTRY(readclut);

                                                        Scale(scaleengine, linebuffer, array,
                                                                RND_SourceWidth, 0,
                                                                RND_LineHook, &readhook,
                                                                TAG_DONE);

                                                        FreeRenderVec(linebuffer);
                                                        success = TRUE;
                                                }
                                                break;                                  
                                        }

                                        case PIXFMT_BITMAP_HAM6:
                                        case PIXFMT_BITMAP_HAM8:
                                        {
                                                UBYTE *linebuffer;
                                                ULONG *rgbbuffer;

                                                DB(kprintf("~reading/scaling HAM bitmap\n"));

                                                if (linebuffer = AllocRenderVec(MemHandler, ((sourcewidth + sourcex + 15) & ~15)))
                                                {
                                                        if (rgbbuffer = AllocRenderVec(MemHandler, sourcewidth * 4))
                                                        {
                                                                struct Hook readhook;
                                                                struct readhamdata hookdata;
                        
                                                                hookdata.rp = &rp;
                                                                hookdata.temprp = &temprp;
                                                                hookdata.sourcex = sourcex;
                                                                hookdata.sourcey = sourcey;
                                                                hookdata.sourcewidth = sourcewidth;
                                                                hookdata.linebuffer = linebuffer;
                                                                hookdata.palette = palette;
                                                                hookdata.colormode = (depth == 8) ? COLORMODE_HAM8 : COLORMODE_HAM6;
                                                                hookdata.lastline = -1;
                
                                                                readhook.h_Data = &hookdata;
                                                                readhook.h_Entry = HOOKENTRY(readham);
        
                                                                Scale(scaleengine, rgbbuffer, array,
                                                                        RND_SourceWidth, 0,
                                                                        RND_LineHook, &readhook,
                                                                        TAG_DONE);
        
                                                                FreeRenderVec(rgbbuffer);
                                                                success = TRUE;
                                                        }
                                                        FreeRenderVec(linebuffer);
                                                }
                                                break;                                  
                                        }
                                }
                        
                        }
                        else
                        {
                                //      no scaling
                                
                                switch (bmapformat)
                                {
                                        case PIXFMT_BITMAP_RGB:
                                        {
                                                DB(kprintf("~reading RGB bitmap\n"));
                                        
                                                ReadPixelArray(array, 0,0, destwidth * 4, &rp,
                                                        sourcex, sourcey, destwidth, destheight, RECTFMT_ARGB);
                                                success = TRUE;
                                                break;
                                        }

                                        case PIXFMT_BITMAP_CLUT:
                                        {
                                                int i;
                                                char *p = array;

                                                DB(kprintf("~reading CLUT bitmap\n"));

                                                for(i = 0; i < destheight; ++i)
                                                {
                                                        ReadPixelLine8(&rp, sourcex, sourcey + i, destwidth, p, &temprp);
                                                        p += destwidth;
                                                }
                                                success = TRUE;
                                                break;
                                        }
                                        
                                        case PIXFMT_BITMAP_HAM6:
                                        case PIXFMT_BITMAP_HAM8:
                                        {
                                                UBYTE *linebuffer;

                                                DB(kprintf("~reading HAM bitmap\n"));

                                                if (linebuffer = AllocRenderVec(MemHandler, ((destwidth+15) & ~15) ))
                                                {
                                                        int i;
                                                        ULONG *p = array;
                                                        for(i = 0; i < destheight; ++i)
                                                        {
                                                                ReadPixelLine8(&rp, sourcex, sourcey + i, destwidth, linebuffer, &temprp);

                                                                Chunky2RGB(linebuffer, destwidth, 1, p, palette,
                                                                        RND_ColorMode, ((depth == 8) ? COLORMODE_HAM8 : COLORMODE_HAM6),
                                                                        TAG_DONE);

                                                                p += destwidth;
                                                        }
                                                        FreeRenderVec(linebuffer);
                                                        success = TRUE;
                                                }
                                                break;
                                        }

                                }
                        }
                
                }
                
                
                        

                //      close down

                if (success)
                {
                        *ptr_pixelformat = pixelformat;
                        *ptr_width = destwidth;
                        *ptr_height = destheight;
                }
                else
                {
                        if (array)
                        {
                                FreeRenderVec(array);
                                array = NULL;
                        }
                }
                
                if (scaleengine)
                {
                        DeleteScaleEngine(scaleengine);
                }

                if (temprp.BitMap)
                {
                        FreeBitMap(temprp.BitMap);
                }

        }

        return array;
}
Exemplo n.º 12
0
// Build requester
BOOL simple_build(simplereq_data *data)
{
	struct DOpusSimpleRequest *simple;
	short count,object,pos;
	struct TextFont *font=0;
	struct RastPort rp;
	struct Screen *scr,*pub=0;
	short font_try;

	// Get simple pointer
	simple=data->simple;

	// Get screen pointer
	if (simple->flags&SRF_SCREEN_PARENT && data->parent) scr=data->parent;
	else
	if (data->parent) scr=((struct Window *)data->parent)->WScreen;
	else
	if ((pub=LockPubScreen(0))) scr=pub;
	else
	return 0;

	// Initialise dummy rastport
	InitRastPort(&rp);

	// Try 3 fonts (screen font, default font, topaz)
	for (font_try=0;font_try<3;font_try++)
	{
		short width,len,pos;
		char *ptr;

		// Get font
		if (font_try==0) font=scr->RastPort.Font;
		else
		if (font_try==1) font=((struct GfxBase *)GfxBase)->DefaultFont;
		else
		font=topaz_font;

		// Set font in dummy rastport
		SetFont(&rp,font);

		// Initialise counts
		data->text_lines=0;
		data->max_text_width=0;

		// Get max text width and number of lines
		for (pos=0,len=0,ptr=simple->message;;pos++)
		{
			// End of a line?
			if (simple->message[pos]=='\0' || simple->message[pos]=='\n')
			{
				// Get text width
				width=TextLength(&rp,ptr,len);

				// See if this is the longest line
				if (width>data->max_text_width)
					data->max_text_width=width;

				// Reset length, increment line count
				len=0;
				ptr=simple->message+pos+1;
				++data->text_lines;

				// End of text?
				if (simple->message[pos]=='\0') break;
			}

			// Otherwise, increment length
			else len++;
		}

		// Will fit in screen?
		if (data->max_text_width<scr->Width-TEXT_X_SPACE) break;
	}

	// Add space to text
	if (data->max_text_width>=scr->Width-TEXT_X_SPACE)
		data->max_text_width=scr->Width;
	else
		data->max_text_width+=TEXT_X_SPACE;

	// Save font to use
	simple->font=font;

	// Unlock public screen
	if (pub) UnlockPubScreen(0,pub);

	// Count gadgets
	for (count=0;simple->gadgets[count];count++)
	{
		short width;

		// Get width of gadget text
		width=TextLength(&rp,simple->gadgets[count],strlen(simple->gadgets[count]));

		// Add to total gadget width
		data->max_gadget_width+=width+GAD_X_EXTRA;
	}

	// Save count
	data->gadget_count=count;

	// Are gadgets bigger than text?
	if (data->max_gadget_width+((count-1)*GAD_X_SPACE)>data->max_text_width)
	{
		// Add spacing between gadgets
		data->max_gadget_width+=((count-1)*GAD_X_SPACE);
	}

	// Calculate window width
	data->req_dims.fine_dim.Width=10+
		((data->max_text_width>data->max_gadget_width)?data->max_text_width:data->max_gadget_width);

	// Height is number of text lines plus one line for gadgets
	data->req_dims.char_dim.Height=data->text_lines+1;
	data->req_dims.fine_dim.Height=39+((data->text_lines-1)*3);

	// String gadget?
	if (simple->string_buffer)
	{
		// Get string length
		data->string_len=simple->string_len;

		// Add height
		data->req_dims.char_dim.Height++;
		data->req_dims.fine_dim.Height+=5;

		// Second string gadget?
		if (data->string_len<0)
		{
			// Fix length
			data->string_len=-data->string_len;
			data->string_buffer_2=simple->string_buffer+data->string_len+1;
			data->string_len_2=data->string_len;

			// Adjust height
			data->req_dims.char_dim.Height++;
			data->req_dims.fine_dim.Height+=5;
		}
		else
		if (simple->flags&SRF_BUFFER2)
		{
			data->string_buffer_2=simple->string_buffer_2;
			data->string_len_2=simple->string_len_2;

			// Adjust height
			data->req_dims.char_dim.Height++;
			data->req_dims.fine_dim.Height+=5;
		}
	}

	// Checkmark?
	if (simple->flags&SRF_CHECKMARK)
	{
		// Adjust height
		data->req_dims.char_dim.Height++;
		data->req_dims.fine_dim.Height+=9;
	}

	// Fill out NewConfigWindow
	data->new_win.dims=&data->req_dims;
	data->new_win.title=simple->title;
	data->new_win.flags=WINDOW_NO_CLOSE|WINDOW_AUTO_KEYS|WINDOW_REQ_FILL;
	if (simple->flags&SRF_SCREEN_PARENT) data->new_win.flags|=WINDOW_SCREEN_PARENT;
	data->new_win.font=simple->font;

	// Calculate number of objects we'll need; area plus text plus gadgets plus end
	data->object_count=data->text_lines+data->gadget_count+2;

	// If strbuf is supplied, need a string gadget
	if (simple->string_buffer)
	{
		++data->object_count;
		if (data->string_buffer_2) ++data->object_count;
		if (simple->flags&SRF_FILEREQ && simple->filereq)
			++data->object_count;
	}

	// Checkmark?
	if (simple->flags&SRF_CHECKMARK) ++data->object_count;

	// Allocate objects
	if (!(data->objects=(ObjectDef *)L_AllocMemH(data->memory,sizeof(ObjectDef)*data->object_count)))
		return 0;

	// Fill out text area
	data->objects[0].type=OD_AREA;
	data->objects[0].char_dims.Width=SIZE_MAXIMUM;
	data->objects[0].char_dims.Height=data->text_lines+((simple->flags&SRF_CHECKMARK)?1:0);
	data->objects[0].fine_dims.Left=3;
	data->objects[0].fine_dims.Top=3;
	data->objects[0].fine_dims.Width=-3;
	data->objects[0].fine_dims.Height=24+((data->text_lines-1)*3)+((simple->flags&SRF_CHECKMARK)?9:0);
	data->objects[0].gadgetid=32767;
	data->objects[0].flags=AREAFLAG_RECESSED|AREAFLAG_ERASE|AREAFLAG_THIN;

	// Layout tags
	data->rel_tags[0].ti_Tag=GTCustom_LayoutRel;
	data->rel_tags[0].ti_Data=32767;
	data->rel_tags[1].ti_Tag=TAG_END;

	// Allocate key array
	data->keys=(unsigned char *)L_AllocMemH(data->memory,data->gadget_count);

	// Build objects; first text
	for (pos=0,object=1,data->start_pos=0;;pos++)
	{
		// End of a text line?
		if (simple->message[pos]=='\0' || simple->message[pos]=='\n')
		{
			// Fill out text object
			data->objects[object].type=OD_TEXT;
			data->objects[object].object_kind=TEXTPEN;
			data->objects[object].char_dims.Top=object-1;
			data->objects[object].char_dims.Width=SIZE_MAXIMUM;
			data->objects[object].char_dims.Height=1;
			data->objects[object].fine_dims.Top=10+((object-1)*3);

			// Get copy of text
			if ((data->objects[object].gadget_text=
				(ULONG)L_AllocMemH(data->memory,(pos-data->start_pos)+1)))
			{
				CopyMem(
					simple->message+data->start_pos,
					(char *)data->objects[object].gadget_text,
					pos-data->start_pos);
				data->objects[object].flags=TEXTFLAG_TEXT_STRING|TEXTFLAG_NO_USCORE;
			}

			// Flags and id
			data->objects[object].flags|=TEXTFLAG_CENTER;
			data->objects[object].gadgetid=GAD_TEXT_ID;
			data->objects[object].taglist=data->rel_tags;

			// Save start position for next line, increment object count
			data->start_pos=pos+1;
			++object;

			// End of text?
			if (simple->message[pos]=='\0') break;
		}
	}

	// String gadget?
	if (simple->string_buffer)
	{
		// Second string gadget?
		if (data->string_buffer_2)
		{
			data->objects[object].type=OD_GADGET;
			data->objects[object].object_kind=(simple->flags&SRF_LONGINT)?INTEGER_KIND:STRING_KIND;
			data->objects[object].char_dims.Top=POS_RIGHT_JUSTIFY-2;
			data->objects[object].char_dims.Width=SIZE_MAXIMUM;
			data->objects[object].char_dims.Height=1;
			data->objects[object].fine_dims.Left=3;
			data->objects[object].fine_dims.Top=-16;
			data->objects[object].fine_dims.Width=-3;
			data->objects[object].fine_dims.Height=4;
			data->objects[object].gadgetid=GAD_STRING2_ID;
			data->objects[object].taglist=data->tags2;

			// String tags
			data->tags2[0].ti_Tag=(simple->flags&SRF_LONGINT)?GTIN_Number:TAG_IGNORE;
			data->tags2[0].ti_Data=(simple->flags&SRF_LONGINT)?(ULONG)atoi(data->string_buffer_2):0;
			data->tags2[1].ti_Tag=(simple->flags&SRF_LONGINT)?GTIN_MaxChars:GTST_MaxChars;
			data->tags2[1].ti_Data=data->string_len;
			data->tags2[2].ti_Tag=STRINGA_Justification;
			data->tags2[2].ti_Data=(simple->flags&SRF_CENTJUST)?
							GACT_STRINGCENTER:((simple->flags&SRF_RIGHTJUST)?GACT_STRINGRIGHT:GACT_STRINGLEFT);
			data->tags2[3].ti_Tag=GTCustom_PathFilter;
			data->tags2[3].ti_Data=(simple->flags&SRF_PATH_FILTER)?1:0;
			data->tags2[4].ti_Tag=GTCustom_Secure;
			data->tags2[4].ti_Data=(simple->flags&SRF_SECURE)?1:0;
			data->tags2[5].ti_Tag=GTCustom_ThinBorders;
			data->tags2[5].ti_Data=TRUE;
			data->tags2[6].ti_Tag=TAG_END;

			// Increment object
			++object;
		}

		// File requester?
		if (simple->flags&SRF_FILEREQ && simple->filereq)
		{
			// Popup button
			data->objects[object].type=OD_GADGET;
			data->objects[object].object_kind=POPUP_BUTTON_KIND;
			data->objects[object].char_dims.Top=POS_RIGHT_JUSTIFY-1;
			data->objects[object].char_dims.Width=0;
			data->objects[object].char_dims.Height=1;
			data->objects[object].fine_dims.Left=3;
			data->objects[object].fine_dims.Top=-11;
			data->objects[object].fine_dims.Width=28;
			data->objects[object].fine_dims.Height=4;
			data->objects[object].gadgetid=GAD_POPUP_ID;
			data->objects[object].taglist=0;

			// Increment object
			++object;
		}

		// String gadget
		data->objects[object].type=OD_GADGET;
		data->objects[object].object_kind=(simple->flags&SRF_LONGINT)?INTEGER_KIND:STRING_KIND;
		data->objects[object].char_dims.Top=POS_RIGHT_JUSTIFY-1;
		data->objects[object].char_dims.Width=SIZE_MAXIMUM;
		data->objects[object].char_dims.Height=1;
		data->objects[object].fine_dims.Left=(simple->flags&SRF_FILEREQ && simple->filereq)?31:3;
		data->objects[object].fine_dims.Top=-11;
		data->objects[object].fine_dims.Width=-3;
		data->objects[object].fine_dims.Height=4;
		data->objects[object].gadgetid=GAD_STRING_ID;
		data->objects[object].taglist=data->tags;

		// String tags
		data->tags[0].ti_Tag=(simple->flags&SRF_LONGINT)?GTIN_Number:TAG_IGNORE;
		data->tags[0].ti_Data=(simple->flags&SRF_LONGINT)?(ULONG)atoi(simple->string_buffer):0;
		data->tags[1].ti_Tag=(simple->flags&SRF_LONGINT)?GTIN_MaxChars:GTST_MaxChars;
		data->tags[1].ti_Data=data->string_len;
		data->tags[2].ti_Tag=STRINGA_Justification;
		data->tags[2].ti_Data=(simple->flags&SRF_CENTJUST)?
							GACT_STRINGCENTER:((simple->flags&SRF_RIGHTJUST)?GACT_STRINGRIGHT:GACT_STRINGLEFT);
		data->tags[3].ti_Tag=GTCustom_NoSelectNext;
		data->tags[3].ti_Data=TRUE;
		data->tags[4].ti_Tag=GTCustom_History;
		data->tags[4].ti_Data=(simple->flags&SRF_HISTORY)?(ULONG)simple->history:0;
		data->tags[5].ti_Tag=GTCustom_PathFilter;
		data->tags[5].ti_Data=(simple->flags&SRF_PATH_FILTER)?1:0;
		data->tags[6].ti_Tag=GTCustom_Secure;
		data->tags[6].ti_Data=(simple->flags&SRF_SECURE)?1:0;
		data->tags[7].ti_Tag=GTCustom_ThinBorders;
		data->tags[7].ti_Data=TRUE;
		data->tags[8].ti_Tag=TAG_END;

		// Increment object
		++object;
	}

	// Checkmark?
	if (simple->flags&SRF_CHECKMARK)
	{
		// Fill out gadget
		data->objects[object].type=OD_GADGET;
		data->objects[object].object_kind=CHECKBOX_KIND;
		data->objects[object].char_dims.Top=POS_RIGHT_JUSTIFY;
		data->objects[object].char_dims.Left=POS_CENTER;
		data->objects[object].char_dims.Height=1;
		data->objects[object].fine_dims.Left=FPOS_TEXT_OFFSET+(strlen(simple->check_text)>>1);
		data->objects[object].fine_dims.Top=-4;
		data->objects[object].fine_dims.Width=28;
		data->objects[object].fine_dims.Height=6;
		data->objects[object].gadget_text=(ULONG)simple->check_text;
		data->objects[object].flags=TEXTFLAG_TEXT_STRING|PLACETEXT_RIGHT;
		data->objects[object].gadgetid=GAD_CHECK_ID;
		data->objects[object].taglist=data->rel_tags;

		// Increment object
		++object;
	}
Exemplo n.º 13
0
main(int argc, char *argv[])
{
    unsigned char str[256];
    int i;
    int j;
    struct RastPort rp;
    unsigned char *pp;
    struct BitMap bm = {
	256, 	/* bytes per row */
	8,	/* rows */
	0,	/* flags */
	1,	/* depth */
	0,	/* pad */
	0 	/* planes */
	};
    struct TextAttr ta;
    struct TextFont *tf;
    struct FontRequester *fr;
    struct TagItem frtags[] = {
	ASL_Hail, (ULONG)"NetBSD font choices",
	ASL_Width, 640,
	ASL_Height, 400,
	ASL_LeftEdge, 10,
	ASL_TopEdge, 10,
	ASL_OKText, (ULONG)"Dump",
	ASL_CancelText, (ULONG)"Cancel",
	ASL_FontName, (ULONG)"topaz.font",
	ASL_FontHeight, 8L,
	ASL_FontStyles, FS_NORMAL,
	ASL_FuncFlags, FONF_STYLES | FONF_FIXEDWIDTH,
	TAG_DONE
	    };

    /* Let the user pick a font to dump */
    if (fr = (struct FontRequester *)
	AllocAslRequest(ASL_FontRequest, frtags)) {
	if (!AslRequest(fr, NULL)) {
	    FreeAslRequest(fr);
	    fprintf(stderr, "User requested exit\n");
	    exit (0);
	}
	ta.ta_Name = (STRPTR)malloc(strlen(fr->fo_Attr.ta_Name));
	strcpy(ta.ta_Name, fr->fo_Attr.ta_Name);
	ta.ta_YSize = fr->fo_Attr.ta_YSize;
	ta.ta_Style = fr->fo_Attr.ta_Style;
	ta.ta_Flags = fr->fo_Attr.ta_Flags;
	FreeAslRequest(fr);
    } else {
	fprintf(stderr, "Can't allocate Font Requestor\n");
	exit (1);
    }

    /* Open the selected font */
    tf = (struct TextFont *)OpenDiskFont (&ta);
    if (! tf) {
	fprintf (stderr, "Can't open font: %s\n", ta.ta_Name);
	exit (1);
    }
#ifdef DEBUG
    fprintf(stderr, "Information on selected font:\n");
    fprintf(stderr, "Name=%s\n", ta.ta_Name);
    fprintf(stderr, "Height=%d tf_Style=%x tf_Flags=%x Width=%d Baseline=%d\n",
	    tf->tf_YSize, tf->tf_Style, tf->tf_Flags, tf->tf_XSize, tf->tf_Baseline);
#endif

    /* Check for NetBSD restrictions */
    if (tf->tf_Flags & FPF_PROPORTIONAL) {
	fprintf(stderr, "NetBSD does not support proportional fonts\n");
	exit (1);
    }
    if (tf->tf_XSize > NetBSDwidth) {
	fprintf(stderr, "NetBSD does not support fonts wider than %d pixels\n", NetBSDwidth);
	exit (1);
    }

    /* Allocate area to render font in */
    InitBitMap(&bm, 1, 256 * NetBSDwidth, tf->tf_YSize);
    InitRastPort (&rp);
    rp.BitMap = &bm;
    bm.Planes[0] = pp = AllocRaster (256 * NetBSDwidth, tf->tf_YSize);
    if (!pp) {
	fprintf (stderr, "Can't allocate raster!\n");
	exit (1);
    }

    /* Initialize string to be rendered */
    for (i = 32; i < 256; i++) {
	str[i - 32] = i;
    }

    /* Render string with selected font */
    SetFont (&rp, tf);
    SetSoftStyle(&rp, ta.ta_Style ^ tf->tf_Style,
		 FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC);
    Move (&rp, 0, tf->tf_Baseline);
    ClearEOL(&rp);
    if (tf->tf_XSize != NetBSDwidth) {
	/* right-justify char in cell */
	Move (&rp, NetBSDwidth - tf->tf_XSize, tf->tf_Baseline);
	/* Narrow font, put each character in space of normal font */
	for (i = 0; i < (256 - 32); i++) {
	    Text (&rp, &str[i], 1);
	    Move (&rp, rp.cp_x + (NetBSDwidth - tf->tf_XSize), rp.cp_y);
	}
    } else {
	Text (&rp, str, 256 - 32);
    }

    /* Dump them.. */
    printf ("/* Generated automatically by fontdumper.c. *DONT* distribute\n");
    printf ("   this file, it may contain information Copyright by Commodore!\n");
    printf ("\n");
    printf ("   Font: %s/%d\n", ta.ta_Name, tf->tf_YSize);
    printf (" */\n\n");

    printf ("unsigned char kernel_font_width  = %d;\n", tf->tf_XSize);
    printf ("unsigned char kernel_font_height = %d;\n", tf->tf_YSize);
    printf ("unsigned char kernel_font_baseline = %d;\n", tf->tf_Baseline);
    printf ("short         kernel_font_boldsmear = %d;\n", tf->tf_BoldSmear);
    printf ("unsigned char kernel_font_lo = 32;\n");
    printf ("unsigned char kernel_font_hi = 255;\n\n");

    printf ("unsigned char kernel_cursor[] = {\n");
    for (j = 0; j < (tf->tf_YSize -1); j++) {
	printf ("0xff, ");
    }
    printf ("0xff };\n\n");

    printf ("unsigned char kernel_font[] = {\n");
    for (i = 0; i < 256 - 32; i++) {
	printf ("/* %c */", i + 32);
	for (j = 0; j < tf->tf_YSize; j++) {
	    printf (" 0x%02x,", pp[i+j*256]);
	    }
	printf ("\n");
    }
    printf ("};\n");

    CloseFont (tf);
    FreeRaster (pp, 256 * NetBSDwidth, tf->tf_YSize);
    return (0);
}
Exemplo n.º 14
0
// Load a backfill pattern; pattern must be locked exclusively
void GetPattern(PatternData *pattern,struct Screen *screen,ULONG border_col)
{
	// Initially make invalid
	pattern->valid=FALSE;
	pattern->border_pen=0;

	// Set screen pointer
	pattern->screen=screen;

	// Check for invalid data
	if (!pattern->data)
	{
		// Update border pen
		GetPatternBorder(pattern,screen,border_col);
		return;
	}

	// Bitmap pattern?
	if (pattern->prefs.wbp_Flags&WBPF_PATTERN)
	{
		UWORD *ptr,*planes[MAXDEPTH];
		short num,row,col,pen;

		// Get plane pointers
		for (num=0;num<pattern->prefs.wbp_Depth;num++)
		{
			planes[num]=((UWORD *)pattern->data)+(PAT_HEIGHT*num);
		}
		pattern->fill_plane_key=0;

		// Clear fill initially
		for (num=0,ptr=pattern->fill[0];num<128;num++,ptr++)
			*ptr=0;

		// Under 37 use fill pattern as supplied
		if (((struct Library *)GfxBase)->lib_Version<39)
		{
			for (num=0;num<pattern->prefs.wbp_Depth;num++)
			{
				CopyMem(
					(char *)planes[num],
					(char *)pattern->fill[num],
					PAT_HEIGHT*sizeof(UWORD));
			}
			pattern->fill_plane_key=pattern->prefs.wbp_Depth;
		}

		// Otherwise, we need to remap
		else
		{
			// Go through pattern rows
			for (row=0;row<PAT_HEIGHT;row++)
			{
				// Go through bits
				for (col=0;col<PAT_WIDTH;col++)
				{
					// Clear pen
					pen=0;

					// Calculate pixel colour
					for (num=0;num<pattern->prefs.wbp_Depth;num++)
					{
						// Is bit set in this bitplane?
						if (planes[num][row]&(1<<col)) pen|=(1<<num);
					}

					// Pixel set?
					if (pen)
					{
						// Map pens 4-7 to top four colours
						if (pen>=4 && screen->RastPort.BitMap->Depth<=8)
						{
							pen=(1<<screen->RastPort.BitMap->Depth)-(8-pen);
						}

						// Remap
						for (num=0;num<8;num++)
						{
							// Want this bit?
							if (pen&(1<<num))
							{
								// Set bit
								pattern->fill[num][row]|=1<<col;
								if (num>=pattern->fill_plane_key)
									pattern->fill_plane_key=num+1;
							}
						}
					}
				}
			}
		}

		// Any data?
		if (pattern->fill_plane_key>0)
		{
			short depth;

			// Get depth for bitmap
			if (((struct Library *)GfxBase)->lib_Version>=39)
				depth=GetBitMapAttr(screen->RastPort.BitMap,BMA_DEPTH);
			else
				depth=screen->RastPort.BitMap->Depth;

			// Check its not too deep
			if (depth>8) depth=8;

			// Allocate bitmap for pattern
			if ((pattern->pattern_bitmap=
				NewBitMap(
					PATTILE_SIZE,
					PATTILE_SIZE,
					depth,
					BMF_CLEAR,
					0)))
			{
				struct RastPort rp;
				struct BitMap *bitmap;

				// Initialise dummy rastport
				InitRastPort(&rp);
				rp.BitMap=pattern->pattern_bitmap;

				// Set fill pattern
				SetAfPt(&rp,pattern->fill[0],-4);

				// Fill bitmap
				SetRast(&rp,0);
				RectFill(&rp,0,0,PATTILE_SIZE-1,PATTILE_SIZE-1);

				// Is the screen a non-standard bitmap?
				if (((struct Library *)GfxBase)->lib_Version>=39 &&
					!(GetBitMapAttr(screen->RastPort.BitMap,BMA_FLAGS)&BMF_STANDARD))
				{
					// Try and allocate friend bitmap
					if ((bitmap=
						NewBitMap(
							PATTILE_SIZE,
							PATTILE_SIZE,
							depth,
							BMF_CLEAR,
							screen->RastPort.BitMap)))
					{
						// Copy to friend bitmap
						BltBitMap(
							pattern->pattern_bitmap,0,0,
							bitmap,0,0,
							PATTILE_SIZE,PATTILE_SIZE,
							0xc0,0xff,0);

						// Free original bitmap
						DisposeBitMap(pattern->pattern_bitmap);

						// Use new bitmap pointer
						pattern->pattern_bitmap=bitmap;
					}
				}

				// Get bitmap pointer
				pattern->bitmap=pattern->pattern_bitmap;

				// Get pattern size
				pattern->width=PATTILE_SIZE;
				pattern->height=PATTILE_SIZE;
			}
		}
	}

	// Picture; must have datatypes
	else
	if (DataTypesBase)
	{
		short len;
		BOOL remap=1;
		long precision=PRECISION_IMAGE;
		char name[256];
		long ver=0;
		struct Library *pdt;
#ifdef PATCH_OK
		APTR patchhandle=0;
#endif

		// Check picture datatype version
		if ((pdt=OpenLibrary("sys:classes/datatypes/picture.datatype",0)) ||
			(pdt=OpenLibrary("picture.datatype",0)))
		{
			// Get version
			ver=pdt->lib_Version;
			CloseLibrary(pdt);
		}

		// No remap?
		if ((len=strlen(pattern->data))>8 &&
			stricmp(pattern->data+len-8,".noremap")==0) remap=0;

		// Precision?
		if (len>6 && stricmp(pattern->data+len-6,".exact")==0)
			precision=PRECISION_EXACT;

		// Specified in prefs?
		else
		if (pattern->precision)
		{
			if (pattern->precision==-1) remap=0;
			else
			if (pattern->precision==1) precision=PRECISION_ICON;
			else
			if (pattern->precision==2) precision=PRECISION_GUI;
			else
			if (pattern->precision==3) precision=PRECISION_EXACT;
		}

#ifdef PATCH_OK
		// If we've got v43 of the datatype, we don't need the fastram patch
		if (ver<43)
		{
			// Add this task to the patchlist for allocbitmap
			patchhandle=AddAllocBitmapPatch(FindTask(0),screen);
		}
#endif

		// Turn back on requesters
		((struct Process *)FindTask(0))->pr_WindowPtr=GUI->window;

		// Check for random pictures, and then load picture
		if (pattern_check_random(pattern,name) &&
			(pattern->object=
				NewDTObject(name,
					DTA_GroupID,GID_PICTURE,
					PDTA_Screen,screen,
					PDTA_FreeSourceBitMap,TRUE,
					(ver>42)?PDTA_DestMode:TAG_IGNORE,MODE_V43,
					(ver>42)?PDTA_UseFriendBitMap:TAG_IGNORE,TRUE,
					TAG_END)))
		{
			struct BitMapHeader *header;
			struct BitMap *bitmap;
			D_S(struct FileInfoBlock, fib)

			// Get file information
			if (GetFileInfo(name,fib) && strnicmp(fib->fib_Comment,"dopus ",6)==0)
			{
				char *args=fib->fib_Comment+6;
				short val;
				rexx_skip_space(&args);
				while ((val=rexx_match_keyword(&args,background_key,0))!=-1)
				{
					// Tile/center/stretch
					if (val==3)
						pattern->flags&=~(PATF_CENTER|PATF_STRETCH);
					else
					if (val==4)
					{
						pattern->flags|=PATF_CENTER;
						pattern->flags&=~PATF_STRETCH;
					}
					else
					if (val==5 && pattern->prefs.wbp_Which==0)
					{
						pattern->flags|=PATF_STRETCH;
						pattern->flags&=~PATF_CENTER;
					}

					// Precision
					else
					if (val==6)
					{
						// Get precision
						rexx_skip_space(&args);
						if ((val=rexx_match_keyword(&args,precision_key,0))>-1)
						{
							if (val==0)
								remap=0;
							else
							if (val==1)
								precision=PRECISION_GUI;
							else
							if (val==2)
								precision=PRECISION_ICON;
							else
							if (val==3)
								precision=PRECISION_IMAGE;
							else
							if (val==4)
								precision=PRECISION_EXACT;
						}
					}

					// Border
					else
					if (val==8)
					{
						// Off?
						rexx_skip_space(&args);
						if (rexx_match_keyword(&args,on_off_strings2,0)==0)
							border_col&=~ENVBF_USE_COLOUR;
						else
						{
							border_col=ENVBF_USE_COLOUR;
							border_col|=Atoh(args,-1)<<8;
						}
					}
				}
			}

			// Layout picture (should check for success)
			SetDTAttrs(pattern->object,0,0,
				OBP_Precision,precision,
				PDTA_Remap,remap,
				TAG_END);
			DoMethod(pattern->object,DTM_PROCLAYOUT,0,1);

			// Get bitmap pointer and header
			GetDTAttrs(pattern->object,
				PDTA_BitMap,&bitmap,
				PDTA_DestBitMap,&pattern->bitmap,
				PDTA_BitMapHeader,&header,
				TAG_END);

			// No dest bitmap?
			if (!pattern->bitmap) pattern->bitmap=bitmap;

			// Valid bitmap?
			if (pattern->bitmap)
			{
				// Get width and height
				pattern->width=header->bmh_Width;
				pattern->height=header->bmh_Height;
			}
		}

		// Turn off requesters
		((struct Process *)FindTask(0))->pr_WindowPtr=(APTR)-1;

#ifdef PATCH_OK
		// Remove this task from the patchlist for allocbitmap
		if (patchhandle)
			RemAllocBitmapPatch(patchhandle);
#endif

		// Got bitmap?
		if (pattern->bitmap)
		{
			// Stretch?
			if (pattern->flags&PATF_STRETCH)
			{
				// Not the size of the screen?
				if (pattern->width!=screen->Width ||
					pattern->height!=screen->Height)
				{
					// Allocate a bitmap for the stretched picture
					if ((pattern->pattern_bitmap=
							NewBitMap(
								screen->Width,
								screen->Height,
								GetBitMapAttr(pattern->bitmap,BMA_DEPTH),
								BMF_CLEAR,
								screen->RastPort.BitMap)))
					{
						struct BitScaleArgs scale;

						// Scale bitmap
						scale.bsa_SrcX=0;
						scale.bsa_SrcY=0;
						scale.bsa_SrcWidth=pattern->width;
						scale.bsa_SrcHeight=pattern->height;
						scale.bsa_DestX=0;
						scale.bsa_DestY=0;
						scale.bsa_DestWidth=screen->Width;
						scale.bsa_DestHeight=screen->Height;
						scale.bsa_XSrcFactor=scale.bsa_SrcWidth;
						scale.bsa_XDestFactor=scale.bsa_DestWidth;
						scale.bsa_YSrcFactor=scale.bsa_SrcHeight;
						scale.bsa_YDestFactor=scale.bsa_DestHeight;
						scale.bsa_SrcBitMap=pattern->bitmap;
						scale.bsa_DestBitMap=pattern->pattern_bitmap;
						scale.bsa_Flags=0;
						BitMapScale(&scale);

						// Get pointer to scaled bitmap
						pattern->bitmap=pattern->pattern_bitmap;
						pattern->width=screen->Width;
						pattern->height=screen->Height;
					}
				}
			}
		}

		// Update border pen
		GetPatternBorder(pattern,screen,border_col);
	}

	// Pattern ok now
	pattern->valid=TRUE;
}
Exemplo n.º 15
0
IPTR Ascii__DTM_ASYNCLAYOUT(Class *cl, Object *o, struct gpLayout *gpl)
{
    struct DTSpecialInfo 	*si = (struct DTSpecialInfo *) G (o)->SpecialInfo;
    struct AsciiData 		*data = INST_DATA (cl, o);
    ULONG 			visible = 0, total = 0;
    struct RastPort 		trp;
    ULONG 			hunit = 1;
    ULONG 			bsig = 0;

    /* Switches */
    BOOL 			linefeed = FALSE;
    BOOL 			newseg = FALSE;
    BOOL 			abort = FALSE;

    /* Attributes obtained from super-class */
    struct TextAttr 		*tattr;
    struct TextFont 		*font;
    struct List 		*linelist;
    struct IBox 		*domain;
    IPTR 			wrap = FALSE;
    IPTR 			bufferlen;
    STRPTR 			buffer;
    STRPTR 			title;

    /* Line information */
    ULONG 			num, offset, swidth;
    ULONG 			anchor = 0, newanchor;
    ULONG 			style = FS_NORMAL;
    struct Line 		*line;
    ULONG 			yoffset = 0;
    ULONG			linelength, max_linelength = 0;
    UBYTE 			fgpen = 1;
    UBYTE 			bgpen = 0;
    ULONG 			tabspace;
    ULONG 			numtabs;
    ULONG 			i;

    ULONG 			nomwidth, nomheight;

    D(bug("AsciiDataType_AsyncLayout\n"));
    
    /* Get all the attributes that we are going to need for a successful layout */
    if (GetDTAttrs (o, DTA_TextAttr	, (IPTR) &tattr		,
                       DTA_TextFont	, (IPTR) &font		,
                       DTA_Domain	, (IPTR) &domain	,
                       DTA_ObjName	, (IPTR) &title		,
                       TDTA_Buffer	, (IPTR) &buffer	,
                       TDTA_BufferLen	, (IPTR) &bufferlen	,
                       TDTA_LineList	, (IPTR) &linelist	,
                       TDTA_WordWrap	, (IPTR) &wrap		,
                       TAG_DONE) == 8)
    {
        D(bug("AsciiDataType_AsyncLayout: Got all attrs\n"));

        /* Lock the global object data so that nobody else can manipulate it */
        ObtainSemaphore (&(si->si_Lock));

        /* Make sure we have a buffer */
        if (buffer)
        {
	    D(bug("AsciiDataType_AsyncLayout: Got buffer\n"));
	    
            /* Initialize the temporary RastPort */
            InitRastPort (&trp);
            SetFont (&trp, font);

    	    D(bug("AsciiDataType_AsyncLayout: Temp RastPort initialized\n"));

            /* Calculate the nominal size */
            nomheight = (ULONG) (24 * font->tf_YSize);
            nomwidth  = (ULONG) (80 * font->tf_XSize);

	    /* Calculate the tab space */
	    tabspace = font->tf_XSize * 8;

            /* We only need to perform layout if we are doing word wrap, or this
             * is the initial layout call */

    	    D(bug("AsciiDataType_AsyncLayout: Checking if layout is needed\n"));
	    
            if (wrap || gpl->gpl_Initial)
            {
		D(bug("AsciiDataType_AsyncLayout: Layout IS needed. Freeing old LineList\n"));
		
                /* Delete the old line list */
                while ((line = (struct Line *) RemHead (linelist)))
                    FreePooled (data->Pool, line, sizeof (struct Line));

    		D(bug("AsciiDataType_AsyncLayout. Old LineList freed\n"));

                /* Step through the text buffer */
                for (i = offset = num = numtabs = 0;
                     (i < bufferlen) && (bsig == 0) && !abort;
                     i++)
                {
                    /* Convert DOS and Mac line endings */
                    if (buffer[i] == '\r')
                    {
                        if (buffer[i + 1] == '\n')
                              i++;
                        else
                            buffer[i] = '\n';
                    }

		    /* Check for end of line */
		    if (buffer[i] == '\n')
		    {
			newseg = linefeed = TRUE;
			newanchor = i + 1;
		    }
		    /* Check for end of page */
		    else if (buffer[i] == 12)
		    {
			newseg = linefeed = TRUE;
			newanchor = i + 1;
		    }
		    /* Check for tab */
		    else if (buffer[i] == '\t')
		    {
			/* See if we need to terminate a line segment */
			if ((numtabs == 0) && num)
			{
			    newseg = TRUE;
			}
			numtabs++;
		    }
		    else
		    {
			/* See if we have any TABs that we need to finish out */
			if (numtabs)
			{
			    offset += (((offset / tabspace) + 1) * tabspace) - offset;
			    num = numtabs = 0;
			    anchor = i;
			}

			/* Compute the width of the line. */
			swidth = TextLength(&trp, &buffer[anchor], num + 1);
			num++;
		    }

    	    	    if (i == bufferlen - 1) newseg = TRUE;
		    
		    /* Time for a new text segment yet? */
		    if (newseg)
		    {
			/* Allocate a new line segment from our memory pool */
			if ((line = AllocPooled(data->Pool, sizeof(struct Line))))
			{
			    swidth = TextLength(&trp, &buffer[anchor], num);
			    line->ln_Text = &buffer[anchor];
			    line->ln_TextLen = num;
			    line->ln_XOffset = offset;
			    line->ln_YOffset = yoffset + font->tf_Baseline;
			    line->ln_Width = swidth;
			    line->ln_Height = font->tf_YSize;
			    line->ln_Flags = (linefeed) ? LNF_LF : 0;
			    line->ln_FgPen = fgpen;
			    line->ln_BgPen = bgpen;
			    line->ln_Style = style;
			    line->ln_Data = NULL;

			    linelength = line->ln_Width + line->ln_XOffset;
			    if (linelength > max_linelength)
			    {
			    	max_linelength = linelength;
			    }
			    			    
			    /* Add the line to the list */
			    AddTail(linelist, (struct Node *) line);

			    /* Increment the line count */
			    if (linefeed)
			    {
				yoffset += font->tf_YSize;
				offset = 0;
				total++;
			    }
			    else
			    {
				/* Increment the offset */
				offset += swidth;
			    }
			}
			else
			{
			    abort = TRUE;
			}

			/* Clear the variables */
			newseg = linefeed = FALSE;
			anchor = newanchor;
			num = 0;

                        /* Check to see if layout has been aborted */
                        bsig = CheckSignal (SIGBREAKF_CTRL_C);
			
                    } /* if (newseg) */
		    
                }

		/*
		 * check for last line
		 */

		D(bug("AsciiDataType_AsyncLayout: end textloop, anchor %ld\n",anchor));

#if 0
		if (buffer[anchor])
		{
			linefeed=TRUE;
			D(bug("AsciiDataType_AsyncLayout: add last line <%s>\n",
				&buffer[anchor]));
			/* Allocate a new line segment from our memory pool */
			if ((line = AllocPooled(data->Pool, sizeof(struct Line))))
			{
			    swidth = TextLength(&trp, &buffer[anchor], num);
			    line->ln_Text = &buffer[anchor];
			    line->ln_TextLen = num;
			    line->ln_XOffset = offset;
			    line->ln_YOffset = yoffset + font->tf_Baseline;
			    line->ln_Width = swidth;
			    line->ln_Height = font->tf_YSize;
			    line->ln_Flags = (linefeed) ? LNF_LF : 0;
			    line->ln_FgPen = fgpen;
			    line->ln_BgPen = bgpen;
			    line->ln_Style = style;
			    line->ln_Data = NULL;

			    linelength = line->ln_Width + line->ln_XOffset;
			    if (linelength > max_linelength)
			    {
				max_linelength = linelength;
			    }
			    			    
			    /* Add the line to the list */
			    AddTail(linelist, (struct Node *) line);

			    /* Increment the line count */
			    if (linefeed)
			    {
				yoffset += font->tf_YSize;
				offset = 0;
				total++;
			    }
			    else
			    {
				/* Increment the offset */
				offset += swidth;
			    }
			}
			else
			{
			    abort = TRUE;
			}
		}
#endif
		
            } /* if (wrap || gpl->gpl_Initial) */
            else
            {
                /* No layout to perform */
                total  = si->si_TotVert;
		max_linelength = si->si_TotHoriz * si->si_HorizUnit;
            }
	    
	    DeinitRastPort(&trp);
	    
        } /* if (buffer) */

        /* Compute the lines and columns type information */
        si->si_VertUnit  = font->tf_YSize;
        si->si_VisVert   = visible = domain->Height / si->si_VertUnit;
        si->si_TotVert   = total;

/*        si->si_HorizUnit = hunit = 1;
        si->si_VisHoriz  = (LONG) domain->Width / hunit;
        si->si_TotHoriz  = domain->Width;*/
	
	si->si_HorizUnit = hunit = font->tf_XSize;
	si->si_VisHoriz  = domain->Width / hunit;
	si->si_TotHoriz  = max_linelength / hunit;
								   
        /* Release the global data lock */
        ReleaseSemaphore (&si->si_Lock);

        /* Were we aborted? */
        if (bsig == 0)
        {
            /* Not aborted, so tell the world of our newest attributes */
            NotifyAttrChanges (o, gpl->gpl_GInfo, 0,
                               GA_ID		, G(o)->GadgetID,

                               DTA_VisibleVert	, visible				,
                               DTA_TotalVert	, total					,
                               DTA_NominalVert	, nomheight				,
                               DTA_VertUnit	, font->tf_YSize			,
                            /* DTA_TopVert   	, si->si_TopVert                        , */

                               DTA_VisibleHoriz	, (domain->Width / hunit)		,
                               DTA_TotalHoriz	, max_linelength / hunit		,
                               DTA_NominalHoriz	, nomwidth				,
                               DTA_HorizUnit	, hunit					,
    	    	    	       DTA_TopHoriz 	, si->si_TopHoriz   	    	    	,
			       
                               DTA_Title	, (IPTR)title				,
                               DTA_Busy		, FALSE					,
                               DTA_Sync		, TRUE					,
                               TAG_DONE);
        } /* if (bsig == 0) */
		
    } /* if GetDTAttrs(... */

    D(bug("AsciiDataType_AsyncLayout: Done. Returning %d\n", total));
    
    return (IPTR)total;
}
Exemplo n.º 16
0
main()
{
  unsigned char str[256], *pp;
  int i;
  struct TextAttr ta = { "topaz.font", 8, FS_NORMAL, FPF_ROMFONT };
  struct RastPort rp;
  struct BitMap bm = { 256, 	/* bytes per row */
		         8,	/* rows */
			 0,	/* flags */
			 1,	/* depth */
			 0,	/* pad */
			 0 };	/* planes */
  struct TextFont *tf;

  InitRastPort (& rp);
  rp.BitMap = &bm;
  bm.Planes[0] = pp = AllocRaster (256 * 8, 8);

  if (!pp)
    {
      fprintf (stderr, "Can't allocate raster!\n");
      exit (1);
    }
  bzero (pp, 256 * 8);
  
  tf = OpenFont (& ta);
  if (! tf)
    {
      fprintf (stderr, "can't open topaz font.\n");
      exit (1);
    }

  SetFont (&rp, tf);

  /* initialize string to be printed */
  for (i = 32; i < 256; i++) str[i - 32] = i;

  Move (&rp, 0, 6);
  
  Text (&rp, str, 256 - 32);
  {
    int bin = open ("bitmap", 1);
    if (bin >= 0)
      {
        write (bin, pp, 256*8);
        close (bin);
      }
  }
  
  /* dump them.. */
  printf ("/* generated automatically by dumpfont.c. *DONT* distribute\n");
  printf ("   this file, it contains information Copyright by Commodore!\n");
  printf ("\n");
  printf ("   This is the (new) topaz80 system font: */\n\n");
  
  printf ("unsigned char kernel_font_width  = 8;\n");
  printf ("unsigned char kernel_font_height = 8;\n");
  printf ("unsigned char kernel_font_lo = 32;\n");
  printf ("unsigned char kernel_font_hi = 255;\n\n");
  
  printf ("unsigned char kernel_cursor[] = {\n");
  printf ("  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };\n\n");
  printf ("unsigned char kernel_font[] = {\n");
  
  for (i = 0; i < 256 - 32; i++)
    {
      printf ("/* %c */ ", i + 32);
      printf ("0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x,\n",
      	      pp[i+0*256], pp[i+1*256], pp[i+2*256], pp[i+3*256],
      	      pp[i+4*256], pp[i+5*256], pp[i+6*256], pp[i+7*256]);
    }
  printf ("};\n");
  
  CloseFont (tf);
  FreeRaster (pp, 256 * 8, 8);
}
Exemplo n.º 17
0
// Update toolbar cache
BOOL GetToolBarCache(ToolBarInfo *toolbar,BOOL real)
{
	short depth,width,height,num,x,y;
	short last_width=0,last_height=0;
	Cfg_Button *button;
	struct TagItem tags[4];
	struct Rectangle rect;

	// Invalid toolbar?
	if (!toolbar) return 0;

	// Free existing cache
	FreeToolBarCache(toolbar);

	// Remap toolbar if this is for real
	if (real && !toolbar->done_remap)
	{
		// Do remap
		RemapToolBar(toolbar);
		toolbar->done_remap=1;
	}

	// Initialise tags
	tags[0].ti_Tag=IM_Depth;
	tags[0].ti_Data=1;
	tags[1].ti_Tag=IM_Width;
	tags[1].ti_Data=0;
	tags[2].ti_Tag=IM_Height;
	tags[2].ti_Data=0;
	tags[3].ti_Tag=TAG_DONE;

	// Minimum depth
	depth=1;

	// Count items in toolbar
	for (button=(Cfg_Button *)toolbar->buttons->buttons.lh_Head,toolbar->count=0;
		button->node.ln_Succ;
		button=(Cfg_Button *)button->node.ln_Succ,toolbar->count++);

	// Allocate position array
	if (!(toolbar->button_array=AllocVec(sizeof(struct Rectangle)*(toolbar->count+2),MEMF_CLEAR)))
	{
		FreeToolBarCache(toolbar);
		return 0;
	}

	// Go through buttons again
	for (button=(Cfg_Button *)toolbar->buttons->buttons.lh_Head,num=0,toolbar->max_width=0;
		button->node.ln_Succ;
		button=(Cfg_Button *)button->node.ln_Succ,num++)
	{
		Cfg_ButtonFunction *func;
		short width,height,x;

		// Get left button image
		if ((func=(Cfg_ButtonFunction *)
			FindFunctionType((struct List *)&button->function_list,FTYPE_LEFT_BUTTON)) &&
			func->image)
		{
			// Get depth and other info
			GetImageAttrs(func->image,tags);

			// Biggest depth so far?
			if (tags[0].ti_Data>depth)
				depth=tags[0].ti_Data;

			// Get size
			width=tags[1].ti_Data;
			height=tags[2].ti_Data;
		}

		// Or textual button?
		else
		if (!(button->button.flags&BUTNF_GRAPHIC) && func)
		{
			struct TextExtent extent;

			// Get length of label
			TextExtent(&GUI->screen_pointer->RastPort,func->label,strlen(func->label),&extent);

			// Get size
			width=extent.te_Width;
			height=extent.te_Height;
		}

		// Use last size
		else
		{
			width=last_width;
			height=last_height;
		}

		// Minimum size
		if (width<2) width=8;
		if (height<2) height=8;

		// Save size
		last_width=width;
		last_height=height;

		// Increase size for border
		if (!(toolbar->buttons->window.flags&BTNWF_BORDERLESS))
		{
			width+=2;
			height+=2;
		}

		// Biggest width so far?
		if (width>toolbar->max_width)
			toolbar->max_width=width;

		// Get last position
		x=(num>0)?toolbar->button_array[num-1].MaxX+1:0;

		// Store position in array
		toolbar->button_array[num].MinX=x;
		toolbar->button_array[num].MinY=0;
		toolbar->button_array[num].MaxX=x+width-1;
		toolbar->button_array[num].MaxY=height-1;
	}

	// No actual buttons?
	if (toolbar->count<1 || depth<1)
	{
		FreeToolBarCache(toolbar);
		return 0;
	}

	// Store rows/cols
	toolbar->cols=toolbar->count;
	toolbar->rows=1;

	// Valid toolbar arrow?
	if (GUI->toolbar_arrow_image)
	{
		short width,height;

		// Get size of the arrow button
		GetImageAttrs(GUI->toolbar_arrow_image,tags);

		// Biggest depth so far?
		if (tags[0].ti_Data>depth)
			depth=tags[0].ti_Data;

		// Get size
		width=tags[1].ti_Data;
		height=tags[2].ti_Data;

		// Increase size for border
		if (!(toolbar->buttons->window.flags&BTNWF_BORDERLESS))
		{
			width+=2;
			height+=2;
		}

		// Store size in array
		toolbar->button_array[toolbar->count].MaxX=width-1;
		toolbar->button_array[toolbar->count].MaxY=height-1;

		// Add to maximum width
		toolbar->max_width+=width;
	}

	// Get height of toolbar
	for (num=0,height=0;num<=toolbar->count;num++)
	{
		if ((width=RECTHEIGHT(&toolbar->button_array[num]))>height)
			height=width;
	}

	// Store toolbar height
	toolbar->button_height=height;

	// Get cache size
	toolbar->width=toolbar->button_array[toolbar->count-1].MaxX+1;
	toolbar->height=toolbar->button_height;

	// Don't want cache?
	if (!real) return 1;

	// Allocate cache bitmap
	if (!(toolbar->bitmap=
		NewBitMap(
			toolbar->width,
			toolbar->height,
			depth,
			BMF_CLEAR,
			GUI->screen_pointer->RastPort.BitMap)))
//			0)))
	{
		// Failed
		FreeToolBarCache(toolbar);
		return 0;
	}

	// Initialise RastPort
	InitRastPort(&toolbar->rp);
	toolbar->rp.BitMap=toolbar->bitmap;

	// Got cache successfully
	toolbar->cache=1;

	// Set pens and font
	SetAPen(&toolbar->rp,1);
	SetBPen(&toolbar->rp,0);
	SetFont(&toolbar->rp,GUI->screen_pointer->RastPort.Font);

	// Initialise draw tags
	tags[0].ti_Tag=IM_Rectangle;
	tags[0].ti_Data=(ULONG)&rect;
	tags[1].ti_Tag=IM_ClipBoundary;
	tags[1].ti_Data=(toolbar->buttons->window.flags&BTNWF_BORDERLESS)?0:2;
	tags[2].ti_Tag=IM_NoIconRemap;
	tags[2].ti_Data=(environment->env->desktop_flags&DESKTOPF_NO_REMAP)?TRUE:FALSE;
	tags[3].ti_Tag=TAG_DONE;

	// Go through buttons
	for (button=(Cfg_Button *)toolbar->buttons->buttons.lh_Head,x=0,y=0,num=0;
		button->node.ln_Succ;
		button=(Cfg_Button *)button->node.ln_Succ,num++)
	{
		Cfg_ButtonFunction *func;
		BOOL ok=0;

		// Get button rectangle
		rect=toolbar->button_array[num];

		// Get left button image
		if ((func=(Cfg_ButtonFunction *)FindFunctionType((struct List *)&button->function_list,FTYPE_LEFT_BUTTON)) &&
			func->image)
		{
			// Draw button image
			RenderImage(&toolbar->rp,func->image,0,0,tags);
			ok=1;
		}

		// Or textual button?
		else
		if (!(button->button.flags&BUTNF_GRAPHIC) &&
			func &&
			func->label && *func->label)
		{
			// Draw label
			Move(&toolbar->rp,x,y+toolbar->rp.TxBaseline);
			Text(&toolbar->rp,func->label,strlen(func->label));
			ok=1;
		}

		// Draw button border
		if (!ok || !(toolbar->buttons->window.flags&BTNWF_BORDERLESS))
			DrawBox(&toolbar->rp,&rect,GUI->draw_info,0);
	}

	return 1;
}
Exemplo n.º 18
0
struct DragObj * PRIVATE CreateDragObj(struct DragGadget *dg,int x,int y)
{
  struct Screen *scr;
  struct RastPort *rp;
  struct DragObj *gdo;
  ULONG line;
  int wordwidth;
  int width,height,depth;
  int i = 0,xpos,ypos;

  scr = dg->dg_Window->WScreen;
  rp = &scr->RastPort;

  if (dg->dg_Flags & DGF_IMAGES && ((struct ImageNode *)dg->dg_Object.od_Object)->in_Image)
    dg->dg_Image = ((struct ImageNode *)dg->dg_Object.od_Object)->in_Image;

  if (!dg->dg_Width || !dg->dg_Height)
  {
    if ((dg->dg_Type == LISTVIEW_KIND) && !dg->dg_Image)
    {
      dg->dg_Width = dg->dg_Gadget->Width-20;
      dg->dg_Height = dg->dg_ItemHeight;
    }
    else if (!dg->dg_RenderHook && dg->dg_Image)
    {
      dg->dg_Width = dg->dg_Image->Width;
      dg->dg_Height = dg->dg_Image->Height;
    }
    else  /* be sure width & height are not zero */
    {
      dg->dg_Width = dg->dg_Gadget->Width;
      dg->dg_Height = dg->dg_Gadget->Height;
    }
  }
  width = dg->dg_Width;
  height = dg->dg_Height;
  memset(&dm,0,sizeof(struct DropMessage));

  if (dg->dg_Type == LISTVIEW_KIND)
  {
    xpos = dg->dg_Gadget->LeftEdge+2;
    ypos = dg->dg_Gadget->TopEdge+2;
    dg->dg_Object.od_Object = NULL;

    if (y < ypos || y > ypos+dg->dg_Gadget->Height-5)
      return(NULL);
    line = (y-ypos)/dg->dg_ItemHeight;
    ypos += line*dg->dg_ItemHeight;

    GT_GetGadgetAttrs(dg->dg_Gadget,dg->dg_Window,NULL,GTLV_Labels,&dg->dg_List,TAG_END);
    if (dg->dg_List && !IsListEmpty(dg->dg_List))
    {
      GT_GetGadgetAttrs(dg->dg_Gadget,dg->dg_Window,NULL,GTLV_Top,&i,TAG_END);
      i += line;
      if (i < CountNodes(dg->dg_List))
      {
        struct Node *ln;

        dm.dm_SourceEntry = i;
        for(ln = dg->dg_List->lh_Head;i;i--,ln = ln->ln_Succ);

        if (dg->dg_Flags & DGF_TREEVIEW && TREENODE(ln)->tn_Flags & TNF_STATIC)
        {
          mx = ~0L;      // avoid a following drag
          return(NULL);
        }
        dg->dg_Object.od_Object = ln;

        if (dg->dg_ObjectFunc)
          dg->dg_ObjectFunc(dg->dg_Window,dg->dg_Gadget,&dg->dg_Object,dm.dm_SourceEntry);
      }
    }
  }
  else
  {
    if (dg->dg_ObjectFunc)
      dg->dg_ObjectFunc(dg->dg_Window,dg->dg_Gadget,&dg->dg_Object,0L);

    dm.dm_SourceEntry = dg->dg_SourceEntry;
    xpos = x-width/2;
    ypos = y-height/2;
  }
  if (!dg->dg_Object.od_Object)
  {
    mx = ~0L;        // avoid a following drag
    return(NULL);
  }
  wordwidth = (width + 15) >> 4;
  depth = GetBitMapAttr(rp->BitMap,BMA_DEPTH);

  if (dg->dg_Object.od_Object && (gdo = AllocMem(sizeof(struct DragObj), MEMF_CLEAR | MEMF_PUBLIC)))
  {
#ifdef LOCKLAYERS
    LockLayers(&scr->LayerInfo);
    UnlockLayer(dg->dg_Window->RPort->Layer);
#endif

    gdo->do_Screen = scr;
    gdo->do_ScrRPort = rp;

    gdo->do_BitMap = AllocBitMap(width,height,depth,BMF_CLEAR | BMF_MINPLANES,!(GetBitMapAttr( rp->BitMap, BMA_FLAGS ) & BMF_INTERLEAVED) ? rp->BitMap : NULL);
    gdo->do_SaveBack = AllocBitMap(width,height,depth,BMF_CLEAR | BMF_MINPLANES,rp->BitMap);
    gdo->do_RefreshMap = AllocBitMap(width*2,height*2,depth,BMF_CLEAR | BMF_MINPLANES,rp->BitMap);

    if (GetBitMapAttr(gdo->do_BitMap,BMA_FLAGS) & BMF_STANDARD)
      i = MEMF_CHIP | MEMF_PUBLIC;
    else
      i = 0;

    gdo->do_FullShadow = AllocMem(2*wordwidth*height,i | MEMF_CLEAR);
    gdo->do_HalfShadow = AllocMem(2*wordwidth*height,i);

    if (gdo->do_BitMap && gdo->do_SaveBack && gdo->do_RefreshMap && gdo->do_FullShadow && gdo->do_HalfShadow)
    {
      InitRastPort(&gdo->do_RPort);
      gdo->do_RPort.BitMap = gdo->do_BitMap;
      InitRastPort(&gdo->do_RefreshRPort);
      gdo->do_RefreshRPort.BitMap = gdo->do_RefreshMap;

      gdo->do_DragGadget = dg;
      CopyMem(&dg->dg_Object,&dm.dm_Object,sizeof(struct ObjectDescription));
      dm.dm_Window = dg->dg_Window;
      dm.dm_Gadget = dg->dg_Gadget;

      /*** create the drag&drop image ***/

      if (dg->dg_RenderHook)
      {
        struct LVDrawMsg lvdm;

        SetFont(&gdo->do_RPort,scr->RastPort.Font);
        lvdm.lvdm_MethodID = LV_DRAW;
        lvdm.lvdm_RastPort = &gdo->do_RPort;
        lvdm.lvdm_DrawInfo = GetScreenDrawInfo(scr);
        lvdm.lvdm_Bounds.MinX = 0;
        lvdm.lvdm_Bounds.MinY = 0;
        lvdm.lvdm_Bounds.MaxX = width-1;
        lvdm.lvdm_Bounds.MaxY = height-1;
        lvdm.lvdm_State = LVR_SELECTED;
        CallHookPkt(dg->dg_RenderHook,dm.dm_Object.od_Object,&lvdm);
        FreeScreenDrawInfo(scr,lvdm.lvdm_DrawInfo);
      }
      else if (dg->dg_Image)
        DrawImage(&gdo->do_RPort,dg->dg_Image,0,0);
      else
        ClipBlit(dg->dg_Window->RPort,xpos,ypos,&gdo->do_RPort,0,0,width,height,0xc0);

      /*** initialize drag object structure ***/

      gdo->do_X = -9999;
      gdo->do_Y = ypos+dg->dg_Window->TopEdge;
      gdo->do_PX = -9999;
      gdo->do_Width = width;
      gdo->do_Height = height;
      gdo->do_DeltaX = xpos-x+dg->dg_Window->LeftEdge;
      gdo->do_DeltaY = ypos-y+dg->dg_Window->TopEdge;
      gdo->do_Mask = gdo->do_FullShadow;

      /*** create masks (transparent and full imagery) ***/

      if (CyberGfxBase && (GetBitMapAttr(gdo->do_BitMap,BMA_FLAGS) & BMF_STANDARD) == 0L)
      {
        struct BitMap tbm;
        ULONG  col;

        InitBitMap(&tbm,1,width,height);
        tbm.Planes[0] = (UBYTE *)gdo->do_FullShadow;

        /* if (!GetCyberMapAttr(gdo->do_BitMap, CYBRMATTR_PIXELFMT)) */

        if (GetBitMapAttr(gdo->do_BitMap, BMA_DEPTH) > 8L)
        {
          ULONG triplet[3];

          GetRGB32(scr->ViewPort.ColorMap,0L,1L,triplet);
          col = (triplet[0] & 0xff0000) | (triplet[1] & 0xff00) | (triplet[2] & 0xff);
        }
        else
          col = 0;

        // ExtractColor(rp,&tbm,col,xpos,ypos,width,height);
        ExtractColor(&gdo->do_RPort,&tbm,col,0,0,width,height);

        BltBitMap(&tbm,0,0,&tbm,0,0,width,height,0x50,0xff,NULL);  // invertieren der Maske
      }
      else
      {
        UWORD *p = gdo->do_FullShadow;

        for(ypos = 0;ypos < height;ypos++)
        {
          for(xpos = 0;xpos < wordwidth;xpos++,p++)
          {
            for(i = 0;i < depth;i++)
              *p |= *((UWORD *)gdo->do_BitMap->Planes[i]+ypos*(gdo->do_BitMap->BytesPerRow >> 1)+xpos);
          }
        }
      }

      {
        UWORD *p = gdo->do_HalfShadow;

        CopyMem(gdo->do_FullShadow,p,2*wordwidth*height);
        for(line = 0x5555,ypos = 0;ypos < height;ypos++)
        {
          line = ~line;
          for(xpos = 0;xpos < wordwidth;xpos++,p++)
            *p &= (UWORD)line;
        }
      }

      if (!boopsigad)
        FakeInputEvent();
      UpdateDragObj(gdo,gdo->do_X,gdo->do_Y);    /* show drag object */

      return(gdo);
    }
Exemplo n.º 19
0
int detect_screen(void)
{
	struct Screen *myScreen;
	struct Window *myWindow;
	struct RastPort myRastPort;
	struct BitMap *myBitMap;

	APTR bitMapHandle;

	ULONG result;

	int bpp = 0;
	
	if((ULONG)IntuitionBase == 0)
	{
	IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39L);	
	}	


	if((ULONG)GfxBase == 0)
	{
	GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39L);
	}

	if((ULONG)CyberGfxBase == 0)
	{
	CyberGfxBase = OpenLibrary("cybergraphics.library", 0);	
	}
	
	if(!CyberGfxBase) {
		if( !(CyberGfxBase=OpenLibrary("cybergraphics.library",40L))) {
			printf("Couldn't open cybergraphics.");
			return(-1);
		}
	}
	

	myScreen = LockPubScreen(NULL);
	if(myScreen != NULL)
	{
		UnlockPubScreen(NULL, myScreen);
	}
	else
	{
		printf("Couldnt get screen data.\n");
		CloseLibrary((struct Library*)IntuitionBase);
		CloseLibrary(CyberGfxBase);
		CloseLibrary((struct Library *)GfxBase);

		return 5;
	}


	myBitMap = AllocBitMap(1, 1, 8, BMF_MINPLANES | BMF_DISPLAYABLE, myScreen->RastPort.BitMap);
	if((ULONG)myBitMap == 0)
	{
		printf("Couldnt allocate bitmap.\n");
		CloseLibrary(CyberGfxBase);
		CloseLibrary((struct Library *)GfxBase);
		CloseLibrary((struct Library *)IntuitionBase);
		return 6;
	}

	//Creates the RastPort used for blitting
	InitRastPort(&myRastPort);
	myRastPort.BitMap = myBitMap;

	result=GetCyberMapAttr(myBitMap, CYBRMATTR_PIXFMT);

	switch(result)
	{
		case 0://PIXFMT_LUT8:
			bpp = 8; //printf("0");
			break;
		case 1://PIXFMT_RGB15:
			bpp = 16; //printf("1");
			break;
		case 2://PIXFMT_BGR15:
			bpp = 16; //printf("2");
			break;
		case 3://PIXFMT_RGB15PC:
			bpp = 16; //printf("3");
			break;
		case 4://PIXFMT_BGR15PC:
			bpp = 16; //printf("4");
			break;
		case 5://PIXFMT_RGB16:
			bpp = 16; //printf("5");
			break;
		case 6://PIXFMT_BGR16:
			bpp = 16; //printf("6");
			break;
		case 7://PIXFMT_RGB16PC:
			bpp = 16; //printf("7");
			break;
		case 8://PIXFMT_BGR16PC:
			bpp = 16; //printf("8");
			break;
		case 9://PIXFMT_RGB24:
			bpp = 24; //printf("9");
			break;
		case 10://PIXFMT_BGR24:
			bpp = 24; //printf("10");
			break;
		case 11://PIXFMT_ARGB32:
			bpp = 32; //printf("11");
			break;
		case 12://PIXFMT_BGRA32:
		#if defined NOVA_SDL 
			bpp = 16; //printf("12");
		#else
			bpp = 32; //printf("12");
		#endif
			break;
		case 13://PIXFMT_RGBA32:
			bpp = 32; //printf("13");
			break;
		default:
			bpp = 16; //printf("14");
	}
#ifdef DEBUG
	printf("Pixel format: %d \n",result);
	printf("Bpp: %d ",bpp);
#endif
	FreeBitMap(myBitMap);

	CloseLibrary((struct Library *)IntuitionBase);
	//CloseLibrary(CyberGfxBase);
	//CloseLibrary((struct Library *)GfxBase);

	return bpp;
}
Exemplo n.º 20
0
// Initialise a new lister
IPC_StartupCode(lister_init, Lister *, lister, static)
{
	// Store IPC and lister pointers
	lister->ipc=ipc;
	ipc->userdata=lister;

	// Store IPC pointer in backdrop info
	lister->backdrop_info->ipc=ipc;

	// Path history list
	lister->path_history=Att_NewList(LISTF_LOCK);

	// Initialise reselection
	InitReselect(&lister->reselect);
	lister->abort_signal=-1;

	// Create message ports and signals
	if (!(lister->app_port=CreateMsgPort()) ||
		!(lister->timer_port=CreateMsgPort()) ||
		(lister->hot_name_bit=AllocSignal(-1))==-1 ||
		(lister->abort_signal=AllocSignal(-1))==-1)
		return 0;

	// Allocate some timers
	if (!(lister->busy_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)) ||
		!(lister->scroll_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)) ||
		!(lister->edit_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)) ||
		!(lister->foo_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)))
		return 0;
	StartTimer(lister->foo_timer,5,0);

	// Create regions
	if (!(lister->title_region=NewRegion()) ||
		!(lister->refresh_extra=NewRegion()))
		return 0;

	// Lock buffer list
	lock_listlock(&GUI->buffer_list,TRUE);

	// Allocate initial buffer
	if (!(lister->cur_buffer=lister_get_empty_buffer()) &&
		!(lister->cur_buffer=lister_new_buffer(lister)))
		return 0;
	lister->cur_buffer->buf_CurrentLister=lister;

	// Unlock buffer list
	unlock_listlock(&GUI->buffer_list);

	// Allocate "special" buffer
	if (!(lister->special_buffer=buffer_new()))
		return 0;

	// Build popup menu
	lister_build_menu(lister);

	// Initialise flags
	lister->flags|=LISTERF_FIRST_TIME;
	lister->flags2|=LISTERF2_UNAVAILABLE;
	lister->tool_sel=-1;
	lister->toolbar_offset=0;

	// Fix priority
	lister->normal_pri=environment->env->settings.pri_lister[0];
	lister->busy_pri=environment->env->settings.pri_lister[1];
	SetTaskPri((struct Task *)lister->ipc->proc,lister->normal_pri);

	// Get font to use
	lister->lister_font.ta_Name=lister->font_name;
	lister->lister_font.ta_YSize=lister->font_size;
	lister->lister_font.ta_Flags=0;
	lister->lister_font.ta_Style=0;

	// Open font
	if ((lister->font=OpenDiskFont(&lister->lister_font)))
	{
		// Proportional	font?
		if (lister->font->tf_Flags&FPF_PROPORTIONAL)
			lister->more_flags|=LISTERF_PROP_FONT;

		// Set font in text area
		InitRastPort(&lister->text_area.rast);
		SetFont(&lister->text_area.rast,lister->font);
	}

	return 1;
}