From d3d258a1b2aab8dd3be4d6ce27e0a664a681a840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 11 Mar 2015 18:14:12 +0100 Subject: iOS: Add platform plugin option to debug window management When the 'debugWindowManagement' option is enabled, e.g. by passing the argument -platform ios:debugWindowManagement to the application, the plugin will add a background color and outline to all QUIViews, as well as draw a grid for the underlying QUIViewController. This makes it easier to see where windows are placed when the window itself doesn't draw anything, e.g. in unit tests. Change-Id: If9a59822e0b320b154ad8e338f9fb5ec7cf191a2 Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/qiosviewcontroller.mm | 51 +++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/plugins/platforms/ios/qiosviewcontroller.mm') diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index d144b419aa..9abd105d94 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -41,6 +41,7 @@ #include +#include "qiosintegration.h" #include "qiosscreen.h" #include "qiosglobal.h" #include "qioswindow.h" @@ -64,6 +65,56 @@ @implementation QIOSDesktopManagerView +- (id)init +{ + if (!(self = [super init])) + return nil; + + QIOSIntegration *iosIntegration = QIOSIntegration::instance(); + if (iosIntegration && iosIntegration->debugWindowManagement()) { + static UIImage *gridPattern = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + CGFloat dimension = 100.f; + + UIGraphicsBeginImageContextWithOptions(CGSizeMake(dimension, dimension), YES, 0.0f); + CGContextRef context = UIGraphicsGetCurrentContext(); + + CGContextTranslateCTM(context, -0.5, -0.5); + + #define gridColorWithBrightness(br) \ + [UIColor colorWithHue:0.6 saturation:0.0 brightness:br alpha:1.0].CGColor + + CGContextSetFillColorWithColor(context, gridColorWithBrightness(0.05)); + CGContextFillRect(context, CGRectMake(0, 0, dimension, dimension)); + + CGFloat gridLines[][2] = { { 10, 0.1 }, { 20, 0.2 }, { 100, 0.3 } }; + for (size_t l = 0; l < sizeof(gridLines) / sizeof(gridLines[0]); ++l) { + CGFloat step = gridLines[l][0]; + for (int c = step; c <= dimension; c += step) { + CGContextMoveToPoint(context, c, 0); + CGContextAddLineToPoint(context, c, dimension); + CGContextMoveToPoint(context, 0, c); + CGContextAddLineToPoint(context, dimension, c); + } + + CGFloat brightness = gridLines[l][1]; + CGContextSetStrokeColorWithColor(context, gridColorWithBrightness(brightness)); + CGContextStrokePath(context); + } + + gridPattern = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + [gridPattern retain]; + }); + + self.backgroundColor = [UIColor colorWithPatternImage:gridPattern]; + } + + return self; +} + - (void)didAddSubview:(UIView *)subview { Q_UNUSED(subview); -- cgit v1.2.3