Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #271

Merged
merged 6 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/wx/core/geometry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
# This software is released under the MIT license.

module Wx

def self.deg_to_rad(deg)
(deg * Math::PI) / 180.0
end

def self.rad_to_deg(rad)
(rad * 180.0) / Math::PI
end

class Point2DInt

alias :x :get_x
Expand Down
18 changes: 18 additions & 0 deletions lib/wx/core/graphics_pen_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.
#
# Some parts are
# Copyright 2004-2007, wxRuby development team
# released under the MIT-like wxRuby2 license

class Wx::GraphicsPenInfo

# make Wx::GraphicsPenInfo#dashes return self
wx_dashes = instance_method :dashes
define_method :dashes do |*args|
wx_dashes.bind(self).call(*args)
self
end

end
49 changes: 49 additions & 0 deletions lib/wx/core/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,55 @@ def find_first_unused_colour(r=1, g=0, b=0)
hist_hash.extend Histogram
hist_hash
end

# import flattened nested classes
HSVValue = Wx::HSVValue
RGBValue = Wx::RGBValue

end

class HSVValue

# More informative output when converted to string
def to_s
"#<Wx::Image::HSVValue: (#{self.hue}, #{self.saturation}, #{self.value})>"
end

def inspect
to_s
end

# make HSVValue usable for parallel assignments like `x, y = pt`
def to_ary
[self.hue, self.saturation, self.value]
end

def to_rgb
Image::hsv_to_rgb(self)
end

end

class RGBValue

# More informative output when converted to string
def to_s
"#<Wx::Image::RGBValue: (#{self.red}, #{self.green}, #{self.blue})>"
end

def inspect
to_s
end

# make RGBValue usable for parallel assignments like `x, y = pt`
def to_ary
[self.red, self.green, self.blue]
end

def to_hsv
Image::rgb_to_hsv(self)
end

end

def self.Image(name, bmp_type = nil, *rest, art_path: nil, art_section: nil)
Expand Down
11 changes: 11 additions & 0 deletions lib/wx/doc/geometry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@


module Wx

# Convert degrees to radians.
# @param [Float] deg degrees
# @return [Float] radians
def self.deg_to_rad(deg) end

# Convert radians to degrees.
# @param [Float] rad radians
# @return [Float] degrees
def self.rad_to_deg(rad) end

class Point2DInt

# @return [Integer]
Expand Down
14 changes: 13 additions & 1 deletion lib/wx/doc/graphics_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,19 @@ class GraphicsGradientStop
# @param col [Wx::Colour] The colour of this stop. Note that the alpha component of the colour is honoured thus allowing the background colours to partially show through the gradient.
# @param pos [Float] The stop position, must be in [0, 1] range with 0 being the beginning and 1 the end of the gradient.
# @return [Wx::GraphicsGradientStop]
def initialize(col=Wx::TransparentColour, pos=0.0) end
def initialize(col=Wx::TRANSPARENT_COLOUR, pos=0.0) end

end

class GraphicsPenInfo

# @param dashes [Array<Integer>]
# @return [Wx::GraphicsPenInfo]
def dashes(dashes) end

# @return [Array<Integer>]
def get_dashes; end
alias_method :dashes, :get_dashes

end

Expand Down
52 changes: 52 additions & 0 deletions lib/wx/doc/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,58 @@ def find_first_unused_colour(r=1, g=0, b=0) end
# @return [Hash] hash object extended with {Wx::Image::Histogram}
def compute_histogram; end

# Converts a color in HSV colour space to RGB colour space.
# @param [Wx::Image::HSVValue,Array(Float,Float,Float)] arg HSV colour
def self.hsv_to_rgb(arg) end

# Converts a color in RGB colour space to HSV colour space.
# @param [Wx::Image::RGBValue,Array(Float,Float,Float)] arg RGB colour
def self.rgb_to_hsv(arg) end

class HSVValue

# Constructor for HSVValue, an object that contains values for hue, saturation and value which represent the value of a color.
# It is used by {Wx::Image.hsv_to_rgb} and {Wx::Image.rgb_to_hsv}, which convert between HSV color space and RGB color space.
# @param [Float] hue
# @param [Float] saturation
# @param [Float] value
# @return [Wx::Image::HSVValue]
def initialize(hue, saturation, value)end

attr :hue, :saturation, :value

# Make HSVValue usable for parallel assignments like `hue, saturation, value = hsv`
# @return [Array(Float,Float,Float)]
def to_ary; end

# Convert to {Wx::Image::RGBValue}
# @return [Wx::Image::RGBValue]
def to_rgb; end

end

class RGBValue

# Constructor for RGBValue, an object that contains values for red, green and blue which represent the value of a color.
# It is used by {Wx::Image.hsv_to_rgb} and {Wx::Image.rgb_to_hsv}, which convert between RGB color space and HSV color space.
# @param [Float] red
# @param [Float] green
# @param [Float] blue
# @return [Wx::Image::RGBValue]
def initialize(red, green, blue)end

attr :red, :green, :blue

# Make RGBValue usable for parallel assignments like `red, green, blue = rgb`
# @return [Array(Float,Float,Float)]
def to_ary; end

# Convert to {Wx::Image::HSVValue}
# @return [Wx::Image::HSVValue]
def to_hsv; end

end

end

# @!group Art creation methods
Expand Down
26 changes: 26 additions & 0 deletions lib/wx/doc/pen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,34 @@ class Pen
# @return [Wx::Pen]
def self.find_or_create_pen(colour, width=1, style=Wx::PenStyle::PENSTYLE_SOLID) end

# Associates an array of dash values with the pen.
#
# @see Wx::Pen#get_dashes
# @param dashes [Array<Integer>]
# @return [void]
def set_dashes(dashes) end

# Gets an array of dashes.
#
# @see Wx::Pen#set_dashes
# @return [Array<Integer>]
def get_dashes; end
alias_method :dashes, :get_dashes

end

ThePenList = Wx::Pen

class PenInfo

# @param dashes [Array<Integer>]
# @return [Wx::PenInfo]
def dashes(dashes) end

# @return [Array<Integer>]
def get_dashes; end
alias_method :dashes, :get_dashes

end

end
2 changes: 1 addition & 1 deletion rakelib/lib/director/graphics_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def setup
# dealt with below - these require special handling because of the use
# of wxDash array, which cannot be freed until the peninfo is disposed of
# or until a new dash pattern is specified.
spec.ignore(%w[wxGraphicsPenInfo::GetDashes wxGraphicsPenInfo::Dashes], ignore_doc: false)
spec.ignore(%w[wxGraphicsPenInfo::GetDashes wxGraphicsPenInfo::Dashes])
spec.ignore 'wxGraphicsPenInfo::GetDash'
spec.add_extend_code 'wxGraphicsPenInfo', <<~__HEREDOC
// Returns a ruby array with the dash lengths
Expand Down
59 changes: 59 additions & 0 deletions rakelib/lib/director/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,65 @@ def setup
return rb_img_hist;
}
__HEREDOC
# make sure to wrap the public attributes
spec.regard 'wxImage::HSVValue::hue',
'wxImage::HSVValue::saturation',
'wxImage::HSVValue::value',
'wxImage::RGBValue::red',
'wxImage::RGBValue::green',
'wxImage::RGBValue::blue'
# ignore these and add customs
spec.ignore 'wxImage::HSVtoRGB',
'wxImage::RGBtoHSV'
spec.add_extend_code 'wxImage', <<~__HEREDOC
static wxImage::RGBValue hsv_to_rgb(VALUE arg)
{
std::unique_ptr<wxImage::HSVValue> tmp;
wxImage::HSVValue* p_hsv;
if ( TYPE(arg) == T_DATA )
{
void* argp;
SWIG_ConvertPtr(arg, &argp, SWIGTYPE_p_wxImage__HSVValue, 0);
p_hsv = reinterpret_cast< wxImage::HSVValue * >(argp);
}
else if ( TYPE(arg) == T_ARRAY && RARRAY_LEN(arg) == 3 )
{
p_hsv = new wxImage::HSVValue( NUM2DBL( rb_ary_entry(arg, 0) ),
NUM2DBL( rb_ary_entry(arg, 1) ),
NUM2DBL( rb_ary_entry(arg, 2) ) );
tmp.reset(p_hsv); // auto destruct when method scope ends
}
else
{
rb_raise(rb_eArgError, "Expected either Array(Float,Float,Float) or Wx::Image::HSVValue for #0");
}
return wxImage::HSVtoRGB(*p_hsv);
}

static wxImage::HSVValue rgb_to_hsv(VALUE arg)
{
std::unique_ptr<wxImage::RGBValue> tmp;
wxImage::RGBValue* p_rgb;
if ( TYPE(arg) == T_DATA )
{
void* argp;
SWIG_ConvertPtr(arg, &argp, SWIGTYPE_p_wxImage__RGBValue, 0);
p_rgb = reinterpret_cast< wxImage::RGBValue * >(argp);
}
else if ( TYPE(arg) == T_ARRAY && RARRAY_LEN(arg) == 3 )
{
p_rgb = new wxImage::RGBValue( NUM2DBL( rb_ary_entry(arg, 0) ),
NUM2DBL( rb_ary_entry(arg, 1) ),
NUM2DBL( rb_ary_entry(arg, 2) ) );
tmp.reset(p_rgb); // auto destruct when method scope ends
}
else
{
rb_raise(rb_eArgError, "Expected either Array(Float,Float,Float) or Wx::Image::RGBValue for #0");
}
return wxImage::RGBtoHSV(*p_rgb);
}
__HEREDOC
spec.do_not_generate(:functions)
end
end # class Image
Expand Down
2 changes: 1 addition & 1 deletion rakelib/lib/director/pen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def setup
# dealt with below - these require special handling because of the use
# of wxDash array, which cannot be freed until the pen(info) is disposed of
# or until a new dash pattern is specified.
spec.ignore(%w[wxPen::GetDashes wxPen::SetDashes wxPenInfo::GetDashes wxPenInfo::Dashes], ignore_doc: false)
spec.ignore(%w[wxPen::GetDashes wxPen::SetDashes wxPenInfo::GetDashes wxPenInfo::Dashes])
spec.ignore 'wxPenInfo::GetDash'
spec.add_extend_code 'wxPen', <<~__HEREDOC
// Returns a ruby array with the dash lengths
Expand Down
2 changes: 1 addition & 1 deletion rakelib/lib/director/system_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setup
'wxSystemSettings::HasFeature',
'wxSystemSettings::GetScreenType'
spec.ignore 'wxSystemSettings::GetAppearance'
spec.add_extend_code <<~__HEREDOC
spec.add_extend_code 'wxSystemSettings', <<~__HEREDOC
static wxString GetAppearanceName()
{
return wxSystemSettings::GetAppearance().GetName();
Expand Down
10 changes: 8 additions & 2 deletions rakelib/lib/typemap/points_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ module PointsList
}
else
{
rb_raise(rb_eTypeError, "Wrong type for wxPoint parameter %i", i);
VALUE str = rb_inspect(rb_item);
rb_raise(rb_eTypeError, "Wrong type for wxPoint parameter %i (%s)", i, StringValuePtr(str));
}
}
}
Expand Down Expand Up @@ -101,7 +102,12 @@ module PointsList
// array of all the points
VALUE all_points = rb_funcall($input, rb_intern("flatten"), 0);
point_arr = std::make_unique<wxPoint[]>(RARRAY_LEN(all_points));
wxRuby_PointArrayRubyToC(all_points, point_arr.get());
wxPoint* point_ptr = point_arr.get();
for ( int i = 0; i < RARRAY_LEN($input); i++ )
{
wxRuby_PointArrayRubyToC(rb_ary_entry($input, i), point_ptr);
point_ptr += count_arr[i];
}
$3 = point_arr.get();
}
__CODE
Expand Down
Loading