Пример #1
0
/* draw image to frame */
static void icvDrawImage( CvWindow* window )
{
    Assert( window != 0 );
    if( window->imageRef == 0 ) return;
    
    CGContextRef myContext;
    CvTrackbar* t; 
    CGRect rect;
    Rect portrect;
    int width = window->imageWidth;
    int height = window->imageHeight;
    
        GetWindowPortBounds(window->window, &portrect);
    
    if( window->flags & CV_WINDOW_AUTOSIZE ) 
	{ 
        CGPoint origin = {0,0}; 
        CGSize size = {portrect.right-portrect.left, portrect.bottom-portrect.top-window->trackbarheight};
        rect.origin = origin; rect.size = size;
    } 
	else 
	{
        CGPoint origin = {0, portrect.bottom - height - window->trackbarheight};
        CGSize size = {width, height};
        rect.origin = origin; rect.size = size;
    }
    
    /* To be sybnchronous we are using this, better would be to susbcribe to the draw event and process whenever requested, we might save SOME CPU cycles*/
    SetPortWindowPort (window->window);
    QDBeginCGContext (GetWindowPort (window->window), &myContext);
    CGContextSetInterpolationQuality (myContext, kCGInterpolationLow); 
    CGContextDrawImage(myContext,rect,window->imageRef);
    CGContextFlush(myContext);// 4
    QDEndCGContext (GetWindowPort(window->window), &myContext);// 5
}
Пример #2
0
void wxOverlayImpl::Init( wxWindowDC* dc, int x , int y , int width , int height )
{
    wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );

    m_window = dc->GetWindow();
    m_x = x ;
    m_y = y ;
    if ( dc->IsKindOf( CLASSINFO( wxClientDC ) ))
    {
        wxPoint origin = m_window->GetClientAreaOrigin();
        m_x += origin.x;
        m_y += origin.y;
    }
    m_width = width ;
    m_height = height ;

    OSStatus err = CreateOverlayWindow();
    wxASSERT_MSG(  err == noErr , _("Couldn't create the overlay window") );
#ifndef __LP64__
    err = QDBeginCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
#endif
    CGContextTranslateCTM( m_overlayContext, 0, m_height );
    CGContextScaleCTM( m_overlayContext, 1, -1 );
    CGContextTranslateCTM( m_overlayContext, -m_x , -m_y );
    wxASSERT_MSG(  err == noErr , _("Couldn't init the context on the overlay window") );
}
Пример #3
0
int createWindowWidthheightoriginXyattrlength(int w,int h,int x,int y,  char * list, int listLength) {
	int index;
	long windowClass,windowAttributes;
	WindowPtr window;
	windowDescriptorBlock *windowBlock;
	if (listLength != 8) return -1;
	
	memmove(&windowClass, list, 4);
	memmove(&windowAttributes, list+4, 4);

	window = SetUpWindow(y,x,y+h,x+w,windowClass,windowAttributes);
	if (window == 0) return -1;
	
	windowBlock = AddWindowBlock();
	windowBlock->handle = (wHandleType) window;
	
	index = windowBlock->windowIndex;
	windowBlock->isInvisible = !MacIsWindowVisible(window);
	SetUpCarbonEventForWindowIndex(index);
	QDBeginCGContext(GetWindowPort(windowBlock->handle),&windowBlock->context); 
//	CreateCGContextForPort(GetWindowPort(windowBlock->handle),&windowBlock->context); 
	windowBlock->width = w;
	windowBlock->height = h; 
	
	sqShowWindow(index);
	return index;
}
Пример #4
0
bool QuartzWindow::pre_draw(bool incremental) {
  if ( get_graphics_semaphore())  return false;
  if (!_is_open) return false;
  if (_was_closed) {
    TheSpy->deactivate();
    _was_closed = false;
    return false;
  }
  if ( myContext == NULL ) {
    // Self does this for Self windows, so only do it for Spy windows--that's why it's here and not in open
    SetPortWindowPort(my_window());
    QDBeginCGContext( GetWindowPort(my_window()), &myContext);
    setupCTM();
    CGContextSetTextMatrix(myContext, CGAffineTransformMake( 1, 0, 0, -1, 0, 0));
    CGContextSelectFont(myContext, 
      default_fixed_font_name(), default_fixed_font_size(), kCGEncodingMacRoman);
    CGContextSetShouldAntialias(myContext, false);
    
    EventTypeSpec es[] = { 
      {kEventClassWindow, kEventWindowBoundsChanged},
      {kEventClassWindow, kEventWindowClose}
    };
    OSStatus e = AddEventTypesToHandler(_my_spy_event_handler,  sizeof(es) / sizeof(es[0]),  es);
    if (e != noErr) fatal1("could not add types to handler %d\n", e);
  }
  if (_bounds_changed) {
    _bounds_changed = false;
    adjust_after_resize();
  }
  if (!incremental) {
    Rect r;  get_window_region_rect( kWindowContentRgn, &r);
    clear_rectangle(0, 0, r.right - r.left, r.bottom - r.top);
  }
  return true;
}
Пример #5
0
static pascal OSStatus EventWindowDrawContent(EventHandlerCallRef callRef, EventRef event, void *userData)
{ // this stuff requires OSX 10.4
	CGContextRef cgc;
    QDBeginCGContext(GetWindowPort(win),&cgc);
	CGImageRef cgi=CGBitmapContextCreateImage(specdc);
    CGRect cr=CGRectMake(0,0,SPECWIDTH,SPECHEIGHT);
	CGContextDrawImage(cgc,cr,cgi);
    CGImageRelease(cgi);
    QDEndCGContext(GetWindowPort(win),&cgc);
	return noErr;
}
void DrawUsingCGImage( void )
{
	OSErr  err = noErr;
	Handle hOpenTypeList = NewHandle(0);
	long   numTypes = 0;
	FSSpec theFSSpec;
	Rect   bounds = { 45, 10, 100, 100 };
	GraphicsImportComponent importer = 0;
    CGImageRef imageRef = 0;
    CGContextRef context = NULL;
    CGRect rect;
	
	BuildGraphicsImporterValidFileTypes( hOpenTypeList, &numTypes );
	HLock( hOpenTypeList );

	err = GetOneFileWithPreview(numTypes, (OSTypePtr)*hOpenTypeList, &theFSSpec, NULL);
	DisposeHandle( hOpenTypeList );
	if ( err ) return;
	
	// locate and open a graphics importer component which can be used to draw the
	// selected file. If a suitable importer is not found the ComponentInstance
	// is set to NULL.
	err = GetGraphicsImporterForFile( &theFSSpec,	// specifies the file to be drawn
									  &importer );	// pointer to the returned GraphicsImporterComponent
                                      
	window = NewCWindow( NULL, &bounds, "\pDraw Using CGImage", false, documentProc, (WindowPtr)-1, true, 0);
    
    // import the image as a CGImage
    err = GraphicsImportCreateCGImage( importer, &imageRef, kGraphicsImportCreateCGImageUsingCurrentSettings );
    if (err) return;
    
    SizeWindow( window, CGImageGetWidth( imageRef ), CGImageGetHeight( imageRef ), false );
    ShowWindow(window);
    
    // create a Core Graphics Context from the window port
	err = QDBeginCGContext(GetWindowPort(window), &context);
	if (err) return;

    // make a rectangle designating the location and dimensions in user space of the bounding box in which to draw the image
    rect = CGRectMake( 0, 0, CGImageGetWidth( imageRef ), CGImageGetHeight( imageRef ) );
    
    // draw the image
    CGContextDrawImage( context, rect, imageRef );
    
    // end the the context we had for the port
	QDEndCGContext(GetWindowPort(window), &context);
	
	// close the importer instance
	CloseComponent( importer );
}
Пример #7
0
static void
flushproc(void *a)
{
	for(;;) {
		if(needflush) {
			drawqlock();
			QDBeginCGContext(GetWindowPort(theWindow), &context);
			CGContextFlush(context);
			QDEndCGContext(GetWindowPort(theWindow), &context);
			needflush = false;
			drawqunlock();
		}
		usleep(33333);
	}
}
Пример #8
0
void MacVegaPrinterListener::SetGraphicsContext(CGrafPtr port)
{
#ifndef SIXTY_FOUR_BIT
	if (m_port) {
		CGContextRestoreGState(m_ctx);
		QDEndCGContext(m_port, &m_ctx);
	}
	m_port = port;
	m_ctx = NULL;
	if (m_port) {
		Rect bounds;
		GetPortBounds(m_port, &bounds);
		m_winHeight = bounds.bottom-bounds.top;
		QDBeginCGContext(m_port, &m_ctx);
		SetColor(0,0,0,255);
		CGContextSaveGState(m_ctx);
	}
#endif
}
Пример #9
0
void QMacWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset)
{
    Q_UNUSED(offset);

    // Get a context for the widget.
#ifndef QT_MAC_USE_COCOA
    CGContextRef context;
    CGrafPtr port = GetWindowPort(qt_mac_window_for(widget));
    QDBeginCGContext(port, &context);
#else
    extern CGContextRef qt_mac_graphicsContextFor(QWidget *);
    CGContextRef context = qt_mac_graphicsContextFor(widget);
#endif
    CGContextRetain(context);
    CGContextSaveGState(context);

    // Flip context.
    CGContextTranslateCTM(context, 0, widget->height());
    CGContextScaleCTM(context, 1, -1);

    // Clip to region.
    const QVector<QRect> &rects = rgn.rects();
    for (int i = 0; i < rects.size(); ++i) {
        const QRect &rect = rects.at(i);
        CGContextAddRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()));
    }
    CGContextClip(context);

    // Draw the image onto the window.
    const CGRect dest = CGRectMake(0, 0, widget->width(), widget->height());
    const CGImageRef image = d_ptr->device.toMacCGImageRef();
    qt_mac_drawCGImage(context, &dest, image);
    CFRelease(image);

    // Restore context.
    CGContextRestoreGState(context);
#ifndef QT_MAC_USE_COCOA
    QDEndCGContext(port, &context);
#else
    CGContextFlush(context);
#endif
    CGContextRelease(context);
}
Пример #10
0
static	pascal	OSStatus OverlayWindowEventHandlerProc( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
{
	#pragma unused( inCallRef )
	Rect				windowRect;
	CGRect				box;
	CGContextRef		cgContext;
	UInt32				eventKind		= GetEventKind( inEvent );
	UInt32				eventClass		= GetEventClass( inEvent );
	OSStatus			err				= eventNotHandledErr;
	WindowStorage		*windowStorage	= (WindowStorage*) inUserData;

	switch ( eventClass )
	{
		case kEventClassWindow:
			if ( eventKind == kEventWindowClose )
			{
				windowStorage->overlayWindow = NULL;		//	Let the default handler DisposeWindow() for us, just set our WindowRef to NULL
			}
			else if ( (eventKind == kEventWindowBoundsChanged) || (eventKind == kEventWindowShown) )	//	Draw the overlay window
			{
				GetWindowPortBounds( windowStorage->overlayWindow, &windowRect );
				//box.origin.x	= box.origin.y	= 0;
				//box.size.width	= windowRect.right - windowRect.left;
				//box.size.height	= windowRect.bottom - windowRect.top;
				box	= CGRectMake( 0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top );
				
				QDBeginCGContext( GetWindowPort(windowStorage->overlayWindow), &cgContext );
				CGContextClearRect( cgContext, box );
				
				//	Paint a semi-transparent box in the middle of our window
				box.origin.x	= (windowRect.right - windowRect.left) / 4;
				box.size.width	= (windowRect.right - windowRect.left) / 2;
				CGContextSetRGBFillColor( cgContext, 0.5, 0.75, 0.75, 0.2 );
				CGContextFillRect( cgContext, box );
				
				CGContextFlush( cgContext );
				QDEndCGContext( GetWindowPort(windowStorage->overlayWindow), &cgContext );
			}
			break;
	}
	return( err );
}
Пример #11
0
// This example is almost identical to the helloworld example, except that
// in this case, there are two styles instead of just one. ATSUSetRunStyle
// is used to apply a style to different parts of the text.
//
void DrawMultipleStylesContents(WindowRef window)
{
	CFStringRef					string;
	UniChar						*text;
	UniCharCount				length;
    UniCharArrayOffset			currentStart, currentEnd;
	ATSUStyle					style1, style2;
	ATSUTextLayout				layout;
	ATSUFontID					font;
	Fixed						pointSize;
    ATSUAttributeTag			tags[2];
    ByteCount					sizes[2];
    ATSUAttributeValuePtr		values[2];
	Fixed						lineWidth, ascent, descent;
	CGContextRef				cgContext;
	float						x, y, cgY, windowHeight;
    ItemCount					numSoftBreaks;
    UniCharArrayOffset			*theSoftBreaks;
    int							i;
    GrafPtr						port, savedPort;
	Rect						portBounds;

    // Set up the graphics port
	port = GetWindowPort(window);
    GetPort(&savedPort);
    SetPort(port);
    GetPortBounds(port, &portBounds);
    EraseRect(&portBounds);

	// Create a style object. This is one of two objects necessary to draw using ATSUI.
	// (The layout is the other.)
	verify_noerr( ATSUCreateStyle(&style1) );

    // Look up the font we are going to use, and set it in the style object, using
	// the aforementioned "triple" (tag, size, value) semantics. This is how almost
	// all settings in ATSUI are applied.
	verify_noerr( ATSUFindFontFromName(kMultipleStylesFontName, strlen(kMultipleStylesFontName), kFontFullName, kFontNoPlatform, kFontNoScript, kFontNoLanguage, &font) );
    tags[0] = kATSUFontTag;
    sizes[0] = sizeof(ATSUFontID);
    values[0] = &font;
    verify_noerr( ATSUSetAttributes(style1, 1, tags, sizes, values) );

    // Set the point size, also using a triple. You can actually set multiple triples at once,
	// since the tag, size, and value parameters are arrays. Other examples do this, such as
	// the vertical text example.
	// 
	pointSize = Long2Fix(kMultipleStylesFontSize);
	tags[0] = kATSUSizeTag;
    sizes[0] = sizeof(Fixed);
    values[0] = &pointSize;
    verify_noerr( ATSUSetAttributes(style1, 1, tags, sizes, values) );
	
	// Now we create the second of two objects necessary to draw text using ATSUI, the layout.
	// You can specify a pointer to the text buffer at layout creation time, or later using
	// the routine ATSUSetTextPointerLocation(). Below, we do it after layout creation time.
	verify_noerr( ATSUCreateTextLayout(&layout) );

	// Before assigning text to the layout, we must first convert the string we plan to draw
	// from a CFStringRef into an array of UniChar.
	string = CFStringCreateWithCString(NULL, "In this example, various parts of the text have different styles applied. The same style is used more than once.", kCFStringEncodingASCII);

    // Extract the raw Unicode from the CFString, then dispose of the CFString
    length = CFStringGetLength(string);
    text = (UniChar *)malloc(length * sizeof(UniChar));
    CFStringGetCharacters(string, CFRangeMake(0, length), text);
	CFRelease(string);

    // Attach the resulting UTF-16 Unicode text to the layout
    verify_noerr( ATSUSetTextPointerLocation(layout, text, kATSUFromTextBeginning, kATSUToTextEnd, length) );
	
	// Now we tie the two necessary objects, the layout and the style, together
	verify_noerr( ATSUSetRunStyle(layout, style1, kATSUFromTextBeginning, kATSUToTextEnd) );

	// Now, for this example we create a second style, and assign it to various runs within
	// the text. For our example, the run offsets are hard-coded for simplicity's sake. In
	// a real application, style runs are often assigned from external sources, such as user
	// selection.
	verify_noerr( ATSUCreateAndCopyStyle(style1, &style2) );

	// Change the font for the second style
	verify_noerr( ATSUFindFontFromName(kMultipleStylesFontName2, strlen(kMultipleStylesFontName2), kFontFullName, kFontNoPlatform, kFontNoScript, kFontNoLanguage, &font) );
    tags[0] = kATSUFontTag;
    sizes[0] = sizeof(ATSUFontID);
    values[0] = &font;
    verify_noerr( ATSUSetAttributes(style2, 1, tags, sizes, values) );

	// Apply the new style to the text in various places
	verify_noerr( ATSUSetRunStyle(layout, style2, 8, 7) ); // The word "example"
	verify_noerr( ATSUSetRunStyle(layout, style2, 65, 7) ); // The word "applied"
	verify_noerr( ATSUSetRunStyle(layout, style2, 83, 5) ); // The word "style"
	verify_noerr( ATSUSetRunStyle(layout, style2, 107, 4) ); // The word "once"

	// In this example, we are breaking text into lines.
	// Therefore, we need to know the width of the line.
    lineWidth = X2Fix(portBounds.right - portBounds.left - 2.0*kMultipleStylesMargin);
    tags[0] = kATSULineWidthTag;
    sizes[0] = sizeof(Fixed);
    values[0] = &lineWidth;
	verify_noerr( ATSUSetLayoutControls(layout, 1, tags, sizes, values) );

	// Prepare the CGContext for drawing
	QDBeginCGContext(port, &cgContext);
	tags[0] = kATSUCGContextTag;
	sizes[0] = sizeof(CGContextRef);
	values[0] = &cgContext;
	verify_noerr( ATSUSetLayoutControls(layout, 1, tags, sizes, values) );
	
	// Prepare the coordinates for drawing. In our example, "x" and "y" are the coordinates
	// in QD space. "cgY" contains the y coordinate in CG space.
	//
	windowHeight = portBounds.bottom - portBounds.top;
	x = kMultipleStylesMargin; // leave a small left margin
	y = kMultipleStylesMargin; // leave a small top margin
	cgY = windowHeight - y; // Subtract the y coordinate from the height of the
							// window to get the coordinate in CG-aware space.

	// Break the text into lines
	verify_noerr( ATSUBatchBreakLines(layout, kATSUFromTextBeginning, length, lineWidth, &numSoftBreaks) );
    verify_noerr( ATSUGetSoftLineBreaks(layout, kATSUFromTextBeginning, kATSUToTextEnd, 0, NULL, &numSoftBreaks) );
    theSoftBreaks = (UniCharArrayOffset *) malloc(numSoftBreaks * sizeof(UniCharArrayOffset));
    verify_noerr( ATSUGetSoftLineBreaks(layout, kATSUFromTextBeginning, kATSUToTextEnd, numSoftBreaks, theSoftBreaks, &numSoftBreaks) );
	
    // Loop over all the lines and draw them
    currentStart = 0;
    for (i=0; i <= numSoftBreaks; i++) {
        currentEnd = ((numSoftBreaks > 0 ) && (numSoftBreaks > i)) ? theSoftBreaks[i] : length;

        // This is the height of a line, the ascent and descent. Getting the values this way is the preferred method.
		ATSUGetLineControl(layout, currentStart, kATSULineAscentTag, sizeof(ATSUTextMeasurement), &ascent, NULL);
        ATSUGetLineControl(layout, currentStart, kATSULineDescentTag, sizeof(ATSUTextMeasurement), &descent, NULL);

        // Make room for the area above the baseline
		y += Fix2X(ascent);
		cgY = windowHeight - y;

		// Draw the text
        verify_noerr( ATSUDrawText(layout, currentStart, currentEnd - currentStart, X2Fix(x), X2Fix(cgY)) );

		// Make room for the area beloww the baseline
        y += Fix2X(descent);
		
		// Prepare for next line
        currentStart = currentEnd;
    }

	// This is a one-shot window, so we are now ready to dispose of all our objects.
	// Normally, we would want to keep everything around in case we needed to redraw or change
	// the text at some point.
	
    // Tear down the CGContext
	CGContextFlush(cgContext);
	QDEndCGContext(port, &cgContext);

	// Deallocate string storage
	free(text);

	// Layout and styles also need to be disposed
	verify_noerr( ATSUDisposeStyle(style1) );
	verify_noerr( ATSUDisposeStyle(style2) );
	verify_noerr( ATSUDisposeTextLayout(layout) );

    // Restore the graphics port
    SetPort(savedPort);
}
Пример #12
0
static
OSStatus RunRoundTripFlatteningSample( 
	WindowRef	windowRef )
{
	OSStatus				err;
	CGrafPtr				windowPort;
	CGContextRef			cgContext;
	Rect					windowRect;
	PixMapHandle			pixMap;
	ATSUTextMeasurement		xPosition;
	ATSUTextMeasurement		yPosition;

	// initialize the global styles 
	err = InitializeGlobalStyles();
	require_noerr( err, RunATSUIFlatteningTest_err );
	
	// get the port for the window
	windowPort = GetWindowPort( windowRef );
	
	// get the port's pixMap. This will be used to find the viewable window area
	pixMap = GetPortPixMap( windowPort );
	
	// get the bounds for the port
	GetPortBounds( windowPort, &windowRect );
	
	// Offset the rect to obtain the window's viewable area
	OffsetRect( &windowRect, -(**pixMap).bounds.left, -(**pixMap).bounds.top );
	
	// calculate the x and y positions
	xPosition = Long2Fix( windowRect.left + kGlobalXOffsetValue );
	yPosition = Long2Fix( windowRect.bottom - kGlobalYSpaceBetweenTests );
	
	// start the cgContext for the port
	err = QDBeginCGContext( windowPort, &cgContext );
	require_noerr( err, RunATSUIFlatteningTest_err );
	
	// add a label to the test
	err = AddTextLabel( "Reference Style\0", cgContext, xPosition, 
		&yPosition );
	require_noerr( err, RunATSUIFlatteningTest_err );
	
	// create the layout for the default run information
	err = DrawLayoutForStyleAndRunInfo( gGlobalStyleArray, kGlobalStyleArraySize,
		gGlobalStyleRunInfoArray, kGlobalStyleRunInfoArraySize, gTestString,
		gTestStringLen, cgContext, xPosition, &yPosition );
	require_noerr( err, RunATSUIFlatteningTest_err );
	
	// add some space to separate the tests
	yPosition -= Long2Fix( kGlobalYSpaceBetweenTests );
	
	// add a label to the test
	err = AddTextLabel( "Flattened And Unflattened Sample\0", cgContext,
		xPosition, &yPosition );
	require_noerr( err, RunATSUIFlatteningTest_err );
	
	// run the default options for this test
	err = RoundTripFlatten( cgContext, xPosition, &yPosition, gGlobalStyleArray,
		kGlobalStyleArraySize, gGlobalStyleRunInfoArray, kGlobalStyleRunInfoArraySize,
		gTestString, gTestStringLen );
	require_noerr( err, RunATSUIFlatteningTest_err );
	
	// kill the cgContext for the port
	err = QDEndCGContext( windowPort, &cgContext );
	require_noerr( err, RunATSUIFlatteningTest_err );
	

RunATSUIFlatteningTest_err:

	return err;

}
Пример #13
0
// Draws the current ATSUI data.  Takes a GrafPtr as an argument so
// that it can handle printing as well as drawing into a window.
//
void DrawATSUIStuff(GrafPtr drawingPort)
{
    GrafPtr                             savedPort;
    Rect                                portBounds, quarterRect2, quarterRect3;
    float								windowHeight, quarter;
    CGContextRef						context;
    TXNTextBoxOptionsData				optionsData;
    Boolean								needToUseCGStrokeMethod;

    // Set up the GrafPort
    GetPort(&savedPort);
    SetPort(drawingPort);
    GetPortBounds(drawingPort, &portBounds);
    EraseRect(&portBounds);

    // Divide the window into vertical quarters, and draw the text in the middle two quarters
    windowHeight = portBounds.bottom - portBounds.top;
    quarter = windowHeight / 4.0;
    MacSetRect(&quarterRect2, portBounds.left, portBounds.top + quarter, portBounds.right, portBounds.bottom - (quarter * 2.0));
    FrameRect(&quarterRect2);
    MacSetRect(&quarterRect3, portBounds.left, portBounds.top + (quarter * 2.0), portBounds.right, portBounds.bottom - quarter);
    FrameRect(&quarterRect3);

    // Set up the CGContext
    if (gNewCG) QDBeginCGContext(drawingPort, &context); else CreateCGContextForPort(drawingPort, &context);

    // Setup the options to pass into TXNDrawUnicodeTextBox
    optionsData.optionTags = kTXNUseCGContextRefMask | kTXNSetFlushnessMask | kTXNUseFontFallBackMask;
    optionsData.flushness = X2Frac(0.5);   // Center the text horizontally, just for this demo.
    optionsData.options = (void *)context; // This parameter really needs to be renamed, see 3198383.

    // Draw the text once without the extr bold
    verify_noerr( TXNDrawUnicodeTextBox(gText, gLength, &quarterRect2, gStyle, &optionsData) );

    // ----------------------------------------------------------
    //
    // Here is where we change the setting to do the extra stroke
    // The value of gStrokeThicknessFactor determines how thick the extra stroke is.
    //   The "standard" value used by ATSUI is 0.024;
    //     this was changed to 0.044 for bug 3189696,
    //     and will probably be changed back, so if you
    //     want the extra stroke, you will have to do it
    //     manually, as is done below.
    //
    // The extra stroke method:
    //  - will look good on-screen when CG anti-aliasing is ON
    //  - will look good when printing
    //  - will *NOT* look good on-screen when CG anti-aliasing is OFF
    //     (just use kATSUQDBoldfaceTag in that case)
    //
    needToUseCGStrokeMethod = gCurrentlyPrinting || IsAntiAliased(gPointSize);
    if ( needToUseCGStrokeMethod ) {
        CGContextSaveGState(context);
        CGContextSetTextDrawingMode(context, kCGTextFillStroke);
        CGContextSetLineWidth(context, gStrokeThicknessFactor * Fix2X(gPointSize));
        // You might want to call CGContextSetStrokeColor() here,
        // just to make certain it is the same as the text/fill color.
    }
    else
        MySetBoldfaceTag(gStyle); // This will look very strong on-screen when CG anti-aliasing is off

    // Draw the text again with the extra bold for comparison
    verify_noerr( TXNDrawUnicodeTextBox(gText, gLength, &quarterRect3, gStyle, &optionsData) );

    // Undo the previous CG text mode setting
    if ( needToUseCGStrokeMethod )
        CGContextRestoreGState(context);
    else
        MyClearBoldfaceTag(gStyle);

    // Tear down the CGContext since we are done with it
    if (gNewCG) QDEndCGContext(drawingPort, &context); else CGContextRelease(context);    

    // Restore the GrafPort
    SetPort(savedPort);
}
Пример #14
0
void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset)
{
    Q_D(QRasterWindowSurface);

    // Not ready for painting yet, bail out. This can happen in
    // QWidget::create_sys()
    if (!d->image || rgn.rectCount() == 0)
        return;

#ifdef Q_WS_WIN
    QRect br = rgn.boundingRect();

    if (!qt_widget_private(window())->isOpaque
        && window()->testAttribute(Qt::WA_TranslucentBackground)
        && (qt_widget_private(window())->data.window_flags & Qt::FramelessWindowHint))
    {
        QRect r = window()->frameGeometry();
        QPoint frameOffset = qt_widget_private(window())->frameStrut().topLeft();
        QRect dirtyRect = br.translated(offset + frameOffset);

        SIZE size = {r.width(), r.height()};
        POINT ptDst = {r.x(), r.y()};
        POINT ptSrc = {0, 0};
        BLENDFUNCTION blend = {AC_SRC_OVER, 0, (BYTE)(255.0 * window()->windowOpacity()), Q_AC_SRC_ALPHA};
        RECT dirty = {dirtyRect.x(), dirtyRect.y(),
            dirtyRect.x() + dirtyRect.width(), dirtyRect.y() + dirtyRect.height()};
        Q_UPDATELAYEREDWINDOWINFO info = {sizeof(info), NULL, &ptDst, &size, d->image->hdc, &ptSrc, 0, &blend, Q_ULW_ALPHA, &dirty};
        ptrUpdateLayeredWindowIndirect(window()->internalWinId(), &info);
    } else

    {
        QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft();

        HDC widget_dc = widget->getDC();

        QRect wbr = br.translated(-wOffset);
        BitBlt(widget_dc, wbr.x(), wbr.y(), wbr.width(), wbr.height(),
               d->image->hdc, br.x() + offset.x(), br.y() + offset.y(), SRCCOPY);
        widget->releaseDC(widget_dc);
    }

#ifndef QT_NO_DEBUG
    static bool flush = !qgetenv("QT_FLUSH_WINDOWSURFACE").isEmpty();
    if (flush) {
        SelectObject(qt_win_display_dc(), GetStockObject(BLACK_BRUSH));
        Rectangle(qt_win_display_dc(), 0, 0, d->image->width() + 2, d->image->height() + 2);
        BitBlt(qt_win_display_dc(), 1, 1, d->image->width(), d->image->height(),
               d->image->hdc, 0, 0, SRCCOPY);
    }
#endif

#endif

#ifdef Q_WS_X11
    extern void *qt_getClipRects(const QRegion &r, int &num); // in qpaintengine_x11.cpp
    extern QWidgetData* qt_widget_data(QWidget *);
    QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft();

    if (widget->window() != window()) {
        XFreeGC(X11->display, d_ptr->gc);
        d_ptr->gc = XCreateGC(X11->display, widget->handle(), 0, 0);
    }

    QRegion wrgn(rgn);
    if (!wOffset.isNull())
        wrgn.translate(-wOffset);

    if (wrgn.rectCount() != 1) {
        int num;
        XRectangle *rects = (XRectangle *)qt_getClipRects(wrgn, num);
        XSetClipRectangles(X11->display, d_ptr->gc, 0, 0, rects, num, YXBanded);
    }

    QPoint widgetOffset = offset + wOffset;
    QRect clipRect = widget->rect().translated(widgetOffset).intersected(d_ptr->image->image.rect());

    QRect br = rgn.boundingRect().translated(offset).intersected(clipRect);
    QPoint wpos = br.topLeft() - widgetOffset;

#ifndef QT_NO_MITSHM
    if (d_ptr->image->xshmpm) {
        XCopyArea(X11->display, d_ptr->image->xshmpm, widget->handle(), d_ptr->gc,
                  br.x(), br.y(), br.width(), br.height(), wpos.x(), wpos.y());
        d_ptr->needsSync = true;
    } else if (d_ptr->image->xshmimg) {
        XShmPutImage(X11->display, widget->handle(), d_ptr->gc, d_ptr->image->xshmimg,
                     br.x(), br.y(), wpos.x(), wpos.y(), br.width(), br.height(), False);
        d_ptr->needsSync = true;
    } else
#endif
    {
        int depth = widget->x11Info().depth();
        const QImage &src = d->image->image;
        if (src.format() != QImage::Format_RGB32 || depth < 24 || X11->bppForDepth.value(depth) != 32) {
            Q_ASSERT(src.depth() >= 16);
            const QImage sub_src(src.scanLine(br.y()) + br.x() * (uint(src.depth()) / 8),
                                 br.width(), br.height(), src.bytesPerLine(), src.format());
            QX11PixmapData *data = new QX11PixmapData(QPixmapData::PixmapType);
            data->xinfo = widget->x11Info();
            data->fromImage(sub_src, Qt::NoOpaqueDetection);
            QPixmap pm = QPixmap(data);
            XCopyArea(X11->display, pm.handle(), widget->handle(), d_ptr->gc, 0 , 0 , br.width(), br.height(), wpos.x(), wpos.y());
        } else {
            // qpaintengine_x11.cpp
            extern void qt_x11_drawImage(const QRect &rect, const QPoint &pos, const QImage &image, Drawable hd, GC gc, Display *dpy, Visual *visual, int depth);
            qt_x11_drawImage(br, wpos, src, widget->handle(), d_ptr->gc, X11->display, (Visual *)widget->x11Info().visual(), depth);
        }
    }

    if (wrgn.rectCount() != 1)
        XSetClipMask(X11->display, d_ptr->gc, XNone);
#endif // FALCON

#ifdef Q_WS_MAC

    Q_UNUSED(offset);

    // This is mainly done for native components like native "open file" dialog.
    if (widget->testAttribute(Qt::WA_DontShowOnScreen)) {
        return;
    }

#ifdef QT_MAC_USE_COCOA

    this->needsFlush = true;
    this->regionToFlush += rgn;

    // The actual flushing will be processed in [view drawRect:rect]
    qt_mac_setNeedsDisplay(widget);

#else
    // Get a context for the widget.
    CGContextRef context;
    CGrafPtr port = GetWindowPort(qt_mac_window_for(widget));
    QDBeginCGContext(port, &context);
    CGContextRetain(context);
    CGContextSaveGState(context);

    // Flip context.
    CGContextTranslateCTM(context, 0, widget->height());
    CGContextScaleCTM(context, 1, -1);

    // Clip to region.
    const QVector<QRect> &rects = rgn.rects();
    for (int i = 0; i < rects.size(); ++i) {
        const QRect &rect = rects.at(i);
        CGContextAddRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()));
    }
    CGContextClip(context);

    QRect r = rgn.boundingRect().intersected(d->image->image.rect());
    const CGRect area = CGRectMake(r.x(), r.y(), r.width(), r.height());
    CGImageRef image = CGBitmapContextCreateImage(d->image->cg);
    CGImageRef subImage = CGImageCreateWithImageInRect(image, area);

    qt_mac_drawCGImage(context, &area, subImage);

    CGImageRelease(subImage);
    CGImageRelease(image);

    QDEndCGContext(port, &context);

    // Restore context.
    CGContextRestoreGState(context);
    CGContextRelease(context);
#endif // QT_MAC_USE_COCOA

#endif // Q_WS_MAC

}
Пример #15
0
// static
pascal OSStatus IGraphicsCarbon::MainEventHandler(EventHandlerCallRef pHandlerCall, EventRef pEvent, void* pGraphicsCarbon)
{
  IGraphicsCarbon* _this = (IGraphicsCarbon*) pGraphicsCarbon;
  IGraphicsMac* pGraphicsMac = _this->mGraphicsMac;
  UInt32 eventClass = GetEventClass(pEvent);
  UInt32 eventKind = GetEventKind(pEvent);

  switch (eventClass)
  {
    case kEventClassKeyboard:
    {
      switch (eventKind)
      {
        case kEventRawKeyDown:
        {
          if (_this->mTextEntryView)
            return eventNotHandledErr;

          bool handle = true;
          int key;
          UInt32 k;
          GetEventParameter(pEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &k);

          char c;
          GetEventParameter(pEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &c);

          if (k == 49) key = KEY_SPACE;
          else if (k == 125) key = KEY_DOWNARROW;
          else if (k == 126) key = KEY_UPARROW;
          else if (k == 123) key = KEY_LEFTARROW;
          else if (k == 124) key = KEY_RIGHTARROW;
          else if (c >= '0' && c <= '9') key = KEY_DIGIT_0+c-'0';
          else if (c >= 'A' && c <= 'Z') key = KEY_ALPHA_A+c-'A';
          else if (c >= 'a' && c <= 'z') key = KEY_ALPHA_A+c-'a';
          else handle = false;

          if(handle)
            handle = pGraphicsMac->OnKeyDown(_this->mPrevX, _this->mPrevY, key);

          if(handle)
            return noErr;
          else
            return eventNotHandledErr;

        }
      }
    }
    case kEventClassControl:
    {
      switch (eventKind)
      {
        case kEventControlDraw:
        {
          int gfxW = pGraphicsMac->Width(), gfxH = pGraphicsMac->Height();

          IRECT r = GetRegionRect(pEvent, gfxW, gfxH);

          CGrafPtr port = 0;

          if (_this->mIsComposited)
          {
            GetEventParameter(pEvent, kEventParamCGContextRef, typeCGContextRef, 0, sizeof(CGContextRef), 0, &(_this->mCGC));
            CGContextTranslateCTM(_this->mCGC, 0, gfxH);
            CGContextScaleCTM(_this->mCGC, 1.0, -1.0);
            pGraphicsMac->Draw(&r);
          }
          else
          {
            GetEventParameter(pEvent, kEventParamGrafPort, typeGrafPtr, 0, sizeof(CGrafPtr), 0, &port);
            QDBeginCGContext(port, &(_this->mCGC));
            
            //RgnHandle clipRegion = NewRgn();
            //GetPortClipRegion(port, clipRegion);
            
            Rect portBounds;
            GetPortBounds(port, &portBounds);

            int offsetW = 0;
            int offsetH = -portBounds.top;
            //int offsetH = (portBounds.bottom - portBounds.top) - gfxH; // this almost works with AS, but clip rect seems wrong when previewing/breaks RTAS
            
            if ((portBounds.right - portBounds.left) >= gfxW)
            {
              offsetW = 0.5 * ((portBounds.right - portBounds.left) - gfxW);
            }
            
            CGContextTranslateCTM(_this->mCGC, portBounds.left + offsetW, offsetH);
            
            r = IRECT(0, 0, pGraphicsMac->Width(), pGraphicsMac->Height());
            pGraphicsMac->Draw(&r); // Carbon non-composited will redraw everything, the IRECT passed here is the entire plugin-gui
            
            QDEndCGContext(port, &(_this->mCGC));
            
            //DisposeRgn(clipRegion);
          }
          return noErr;
        }
      }
      break;
    }
    case kEventClassMouse:
    {
      HIPoint hp;
      GetEventParameter(pEvent, kEventParamWindowMouseLocation, typeHIPoint, 0, sizeof(HIPoint), 0, &hp);

      #ifdef RTAS_API
      // Header offset
      hp.x -= _this->GetLeftOffset();
      hp.y -= _this->GetTopOffset();

      Rect bounds;
      GetWindowBounds(_this->mWindow, kWindowTitleBarRgn, &bounds);

      // adjust x mouse coord if the gui is less wide than the window
//      int windowWidth = (bounds.right - bounds.left);
//
//      if (windowWidth > pGraphicsMac->Width())
//      {
//        hp.x -= (int) floor((windowWidth - pGraphicsMac->Width()) / 2.);
//      }

      // Title bar Y offset
      hp.y -= bounds.bottom - bounds.top;

      int x = (int) hp.x;
      int y = (int) hp.y;

      #else // NOT RTAS
      HIPointConvert(&hp, kHICoordSpaceWindow, _this->mWindow, kHICoordSpaceView, _this->mView);
      int x = (int) hp.x - 2;
      int y = (int) hp.y - 3;
      #endif

      UInt32 mods;
      GetEventParameter(pEvent, kEventParamKeyModifiers, typeUInt32, 0, sizeof(UInt32), 0, &mods);
      EventMouseButton button;
      GetEventParameter(pEvent, kEventParamMouseButton, typeMouseButton, 0, sizeof(EventMouseButton), 0, &button);
      if (button == kEventMouseButtonPrimary && (mods & cmdKey)) button = kEventMouseButtonSecondary;
      IMouseMod mmod(true, button == kEventMouseButtonSecondary, (mods & shiftKey), (mods & controlKey), (mods & optionKey));

      switch (eventKind)
      {
        case kEventMouseDown:
        {
          if (_this->mTextEntryView)
          {
            #if !(USE_MLTE)
            HIViewRef view;
            HIViewGetViewForMouseEvent(_this->mView, pEvent, &view);
            if (view == _this->mTextEntryView) break;
            #endif
            _this->EndUserInput(true);
          }

          #ifdef RTAS_API // RTAS triple click
          if (mmod.L && mmod.R && mmod.C && (pGraphicsMac->GetParamIdxForPTAutomation(x, y) > -1))
          {
            return CallNextEventHandler(pHandlerCall, pEvent);
          }
          #endif

          CallNextEventHandler(pHandlerCall, pEvent);

          UInt32 clickCount = 0;
          GetEventParameter(pEvent, kEventParamClickCount, typeUInt32, 0, sizeof(UInt32), 0, &clickCount);

          if (clickCount > 1)
          {
            pGraphicsMac->OnMouseDblClick(x, y, &mmod);
          }
          else
          {
            pGraphicsMac->OnMouseDown(x, y, &mmod);
          }

          return noErr;
        }

        case kEventMouseUp:
        {
          pGraphicsMac->OnMouseUp(x, y, &mmod);
          return noErr;
        }

        case kEventMouseMoved:
        {
          _this->mPrevX = x;
          _this->mPrevY = y;
          pGraphicsMac->OnMouseOver(x, y, &mmod);
          return noErr;
        }

        case kEventMouseDragged:
        {
          if (!_this->mTextEntryView)
            pGraphicsMac->OnMouseDrag(x, y, &mmod);
          return noErr;
        }

        case kEventMouseWheelMoved:
        {
          EventMouseWheelAxis axis;
          GetEventParameter(pEvent, kEventParamMouseWheelAxis, typeMouseWheelAxis, 0, sizeof(EventMouseWheelAxis), 0, &axis);

          if (axis == kEventMouseWheelAxisY)
          {
            int d;
            GetEventParameter(pEvent, kEventParamMouseWheelDelta, typeSInt32, 0, sizeof(SInt32), 0, &d);

            if (_this->mTextEntryView) _this->EndUserInput(false);

            pGraphicsMac->OnMouseWheel(x, y, &mmod, d);
            return noErr;
          }
        }
      }

      break;
    }

    case kEventClassWindow:
    {
      WindowRef window;

      if (GetEventParameter(pEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof (WindowRef), NULL, &window) != noErr)
        break;

      switch (eventKind)
      {
        case kEventWindowDeactivated:
        {
          if (_this->mTextEntryView)
            _this->EndUserInput(false);
          break;
        }
      }
      break;
    }
  }

  return eventNotHandledErr;
}
Пример #16
0
CGContextRef QDBeginCGContext_wrap( OpaqueGrafPtr* port, void* FH ) {
  CGContextRef c;
  OSStatus e = QDBeginCGContext(port, &c);
  return  e != noErr  ?  (CGContextRef)reportOSError(e, "QDBeginContext", FH)  : c;
}
Пример #17
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
Пример #18
0
void nuiSoftwarePainter::Display(nglWindow* pWindow, const nuiRect& rRect)
{
  if (!pWindow)
    return;
  const nglWindow::OSInfo* pInfo = pWindow->GetOSInfo();
  
  NGL_ASSERT(pInfo);

  if (!pInfo)
    return;

  //TestAgg((char*)&mBuffer[0], mWidth, mHeight);
  
  int32 x, y, w, h;
  x = ToBelow(rRect.Left());
  y = ToBelow(rRect.Top());
  w = ToBelow(rRect.GetWidth());
  h = ToBelow(rRect.GetHeight());
  int32 offset = (x + mWidth * y);
  
#ifdef _WIN32_
  HDC hdc = GetDC(pInfo->GLWindowHandle);

  BITMAPV5HEADER bminfo;

  // BITMAPV5HEADER
  bminfo.bV5Size = sizeof(BITMAPV5HEADER);
  bminfo.bV5Width = (LONG)mWidth;
  bminfo.bV5Height = -(LONG)mHeight;
  bminfo.bV5Planes = 1;
  bminfo.bV5BitCount = 32;
  bminfo.bV5Compression = BI_RGB;
  bminfo.bV5SizeImage = 0;
  bminfo.bV5XPelsPerMeter = 0;
  bminfo.bV5YPelsPerMeter = 0;
  bminfo.bV5ClrUsed = 0;
  bminfo.bV5ClrImportant =0;

  bminfo.bV5RedMask = 0;
  bminfo.bV5GreenMask = 0;
  bminfo.bV5BlueMask = 0;
  bminfo.bV5AlphaMask = 0;

  bminfo.bV5CSType = LCS_WINDOWS_COLOR_SPACE;
  bminfo.bV5Endpoints.ciexyzRed.ciexyzX = 0;
  bminfo.bV5Endpoints.ciexyzRed.ciexyzY = 0;
  bminfo.bV5Endpoints.ciexyzRed.ciexyzZ = 0;
  bminfo.bV5Endpoints.ciexyzGreen.ciexyzX = 0;
  bminfo.bV5Endpoints.ciexyzGreen.ciexyzY = 0;
  bminfo.bV5Endpoints.ciexyzGreen.ciexyzZ = 0;
  bminfo.bV5Endpoints.ciexyzBlue.ciexyzX = 0;
  bminfo.bV5Endpoints.ciexyzBlue.ciexyzY = 0;
  bminfo.bV5Endpoints.ciexyzBlue.ciexyzZ = 0;
  bminfo.bV5GammaRed = 0;
  bminfo.bV5GammaGreen = 0;
  bminfo.bV5GammaBlue = 0;
  bminfo.bV5Intent = LCS_GM_IMAGES;
  bminfo.bV5ProfileData = 0;
  bminfo.bV5ProfileSize = 0;

  bminfo.bV5Reserved = 0;

  RECT r;
  GetClientRect(pInfo->GLWindowHandle, &r);

  r.right = (LONG)mWidth;
  r.bottom = (LONG)mHeight;

  uint32* pBuffer = mpRasterizer->GetBuffer();
/*
  for (uint32 i = 0; i < mWidth * mHeight; i++)
    pBuffer[i] = rand();
*/

  SetDIBitsToDevice(
    hdc,              // handle to DC
    x,                // x-coord of destination upper-left corner
    y,                // y-coord of destination upper-left corner
    w,          // width of destination rectangle
    h,         // height of destination rectangle
    x,                // x-coord of source upper-left corner
    mHeight - h - y,                // y-coord of source upper-left corner

    0,                // first scan line
    (LONG)mHeight,    // number of scan lines

    pBuffer,          // bitmap bits
    (const BITMAPINFO*)&bminfo,          // bitmap data
    DIB_RGB_COLORS    // usage options
    );

  ReleaseDC(pInfo->GLWindowHandle, hdc);

#elif (defined _CARBON_)

  WindowRef win = pInfo->WindowHandle;
  if (!win)
    win = pInfo->Parent;
  
  //CGContextRef myMemoryContext;
  CGColorSpaceRef cspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
  CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, mpRasterizer->GetBuffer() + offset, mWidth * h * 4, NULL);
  
  CGImageRef img = CGImageCreate(
                                 w,
                                 h,
                                 8,
                                 32,
                                 mWidth * 4,
                                 cspace,
                                 kCGBitmapByteOrder32Host | kCGImageAlphaNoneSkipFirst,
                                 provider,
                                 NULL,
                                 0,
                                 kCGRenderingIntentDefault
                                 );
  
  CGContextRef myContext;
  
  SetPortWindowPort (win);// 1
  QDBeginCGContext (GetWindowPort (win), &myContext);

  CGRect rect = CGRectMake(x, mHeight - h - y, w, h);
  CGContextDrawImage(myContext, rect, img);
  
  QDEndCGContext (GetWindowPort(win), &myContext);  
          
#endif
}
Пример #19
0
void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset)
{
    Q_D(QRasterWindowSurface);

    // Not ready for painting yet, bail out. This can happen in
    // QWidget::create_sys()
    if (!d->image)
        return;

#ifdef Q_WS_WIN
    QRect br = rgn.boundingRect();

#ifndef Q_OS_WINCE
    if (!qt_widget_private(window())->isOpaque && d->canUseLayeredWindow) {
        QRect r = window()->frameGeometry();
        QPoint frameOffset = qt_widget_private(window())->frameStrut().topLeft();
        QRect dirtyRect = br.translated(offset + frameOffset);

        SIZE size = {r.width(), r.height()};
        POINT ptDst = {r.x(), r.y()};
        POINT ptSrc = {0, 0};
        Q_BLENDFUNCTION blend = {AC_SRC_OVER, 0, (int)(255.0 * window()->windowOpacity()), Q_AC_SRC_ALPHA};
        RECT dirty = {dirtyRect.x(), dirtyRect.y(),
            dirtyRect.x() + dirtyRect.width(), dirtyRect.y() + dirtyRect.height()};
        Q_UPDATELAYEREDWINDOWINFO info = {sizeof(info), NULL, &ptDst, &size, d->image->hdc, &ptSrc, 0, &blend, Q_ULW_ALPHA, &dirty};

        (*ptrUpdateLayeredWindowIndirect)(window()->internalWinId(), &info);
    } else
#endif
    {
        QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft();

        HDC widget_dc = widget->getDC();

        QRect wbr = br.translated(-wOffset);
        BitBlt(widget_dc, wbr.x(), wbr.y(), wbr.width(), wbr.height(),
               d->image->hdc, br.x() + offset.x(), br.y() + offset.y(), SRCCOPY);
        widget->releaseDC(widget_dc);
    }

#ifndef QT_NO_DEBUG
    static bool flush = !qgetenv("QT_FLUSH_WINDOWSURFACE").isEmpty();
    if (flush) {
        SelectObject(qt_win_display_dc(), GetStockObject(BLACK_BRUSH));
        Rectangle(qt_win_display_dc(), 0, 0, d->image->width() + 2, d->image->height() + 2);
        BitBlt(qt_win_display_dc(), 1, 1, d->image->width(), d->image->height(),
               d->image->hdc, 0, 0, SRCCOPY);
    }
#endif

#endif

#ifdef Q_WS_X11
    extern void *qt_getClipRects(const QRegion &r, int &num); // in qpaintengine_x11.cpp
    extern QWidgetData* qt_widget_data(QWidget *);
    QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft();

    if (widget->window() != window()) {
        XFreeGC(X11->display, d_ptr->gc);
        d_ptr->gc = XCreateGC(X11->display, widget->handle(), 0, 0);
    }

    QRegion wrgn(rgn);
    if (!wOffset.isNull())
        wrgn.translate(-wOffset);
    QRect wbr = wrgn.boundingRect();

    int num;
    XRectangle *rects = (XRectangle *)qt_getClipRects(wrgn, num);
    XSetClipRectangles(X11->display, d_ptr->gc, 0, 0, rects, num, YXBanded);

    QRect br = rgn.boundingRect().translated(offset);
#ifndef QT_NO_MITSHM
    if (d_ptr->image->xshmpm) {
        XCopyArea(X11->display, d_ptr->image->xshmpm, widget->handle(), d_ptr->gc,
                  br.x(), br.y(), br.width(), br.height(), wbr.x(), wbr.y());
        XSync(X11->display, False);
    } else
#endif
    {
        const QImage &src = d->image->image;
        br = br.intersected(src.rect());
        if (src.format() != QImage::Format_RGB32) {
            QX11PixmapData *data = new QX11PixmapData(QPixmapData::PixmapType);
            data->xinfo = widget->x11Info();
            data->fromImage(src, Qt::AutoColor);
            QPixmap pm = QPixmap(data);
            XCopyArea(X11->display, pm.handle(), widget->handle(), d_ptr->gc, br.x() , br.y() , br.width(), br.height(), wbr.x(), wbr.y());
        } else {
            // qpaintengine_x11.cpp
            extern void qt_x11_drawImage(const QRect &rect, const QPoint &pos, const QImage &image, Drawable hd, GC gc, Display *dpy, Visual *visual, int depth);
            qt_x11_drawImage(br, wbr.topLeft(), src, widget->handle(), d_ptr->gc, X11->display, (Visual *)widget->x11Info().visual(), widget->x11Info().depth());
        }
    }
#endif // FALCON

#ifdef Q_WS_MAC

//     qDebug() << "Flushing" << widget << rgn << offset;

//     d->image->image.save("flush.png");

    // Get a context for the widget.
#ifndef QT_MAC_USE_COCOA
    CGContextRef context;
    CGrafPtr port = GetWindowPort(qt_mac_window_for(widget));
    QDBeginCGContext(port, &context);
#else
    extern CGContextRef qt_mac_graphicsContextFor(QWidget *);
    CGContextRef context = qt_mac_graphicsContextFor(widget);
#endif
    CGContextSaveGState(context);

    // Flip context.
    CGContextTranslateCTM(context, 0, widget->height());
    CGContextScaleCTM(context, 1, -1);

    // Clip to region.
    const QVector<QRect> &rects = rgn.rects();
    for (int i = 0; i < rects.size(); ++i) {
        const QRect &rect = rects.at(i);
        CGContextAddRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()));
    }
    CGContextClip(context);

    QRect r = rgn.boundingRect();
    const CGRect area = CGRectMake(r.x(), r.y(), r.width(), r.height());
    CGImageRef image = CGBitmapContextCreateImage(d->image->cg);
    CGImageRef subImage = CGImageCreateWithImageInRect(image, area);

    qt_mac_drawCGImage(context, &area, subImage);
    CGImageRelease(subImage);
    CGImageRelease(image);

//     CGSize size = { d->image->image.width(), d->image->image.height() };
//     CGLayerRef layer = CGLayerCreateWithContext(d->image->cg, size, 0);
//     CGPoint pt = { 0, 0 };
//     CGContextDrawLayerAtPoint(context, pt, layer);
//     CGLayerRelease(layer);

    // Restore context.
    CGContextRestoreGState(context);
#ifndef QT_MAC_USE_COCOA
    QDEndCGContext(port, &context);
#else
    CGContextFlush(context);
#endif
#endif
}
Пример #20
0
static pascal OSStatus TransparentWindowHandler(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
{
    OSStatus status = eventNotHandledErr;

    switch(GetEventKind(inEvent))
    {
    case kEventWindowGetRegion:
    {
        WindowRegionCode code;
        RgnHandle rgn;

        // which region code is being queried?
        GetEventParameter(inEvent, kEventParamWindowRegionCode, typeWindowRegionCode, NULL, sizeof(code), NULL, &code);

        // if it is the opaque region code then set the region to Empty and return noErr to stop the propagation
        if (code == kWindowOpaqueRgn)
        {
            GetEventParameter(inEvent, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof(rgn), NULL, &rgn);
            SetEmptyRgn(rgn);
            status = noErr;
        }
        break;
    }

    case kEventWindowDrawContent:
    {
        GrafPtr port;
        CGContextRef context;
        Rect portBounds;
        HIRect bounds;

        GetPort(&port);
        GetPortBounds(port, &portBounds);

        // we need a Quartz context so that we can use transparency
        QDBeginCGContext(port, &context);

        // make the whole content transparent
        bounds = CGRectMake(0, 0, portBounds.right, portBounds.bottom);
        CGContextClearRect(context, bounds);

        QDEndCGContext(port, &context);

        // we need to let the HIToolbox and the regular kEventWindowDrawContent handler do their work,
        // mainly draw the subviews, so we return eventNotHandledErr to propagate.
        status = eventNotHandledErr;
        break;
    }

    case kEventControlDraw:
    {
        CGContextRef context;
        HIRect bounds;

        GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(context), NULL, &context);
        HIViewGetBounds((HIViewRef)inUserData, &bounds);

        // make the whole content transparent
        CGContextClearRect(context, bounds);

        // we must not let the default draw handler of the content view be called (it would draw the default opaque theme)
        // so we return noErr to stop the propagation.
        status = noErr;
        break;
    }
    }

    return status;
}
Пример #21
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
Пример #22
0
void wxAuiDefaultDockArt::DrawSash(wxDC& dc, wxWindow *window, int orientation, const wxRect& rect)
{
#if defined(__WXMAC__)
    HIRect splitterRect = CGRectMake( rect.x , rect.y , rect.width , rect.height );
    CGContextRef cgContext ;
#if wxMAC_USE_CORE_GRAPHICS
    cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext() ;
#else
    Rect bounds ;
    GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
    QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
    CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
    CGContextScaleCTM( cgContext , 1 , -1 ) ;

    if ( window )
    {
        wxPoint origin = window->GetClientAreaOrigin();
        int x, y;
        x = origin.x;
        y = origin.y;
        window->MacWindowToRootWindow( &x , &y );
        CGContextTranslateCTM( cgContext, x, y);
    }
#endif

    HIThemeSplitterDrawInfo drawInfo ;
    drawInfo.version = 0 ;
    drawInfo.state = kThemeStateActive ;
    drawInfo.adornment = kHIThemeSplitterAdornmentNone ;
    HIThemeDrawPaneSplitter( &splitterRect , &drawInfo , cgContext , kHIThemeOrientationNormal ) ;

#if wxMAC_USE_CORE_GRAPHICS
#else
    QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
#endif

#elif defined(__WXGTK__)
    // clear out the rectangle first
    dc.SetPen(*wxTRANSPARENT_PEN);
    dc.SetBrush(m_sash_brush);
    dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);

    GdkRectangle gdk_rect;
    if (orientation == wxVERTICAL )
    {
        gdk_rect.x = rect.x;
        gdk_rect.y = rect.y;
        gdk_rect.width = m_sash_size;
        gdk_rect.height = rect.height;
    }
    else
    {
        gdk_rect.x = rect.x;
        gdk_rect.y = rect.y;
        gdk_rect.width = rect.width;
        gdk_rect.height = m_sash_size;
    }

    if (!window) return;
    if (!window->m_wxwindow) return;
    if (!GTK_PIZZA(window->m_wxwindow)->bin_window) return;

    gtk_paint_handle
    (
        window->m_wxwindow->style,
        GTK_PIZZA(window->m_wxwindow)->bin_window,
        // flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL,
        GTK_STATE_NORMAL,
        GTK_SHADOW_NONE,
        NULL /* no clipping */,
        window->m_wxwindow,
        "paned",
        rect.x,
        rect.y,
        rect.width,
        rect.height,
        (orientation == wxVERTICAL) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL
    );

#else
    wxUnusedVar(window);
    wxUnusedVar(orientation);
    dc.SetPen(*wxTRANSPARENT_PEN);
    dc.SetBrush(m_sash_brush);
    dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
#endif
}