mirror of
https://github.com/gnustep/libs-back.git
synced 2025-04-22 15:31:14 +00:00
Use new display server methods to implement without X calls. This
class can now be moved to frontend. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@15834 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8dcfa3a567
commit
6dc01011b4
1 changed files with 69 additions and 137 deletions
|
@ -1,10 +1,12 @@
|
|||
/*
|
||||
XGSlideView
|
||||
/** <title>XGSlideView</title>
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 2002, 2003 Free Software Foundation, Inc.
|
||||
|
||||
Created by: Enrico Sersale <enrico@imago.ro>
|
||||
Date: Jan 2002
|
||||
Author: Fred Kiefer <fredkiefer@gmx.de>
|
||||
Date: Jan 2003
|
||||
Removed all dependencies on X.
|
||||
|
||||
This file is part of the GNU Objective C User Interface Library.
|
||||
|
||||
|
@ -21,135 +23,85 @@
|
|||
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <AppKit/NSApplication.h>
|
||||
#include <AppKit/NSCell.h>
|
||||
#include <AppKit/NSColor.h>
|
||||
#include <AppKit/NSCursor.h>
|
||||
#include <AppKit/NSEvent.h>
|
||||
#include <AppKit/NSImage.h>
|
||||
#include <AppKit/NSScreen.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
|
||||
#include "x11/XGServer.h"
|
||||
#include "x11/XGServerWindow.h"
|
||||
#include "AppKit/GSDisplayServer.h"
|
||||
#include "x11/XGSlideView.h"
|
||||
#include <math.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
|
||||
#define DWZ 48
|
||||
#define ALPHA_THRESHOLD 158
|
||||
|
||||
#define XDPY [XGServer currentXDisplay]
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) ((a) > (b) ? (a): (b))
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) ((a) < (b) ? (a): (b))
|
||||
#endif
|
||||
|
||||
#define DMAX 1800
|
||||
#define MAXSTEPS 100
|
||||
|
||||
@interface XGSlideRawWindow : NSWindow
|
||||
@end
|
||||
|
||||
@interface NSImage (BackEnd)
|
||||
- (Pixmap) xPixmapMask;
|
||||
@end
|
||||
// Minimal slide distance per step in pixel
|
||||
#define MINDIST 18
|
||||
// Time for each slide step in seconds
|
||||
#define SLIDE_TIME_STEP 0.02
|
||||
|
||||
@interface XGSlideView (Private)
|
||||
- (void) _setupWindow: (NSPoint)slideStart;
|
||||
- (BOOL) _slideFrom: (NSPoint)fromPoint to: (NSPoint)toPoint;
|
||||
- (void) _setupImage: (NSImage*) image startPoint: (NSPoint)slideStart;
|
||||
- (void) _slideFrom: (NSPoint)fromPoint to: (NSPoint)toPoint;
|
||||
@end
|
||||
|
||||
@implementation XGSlideView (Private)
|
||||
|
||||
- (void) _setupWindow: (NSPoint)slideStart
|
||||
- (void) _setupImage: (NSImage*) image startPoint: (NSPoint)slideStart
|
||||
{
|
||||
NSSize imageSize = [[slideCell image] size];
|
||||
Pixmap pixmap = 0;
|
||||
NSSize imageSize = [image size];
|
||||
|
||||
[_window setFrame: NSMakeRect (slideStart.x, slideStart.y,
|
||||
imageSize.width, imageSize.height) display: NO];
|
||||
[slideCell setImage: image];
|
||||
[_window setFrame: NSMakeRect(slideStart.x, slideStart.y,
|
||||
imageSize.width, imageSize.height)
|
||||
display: NO];
|
||||
|
||||
if ([[[slideCell image] backgroundColor] alphaComponent] * 256
|
||||
<= ALPHA_THRESHOLD)
|
||||
{
|
||||
[self lockFocus];
|
||||
pixmap = [[slideCell image] xPixmapMask];
|
||||
[self unlockFocus];
|
||||
}
|
||||
|
||||
if (pixmap)
|
||||
{
|
||||
XShapeCombineMask(XDPY, slideWindev->ident, ShapeBounding, 0, 0,
|
||||
pixmap, ShapeSet);
|
||||
XFreePixmap(XDPY, pixmap);
|
||||
}
|
||||
else
|
||||
{
|
||||
XShapeCombineMask(XDPY, slideWindev->ident, ShapeBounding,
|
||||
0, 0, 0, ShapeSet);
|
||||
}
|
||||
// Only display the image
|
||||
[GSServerForWindow(_window) restrictWindow: [_window windowNumber]
|
||||
toImage: image];
|
||||
|
||||
[_window orderFrontRegardless];
|
||||
}
|
||||
|
||||
- (BOOL) _slideFrom: (NSPoint)fromPoint to: (NSPoint)toPoint
|
||||
- (void) _slideFrom: (NSPoint)fromPoint to: (NSPoint)toPoint
|
||||
{
|
||||
float sheight = [[NSScreen mainScreen] frame].size.height;
|
||||
float iheight = [[slideCell image] size].height;
|
||||
NSPoint fPoint = NSMakePoint(fromPoint.x, sheight - fromPoint.y - iheight);
|
||||
NSPoint tPoint = NSMakePoint(toPoint.x, sheight - toPoint.y - iheight);
|
||||
float distx = max(fPoint.x, tPoint.x) - min(fPoint.x, tPoint.x);
|
||||
float disty = max(fPoint.y, tPoint.y) - min(fPoint.y, tPoint.y);
|
||||
float distx = toPoint.x - fromPoint.x;
|
||||
float disty = toPoint.y - fromPoint.y;
|
||||
float dist = sqrt((distx * distx) + (disty * disty));
|
||||
float r = DMAX / dist;
|
||||
int steps = (int)(MAXSTEPS / r);
|
||||
float unitx = distx / steps;
|
||||
float unity = disty / steps;
|
||||
float xp = fPoint.x;
|
||||
float yp = fPoint.y;
|
||||
float *xpositions
|
||||
= NSZoneMalloc (NSDefaultMallocZone(), sizeof(float) * steps);
|
||||
float *ypositions
|
||||
= NSZoneMalloc (NSDefaultMallocZone(), sizeof(float) * steps);
|
||||
NSEvent *theEvent;
|
||||
int i;
|
||||
int steps = (int)(dist / MINDIST);
|
||||
int windowNumber = [_window windowNumber];
|
||||
GSDisplayServer *server = GSServerForWindow(_window);
|
||||
|
||||
unitx = (tPoint.x > fPoint.x) ? unitx : -unitx;
|
||||
unity = (tPoint.y > fPoint.y) ? unity : -unity;
|
||||
|
||||
for (i = 0; i < steps; i++)
|
||||
if (steps > 2)
|
||||
{
|
||||
xp += unitx;
|
||||
yp += unity;
|
||||
xpositions[i] = xp;
|
||||
ypositions[i] = yp;
|
||||
float unitx = distx / steps;
|
||||
float unity = disty / steps;
|
||||
|
||||
[NSEvent startPeriodicEventsAfterDelay: SLIDE_TIME_STEP
|
||||
withPeriod: SLIDE_TIME_STEP];
|
||||
while(steps--)
|
||||
{
|
||||
NSEvent *theEvent = [NSApp nextEventMatchingMask: NSPeriodicMask
|
||||
untilDate: [NSDate distantFuture]
|
||||
inMode: NSEventTrackingRunLoopMode
|
||||
dequeue: YES];
|
||||
|
||||
if ([theEvent type] != NSPeriodic)
|
||||
{
|
||||
NSDebugLLog (@"NSDragging",
|
||||
@"Unexpected event type: %d during slide",
|
||||
[theEvent type]);
|
||||
}
|
||||
fromPoint.x += unitx;
|
||||
fromPoint.y += unity;
|
||||
[server movewindow: fromPoint : windowNumber];
|
||||
}
|
||||
[NSEvent stopPeriodicEvents];
|
||||
}
|
||||
|
||||
XFlush(XDPY);
|
||||
[NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.02];
|
||||
for (i = 0; i < steps; i++)
|
||||
{
|
||||
theEvent = [NSApp nextEventMatchingMask: NSPeriodicMask
|
||||
untilDate: [NSDate distantFuture]
|
||||
inMode: NSEventTrackingRunLoopMode
|
||||
dequeue: YES];
|
||||
XMoveWindow (XDPY, slideWindev->ident, xpositions[i], ypositions[i]);
|
||||
}
|
||||
[NSEvent stopPeriodicEvents];
|
||||
|
||||
NSZoneFree (NSDefaultMallocZone(), xpositions);
|
||||
NSZoneFree (NSDefaultMallocZone(), ypositions);
|
||||
|
||||
[[self window] orderOut: nil];
|
||||
|
||||
return YES;
|
||||
// Go exactly to the point
|
||||
[server movewindow: toPoint : windowNumber];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -160,8 +112,8 @@
|
|||
from: (NSPoint)fromPoint
|
||||
to: (NSPoint)toPoint
|
||||
{
|
||||
static XGSlideView *v = nil;
|
||||
BOOL result = NO;
|
||||
static XGSlideView *v = nil;
|
||||
BOOL result = NO;
|
||||
|
||||
if (image != nil)
|
||||
{
|
||||
|
@ -170,9 +122,11 @@
|
|||
v = [[self alloc] init];
|
||||
}
|
||||
[NSApp preventWindowOrdering];
|
||||
[v->slideCell setImage: image];
|
||||
[v _setupWindow: fromPoint];
|
||||
result = [v _slideFrom: fromPoint to: toPoint];
|
||||
[v _setupImage: image startPoint: fromPoint];
|
||||
[v _slideFrom: fromPoint to: toPoint];
|
||||
[[v window] orderOut: nil];
|
||||
|
||||
result = YES;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -182,21 +136,21 @@
|
|||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
NSRect winRect = {{0, 0}, {DWZ, DWZ}};
|
||||
XGSlideRawWindow *slideWindow = [XGSlideRawWindow alloc];
|
||||
// This is never used, as the window gets resized before displaying
|
||||
NSRect winRect = {{0, 0}, {48, 48}};
|
||||
NSWindow *slideWindow;
|
||||
|
||||
slideCell = [[NSCell alloc] initImageCell: nil];
|
||||
[slideCell setBordered: NO];
|
||||
|
||||
slideWindow = [slideWindow initWithContentRect: winRect
|
||||
slideWindow = [[NSWindow alloc] initWithContentRect: winRect
|
||||
styleMask: NSBorderlessWindowMask
|
||||
backing: NSBackingStoreNonretained
|
||||
defer: NO];
|
||||
[slideWindow setReleasedWhenClosed: YES];
|
||||
[slideWindow setExcludedFromWindowsMenu: YES];
|
||||
[slideWindow setContentView: self];
|
||||
RELEASE (self);
|
||||
|
||||
slideWindev
|
||||
= [XGServer _windowWithTag: [slideWindow windowNumber]];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -213,26 +167,4 @@
|
|||
[slideCell drawWithFrame: rect inView: self];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation XGSlideRawWindow
|
||||
|
||||
- (BOOL) canBecomeMainWindow
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) canBecomeKeyWindow
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) _initDefaults
|
||||
{
|
||||
[super _initDefaults];
|
||||
[self setReleasedWhenClosed: YES];
|
||||
[self setExcludedFromWindowsMenu: YES];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue