コード例 #1
0
ファイル: MacIcons.cpp プロジェクト: prestocore/browser
OpBitmap* CreateOpBitmapFromIcon(IconRef iconin, int cx, int cy)
{
	if (iconin)
	{
		OpBitmap* bm;
		if (OpStatus::IsSuccess(OpBitmap::Create(&bm, cx, cy, FALSE, TRUE, 0, 0, TRUE)))
		{
			CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
			void* p = bm->GetPointer(OpBitmap::ACCESS_WRITEONLY);
			memset(p, 0, bm->Height()*bm->GetBytesPerLine());
			CGBitmapInfo alpha = kCGBitmapByteOrderVegaInternal;
			CGContextRef ctx = 	CGBitmapContextCreate(p, bm->Width(), bm->Height(), 8, bm->GetBytesPerLine(), colorSpace, alpha);
			CGColorSpaceRelease(colorSpace);
			CGRect cgrect = CGRectMake(0,0,cx,cy);
			PlotIconRefInContext(ctx, &cgrect, kAlignAbsoluteCenter, kTransformNone, NULL, kPlotIconRefNormalFlags, iconin);
			CGContextFlush(ctx);
			CGContextRelease(ctx);
			bm->ReleasePointer();
			return bm;
		}
	}
	return NULL;
}
コード例 #2
0
ファイル: mac-gworld.cpp プロジェクト: 7sevenx7/snes9x
void CreateIconImages (void)
{
	CGDataProviderRef	prov;
	CGImageRef			image;
	CFURLRef			url;

	image = NULL;
	memset(macIconImage, 0, sizeof(macIconImage));
#ifdef MAC_PANTHER_SUPPORT
	if (systemVersion < 0x1040)
		memset(macIconRef, 0, sizeof(macIconRef));
#endif

	url = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("icons"),  CFSTR("png"), NULL);
	if (url)
	{
		prov = CGDataProviderCreateWithURL(url);
		if (prov)
		{
			image = CGImageCreateWithPNGDataProvider(prov, NULL, true, kCGRenderingIntentDefault);
			CGDataProviderRelease(prov);
		}

		CFRelease(url);
	}

	if (image)
	{
		int	x, y, v = 0, n = 0;

		macPadIconIndex = n;
		for (y = 0; y < 8; y++)
		{
			for (x = 0; x < 12; x++)
				SetIconImage(image, CGRectMake(x * kIconSize, v, kIconSize, kIconSize), n++);
			v += kIconSize;
		}

		macLegendIconIndex = n;
		for (x = 0; x < 2; x++)
			SetIconImage(image, CGRectMake(x * kIconSize, v, kIconSize, kIconSize), n++);
		v += kIconSize;

		macMusicBoxIconIndex = n;
		for (x = 0; x < 3; x++)
			SetIconImage(image, CGRectMake(x * kIconSize, v, kIconSize, kIconSize), n++);
		v += kIconSize;

		macFunctionIconIndex = n;
		for (x = 0; x < 17; x++)
			SetIconImage(image, CGRectMake(x * kIconSize, v, kIconSize, kIconSize), n++);

		CGImageRelease(image);
		
	#ifdef MAC_PANTHER_SUPPORT
		if (systemVersion < 0x1040)
		{
			CGColorSpaceRef		color;
			CGContextRef		ctx;
			CGRect				rct;
			static UInt32		data[2][kIconSize * kIconSize];

			rct = CGRectMake(0, 0, kIconSize, kIconSize);

			color = CGColorSpaceCreateDeviceRGB();
			if (color)
			{
				for (int i = 0; i < 2; i++)
				{
					ctx = CGBitmapContextCreate(data[i], kIconSize, kIconSize, 8, kIconSize * 4, color, kCGImageAlphaNoneSkipFirst);
					if (ctx)
					{
						PlotIconRefInContext(ctx, &rct, kAlignNone, kTransformNone, NULL, kPlotIconRefNormalFlags, macIconRef[macLegendIconIndex + i]);
						CGContextRelease(ctx);

						prov = CGDataProviderCreateWithData(NULL, data[i], kIconSize * kIconSize * 4, NULL);
						if (prov)
						{
							macIconImage[macLegendIconIndex + i] = CGImageCreate(kIconSize, kIconSize, 8, 32, kIconSize * 4, color, kCGImageAlphaNoneSkipFirst, prov, NULL, 1, kCGRenderingIntentDefault);
							CGDataProviderRelease(prov);
						}
					}
				}

				CGColorSpaceRelease(color);
			}
		}
	#endif
	}
}
コード例 #3
0
// --------------------------------------------------------------------------------------
pascal void DrawIconDataBrowserItem104CB(ControlRef browser, DataBrowserItemID item, 
											DataBrowserPropertyID property, 
											DataBrowserItemState itemState, 
											const Rect *theRect, SInt16 gdDepth, 
											Boolean colorDevice)
{
#pragma unused (theRect, gdDepth, colorDevice)
	Rect enclosingRect, portBounds;
	GrafPtr port;
	CGRect enclosingCGRect, iconCGRect, textCGRect;
	Boolean active;
	CGContextRef context;
	IconDBItemDataRec *itemData;
	RGBColor labelColor;
	HIThemeTextInfo textInfo;
	
		/* The data browser currently gives us the content part bounds in the theRect 
		   parameter but we want the enclosing part bounds to draw in so that we can 
		   draw a fill style highlight. */
	GetDataBrowserItemPartBounds(browser, item, property, kDataBrowserPropertyEnclosingPart, 
									&enclosingRect);
	
		/* In Mac OS X we're going to use Quartz 2D/Core Graphics for the drawing, so we 
		   need to convert the enclosing part bounds to a CGRect */
	GetPort(&port);		// the data browser sets the port up for us so we just need to get it
	GetPortBounds(port, &portBounds);
	enclosingCGRect = CGRectMake(enclosingRect.left, 
									portBounds.bottom - portBounds.top - 
									enclosingRect.bottom, 
									enclosingRect.right - enclosingRect.left, 
									enclosingRect.bottom - enclosingRect.top);
	calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect);
	
	active = IsControlActive(browser);
	
	if ((itemState & kDataBrowserItemIsSelected) != 0)
	{
		CGRect clipRect;
		
		clipRect = getClipCGRect(&portBounds);	// call this before beginning the context
		
		QDBeginCGContext(port, &context);
		CGContextClipToRect(context, clipRect);
		CGContextSaveGState(context);
		
		HIThemeSetFill(active ? kThemeBrushPrimaryHighlightColor : kThemeBrushSecondaryHighlightColor, 
						NULL, context, kHIThemeOrientationInverted);
		CGContextFillRect(context, enclosingCGRect);
		
		CGContextRestoreGState(context);
	}
	else
	{
			/* The data browser will redraw items on the edge of its content view.  
			   Because HIThemeDrawTextBox does not erase the drawing rectangle before 
			   it draws, the text becomes thicker with every draw due to anti-aliasing.  
			   As a workaround, this section erases the text rectangle (if the item was 
			   selected then the enclosing rectangle was erased above). */
		CGRect clipRect;
		RGBColor backgroundColor;
		
		clipRect = getClipCGRect(&portBounds);	// call these before beginning the context
		GetBackColor(&backgroundColor);
		
		QDBeginCGContext(port, &context);
		CGContextClipToRect(context, clipRect);
		CGContextSaveGState(context);
		
		CGContextSetRGBFillColor(context, (float)backgroundColor.red / (float)USHRT_MAX, 
									(float)backgroundColor.green / (float)USHRT_MAX, 
									(float)backgroundColor.blue / (float)USHRT_MAX, 1.0);
		CGContextFillRect(context, textCGRect);
		
		CGContextRestoreGState(context);
	}
	
	itemData = (IconDBItemDataRec *)item;
	
	labelColor.red = 0;
	labelColor.green = 0;
	labelColor.blue = 0;
	PlotIconRefInContext(context, &iconCGRect, kAlignNone, 
							active ? kTransformNone : kTransformDisabled, &labelColor, 
							kPlotIconRefNormalFlags, itemData->icon);
	
	textInfo.version = kHIThemeTextInfoVersionZero;
	textInfo.state = active ? kThemeStateActive : kThemeStateInactive;
	textInfo.fontID = kThemeViewsFont;
	textInfo.horizontalFlushness = kHIThemeTextHorizontalFlushCenter;
	textInfo.verticalFlushness = kHIThemeTextVerticalFlushTop;
	textInfo.options = kHIThemeTextBoxOptionNone;
	textInfo.truncationPosition = kHIThemeTextTruncationNone;
	HIThemeDrawTextBox(itemData->name, &textCGRect, &textInfo, context, 
						kHIThemeOrientationInverted);
	
	QDEndCGContext(port, &context);
} // DrawIconDataBrowserItem104CB
コード例 #4
0
// --------------------------------------------------------------------------------------
pascal void DrawIconDataBrowserItem101CB(ControlRef browser, DataBrowserItemID item, 
											DataBrowserPropertyID property, 
											DataBrowserItemState itemState, 
											const Rect *theRect, SInt16 gdDepth, 
											Boolean colorDevice)
{
#pragma unused (theRect)
	Rect enclosingRect, portBounds, iconRect, textRect;
	GrafPtr port;
	CGRect enclosingCGRect, iconCGRect, textCGRect;
	Boolean active;
	ThemeDrawingState savedState = NULL;
	CGContextRef context;
	IconDBItemDataRec *itemData;
	RGBColor labelColor;
	
		/* The data browser currently gives us the content part bounds in the theRect 
		   parameter but we want the enclosing part bounds to draw in so that we can 
		   draw a fill style highlight. */
	GetDataBrowserItemPartBounds(browser, item, property, kDataBrowserPropertyEnclosingPart, 
									&enclosingRect);
	
		/* In Mac OS X we're going to use Quartz 2D/Core Graphics for the drawing, so we 
		   need to convert the enclosing part bounds to a CGRect */
	GetPort(&port);		// the data browser sets the port up for us so we just need to get it
	GetPortBounds(port, &portBounds);
	enclosingCGRect = CGRectMake(enclosingRect.left, 
									portBounds.bottom - portBounds.top - 
									enclosingRect.bottom, 
									enclosingRect.right - enclosingRect.left, 
									enclosingRect.bottom - enclosingRect.top);
	
	active = IsControlActive(browser);
	
	if ((itemState & kDataBrowserItemIsSelected) != 0)
	{
		CGRect clipRect;
		RGBColor foregroundColor;
		
		GetThemeDrawingState(&savedState);
		
		SetThemePen(active ? kThemeBrushPrimaryHighlightColor : kThemeBrushSecondaryHighlightColor, 
					gdDepth, colorDevice);

		clipRect = getClipCGRect(&portBounds);	// call these before beginning the context
		GetForeColor(&foregroundColor);
		
		QDBeginCGContext(port, &context);
		CGContextClipToRect(context, clipRect);
		CGContextSaveGState(context);
		
		CGContextSetRGBFillColor(context, (float)foregroundColor.red / (float)USHRT_MAX, 
									(float)foregroundColor.green / (float)USHRT_MAX, 
									(float)foregroundColor.blue / (float)USHRT_MAX, 1.0);
		CGContextFillRect(context, enclosingCGRect);
		
		CGContextRestoreGState(context);
	}
	else
	{
		CGRect clipRect;
		
		clipRect = getClipCGRect(&portBounds);	// call this before beginning the context
		
		QDBeginCGContext(port, &context);
		CGContextClipToRect(context, clipRect);
	}

	calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect);
		/* DrawThemeTextBox wants the bounding rectangle to be QuickDraw coordinates 
		   relative to the current port, not Core Graphics coordinates relative to the 
		   passed context. */
	calculateDrawingBounds(&enclosingRect, &iconRect, &textRect);
	itemData = (IconDBItemDataRec *)item;
	
	labelColor.red = 0;
	labelColor.green = 0;
	labelColor.blue = 0;
	PlotIconRefInContext(context, &iconCGRect, kAlignNone, 
							active ? kTransformNone : kTransformDisabled, &labelColor, 
							kPlotIconRefNormalFlags, itemData->icon);
	
	DrawThemeTextBox(itemData->name, kThemeViewsFont, 
						active ? kThemeStateActive : kThemeStateInactive, true, 
						&textRect, teCenter, context);
	
	QDEndCGContext(port, &context);
	if (savedState != NULL)
		SetThemeDrawingState(savedState, true);
} // DrawIconDataBrowserItem101CB