ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/EmulatorView.mm
(Generate patch)

Comparing BasiliskII/src/MacOSX/EmulatorView.mm (file contents):
Revision 1.6 by nigel, 2002-10-06T23:26:07Z vs.
Revision 1.8 by nigel, 2003-03-11T11:27:20Z

# Line 49 | Line 49
49          drawView = NO;          // Disable drawing until later
50          fullScreen = NO;
51  
52 #ifdef SAVE_GSTATE
53        [self allocateGState];
54 #endif
55
52          return self;
53   }
54  
55 < - (void) dealloc
55 > - (void) awakeFromNib
56   {
57 < #ifdef SAVE_GSTATE
58 <        [self releaseGState];
59 < #endif
64 <        [super dealloc];
57 >        // Here we store the height of the screen which the app was opened on.
58 >        // NSApplication's sendEvent: always uses that screen for its mouse co-ords
59 >        screen_height = (int) [[NSScreen mainScreen] frame].size.height;
60   }
61  
62 +
63   // Mouse click in this window. If window is not active,
64   // should the click be passed to this view?
65   - (BOOL) acceptsFirstMouse: (NSEvent *) event
# Line 72 | Line 68
68   }
69  
70  
71 + //
72 + // Key event processing.
73 + // OS X doesn't send us separate events for the modifier keys
74 + // (shift/control/command), so we need to monitor them separately
75 + //
76 +
77   #include <adb.h>
78  
79   static int prevFlags;
# Line 113 | Line 115 | static int prevFlags;
115          prevFlags = flags;
116   }
117  
118 + //
119 + // Windowed mode. We only send mouse/key events
120 + // if the OS X mouse is within the little screen
121 + //
122   - (BOOL) mouseInView: (NSEvent *) event
123   {
124          NSRect  box;
# Line 163 | Line 169 | static int prevFlags;
169                  [bitmap draw];
170   #endif
171   #ifdef CGIMAGEREF
172 <                cgDrawInto([self bounds], bitmap);
172 >                cgDrawInto([self bounds], cgImgRep);
173   #endif
174   #ifdef CGDRAWBITMAP
175                  [self CGDrawBitmap];
# Line 195 | Line 201 | static int prevFlags;
201                    imageWidth: (short) width
202                   imageHeight: (short) height
203   {
204 +        D(NSLog(@"readyToDraw: theBitmap=%lx\n", theBitmap));
205 +
206          bitmap = theBitmap;
207 +        numBytes = [theBitmap bytesPerRow] * height;
208   #endif
209   #ifdef CGIMAGEREF
210   - (void) readyToDraw: (CGImageRef) image
211                    imageWidth: (short) width
212                   imageHeight: (short) height
213   {
214 <        bitmap = image;
214 >        D(NSLog(@"readyToDraw: theBitmap=%lx\n", [cgImgRef bitmap]));
215 >
216 >        cgImgRep = image;
217 >        numBytes = CGImageGetBytesPerRow(image) * height;
218   #endif
219   #ifdef CGDRAWBITMAP
220   - (void) readyToDraw: (void *) theBitmap
# Line 215 | Line 227 | static int prevFlags;
227                          isPlanar: (BOOL)  planar
228                          hasAlpha: (BOOL)  alpha
229   {
230 +        D(NSLog(@"readyToDraw: theBitmap=%lx\n", theBitmap));
231 +
232          bitmap = theBitmap;
233          bps = bitsPerSample;
234          spp = samplesPerPixel;
# Line 222 | Line 236 | static int prevFlags;
236          bytesPerRow = bpr;
237          isPlanar = planar;
238          hasAlpha = alpha;
239 +        numBytes = bpr * height;
240   #endif
241          x = width, y = height;
242          drawView = YES;
228
243          [[self window] setAcceptsMouseMovedEvents:      YES];
244   //      [[self window] setInitialFirstResponder:        self];
245          [[self window] makeFirstResponder:                      self];
# Line 242 | Line 256 | static int prevFlags;
256  
257          fullScreen = YES;
258          memcpy(&displayBox, &displayBounds, sizeof(displayBox));
245        screen_height = (int)displayBounds.size.height;
259   }
260  
261   - (short) width
# Line 307 | Line 320 | static int prevFlags;
320          }
321   }
322  
323 +
324 + - (void) fullscreenMouseMove
325 + {
326 +        NSPoint location = [NSEvent mouseLocation];
327 +
328 +        D(NSLog (@"%s - loc.x=%f, loc.y=%f",
329 +                                __PRETTY_FUNCTION__, location.x, location.y));
330 +        D(NSLog (@"%s - Sending ADBMouseMoved(%d,%d). (%d-%d)",
331 +                                        __PRETTY_FUNCTION__, (int)location.x,
332 +                                        screen_height - (int)location.y, screen_height, (int)location.y));
333 +        ADBMouseMoved((int)location.x, screen_height - (int)location.y);
334 + }
335 +
336   static NSPoint  mouse;                  // Previous/current mouse location
337  
338   - (BOOL) processMouseMove: (NSEvent *) event
# Line 314 | Line 340 | static NSPoint mouse;                  // Previous/curr
340          NSPoint location;
341  
342          if ( fullScreen )
343 <                location = [NSEvent mouseLocation];
344 <        else
345 <                location = [self convertPoint: [event locationInWindow] fromView:nil];
343 >        {
344 >                [self fullscreenMouseMove];
345 >                return YES;
346 >        }
347 >
348 >        location = [self convertPoint: [event locationInWindow] fromView:nil];
349 >
350 >        D(NSLog (@"%s - loc.x=%f, loc.y=%f",
351 >                                __PRETTY_FUNCTION__, location.x, location.y));
352  
353          if ( NSEqualPoints(location, mouse) )
354                  return NO;
355  
356          mouse = location;
357  
326        if ( fullScreen )
327        {
328                ADBMouseMoved((int)mouse.x, screen_height - (int)mouse.y);
329                return YES;
330        }
331
358   #ifdef CAN_RESIZE_VIEW
359          int     mouseY = y - y * mouse.y / [self height];
360          int     mouseX =         x * mouse.x / [self width];
# Line 370 | Line 396 | static NSPoint mouse;                  // Previous/curr
396          ADBMouseUp(0);
397   }
398  
399 < #if DEBUG
399 > #if DEBUG && ! defined(CGIMAGEREF)
400   - (void) randomise              // Draw some coloured snow in the bitmap
401   {
402 <        unsigned char    *pixel;
402 >        unsigned char   *data,
403 >                                        *pixel;
404 >
405 >  #ifdef CGDRAWBITMAP
406 >        data = bitmap;
407 >  #endif
408 >  #ifdef NSBITMAP
409 >        data = [bitmap bitmapData];
410 >  #endif
411  
412          for ( int i = 0; i < 1000; ++i )
413          {
414 <                pixel = [bitmap bitmapData]
381 <                                + (int) (1.0 * [bitmap bytesPerRow] * 342       //[bitmap height]
382 <                                                         * rand() / RAND_MAX);
414 >                pixel  = data + (int) (numBytes * rand() / RAND_MAX);
415                  *pixel = (unsigned char) (256.0 * rand() / RAND_MAX);
416          }
417   }
# Line 392 | Line 424 | static NSPoint mouse;                  // Previous/curr
424  
425   #if DEBUG
426          NSLog(@"In drawRect");
427 <        //[self randomise];
427 > # ifndef CGIMAGEREF
428 >        [self randomise];
429 > # endif
430   #endif
431  
432   #ifdef NSBITMAP
# Line 400 | Line 434 | static NSPoint mouse;                  // Previous/curr
434          [bitmap draw];
435   #endif
436   #ifdef CGIMAGEREF
437 <        cgDrawInto(rect, bitmap);
437 >        cgDrawInto(rect, cgImgRep);
438   #endif
439   #ifdef CGDRAWBITMAP
440          [self CGDrawBitmap];
# Line 416 | Line 450 | extern "C" void CGDrawBitmap(...);
450  
451   - (void) CGDrawBitmap
452   {
453 <        CGContextRef    cgContext = [[NSGraphicsContext currentContext]
454 <                                                                                                                graphicsPort];
453 >        CGContextRef    cgContext = (CGContextRef) [[NSGraphicsContext currentContext]
454 >                                                                                                graphicsPort];
455          NSRect                  rect = [self bounds];
456          CGRect                  cgRect = {
457                                                                  {rect.origin.x, rect.origin.y},
# Line 427 | Line 461 | extern "C" void CGDrawBitmap(...);
461          CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
462  
463  
464 <        CGContextSetShouldAntialias(cgContext, NO);             // Seems to have no effect?
464 > //      CGContextSetShouldAntialias(cgContext, NO);             // Seems to have no effect?
465  
466          CGDrawBitmap(cgContext, cgRect, x, y, bps, spp, bpp,
467                                          bytesPerRow, isPlanar, hasAlpha, colourSpace, &bitmap);
# Line 436 | Line 470 | extern "C" void CGDrawBitmap(...);
470  
471   #ifdef CGIMAGEREF
472   void
473 < cgDrawInto(NSRect rect, CGImageRef bitmap)
473 > cgDrawInto(NSRect rect, CGImageRef cgImgRep)
474   {
475 <        CGContextRef    cgContext = [[NSGraphicsContext currentContext]
476 <                                                                                                                graphicsPort];
475 >        CGContextRef    cgContext = (CGContextRef) [[NSGraphicsContext currentContext]
476 >                                                                                                graphicsPort];
477          CGRect                  cgRect = {
478                                                                  {rect.origin.x, rect.origin.y},
479                                                                  {rect.size.width, rect.size.height}
480                                                           };
481  
482 <        CGContextSetShouldAntialias(cgContext, NO);             // Seems to have no effect?
482 > //      CGContextSetShouldAntialias(cgContext, NO);             // Seems to have no effect?
483  
484 <        CGContextDrawImage(cgContext, cgRect, bitmap);
484 >        CGContextDrawImage(cgContext, cgRect, cgImgRep);
485   }
486   #endif
487  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines