freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype-demos][gsoc-2024-ahmet] make rules works, a draf


From: @goksu
Subject: [Git][freetype/freetype-demos][gsoc-2024-ahmet] make rules works, a draft swift code developed
Date: Mon, 05 Aug 2024 00:05:19 +0000

Ahmet Göksu pushed to branch gsoc-2024-ahmet at FreeType / FreeType Demo Programs

Commits:

  • 4c894b88
    by Ahmet Goksu at 2024-08-05T03:04:57+03:00
    make rules works, a draft swift code developed
    

4 changed files:

Changes:

  • graph/cocoa/grcocoa.h
    1
    +#ifndef GRCOCOA_H_
    
    2
    +#define GRCOCOA_H_
    
    3
    +
    
    4
    +#include "../grobjs.h"
    
    5
    +#include "../grdevice.h"
    
    6
    +#include <Cocoa/Cocoa.h>
    
    7
    +
    
    8
    +int gr_cocoa_device_init(void);
    
    9
    +void gr_cocoa_device_done(void);
    
    10
    +int gr_cocoa_surface_init(grSurface *surface, grBitmap *bitmap);
    
    11
    +void gr_cocoa_surface_done(grSurface *surface);
    
    12
    +void gr_cocoa_surface_refresh_rectangle(grSurface *surface, int x, int y, int w, int h);
    
    13
    +int gr_cocoa_surface_listen_event(grSurface *surface, int event_mask, grEvent *event);
    
    14
    +
    
    15
    +extern grDevice gr_cocoa_device;
    
    16
    +
    
    17
    +#endif /* GRCOCOA_H_ */

  • graph/cocoa/grcocoa.swift
    1
    +import Cocoa
    
    2
    +
    
    3
    +struct GrCocoaSurface {
    
    4
    +    var root: grSurface
    
    5
    +    var window: NSWindow?
    
    6
    +    var bitmapRep: NSBitmapImageRep?
    
    7
    +    var imageView: NSImageView?
    
    8
    +
    
    9
    +    init(root: grSurface) {
    
    10
    +        self.root = root
    
    11
    +    }
    
    12
    +
    
    13
    +    mutating func initializeSurface(bitmap: inout grBitmap) -> Bool {
    
    14
    +        let width = Int(bitmap.width)
    
    15
    +        let height = Int(bitmap.rows)
    
    16
    +
    
    17
    +        self.bitmapRep = NSBitmapImageRep(
    
    18
    +            bitmapDataPlanes: nil,
    
    19
    +            pixelsWide: width,
    
    20
    +            pixelsHigh: height,
    
    21
    +            bitsPerSample: 8,
    
    22
    +            samplesPerPixel: 4,
    
    23
    +            hasAlpha: true,
    
    24
    +            isPlanar: false,
    
    25
    +            colorSpaceName: .deviceRGB,
    
    26
    +            bitmapFormat: [],
    
    27
    +            bytesPerRow: width * 4,
    
    28
    +            bitsPerPixel: 32
    
    29
    +        )
    
    30
    +
    
    31
    +        self.window = NSWindow(
    
    32
    +            contentRect: NSMakeRect(0, 0, CGFloat(width), CGFloat(height)),
    
    33
    +            styleMask: [.titled, .closable, .resizable],
    
    34
    +            backing: .buffered,
    
    35
    +            defer: false
    
    36
    +        )
    
    37
    +        self.window?.title = "FreeType Cocoa Demo"
    
    38
    +
    
    39
    +        self.imageView = NSImageView(frame: NSMakeRect(0, 0, CGFloat(width), CGFloat(height)))
    
    40
    +        self.imageView?.image = NSImage(size: NSSize(width: width, height: height))
    
    41
    +        self.window?.contentView?.addSubview(self.imageView!)
    
    42
    +        self.window?.makeKeyAndOrderFront(nil)
    
    43
    +
    
    44
    +        self.root.bitmap = bitmap
    
    45
    +        return true
    
    46
    +    }
    
    47
    +
    
    48
    +    mutating func releaseSurface() {
    
    49
    +        self.window?.close()
    
    50
    +        self.bitmapRep = nil
    
    51
    +    }
    
    52
    +
    
    53
    +    func refreshRectangle(x: Int, y: Int, width: Int, height: Int) {
    
    54
    +        // update bitmap data here
    
    55
    +
    
    56
    +        self.imageView?.image?.addRepresentation(self.bitmapRep!)
    
    57
    +        let rect = NSRect(x: CGFloat(x), y: CGFloat(y), width: CGFloat(width), height: CGFloat(height))
    
    58
    +        self.imageView?.setNeedsDisplay(rect)
    
    59
    +    }
    
    60
    +
    
    61
    +    func listenEvent(eventMask: Int32, event: UnsafeMutablePointer<grEvent>) -> Int32 {
    
    62
    +        // event handling here
    
    63
    +        return 0
    
    64
    +    }
    
    65
    +}
    
    66
    +
    
    67
    +// Expose functions to C
    
    68
    +@_cdecl("gr_cocoa_device_init")
    
    69
    +func gr_cocoa_device_init() -> Int32 {
    
    70
    +    // Initialization code for Cocoa
    
    71
    +    return 0
    
    72
    +}
    
    73
    +
    
    74
    +@_cdecl("gr_cocoa_device_done")
    
    75
    +func gr_cocoa_device_done() {
    
    76
    +    // Cleanup code for Cocoa
    
    77
    +}
    
    78
    +
    
    79
    +@_cdecl("gr_cocoa_surface_init")
    
    80
    +func gr_cocoa_surface_init(surface: UnsafeMutablePointer<grSurface>?, bitmap: UnsafeMutablePointer<grBitmap>?) -> Int32 {
    
    81
    +    guard let surface = surface, let bitmap = bitmap else { return 0 }
    
    82
    +    var cocoaSurface = GrCocoaSurface(root: surface.pointee)
    
    83
    +    return cocoaSurface.initializeSurface(bitmap: &bitmap.pointee) ? 1 : 0
    
    84
    +}
    
    85
    +
    
    86
    +@_cdecl("gr_cocoa_surface_done")
    
    87
    +func gr_cocoa_surface_done(surface: UnsafeMutablePointer<grSurface>?) {
    
    88
    +    guard let surface = surface else { return }
    
    89
    +    var cocoaSurface = GrCocoaSurface(root: surface.pointee)
    
    90
    +    cocoaSurface.releaseSurface()
    
    91
    +}
    
    92
    +
    
    93
    +@_cdecl("gr_cocoa_surface_refresh_rectangle")
    
    94
    +func gr_cocoa_surface_refresh_rectangle(surface: UnsafeMutablePointer<grSurface>?, x: Int32, y: Int32, width: Int32, height: Int32) {
    
    95
    +    guard let surface = surface else { return }
    
    96
    +    let cocoaSurface = GrCocoaSurface(root: surface.pointee)
    
    97
    +    cocoaSurface.refreshRectangle(x: Int(x), y: Int(y), width: Int(width), height: Int(height))
    
    98
    +}
    
    99
    +
    
    100
    +@_cdecl("gr_cocoa_surface_listen_event")
    
    101
    +func gr_cocoa_surface_listen_event(surface: UnsafeMutablePointer<grSurface>?, eventMask: Int32, event: UnsafeMutablePointer<grEvent>?) -> Int32 {
    
    102
    +    guard let surface = surface, let event = event else { return 0 }
    
    103
    +    let cocoaSurface = GrCocoaSurface(root: surface.pointee)
    
    104
    +    return cocoaSurface.listenEvent(eventMask: eventMask, event: event)
    
    105
    +}

  • graph/cocoa/rules.mk
    1
    +#**************************************************************************
    
    2
    +#*
    
    3
    +#*  Cocoa specific rules file, used to compile the Cocoa graphics driver
    
    4
    +#*  to the graphics subsystem
    
    5
    +#*
    
    6
    +#**************************************************************************
    
    7
    +
    
    8
    +# Compiler and Flags
    
    9
    +SWIFT := swiftc
    
    10
    +SWIFTFLAGS := -import-objc-header $(GRAPH)/cocoa/grcocoa.h
    
    11
    +
    
    12
    +
    
    13
    +# Cocoa specific settings
    
    14
    +ifeq ($(shell uname -s), Darwin)
    
    15
    +  SWIFT_OBJS += $(OBJ_DIR_2)/grcocoa.o
    
    16
    +  FRAMEWORKS = -framework Cocoa
    
    17
    +  LDFLAGS += $(FRAMEWORKS)
    
    18
    +endif
    
    19
    +
    
    20
    +# Targets
    
    21
    +all: cocoa
    
    22
    +
    
    23
    +cocoa: $(SWIFT_OBJS)
    
    24
    +	@echo "Building Cocoa driver"
    
    25
    +
    
    26
    +$(OBJ_DIR_2)/grcocoa.o: $(GRAPH)/cocoa/grcocoa.swift
    
    27
    +	$(SWIFT) $(SWIFTFLAGS) -c $< -o $@
    
    28
    +
    
    29
    +clean:
    
    30
    +	rm -rf $(OBJ_DIR_2)/*.o

  • graph/grinit.c
    ... ... @@ -29,6 +29,10 @@
    29 29
     #include "mac/grmac.h"
    
    30 30
     #endif
    
    31 31
     
    
    32
    +#ifdef DEVICE_COCOA
    
    33
    +#include "cocoa/grcocoa.h"
    
    34
    +#endif
    
    35
    +
    
    32 36
     #ifdef DEVICE_ALLEGRO
    
    33 37
     #include "allegro/gralleg.h"
    
    34 38
     #endif
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]