Search in sources :

Example 6 with CGRect

use of org.robovm.apple.coregraphics.CGRect in project libgdx by libgdx.

the class IOSApplication method getBounds.

/** GL View spans whole screen, that is, even under the status bar. iOS can also rotate the screen, which is not handled
	 * consistently over iOS versions. This method returns, in pixels, rectangle in which libGDX draws.
	 *
	 * @return dimensions of space we draw to, adjusted for device orientation */
protected CGRect getBounds() {
    final CGRect screenBounds = UIScreen.getMainScreen().getBounds();
    final CGRect statusBarFrame = uiApp.getStatusBarFrame();
    final UIInterfaceOrientation statusBarOrientation = uiApp.getStatusBarOrientation();
    double statusBarHeight = Math.min(statusBarFrame.getWidth(), statusBarFrame.getHeight());
    double screenWidth = screenBounds.getWidth();
    double screenHeight = screenBounds.getHeight();
    // Make sure that the orientation is consistent with ratios. Should be, but may not be on older iOS versions
    switch(statusBarOrientation) {
        case LandscapeLeft:
        case LandscapeRight:
            if (screenHeight > screenWidth) {
                debug("IOSApplication", "Switching reported width and height (w=" + screenWidth + " h=" + screenHeight + ")");
                double tmp = screenHeight;
                // noinspection SuspiciousNameCombination
                screenHeight = screenWidth;
                screenWidth = tmp;
            }
    }
    // update width/height depending on display scaling selected
    screenWidth *= displayScaleFactor;
    screenHeight *= displayScaleFactor;
    if (statusBarHeight != 0.0) {
        debug("IOSApplication", "Status bar is visible (height = " + statusBarHeight + ")");
        statusBarHeight *= displayScaleFactor;
        screenHeight -= statusBarHeight;
    } else {
        debug("IOSApplication", "Status bar is not visible");
    }
    debug("IOSApplication", "Total computed bounds are w=" + screenWidth + " h=" + screenHeight);
    return lastScreenBounds = new CGRect(0.0, statusBarHeight, screenWidth, screenHeight);
}
Also used : UIInterfaceOrientation(org.robovm.apple.uikit.UIInterfaceOrientation) CGRect(org.robovm.apple.coregraphics.CGRect)

Example 7 with CGRect

use of org.robovm.apple.coregraphics.CGRect in project libgdx by libgdx.

the class IOSInput method toTouchEvents.

private void toTouchEvents(long touches) {
    long array = NSSetExtensions.allObjects(touches);
    int length = (int) NSArrayExtensions.count(array);
    for (int i = 0; i < length; i++) {
        long touchHandle = NSArrayExtensions.objectAtIndex$(array, i);
        UITouch touch = UI_TOUCH_WRAPPER.wrap(touchHandle);
        final int locX, locY;
        // Get and map the location to our drawing space
        {
            CGPoint loc = touch.getLocationInView(touch.getWindow());
            final CGRect bounds = app.getCachedBounds();
            locX = (int) (loc.getX() * app.displayScaleFactor - bounds.getMinX());
            locY = (int) (loc.getY() * app.displayScaleFactor - bounds.getMinY());
        // app.debug("IOSInput","pos= "+loc+"  bounds= "+bounds+" x= "+locX+" locY= "+locY);
        }
        synchronized (touchEvents) {
            UITouchPhase phase = touch.getPhase();
            TouchEvent event = touchEventPool.obtain();
            event.x = locX;
            event.y = locY;
            event.phase = phase;
            event.timestamp = (long) (touch.getTimestamp() * 1000000000);
            touchEvents.add(event);
            if (phase == UITouchPhase.Began) {
                event.pointer = getFreePointer();
                touchDown[event.pointer] = touch.getHandle();
                touchX[event.pointer] = event.x;
                touchY[event.pointer] = event.y;
                deltaX[event.pointer] = 0;
                deltaY[event.pointer] = 0;
                numTouched++;
            }
            if (phase == UITouchPhase.Moved || phase == UITouchPhase.Stationary) {
                event.pointer = findPointer(touch);
                deltaX[event.pointer] = event.x - touchX[event.pointer];
                deltaY[event.pointer] = event.y - touchY[event.pointer];
                touchX[event.pointer] = event.x;
                touchY[event.pointer] = event.y;
            }
            if (phase == UITouchPhase.Cancelled || phase == UITouchPhase.Ended) {
                event.pointer = findPointer(touch);
                touchDown[event.pointer] = 0;
                touchX[event.pointer] = event.x;
                touchY[event.pointer] = event.y;
                deltaX[event.pointer] = 0;
                deltaY[event.pointer] = 0;
                numTouched--;
            }
        }
    }
}
Also used : CGPoint(org.robovm.apple.coregraphics.CGPoint) UITouchPhase(org.robovm.apple.uikit.UITouchPhase) UITouch(org.robovm.apple.uikit.UITouch) CGRect(org.robovm.apple.coregraphics.CGRect) CGPoint(org.robovm.apple.coregraphics.CGPoint)

Example 8 with CGRect

use of org.robovm.apple.coregraphics.CGRect in project playn by threerings.

the class RoboTextLayout method wrapLines.

private static CFArray wrapLines(NSAttributedString astring, float wrapWidth) {
    CTFramesetter fs = CTFramesetter.create(astring);
    try {
        // iOS lays things out from max-y up to zero (inverted coordinate system); so we need to
        // provide a large height for our rectangle to ensure that all lines "fit"
        CGPath path = CGPath.createWithRect(new CGRect(0, 0, wrapWidth, Float.MAX_VALUE / 2), CGAffineTransform.Identity());
        CTFrame frame = fs.createFrame(new CFRange(0, 0), path, null);
        return frame.getLines();
    } finally {
        fs.dispose();
    }
}
Also used : CGPath(org.robovm.apple.coregraphics.CGPath) CGRect(org.robovm.apple.coregraphics.CGRect) CFRange(org.robovm.apple.corefoundation.CFRange)

Example 9 with CGRect

use of org.robovm.apple.coregraphics.CGRect in project playn by threerings.

the class TestsGameRoboVM method didFinishLaunching.

@Override
public boolean didFinishLaunching(UIApplication app, UIApplicationLaunchOptions launchOpts) {
    // create a full-screen window
    CGRect bounds = UIScreen.getMainScreen().getBounds();
    UIWindow window = new UIWindow(bounds);
    // configure and register the PlayN platform; start our game
    RoboPlatform.Config config = new RoboPlatform.Config();
    config.orients = UIInterfaceOrientationMask.All;
    RoboPlatform pf = RoboPlatform.register(window, config);
    pf.run(new TestsGame());
    // make our main window visible
    window.makeKeyAndVisible();
    addStrongRef(window);
    return true;
}
Also used : TestsGame(playn.tests.core.TestsGame) CGRect(org.robovm.apple.coregraphics.CGRect) RoboPlatform(playn.robovm.RoboPlatform) UIWindow(org.robovm.apple.uikit.UIWindow)

Example 10 with CGRect

use of org.robovm.apple.coregraphics.CGRect in project playn by threerings.

the class RoboCanvas method fillText.

@Override
public Canvas fillText(TextLayout layout, float x, float y) {
    RoboGradient gradient = currentState().gradient;
    RoboTextLayout ilayout = (RoboTextLayout) layout;
    if (gradient == null) {
        ilayout.fill(bctx, x, y, fillColor);
    } else {
        // draw our text into a fresh context so we can use it as a mask for the gradient
        CGBitmapContext maskContext = RoboGraphics.createCGBitmap(texWidth, texHeight);
        maskContext.clearRect(new CGRect(0, 0, texWidth, texHeight));
        // scale the context based on our scale factor
        maskContext.scaleCTM(ctx.scale.factor, ctx.scale.factor);
        // fill the text into this temp context in white for use as a mask
        setFillColor(maskContext, 0xFFFFFFFF);
        ilayout.fill(maskContext, 0, 0, fillColor);
        // now fill the gradient, using our temp context as a mask
        bctx.saveGState();
        bctx.clipToMask(new CGRect(x, y, width, height), maskContext.toImage());
        gradient.fill(bctx);
        bctx.restoreGState();
        // finally free the temp context
        maskContext.dispose();
    }
    isDirty = true;
    return this;
}
Also used : CGBitmapContext(org.robovm.apple.coregraphics.CGBitmapContext) CGRect(org.robovm.apple.coregraphics.CGRect)

Aggregations

CGRect (org.robovm.apple.coregraphics.CGRect)14 CGBitmapContext (org.robovm.apple.coregraphics.CGBitmapContext)2 CFRange (org.robovm.apple.corefoundation.CFRange)1 CGImage (org.robovm.apple.coregraphics.CGImage)1 CGMutablePath (org.robovm.apple.coregraphics.CGMutablePath)1 CGPath (org.robovm.apple.coregraphics.CGPath)1 CGPoint (org.robovm.apple.coregraphics.CGPoint)1 UIInterfaceOrientation (org.robovm.apple.uikit.UIInterfaceOrientation)1 UITextField (org.robovm.apple.uikit.UITextField)1 UITouch (org.robovm.apple.uikit.UITouch)1 UITouchPhase (org.robovm.apple.uikit.UITouchPhase)1 UIWindow (org.robovm.apple.uikit.UIWindow)1 RoboPlatform (playn.robovm.RoboPlatform)1 TestsGame (playn.tests.core.TestsGame)1