Author: fredkiefer
Date: Tue Aug 25 23:33:04 2015
New Revision: 38929

URL: http://svn.gna.org/viewcvs/gnustep?rev=38929&view=rev
Log:
        * Tests/gui/NSView/NSView_autoresize_and_rounding.m: Add tests
        for centerScanRect: with flipped view.
        * Source/NSView.m (-centerScanRect:): Change to get the failed
        tests to pass.
        * Source/GSThemeTools.m (-drawRoundBezel:withColor:): Make round
        bezel look a bit nicer.
        * Source/NSButtonCell.m (-drawImage:withFrame:inView:): Use
        centerScanRect: instead of similar code.
        * Source/NSCell.m: Use imageRectForBounds: and
        titleRectForBounds: in drawInteriorWithFrame:inView:.

Modified:
    libs/gui/trunk/ChangeLog
    libs/gui/trunk/Source/GSThemeTools.m
    libs/gui/trunk/Source/NSButtonCell.m
    libs/gui/trunk/Source/NSCell.m
    libs/gui/trunk/Source/NSView.m
    libs/gui/trunk/Tests/gui/NSView/NSView_autoresize_and_rounding.m

Modified: libs/gui/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=38929&r1=38928&r2=38929&view=diff
==============================================================================
--- libs/gui/trunk/ChangeLog    (original)
+++ libs/gui/trunk/ChangeLog    Tue Aug 25 23:33:04 2015
@@ -1,3 +1,16 @@
+2015-08-25 Fred Kiefer <[email protected]>
+
+       * Tests/gui/NSView/NSView_autoresize_and_rounding.m: Add tests for
+       centerScanRect: with flipped view.
+       * Source/NSView.m (-centerScanRect:): Change to get the failed
+       tests to pass.
+       * Source/GSThemeTools.m (-drawRoundBezel:withColor:): Make round
+       bezel look a bit nicer.
+       * Source/NSButtonCell.m (-drawImage:withFrame:inView:): Use
+       centerScanRect: instead of similar code.
+       * Source/NSCell.m: Use imageRectForBounds: and titleRectForBounds:
+       in drawInteriorWithFrame:inView:.
+
 2015-08-24 Riccardo Mottola <[email protected]>
 
        * Headers/AppKit/NSWindow.h

Modified: libs/gui/trunk/Source/GSThemeTools.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/GSThemeTools.m?rev=38929&r1=38928&r2=38929&view=diff
==============================================================================
--- libs/gui/trunk/Source/GSThemeTools.m        (original)
+++ libs/gui/trunk/Source/GSThemeTools.m        Tue Aug 25 23:33:04 2015
@@ -409,16 +409,16 @@
 
 - (void) drawRoundBezel: (NSRect)cellFrame withColor: (NSColor*)backgroundColor
 {
-  NSBezierPath *p = [NSBezierPath bezierPath];
+  NSBezierPath *p;
   NSPoint point;
   CGFloat radius;
 
   // make smaller than enclosing frame
-  cellFrame = NSInsetRect(cellFrame, 4, floor(cellFrame.size.height * 0.1875));
+  cellFrame = NSInsetRect(cellFrame, 4, 4);
   radius = cellFrame.size.height / 2.0;
   point = cellFrame.origin;
   point.x += radius;
-  point.y += radius;
+  point.y += radius - 0.5;
 
   // Draw initial path to enclose the button...
   // left half-circle
@@ -446,13 +446,13 @@
 
   // Add highlights...
   point = cellFrame.origin;
-  point.x += radius;
-  point.y += radius;
+  point.x += radius - 0.5;
+  point.y += radius - 0.5;
   p = [NSBezierPath bezierPath];
-  [p setLineWidth: 2.0];
+  [p setLineWidth: 1.0];
   [p appendBezierPathWithArcWithCenter: point
                                radius: radius
-                           startAngle: 120.0
+                           startAngle: 135.0
                              endAngle: 270.0];
 
   // line to first point and right halfcircle
@@ -460,7 +460,7 @@
   [p appendBezierPathWithArcWithCenter: point
                                radius: radius
                            startAngle: 270.0
-                             endAngle: 270.0];
+                             endAngle: 315.0];
   [[NSColor controlLightHighlightColor] set];
   [p stroke];
 }

Modified: libs/gui/trunk/Source/NSButtonCell.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSButtonCell.m?rev=38929&r1=38928&r2=38929&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSButtonCell.m        (original)
+++ libs/gui/trunk/Source/NSButtonCell.m        Tue Aug 25 23:33:04 2015
@@ -1015,47 +1015,23 @@
                                  toFitInSize: cellFrame.size
                                  scalingType: _imageScaling];
 
-      /* Pixel-align size */
-
-      if (controlView)
-       {
-         NSSize sizeInBase = [controlView convertSizeToBase: size];
-         sizeInBase.width = GSRoundTowardsInfinity(sizeInBase.width);
-         sizeInBase.height = GSRoundTowardsInfinity(sizeInBase.height);
-         size = [controlView convertSizeFromBase: sizeInBase];
-       }
-
       /* Calculate an offset from the cellFrame origin */
-     
       offset = NSMakePoint((NSWidth(cellFrame) - size.width) / 2.0,
-                                (NSHeight(cellFrame) - size.height) / 2.0);
-
-      /* Pixel-align the offset */
-
-      if (controlView)
-       {
-         NSPoint inBase = [controlView convertPointToBase: offset];
-         
-         // By convention we will round down and to the right.
-         // With the standard button design this looks good
-         // because the bottom and right edges of the button look 'heavier'
-         // so if the image's center must be offset from the button's geometric
-         // center, it looks beter if it's closer to the 'heavier' part
-         
-         inBase.x = GSRoundTowardsInfinity(inBase.x);
-         inBase.y = [controlView isFlipped] ? 
-           GSRoundTowardsInfinity(inBase.y) :
-           GSRoundTowardsNegativeInfinity(inBase.y);
-         
-         offset = [controlView convertPointFromBase: inBase];
-       }
-
-      /* Draw the image */
+                           (NSHeight(cellFrame) - size.height) / 2.0);
 
       rect = NSMakeRect(cellFrame.origin.x + offset.x,
                        cellFrame.origin.y + offset.y,
                        size.width,
                        size.height);
+
+      /* Pixel-align */
+      if (nil != controlView)
+        {
+          rect = [controlView centerScanRect: rect];
+        }
+
+      /* Draw the image */
+
       fraction = (![self isEnabled] &&
                  [self imageDimsWhenDisabled]) ? 0.5 : 1.0;
       

Modified: libs/gui/trunk/Source/NSCell.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSCell.m?rev=38929&r1=38928&r2=38929&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSCell.m      (original)
+++ libs/gui/trunk/Source/NSCell.m      Tue Aug 25 23:33:04 2015
@@ -1979,18 +1979,11 @@
   return NSInsetRect(theRect, borderSize.width, borderSize.height);
 }
 
-/**<p>The GNUstep implementation returns -drawingRectForBounds:</p>
+/**<p>Frame the image gets drawn in</p>
  */
 - (NSRect) imageRectForBounds: (NSRect)theRect
 {
-  return [self drawingRectForBounds: theRect];
-}
-
-/** <p>TODO</p>
- */
-- (NSRect) titleRectForBounds: (NSRect)theRect
-{
-  if (_cell.type == NSTextCellType)
+  if (_cell.type == NSImageCellType)
     {
       NSRect frame = [self drawingRectForBounds: theRect];
       
@@ -2010,6 +2003,30 @@
     }
 }
 
+/** <p>Frame the title gets drawn in</p>
+ */
+- (NSRect) titleRectForBounds: (NSRect)theRect
+{
+  if (_cell.type == NSTextCellType)
+    {
+      NSRect frame = [self drawingRectForBounds: theRect];
+      
+      // Add spacing between border and inside 
+      if (_cell.is_bordered || _cell.is_bezeled)
+        {
+          frame.origin.x += 3;
+          frame.size.width -= 6;
+          frame.origin.y += 1;
+          frame.size.height -= 2;
+        }
+      return frame;
+    }
+  else
+    {
+      return theRect;
+    }
+}
+
 - (void) setControlSize: (NSControlSize)controlSize
 {
   _cell.control_size = controlSize;
@@ -2050,18 +2067,6 @@
  */
 - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
 {
-  NSRect drawingRect = [self drawingRectForBounds: cellFrame];
-
-  //FIXME: Check if this is also neccessary for images,
-  // Add spacing between border and inside 
-  if (_cell.is_bordered || _cell.is_bezeled)
-    {
-      drawingRect.origin.x += 3;
-      drawingRect.size.width -= 6;
-      drawingRect.origin.y += 1;
-      drawingRect.size.height -= 2;
-    }
-
   switch (_cell.type)
     {
       case NSTextCellType:
@@ -2069,7 +2074,7 @@
          [self _drawEditorWithFrame: cellFrame inView: controlView];
        else
          [self _drawAttributedText: [self _drawAttributedString]
-                           inFrame: drawingRect];
+                           inFrame: [self titleRectForBounds: cellFrame]];
         break;
 
       case NSImageCellType:
@@ -2077,12 +2082,20 @@
           {
             NSSize size;
             NSPoint position;
-            
+            NSRect drawingRect = [self imageRectForBounds: cellFrame];
+            NSRect rect;
+           
             size = [_cell_image size];
             position.x = MAX(NSMidX(drawingRect) - (size.width/2.),0.);
             position.y = MAX(NSMidY(drawingRect) - (size.height/2.),0.);
-
-            [_cell_image drawInRect: NSMakeRect(position.x, position.y, 
size.width, size.height)
+            rect = NSMakeRect(position.x, position.y, size.width, size.height);
+
+            if (nil != controlView)
+              {
+                rect = [controlView centerScanRect: rect];
+              }
+
+            [_cell_image drawInRect: rect
                           fromRect: NSZeroRect
                          operation: NSCompositeSourceOver
                           fraction: 1.0

Modified: libs/gui/trunk/Source/NSView.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSView.m?rev=38929&r1=38928&r2=38929&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSView.m      (original)
+++ libs/gui/trunk/Source/NSView.m      Tue Aug 25 23:33:04 2015
@@ -1656,6 +1656,8 @@
 - (NSRect) centerScanRect: (NSRect)aRect
 {
   NSAffineTransform    *matrix;
+  CGFloat x_org;
+  CGFloat y_org;
 
   /*
    *   Hmm - we assume that the windows coordinate system is centered on the
@@ -1670,10 +1672,12 @@
       aRect.size.height = -aRect.size.height;
     }
 
+  x_org = aRect.origin.x;
+  y_org = aRect.origin.y;
   aRect.origin.x = GSRoundTowardsInfinity(aRect.origin.x);
-  aRect.origin.y = GSRoundTowardsInfinity(aRect.origin.y);
-  aRect.size.width = GSRoundTowardsInfinity(aRect.size.width);
-  aRect.size.height = GSRoundTowardsInfinity(aRect.size.height);
+  aRect.origin.y = [self isFlipped] ? 
GSRoundTowardsNegativeInfinity(aRect.origin.y) : 
GSRoundTowardsInfinity(aRect.origin.y);
+  aRect.size.width = GSRoundTowardsInfinity(aRect.size.width + (x_org - 
aRect.origin.x) / 2.0);
+  aRect.size.height = GSRoundTowardsInfinity(aRect.size.height + (y_org - 
aRect.origin.y) / 2.0);
 
   matrix = [self _matrixFromWindow];
   aRect.origin = [matrix transformPoint: aRect.origin];

Modified: libs/gui/trunk/Tests/gui/NSView/NSView_autoresize_and_rounding.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Tests/gui/NSView/NSView_autoresize_and_rounding.m?rev=38929&r1=38928&r2=38929&view=diff
==============================================================================
--- libs/gui/trunk/Tests/gui/NSView/NSView_autoresize_and_rounding.m    
(original)
+++ libs/gui/trunk/Tests/gui/NSView/NSView_autoresize_and_rounding.m    Tue Aug 
25 23:33:04 2015
@@ -37,7 +37,14 @@
        return rects_almost_equal(r, frame);
 }
 
-
+@interface TestView : NSView
+@end
+@implementation TestView
+-(BOOL) isFlipped
+{
+  return YES;
+}
+@end
 
 
 int main(int argc, char **argv)
@@ -225,6 +232,27 @@
          [view2 release];
        }
 
+       {
+         NSView *view2 = [[TestView alloc] initWithFrame: NSMakeRect(0, 0, 
100, 100)];
+         
+          testHopeful = YES;
+         PASS(rects_almost_equal([view2 centerScanRect: NSMakeRect(0.5, 0.5, 
100, 100)],
+                                 NSMakeRect(1, 0, 100, 100)),
+              "centerScanRect works 1");
+         PASS(rects_almost_equal([view2 centerScanRect: NSMakeRect(0.9, 0.9, 
99.9, 99.9)],
+                                 NSMakeRect(1, 1, 100, 100)),
+              "centerScanRect works 2");       
+         PASS(rects_almost_equal([view2 centerScanRect: NSMakeRect(0.9, 0.9, 
99.4, 99.4)],
+                                 NSMakeRect(1, 1, 99, 99)),
+              "centerScanRect works 3");
+         PASS(rects_almost_equal([view2 centerScanRect: NSMakeRect(0.4, 0.4, 
99.4, 99.4)],
+                                 NSMakeRect(0, 0, 100, 100)),
+              "centerScanRect works 4");
+          testHopeful = NO;
+
+         [view2 release];
+       }
+
        DESTROY(arp);
        return 0;
 }


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to