示例#1
0
static boolean initcolorpopup (void) {
	
	CTabHandle syspal;
	Handle mdefh;
	
	if (!systemhascolor ()) 
		return (false);
		
	syspal = GetCTable (8);
	
	HLock ((Handle) syspal);
	
	ctable = &(**syspal).ctTable;
	
	mdefh = appnewhandle (6);
	
	*(short *)*mdefh = 0x4EF9;
	
	*(long *)(*mdefh + sizeof (short)) = (long) &colormenuhandler;
	
	colormenu = GetMenu (256); /*256 blank entries in this menu*/
	
	(**colormenu).menuProc = mdefh;
	
	CalcMenuSize (colormenu);
	
	/*create a picture, didn't make it faster, commented*/ {
	
		/*
		WindowPtr w;
		Rect r;
		
		w = GetNewCWindow (128, nil, (WindowPtr) -1);
		
		pushmacport (w);
		
		r.top = r.left = 0;
		
		r.bottom = (**colormenu).menuHeight;
		
		r.right = (**colormenu).menuWidth;
		
		ClipRect (&r);
		
		colorpopuppict = OpenPicture (&r);
		
		drawcolorpopup (r);
		
		ClosePicture ();
		
		popmacport ();
		
		DisposeWindow (w);
		*/
		}
	
	return (true);
	} /*initcolorpopup*/
示例#2
0
int main (int argc, const char * argv[]) {
    // These were removed from the headers in 10.7, but are still in the framework
    extern CTabHandle GetCTable(short);
    extern void DisposeCTable(CTabHandle);

    FILE *f = fopen("palettes.htm", "w");
    fprintf(f, "<html><head><title>GetCTable</title><style>td {width: 50px; height: 50px; }</style></head><body>\n");
    short i = -32768;
    for (int n = 0; n < 65536; ++i, ++n) {
        CTabHandle t = GetCTable(i);
        if (t) {
            CTabPtr ptr = *t;
            const int sz = ptr->ctSize + 1;
            printf("let palette%d: [FVRGBColor] = [\n", i);
            fprintf(f, "<h1>[%d] %d</h1>\n", i, sz);
            fprintf(f, "<table>\n");
            for (int j = 0; j < sz; ++j) {
                const ColorSpec *s = &ptr->ctTable[j];
                if (j == 0 || (j % 16) == 0) {
                    if (n > 0) {
                        fprintf(f, "</tr>\n");
                    }
                    fprintf(f, "<tr>\n");
                }
                int r = (s->rgb.red / 65535.) * 255;
                int g = (s->rgb.green / 65535.) * 255;
                int b = (s->rgb.blue / 65535.) * 255;
                printf("    FVRGBColor(r: %d, g: %d, b: %d),\n", r, g, b);
                fprintf(f, "<td bgcolor=\"#%02X%02X%02X\"></td>\n", r, g, b);
            }
            printf("]\n");
            fprintf(f, "</tr></table>\n");
            DisposeCTable(t);
        }
    }
    fprintf(f, "</body></html>\n");
    fclose(f);
    return 0;
}
示例#3
0
bool MCImageBitmapToPICT(MCImageBitmap *p_bitmap, MCMacSysPictHandle &r_pict)
{
#ifdef LIBGRAPHICS_BROKEN
	bool t_success = true;
	
	Pixmap drawdata = nil, drawmask = nil;
	MCBitmap *maskimagealpha = nil;
	
	t_success = MCImageSplitPixmaps(p_bitmap, drawdata, drawmask, maskimagealpha);
	
	if (!t_success)
		return false;

	Rect t_rect;
	SetRect(&t_rect, 0, 0, p_bitmap->width, p_bitmap->height);
	
	GWorldPtr t_old_gworld;
	GDHandle t_old_gdevice;
	GetGWorld(&t_old_gworld, &t_old_gdevice);

	PixMapHandle t_draw_pixmap;
	t_draw_pixmap = GetGWorldPixMap((CGrafPtr)drawdata -> handle . pixmap);
	
	GWorldPtr t_img_gworld;
	t_img_gworld = NULL;
	if (t_success)
	{
		QDErr t_err;
		t_err = NewGWorld(&t_img_gworld, 32, &t_rect, NULL, NULL, 0);
		if (t_err != noErr)
			t_success = false;
	}
	
	if (t_success)
	{
		SetGWorld(t_img_gworld, GetGDevice());
		
		PenMode(srcCopy);
		ForeColor(blackColor);
		BackColor(whiteColor);
		
		if (maskimagealpha != NULL)
		{
			GWorldPtr t_alpha_gworld;
			if (NewGWorldFromPtr(&t_alpha_gworld, 8, &t_rect, GetCTable(40), NULL, 0, maskimagealpha -> data, maskimagealpha -> bytes_per_line) == noErr)
			{
				const BitMap *t_dst_bits;
				t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld);
				
				const BitMap *t_src_bits;
				t_src_bits = GetPortBitMapForCopyBits((CGrafPtr)drawdata -> handle . pixmap);
				
				const BitMap *t_mask_bits;
				t_mask_bits = GetPortBitMapForCopyBits(t_alpha_gworld);
				
				EraseRect(&t_rect);
				
				CopyDeepMask(t_src_bits, t_mask_bits, t_dst_bits, &t_rect, &t_rect, &t_rect, srcCopy, NULL);
			}
		}
		else if (drawmask != NULL)
		{
			PixMapHandle t_mask_pixmap;
			t_mask_pixmap = GetGWorldPixMap((CGrafPtr)drawmask -> handle . pixmap);
			
			EraseRect(&t_rect);
			
			const BitMap *t_dst_bits;
			t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld);
			
			const BitMap *t_src_bits;
			LockPixels(t_draw_pixmap);
			t_src_bits = (BitMap *)*t_draw_pixmap;
			
			const BitMap *t_mask_bits;
			LockPixels(t_mask_pixmap);
			t_mask_bits = (BitMap *)*t_mask_pixmap;
			
			CopyMask(t_src_bits, t_mask_bits, t_dst_bits, &t_rect, &t_rect, &t_rect);
			
			UnlockPixels(t_mask_pixmap);
			
			UnlockPixels(t_draw_pixmap);
		}
		else
		{
			const BitMap *t_dst_bits;
			t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld);
			
			const BitMap *t_src_bits;
			LockPixels(t_draw_pixmap);
			t_src_bits = (BitMap *)*t_draw_pixmap;
			CopyBits(t_src_bits, t_dst_bits, &t_rect, &t_rect, srcCopy, NULL);
			UnlockPixels(t_draw_pixmap);
		}
	}
	
	PicHandle t_handle;
	t_handle = NULL;
	if (t_success)
	{
		OpenCPicParams t_params;
		t_params . srcRect = t_rect;
		t_params . hRes = 72 << 16;
		t_params . vRes = 72 << 16;
		t_params . version = -2;
		t_params . reserved1 = 0;
		t_params . reserved2 = 0;
		t_handle = OpenCPicture(&t_params);
		if (t_handle == NULL)
			t_success = false;
	}

	if (t_success)
	{
		GWorldPtr t_pict_gworld;
		GDHandle t_pict_gdevice;
		GetGWorld(&t_pict_gworld, &t_pict_gdevice);
		
		PenMode(srcCopy);
		ForeColor(blackColor);
		BackColor(whiteColor);
		
		const BitMap *t_dst_bits;
		t_dst_bits = GetPortBitMapForCopyBits(t_pict_gworld);

		const BitMap *t_src_bits;
		t_src_bits = GetPortBitMapForCopyBits(t_img_gworld);
		CopyBits(t_src_bits, t_dst_bits, &t_rect, &t_rect, srcCopy, NULL);
		
		ClosePicture();
	}
	
	if (t_img_gworld != NULL)
		DisposeGWorld(t_img_gworld);
	
	SetGWorld(t_old_gworld, t_old_gdevice);

	MCscreen->freepixmap(drawdata);
	MCscreen->freepixmap(drawmask);
	if (maskimagealpha != nil)
		MCscreen->destroyimage(maskimagealpha);
	
	if (t_success)
		r_pict = (MCMacSysPictHandle)t_handle;
	
	return t_success;
#else
	return false;
#endif
}
示例#4
0
void wxCursor::CreateFromImage(const wxImage & image)
{
    m_refData = new wxCursorRefData;

    int w = 16;
    int h = 16;

    int hotSpotX = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
    int hotSpotY = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
    int image_w = image.GetWidth();
    int image_h = image.GetHeight();

    wxASSERT_MSG( hotSpotX >= 0 && hotSpotX < image_w &&
                  hotSpotY >= 0 && hotSpotY < image_h,
                  _T("invalid cursor hot spot coordinates") );

    wxImage image16(image); // final image of correct size

    // if image is too small then place it in the center, resize it if too big
    if ((w > image_w) && (h > image_h))
    {
        wxPoint offset((w - image_w)/2, (h - image_h)/2);
        hotSpotX = hotSpotX + offset.x;
        hotSpotY = hotSpotY + offset.y;

        image16 = image.Size(wxSize(w, h), offset);
    }
    else if ((w != image_w) || (h != image_h))
    {
        hotSpotX = int(hotSpotX * double(w) / double(image_w));
        hotSpotY = int(hotSpotY * double(h) / double(image_h));

        image16 = image.Scale(w, h);
    }

    unsigned char * rgbBits = image16.GetData();
    bool bHasMask = image16.HasMask() ;

#if 0
    // monochrome implementation
    M_CURSORDATA->m_hCursor = NewHandle( sizeof( Cursor ) ) ;
    M_CURSORDATA->m_disposeHandle = true ;
    HLock( (Handle) M_CURSORDATA->m_hCursor ) ;
    CursPtr cp = *(CursHandle)M_CURSORDATA->m_hCursor ;
    memset( cp->data , 0 , sizeof( Bits16 ) ) ;
    memset( cp->mask , 0 , sizeof( Bits16 ) ) ;

    unsigned char mr = image16.GetMaskRed() ;
    unsigned char mg = image16.GetMaskGreen() ;
    unsigned char mb = image16.GetMaskBlue() ;
    for ( int y = 0 ; y < h ; ++y )
    {
        short rowbits = 0 ;
        short maskbits = 0 ;

        for ( int x = 0 ; x < w ; ++x )
        {
            long pos = (y * w + x) * 3;

            unsigned char r = rgbBits[pos] ;
            unsigned char g = rgbBits[pos+1] ;
            unsigned char b = rgbBits[pos+2] ;
            if ( bHasMask && r==mr && g==mg && b==mb )
            {
                // masked area, does not appear anywhere
            }
            else
            {
                if ( (int)r + (int)g + (int)b < 0x0200 )
                {
                    rowbits |= ( 1 << (15-x) ) ;
                }
                maskbits |= ( 1 << (15-x) ) ;
            }
        }
        cp->data[y] = rowbits ;
        cp->mask[y] = maskbits ;
    }
    if ( !bHasMask )
    {
        memcpy( cp->mask , cp->data , sizeof( Bits16) ) ;
    }
    cp->hotSpot.h = hotSpotX ;
    cp->hotSpot.v = hotSpotY ;
    HUnlock( (Handle) M_CURSORDATA->m_hCursor ) ;
#else
    PixMapHandle pm = (PixMapHandle) NewHandleClear( sizeof (PixMap))  ;
    short extent = 16 ;
    short bytesPerPixel = 1 ;
    short depth = 8 ;
    Rect bounds = { 0 , 0 , extent , extent } ;
    CCrsrHandle ch = (CCrsrHandle) NewHandleClear ( sizeof( CCrsr ) ) ;
    CTabHandle newColors = GetCTable( 8 ) ;
    HandToHand((Handle *) &newColors);
    // set the values to the indices
    for ( int i = 0 ; i < (**newColors).ctSize ; ++i )
    {
        (**newColors).ctTable[i].value = i ;
    }
    HLock( (Handle) ch) ;
    (**ch).crsrType = 0x8001 ; // color cursors
    (**ch).crsrMap = pm ;
    short bytesPerRow = bytesPerPixel * extent ;

    (**pm).baseAddr = 0;
    (**pm).rowBytes = bytesPerRow | 0x8000;
    (**pm).bounds = bounds;
    (**pm).pmVersion = 0;
    (**pm).packType = 0;
    (**pm).packSize = 0;
    (**pm).hRes = 0x00480000; /* 72 DPI default res */
    (**pm).vRes = 0x00480000; /* 72 DPI default res */
    (**pm).pixelSize = depth;
    (**pm).pixelType = 0;
    (**pm).cmpCount = 1;
    (**pm).cmpSize = depth;
    (**pm).pmTable = newColors;

    (**ch).crsrData = NewHandleClear( extent * bytesPerRow ) ;
    (**ch).crsrXData = NULL ;
    (**ch).crsrXValid = 0;
    (**ch).crsrXHandle = NULL;

    (**ch).crsrHotSpot.h = hotSpotX ;
    (**ch).crsrHotSpot.v = hotSpotY ;
    (**ch).crsrXTable = NULL ;
    (**ch).crsrID = GetCTSeed() ;

    memset( (**ch).crsr1Data  , 0 , sizeof( Bits16 ) ) ;
    memset( (**ch).crsrMask , 0 , sizeof( Bits16 ) ) ;

    unsigned char mr = image16.GetMaskRed() ;
    unsigned char mg = image16.GetMaskGreen() ;
    unsigned char mb = image16.GetMaskBlue() ;
    for ( int y = 0 ; y < h ; ++y )
    {
        short rowbits = 0 ;
        short maskbits = 0 ;

        for ( int x = 0 ; x < w ; ++x )
        {
            long pos = (y * w + x) * 3;

            unsigned char r = rgbBits[pos] ;
            unsigned char g = rgbBits[pos+1] ;
            unsigned char b = rgbBits[pos+2] ;
            RGBColor col = { 0xFFFF ,0xFFFF, 0xFFFF } ;

            if ( bHasMask && r==mr && g==mg && b==mb )
            {
                // masked area, does not appear anywhere
            }
            else
            {
                if ( (int)r + (int)g + (int)b < 0x0200 )
                {
                    rowbits |= ( 1 << (15-x) ) ;
                }
                maskbits |= ( 1 << (15-x) ) ;

                col = *((RGBColor*) wxColor( r , g , b ).GetPixel()) ;
            }
            *((*(**ch).crsrData) + y * bytesPerRow + x) =
                GetCTabIndex( newColors , &col) ;
        }
        (**ch).crsr1Data[y] = rowbits ;
        (**ch).crsrMask[y] = maskbits ;
    }
    if ( !bHasMask )
    {
        memcpy( (**ch).crsrMask , (**ch).crsr1Data , sizeof( Bits16) ) ;
    }

    HUnlock((Handle) ch) ;
    M_CURSORDATA->m_hCursor = ch ;
    M_CURSORDATA->m_isColorCursor = true ;
#endif
}
void createOffscreen()
{
	Rect		rect;
	Handle		iclHandle;
	char		*image;
	int			row, col, index, value;
	
	
	SetRect( &rect, 0, 0, 32, 32 );
	
	/* Create offscreen pixmap image using an 'icl8' icon resource. */

	iclHandle = GetResource( 'icl8', 129 );
    HandToHand( &iclHandle );
    HLock( iclHandle );
	HNoPurge( iclHandle );
	
	//gPixmap = (PixMapHandle)NewHandle( sizeof( PixMap ) );
	gPixmap = NewPixMap();
	
	(**gPixmap).baseAddr = *iclHandle;
	(**gPixmap).rowBytes = ((32 * 8) / 8) | 0x8000;
	(**gPixmap).bounds = rect;
	(**gPixmap).pmVersion = 0;
	(**gPixmap).packType = 0;
	(**gPixmap).packSize = 0;
	(**gPixmap).hRes = 72;
	(**gPixmap).vRes = 72;
	(**gPixmap).pixelSize = 8;
	//(**gPixmap).planeBytes = 0;
	//(**gPixmap).pmReserved = 0;
	(**gPixmap).pixelType = 0;
	(**gPixmap).cmpCount = 1;
	(**gPixmap).cmpSize = 8;
	(**gPixmap).pmTable = GetCTable( 8 );
	(**gPixmap).pixelFormat = 0;
	
	/* Give a unique seed for the pixmap's colortable. */
	(**(**gPixmap).pmTable).ctSeed = GetCTSeed();
	
	SetRect( &rect, 0, 0, 20, 20 );
	
	/* Set the pointer to the beginning of the pixel image. */
	image = GetPixBaseAddr( gPixmap );
	
	/*****************************************************************/
	/* For this example, let's set the pixel values of the left half */
	/*   of the image to half their original values.				 */
	/*****************************************************************/
	
	for (row = 0; row < rect.bottom; row++)
	{
		// Loop through the first 10 columns of the pixel image. 
		for (index = 0, col = 0; col < rect.right / 2; col++)
		{
			// Set the value at this index to half its value. 
			value = (unsigned char)*(image + index);
			*(image + index) = value / 2;
			
			index++;
		}
		
		// Increment the pointer to the next row of the pixel image. 
		image += ((**gPixmap).rowBytes & 0x7fff);
	}

}
void init()
{
	RgnHandle			tempRgn;
	Rect				BaseRect;
	OSErr				err;
	long				QDfeature/*, OSfeature*/;
	GDHandle			SaveGD;
	CGrafPtr			SavePort;

	/*	Initialize Managaer.	*/
	//InitGraf(&qd.thePort);
	//InitWindows();
	//InitDialogs(nil);
	InitCursor();
	FlushEvents(everyEvent, 0);
	
	/*	Set up menus.	*/
	mymenu0 = GetMenu(appleID);
	//AppendResMenu(mymenu0, 'DRVR');
	InsertMenu(mymenu0,0);
	mymenu1 = GetMenu(fileID);
	InsertMenu(mymenu1,0);
	DrawMenuBar();
	DoneFlag = false;
	ThePict = GetPicture(PictID);
	if (ThePict == nil)
		DoneFlag = true;

	/*	Use Gestalt to find is QuickDraw is avaiable.	*/
	/*if ((GetOSTrapAddress(Gestalttest) != GetOSTrapAddress(NoTrap))) {
		err = Gestalt(gestaltQuickdrawVersion, &QDfeature);
		if (err)
			DoneFlag = true;
		err = Gestalt(gestaltSystemVersion, &OSfeature);
		if (err)
			DoneFlag = true;
		if (!DoneFlag && (QDfeature & 0x0f00) != 0x0200 && OSfeature < 0x0605)
			DoneFlag = true;
		}
	else
		DoneFlag = true;*/
	
	err = Gestalt(gestaltQuickdrawVersion, &QDfeature);
	if (err != noErr || QDfeature < gestalt32BitQD)
		DoneFlag = true;

	/*	Set Rects.	*/
	SetRect(&BaseRect, 40, 60, 472, 282);
	SetRect(&WinMinusScroll, BaseRect.left-40, BaseRect.top-60, BaseRect.right-60, 
				BaseRect.bottom - 80);
	SetRect(&InitWindowSize, WinMinusScroll.left, WinMinusScroll.top, 
							WinMinusScroll.right, WinMinusScroll.bottom);
	tempRgn = GetGrayRgn();
	HLock ((Handle) tempRgn);
	//TotalRect = (**tempRgn).rgnBBox;
	GetRegionBounds(tempRgn, &TotalRect);
	/*SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40, 
				(**tempRgn).rgnBBox.bottom - 40);*/
	SetRect(&minRect, 80, 80, TotalRect.right - 40, TotalRect.bottom - 40);
	HUnlock ((Handle) tempRgn);

	/*	Open window and set up picture.	*/
	GetGWorld (&SavePort, &SaveGD);
	mycolors = GetCTable (clutID);
	(*mycolors)->ctFlags |= 0x4000;

	myWindow = NewCWindow(nil, &BaseRect, (ConstStr255Param)"", true, zoomDocProc, 
							(WindowPtr) -1, true, 150);
	SetGWorld(GetWindowPort(myWindow), SaveGD);
	DrawGrowIcon (myWindow);

	srcPalette = NewPalette (((**mycolors).ctSize)+1, mycolors,
			pmTolerant + pmExplicit + pmAnimated, 0);
	SetPalette ((WindowPtr) myWindow, srcPalette, true);
	
	GetGWorld (&SavePort, &SaveGD);
	err = NewGWorld (&offscreenGWorld, 8, &InitWindowSize, mycolors, nil, 0);
	if (err)
		Debugger();
	SetGWorld (offscreenGWorld, nil);
	EraseRect (&InitWindowSize);
	DrawPicture (ThePict, &InitWindowSize);
	SetGWorld (SavePort, SaveGD);
}