D言語からObjective-CとCocoaAPIを使いたい

NSImage関連を含 NSControl関連から分けてみました。

サンプルコード

Powered by Prism

cocoa/images.d

/**
 *    cocoa.images.d      version 0.0.1;
 */
module cocoa.images;
import core.attribute : optional, selector;
// import std.conv : to;
import std.stdio;
import cocoa.window;
import cocoa.control;

/*  control.d   === 
extern (Objective-C)
extern class NSImage {
    static NSImage alloc() @selector("alloc");
    NSImage init(NSString) @selector("initWithContentsOfFile:");
    NSImage init(NSURL) @selector("initWithContentsOfURL:");
    void draw(NSRect) @selector("drawInRect:");
    void draw(NSPoint, NSRect, NSUInteger, CGFloat)
        @selector("drawAtPoint:fromRect:operation:fraction:");
    NSSize size() @selector("size");
    // void drawInRect(NSRect, NSRect, NSUInteger, CGFloat, BOOL, NSDictionary)
    //     @selector("drawInRect:fromRect:operation:fraction:respectFlipped, hints");
    // void drawRepresentation() @selector("drawRepresentation:inRect:");
    // void setScale(NSUInteger) @selector("setImageScaling:");
} */

/*   window.d ===
extern (Objective-C) 
extern class NSURL {
    static NSURL urlPath(NSString) @selector("fileURLWithPath:");
    static NSURL url(NSString, NSURL) @selector("URLWithString:relativeToURL:");
    NSString toNsStr() @selector("absoluteString");
    static NSURL toNsURL(NSString) @selector("URLWithString:");
} */

extern (Objective-C)
extern class NSBundle : NSObject {
    static NSBundle mainBundle() @selector("mainBundle");
    NSString path(NSString, NSString) @selector("pathForResource:ofType:");
    NSString url(NSString) @selector("bundleWithURL:");
}

extern (Objective-C)
extern class NSImageView : NSControl {
    /* Creating the view */
    override static NSImageView alloc() @selector("alloc"); // ??
    override NSImageView init(NSRect) @selector("initWithFrame:");   // ??
    static NSImageView imageViewWithImage(NSImage) @selector("imageViewWithImage:");
    static NSImageView init(NSImage) @selector("imageViewWithImage:");
    /* Configuring the cell */ 
    /* Specifying the image */
    NSImageSymbolConfiguration symbolConfiguration() @selector("symbolConfiguration");
    NSImage image() @selector("image");
    void image(NSImage) @selector("setImage:");
    /* Specifying the visual characteristics */  
    NSImageFrameStyle imageFrameStyle() @selector("imageFrameStyle");
    NSImageAlignment imageAlignment() @selector("imageAlignment");
    NSImageScaling imageScaling() @selector("imageScaling");
    NSImageScaling imageScale() @selector("imageScaling");
    void imageScale(NSUInteger) @selector("setImageScaling:");
    bool animates() @selector("animates");
    NSColor contentTintColor() @selector("contentTintColor");
    /* Specifying the dynamic range */  

}

alias ImageFrame = NSImageFrameStyle;
enum NSImageFrameStyle : NSUInteger {
    None = 0,
    // photo,      // Deprecated
    GrayBezel,
    // Groove,     // Deprecated
    // Button,     // Deprecated
}

alias ImageAlign = NSImageAlignment;
enum NSImageAlignment : NSUInteger {
    Center = 0,
    Top,
    TopLeft,
    TopRight,
    Left,
    Bottom,
    BottomLeft,
    BottomRight,
    Right,
}

alias ImageScale = NSImageScaling;
enum NSImageScaling : NSUInteger {
    ProportionallyDown = 0, // 縦横比を維持したまま画像を縮小
    AxesIndependently,      // 画像の縦横比は保持されない
    None,                   // 画像の拡大縮小をしない
    ProportionallyUpOrDown  // 縦横比を維持しながら、最大にする
}

extern (Objective-C)
extern class NSImageCell : NSCell { }

extern (Objective-C)
extern class NSCell :NSObject { }

extern (Objective-C)
extern class NSImageSymbolConfiguration : NSObject { } 
            
cocoa/window.d
cocoa/control.d