From b51965dbd99d7f3401ce486de82ca3a3ce503dd8 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Sun, 2 Oct 2022 20:49:10 -0500 Subject: [PATCH] Simplify linking to only be in gosu.cr, added windows only linker calls, ran formatter, added new Gosu.clipboard/clipboard= methods --- src/gosu.cr | 16 ++++++++++++++++ src/gosu/channel.cr | 1 - src/gosu/color.cr | 1 - src/gosu/font.cr | 1 - src/gosu/image.cr | 1 - src/gosu/sample.cr | 1 - src/gosu/song.cr | 1 - src/gosu/text_input.cr | 1 - src/gosu/window.cr | 1 - 9 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/gosu.cr b/src/gosu.cr index f578c60..fdf2f77 100644 --- a/src/gosu.cr +++ b/src/gosu.cr @@ -17,6 +17,11 @@ module Gosu # Returns version of Gosu that gosu.cr was built/tested against VERSION = "1.2.0" + {% if flag?(:windows) %} + @[Link("gdi32")] + @[Link("user32")] + @[Link("Gosu")] + {% end %} @[Link("gosu-ffi")] lib GosuC fun fps = Gosu_fps : UInt32 @@ -76,6 +81,9 @@ module Gosu fun screen_height = Gosu_screen_height(window : UInt8*) : UInt32 fun available_width = Gosu_available_width(window : UInt8*) : UInt32 fun available_height = Gosu_available_height(window : UInt8*) : UInt32 + + fun clipboard = Gosu_clipboard() : UInt8* + fun set_clipboard = Gosu_set_clipboard(text : UInt8*) end # Returns the current framerate, in frames per second. @@ -306,6 +314,14 @@ module Gosu GosuC.available_height(window) end + def clipboard : String + String.new(GosuC.clipboard(pointer)) + end + + def clipboard=(text : String) + GosuC.set_clipboard(text) + end + def self.color_to_drawop(color : Gosu::Color | Int64 | UInt32) color.is_a?(Gosu::Color) ? color.gl : color end diff --git a/src/gosu/channel.cr b/src/gosu/channel.cr index 9e046e4..ad15e08 100644 --- a/src/gosu/channel.cr +++ b/src/gosu/channel.cr @@ -1,5 +1,4 @@ module Gosu - @[Link("gosu-ffi")] lib ChannelC fun channel_destroy = Gosu_Channel_destroy(pointer : UInt8*) diff --git a/src/gosu/color.cr b/src/gosu/color.cr index 81608b9..d1e5a5a 100644 --- a/src/gosu/color.cr +++ b/src/gosu/color.cr @@ -1,5 +1,4 @@ module Gosu - @[Link("gosu-ffi")] lib ColorC fun create_color = Gosu_Color_create(color : UInt32) : UInt32 fun create_color_argb = Gosu_Color_create_argb(alpha : UInt8, red : UInt8, green : UInt8, blue : UInt8) : UInt32 diff --git a/src/gosu/font.cr b/src/gosu/font.cr index cc73e6d..081d652 100644 --- a/src/gosu/font.cr +++ b/src/gosu/font.cr @@ -1,5 +1,4 @@ module Gosu - @[Link("gosu-ffi")] lib FontC fun create_font = Gosu_Font_create(line_height : Int32, name : UInt8*, font_flags : UInt32) : UInt8* diff --git a/src/gosu/image.cr b/src/gosu/image.cr index e56107b..a3cf3df 100644 --- a/src/gosu/image.cr +++ b/src/gosu/image.cr @@ -1,5 +1,4 @@ module Gosu - @[Link("gosu-ffi")] lib ImageC fun create_image = Gosu_Image_create(filename : UInt8*, flags : UInt32) : UInt8* fun create_image_from_text = Gosu_Image_create_from_text(text : UInt8*, font : UInt8*, line_height : Float64, diff --git a/src/gosu/sample.cr b/src/gosu/sample.cr index f5eadf8..4a73b48 100644 --- a/src/gosu/sample.cr +++ b/src/gosu/sample.cr @@ -1,5 +1,4 @@ module Gosu - @[Link("gosu-ffi")] lib SampleC fun create_sample = Gosu_Sample_create(filename : UInt8*) : UInt8* fun destroy_sample = Gosu_Sample_destroy(pointer : UInt8*) diff --git a/src/gosu/song.cr b/src/gosu/song.cr index 5532b3e..9ae8014 100644 --- a/src/gosu/song.cr +++ b/src/gosu/song.cr @@ -1,5 +1,4 @@ module Gosu - @[Link("gosu-ffi")] lib SongC fun create_song = Gosu_Song_create(filename : UInt8*) : UInt8* fun destroy_song = Gosu_Song_destroy(song : UInt8*) diff --git a/src/gosu/text_input.cr b/src/gosu/text_input.cr index db84f1d..bafe2c8 100644 --- a/src/gosu/text_input.cr +++ b/src/gosu/text_input.cr @@ -1,5 +1,4 @@ module Gosu - @[Link("gosu-ffi")] lib TextInputC fun create_textinput = Gosu_TextInput_create : UInt8* fun destroy_textinput = Gosu_TextInput_destroy(textinput : UInt8*) diff --git a/src/gosu/window.cr b/src/gosu/window.cr index 0c2bcb4..c42dc95 100644 --- a/src/gosu/window.cr +++ b/src/gosu/window.cr @@ -1,5 +1,4 @@ module Gosu - @[Link("gosu-ffi")] lib WindowC fun create_window = Gosu_Window_create(width : Int32, height : Int32, window_flags : UInt32, update_interval : Float64) : UInt8* fun window_show = Gosu_Window_show(window : UInt8*)