view dwt/internal/cocoa/NSGraphicsContext.d @ 1:8b48be5454ce

The internal cocoa classes compile now
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Tue, 19 Aug 2008 17:35:17 +0200
parents 380af2bdd8e5
children f565d3a95c0a
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     
 * Port to the D Programming language:
 *     Jacob Carlborg <jacob.carlborg@gmail.com>
 *******************************************************************************/
module dwt.internal.cocoa.NSGraphicsContext;

import dwt.internal.cocoa.id;
import dwt.internal.cocoa.NSBitmapImageRep;
import dwt.internal.cocoa.NSDictionary;
import dwt.internal.cocoa.NSImage : NSCompositingOperation;
import dwt.internal.cocoa.NSInteger;
import dwt.internal.cocoa.NSObject;
import dwt.internal.cocoa.NSPoint;
import dwt.internal.cocoa.NSWindow;
import dwt.internal.cocoa.OS;
import objc = dwt.internal.objc.runtime;

alias NSInteger NSColorRenderingIntent;

enum
{
    NSColorRenderingIntentDefault,
    NSColorRenderingIntentAbsoluteColorimetric,
    NSColorRenderingIntentRelativeColorimetric,
    NSColorRenderingIntentPerceptual,
    NSColorRenderingIntentSaturation
}

enum NSImageInterpolation
{
    NSImageInterpolationDefault,
    NSImageInterpolationNone,
    NSImageInterpolationLow,
    NSImageInterpolationHigh
}

public class NSGraphicsContext : NSObject
{

    public this ()
    {
        super();
    }

    public this (objc.id id)
    {
        super(id);
    }

    //public CIContext CIContext() {
    //  objc.id result = OS.objc_msgSend(this.id_, OS.sel_CIContext);
    //  return result !is null ? new CIContext(result) : null;
    //}

    public NSDictionary attributes ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_attributes);
        return result !is null ? new NSDictionary(result) : null;
    }

    public NSColorRenderingIntent colorRenderingIntent ()
    {
        return cast(NSColorRenderingIntent) OS.objc_msgSend(this.id_, OS.sel_colorRenderingIntent);
    }

    public NSCompositingOperation compositingOperation ()
    {
        return cast(NSCompositingOperation) OS.objc_msgSend(this.id_, OS.sel_compositingOperation);
    }

    public static NSGraphicsContext currentContext ()
    {
        objc.id result = OS.objc_msgSend(OS.class_NSGraphicsContext, OS.sel_currentContext);
        return result !is null ? new NSGraphicsContext(result) : null;
    }

    public static bool currentContextDrawingToScreen ()
    {
        return OS.objc_msgSend(OS.class_NSGraphicsContext, OS.sel_currentContextDrawingToScreen) !is null;
    }

    public void flushGraphics ()
    {
        OS.objc_msgSend(this.id_, OS.sel_flushGraphics);
    }

    public id focusStack ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_focusStack);
        return result !is null ? new id(result) : null;
    }

    public static NSGraphicsContext graphicsContextWithAttributes (NSDictionary attributes)
    {
        objc.id result = OS.objc_msgSend(OS.class_NSGraphicsContext, OS.sel_graphicsContextWithAttributes_1,
                attributes !is null ? attributes.id_ : null);
        return result !is null ? new NSGraphicsContext(result) : null;
    }

    public static NSGraphicsContext graphicsContextWithBitmapImageRep (NSBitmapImageRep bitmapRep)
    {
        objc.id result = OS.objc_msgSend(OS.class_NSGraphicsContext, OS.sel_graphicsContextWithBitmapImageRep_1,
                bitmapRep !is null ? bitmapRep.id_ : null);
        return result !is null ? new NSGraphicsContext(result) : null;
    }

    public static NSGraphicsContext graphicsContextWithGraphicsPort (void* graphicsPort, bool initialFlippedState)
    {
        objc.id result = OS.objc_msgSend(OS.class_NSGraphicsContext, OS.sel_graphicsContextWithGraphicsPort_1flipped_1, graphicsPort,
                initialFlippedState);
        return result !is null ? new NSGraphicsContext(result) : null;
    }

    public static NSGraphicsContext graphicsContextWithWindow (NSWindow window)
    {
        objc.id result = OS.objc_msgSend(OS.class_NSGraphicsContext, OS.sel_graphicsContextWithWindow_1, window !is null ? window.id_ : null);
        return result !is null ? new NSGraphicsContext(result) : null;
    }

    public void* graphicsPort ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_graphicsPort);
    }

    public NSImageInterpolation imageInterpolation ()
    {
        return cast(NSImageInterpolation) OS.objc_msgSend(this.id_, OS.sel_imageInterpolation);
    }

    public bool isDrawingToScreen ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_isDrawingToScreen) !is null;
    }

    public bool isFlipped ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_isFlipped) !is null;
    }

    public NSPoint patternPhase ()
    {
        NSPoint result;
        OS.objc_msgSend_stret(&result, this.id_, OS.sel_patternPhase);
        return result;
    }

    public void restoreGraphicsState ()
    {
        OS.objc_msgSend(this.id_, OS.sel_restoreGraphicsState);
    }

    public static void static_restoreGraphicsState ()
    {
        OS.objc_msgSend(OS.class_NSGraphicsContext, OS.sel_restoreGraphicsState);
    }

    public void saveGraphicsState ()
    {
        OS.objc_msgSend(this.id_, OS.sel_saveGraphicsState);
    }

    public static void static_saveGraphicsState ()
    {
        OS.objc_msgSend(OS.class_NSGraphicsContext, OS.sel_saveGraphicsState);
    }

    public void setColorRenderingIntent (NSColorRenderingIntent renderingIntent)
    {
        OS.objc_msgSend(this.id_, OS.sel_setColorRenderingIntent_1, renderingIntent);
    }

    public void setCompositingOperation (NSCompositingOperation operation)
    {
        OS.objc_msgSend(this.id_, OS.sel_setCompositingOperation_1, operation);
    }

    public static void setCurrentContext (NSGraphicsContext context)
    {
        OS.objc_msgSend(OS.class_NSGraphicsContext, OS.sel_setCurrentContext_1, context !is null ? context.id_ : null);
    }

    public void setFocusStack (id stack)
    {
        OS.objc_msgSend(this.id_, OS.sel_setFocusStack_1, stack !is null ? stack.id_ : null);
    }

    public static void setGraphicsState (NSInteger gState)
    {
        OS.objc_msgSend(OS.class_NSGraphicsContext, OS.sel_setGraphicsState_1, gState);
    }

    public void setImageInterpolation (NSImageInterpolation interpolation)
    {
        OS.objc_msgSend(this.id_, OS.sel_setImageInterpolation_1, interpolation);
    }

    public void setPatternPhase (NSPoint phase)
    {
        OS.objc_msgSend(this.id_, OS.sel_setPatternPhase_1, phase);
    }

    public void setShouldAntialias (bool antialias)
    {
        OS.objc_msgSend(this.id_, OS.sel_setShouldAntialias_1, antialias);
    }

    public bool shouldAntialias ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_shouldAntialias) !is null;
    }

}