Fix up lockFocus, restoring graphics context.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4243 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 1999-05-11 15:43:10 +00:00
parent 0c507ab2d0
commit ac26385d09
12 changed files with 129 additions and 12 deletions

View file

@ -1,3 +1,29 @@
1999-05-11 Adam Fedor <fedor@gnu.org>
* Source/NSButtonCell.m ([NSButtonCell
-drawInteriorWithFrame:inView:]): gsave/grestore around image/text
to return to original clipping rect for second half of drawing.
* Source/NSCell.m ([NSCell -_drawText:title:cellFrame]): PointSize
does not include descender.
(-highlight:withFrame:inView:): gsave/grestore to return to
original for second highlight call.
* Source/NSControl.m ([NSControl -mouseDown:]): Remove extra
lockFocus.
* Source/NSMenu.m ([NSMenuMatrix -initWithFrame:]): Font descender
is a negative number.
* Source/NSStringDrawing.m (sizeLine): Likewise.
(setupRun): Likewise.
(drawRun): Awful hack to get DGS to flush strings.
* Headers/gnustep/gui/DPSOperators.h (DPSflush): Added operator.
* Headers/gnustep/gui/GSMethodTable.h: Likewise.
* Headers/gnustep/gui/NSGraphicsContext.h: Likewise.
* Headers/gnustep/gui/PSOperators.h: Likewise.
* Source/NSGraphicsContext.m: Likewise.
Mon May 10 9:50:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Headers/AppKit/NSGraphicsContext.h: Added GSCurrentContext() for

View file

@ -340,6 +340,13 @@ static inline void
DPStranslate(GSCTXT *ctxt, float x, float y)
__attribute__((unused));
/* ----------------------------------------------------------------------- */
/* I/O Operations operations */
/* ----------------------------------------------------------------------- */
static inline void
DPSflush(GSCTXT *ctxt)
__attribute__((unused));
/* ----------------------------------------------------------------------- */
/* Matrix operations */
/* ----------------------------------------------------------------------- */
@ -1223,6 +1230,16 @@ DPStranslate(GSCTXT *ctxt, float x, float y)
(ctxt, @selector(DPStranslate::), x, y);
}
/* ----------------------------------------------------------------------- */
/* I/O Operations operations */
/* ----------------------------------------------------------------------- */
static inline void
DPSflush(GSCTXT *ctxt)
{
(ctxt->methods->DPSflush)
(ctxt, @selector(DPSflush));
}
/* ----------------------------------------------------------------------- */
/* Matrix operations */
/* ----------------------------------------------------------------------- */

View file

@ -196,6 +196,11 @@ typedef struct {
void (*DPStranslate__)
(NSGraphicsContext*, SEL, float, float);
/* ----------------------------------------------------------------------- */
/* I/O operations */
/* ----------------------------------------------------------------------- */
void (*DPSflush)
(NSGraphicsContext*, SEL);
/* ----------------------------------------------------------------------- */
/* Matrix operations */
/* ----------------------------------------------------------------------- */
void (*DPSconcatmatrix)

View file

@ -229,6 +229,10 @@ NSGraphicsContext *GSCurrentContext();
- (void) DPSsettransfer;
- (void) DPStranslate: (float)x : (float)y ;
/* ----------------------------------------------------------------------- */
/* I/O operations */
/* ----------------------------------------------------------------------- */
- (void) DPSflush;
/* ----------------------------------------------------------------------- */
/* Matrix operations */
/* ----------------------------------------------------------------------- */
- (void) DPSconcatmatrix;

View file

@ -340,6 +340,13 @@ static inline void
PStranslate(float x, float y)
__attribute__((unused));
/* ----------------------------------------------------------------------- */
/* I/O Operations operations */
/* ----------------------------------------------------------------------- */
static inline void
PSflush()
__attribute__((unused));
/* ----------------------------------------------------------------------- */
/* Matrix operations */
/* ----------------------------------------------------------------------- */
@ -1147,6 +1154,15 @@ PStranslate(float x, float y)
DPStranslate(DEFCTXT, x, y);
}
/* ----------------------------------------------------------------------- */
/* I/O Operations operations */
/* ----------------------------------------------------------------------- */
static inline void
PSflush()
{
DPSflush(DEFCTXT);
}
/* ----------------------------------------------------------------------- */
/* Matrix operations */
/* ----------------------------------------------------------------------- */

View file

@ -54,10 +54,10 @@ ADDITIONAL_CPPFLAGS = -DGNUSTEP_INSTALL_LIBDIR=\"$(GNUSTEP_INSTALL_LIBDIR)\" \
# Additional flags to pass to the Objective-C compiler
ADDITIONAL_OBJCFLAGS = -g -Wall
ADDITIONAL_OBJCFLAGS = -Wall
# Additional flags to pass to the C compiler
ADDITIONAL_CFLAGS = -g
ADDITIONAL_CFLAGS =
# Additional include directories the compiler should search
ADDITIONAL_INCLUDE_DIRS = -I../Headers

View file

@ -501,7 +501,11 @@
rect.origin = cellFrame.origin;
rect.size.width = imageSize.width;
rect.size.height = cellFrame.size.height;
/* Have to save the gstate, since a new clip rect may be defined
when drawing */
PSgsave();
[self _drawImage: imageToDisplay inFrame: rect];
PSgrestore();
// draw title
rect.origin.x += imageSize.width + xDist;
@ -515,7 +519,11 @@
rect.origin.y = cellFrame.origin.y;
rect.size.width = imageSize.width;
rect.size.height = cellFrame.size.height;
/* Have to save the gstate, since a new clip rect may be defined
when drawing */
PSgsave();
[self _drawImage: imageToDisplay inFrame: rect];
PSgrestore();
// draw title
rect.origin = cellFrame.origin;
@ -527,7 +535,11 @@
case NSImageBelow:
// draw image below title
cellFrame.size.height /= 2;
/* Have to save the gstate, since a new clip rect may be defined
when drawing */
PSgsave();
[self _drawImage: imageToDisplay inFrame: cellFrame];
PSgrestore();
cellFrame.origin.y += cellFrame.size.height;
[self _drawText: titleToDisplay inFrame: cellFrame];
break;
@ -535,14 +547,22 @@
case NSImageAbove:
// draw image above title
cellFrame.size.height /= 2;
/* Have to save the gstate, since a new clip rect may be defined
when drawing */
PSgsave();
[self _drawText: titleToDisplay inFrame: cellFrame];
PSgrestore();
cellFrame.origin.y += cellFrame.size.height;
[self _drawImage: imageToDisplay inFrame: cellFrame];
break;
case NSImageOverlaps:
// draw title over the image
/* Have to save the gstate, since a new clip rect may be defined
when drawing */
PSgsave();
[self _drawImage: imageToDisplay inFrame: cellFrame];
PSgrestore();
[self _drawText: titleToDisplay inFrame: cellFrame];
break;
}

View file

@ -573,7 +573,7 @@
[NSException raise: NSInvalidArgumentException
format: @"Request to draw a text cell but no font specified!"];
titleWidth = [font widthOfString: title];
titleHeight = [font pointSize];
titleHeight = [font pointSize] - [font descender];
// Determine the y position of the text
cellFrame.origin.y = NSMidY (cellFrame) - titleHeight / 2;
@ -708,7 +708,9 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
if (cell_highlighted != lit)
{
cell_highlighted = lit;
PSgsave();
[self drawWithFrame: cellFrame inView: controlView];
PSgrestore();
}
}

View file

@ -473,7 +473,6 @@ static id _NSCONTROL_CELL_CLASS = nil;
if (mouseUp)
{
[self lockFocus];
// [cell setState: ![cell state]];
[cell highlight: NO withFrame: bounds inView: self];
[window flushWindow];

View file

@ -436,6 +436,11 @@ struct NSWindow_struct
methodTable.DPStranslate__ =
GET_IMP(@selector(DPStranslate::));
/* ----------------------------------------------------------------------- */
/* I/O operations */
/* ----------------------------------------------------------------------- */
methodTable.DPSflush =
GET_IMP(@selector(DPSflush));
/* ----------------------------------------------------------------------- */
/* Matrix operations */
/* ----------------------------------------------------------------------- */
methodTable.DPSconcatmatrix =
@ -1031,6 +1036,14 @@ struct NSWindow_struct
[self subclassResponsibility: _cmd];
}
/* ----------------------------------------------------------------------- */
/* Matrix operations */
/* ----------------------------------------------------------------------- */
- (void) DPSflush
{
[self subclassResponsibility: _cmd];
}
/* ----------------------------------------------------------------------- */
/* Matrix operations */
/* ----------------------------------------------------------------------- */

View file

@ -83,7 +83,7 @@ static NSFont* menuFont = nil;
if (!menuFont)
menuFont = [[NSFont systemFontOfSize: 0] retain];
cellSize = NSMakeSize (1, [menuFont pointSize] - [menuFont descender] + 6);
cellSize = NSMakeSize (1, [menuFont pointSize] + [menuFont descender] + 6);
return self;
}

View file

@ -238,8 +238,8 @@ sizeLine(NSAttributedString *str,
*/
// FIXME - superscript should have some effect on height.
below = [font descender];
above = [font pointSize] - below;
below = -([font descender]);
above = [font pointSize];
if (base > 0)
above += base; // Character is above baseline.
else if (base < 0)
@ -484,11 +484,11 @@ drawRun(GSTextRun *run, NSPoint origin, GSDrawInfo *draw)
*/
if (draw->flip)
{
origin.y += run->height - run->baseline;
origin.y += (run->height - run->baseline);
}
else
{
origin.y -= run->height - run->baseline;
origin.y -= (run->height - run->baseline);
}
/*
@ -522,6 +522,14 @@ drawRun(GSTextRun *run, NSPoint origin, GSDrawInfo *draw)
buf[i] = '\0';
DPSmoveto(draw->ctxt, origin.x, origin.y);
DPSshow(draw->ctxt, buf);
/* FIXME - Figure out why DGS fails to flush strings and remove this
aweful hack which doesn't even work all the time: */
DPSmoveto(draw->ctxt, origin.x, origin.y);
DPSshow(draw->ctxt, buf);
DPSmoveto(draw->ctxt, origin.x, origin.y);
DPSshow(draw->ctxt, buf);
DPSmoveto(draw->ctxt, origin.x, origin.y);
DPSshow(draw->ctxt, buf);
}
else
{
@ -536,6 +544,14 @@ drawRun(GSTextRun *run, NSPoint origin, GSDrawInfo *draw)
DPSshow(draw->ctxt, buf);
origin.x += run->glyphs[i].adv.width;
}
/* FIXME - Figure out why DGS fails to flush strings and remove this
aweful hack which doesn't even work all the time: */
DPSmoveto(draw->ctxt, origin.x, origin.y);
DPSshow(draw->ctxt, buf);
DPSmoveto(draw->ctxt, origin.x, origin.y);
DPSshow(draw->ctxt, buf);
DPSmoveto(draw->ctxt, origin.x, origin.y);
DPSshow(draw->ctxt, buf);
}
if (run->underline)
@ -623,8 +639,8 @@ setupRun(GSTextRun *run, unsigned length, unichar *chars, unsigned pos,
* Calculate height of line from font information and base offset.
* FIXME - should include superscript information here.
*/
below = [run->font descender];
above = [run->font pointSize] - below;
below = -([run->font descender]);
above = [run->font pointSize];
if (run->base > 0)
above += run->base; // Character is above baseline.
else if (run->base < 0)
@ -1236,7 +1252,6 @@ setupLine(GSTextLine *line, NSAttributedString *str, NSRange range,
point.y = rect.origin.y + rect.size.height;
[self drawAtPoint: point];
NSRectClip([view bounds]);
}
- (NSSize) size