gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Image drawing in flipped view


From: Fred Kiefer
Subject: Image drawing in flipped view
Date: Wed, 01 Mar 2006 16:03:32 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921

I am currently working on the image draw code for the cairo backend and
stumbled over a problem there. To better understand, what the expected
behaviour for flipped views is, I would like to see the results the
attached application produces on MacOSX. Could somebody please run this
code on Cocoa and mail me the results? (You will need to add the GNUstep
logo as a resource) I need a screen shot with both windows.

I was surprised that even our two backends xlib and art produce
different results here (I did not try with winlib). It may as well be
that I am using the isFlipped method in a totally wrong way and that
this should only be used with a suitable transformation in place.
Perhaps somebody is able to enlighten me on this?

Cheers
Fred
/* 
   Tester for image drawing
   Copyright (C) 2006 Free Software Foundation, Inc.

   Written by: Fred Kiefer <address@hidden>
   Created: February 2006

   This file is part of the GNUstep Base Library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSString.h>
#include <AppKit/NSApplication.h>
#include <AppKit/NSBezierPath.h>
#include <AppKit/NSColor.h>
#include <AppKit/NSImage.h>
#include <AppKit/NSMenu.h>
#include <AppKit/NSView.h>
#include <AppKit/NSWindow.h>

#include <AppKit/PSOperators.h>

@interface FlippedView: NSView
{
}
@end


@implementation FlippedView

- (BOOL) isFlipped
{
  return YES;
}

@end

@interface AppController: NSObject
{
}
@end


@implementation AppController

-(void) draw
{
  NSImage *image = [NSImage imageNamed: @"GNUstep"];
  NSPoint point = NSMakePoint(20, 20);

  [image compositeToPoint: point
                operation: NSCompositeSourceOver
                 fraction: 0.8];

  [image compositeToPoint: NSMakePoint(20, 70)
                operation: NSCompositeCopy];

  [image compositeToPoint: NSMakePoint(70, 20)
                operation: NSCompositeDestinationOver
                 fraction: 0.8];

  [[NSColor redColor] set];
  [[NSBezierPath bezierPathWithRect: NSMakeRect(69, 69, 50, 50)] stroke];

  [[image bestRepresentationForDevice: nil] drawAtPoint: NSMakePoint(70, 70)];
  
}

-(void) normalWindow
{
  NSWindow *aWin;

  aWin = [[NSWindow alloc] initWithContentRect: NSMakeRect(200,200,140,140)
                           styleMask: NSTitledWindowMask
                           backing: NSBackingStoreBuffered
                           defer: NO];
  [aWin setTitle: @"Normal Window"];
  [aWin setBackgroundColor: [NSColor blueColor]];
  [aWin makeKeyAndOrderFront: nil];
  
  [[aWin contentView] lockFocus];
  [self draw];
  [[aWin contentView] unlockFocus];
  [aWin flushWindow];
}

-(void) flippedWindow
{
  NSWindow *aWin;

  aWin = [[NSWindow alloc] initWithContentRect: NSMakeRect(400,400,140,140)
                           styleMask: NSTitledWindowMask
                           backing: NSBackingStoreBuffered
                           defer: NO];
  [aWin setTitle: @"Flipped Window"];
  [aWin setContentView: AUTORELEASE([[FlippedView alloc] initWithFrame: 
NSMakeRect(0,0,140,140)])];
  [aWin setBackgroundColor: [NSColor blueColor]];
  [aWin makeKeyAndOrderFront: nil];
  
  [[aWin contentView] lockFocus];
  [self draw];
  [[aWin contentView] unlockFocus];
  [aWin flushWindow];
}

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
  NSMenu *menu = [NSMenu new];

  [menu addItemWithTitle: @"Quit"
        action: @selector(terminate:)
        keyEquivalent: @"q"];
  [NSApp setMainMenu: menu];
  RELEASE(menu);

  [self normalWindow];
  [self flippedWindow];
}

@end

int main (int argc, const char *argv[])
{
  CREATE_AUTORELEASE_POOL(pool);
  id app;

  app = [NSApplication sharedApplication];
  [app setDelegate: [AppController new]];
  [app run];
  RELEASE(pool);
  return 0;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]