Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
adding scale and bounds methods to track - closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jul 13, 2009
1 parent be393c5 commit 7604316
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
39 changes: 39 additions & 0 deletions ext/track.c
Expand Up @@ -246,6 +246,43 @@ static VALUE track_enable_alpha(VALUE obj)
return obj;
}

/*
call-seq: scale
Scale the track's size by width and height respectively.
The value passed is a relative float where "1" is the current size.
*/
static VALUE track_scale(VALUE obj, VALUE width, VALUE height)
{
MatrixRecord matrix;
GetTrackMatrix(TRACK(obj), &matrix);
ScaleMatrix(&matrix, FloatToFixed(NUM2DBL(width)), FloatToFixed(NUM2DBL(height)), 0, 0);
SetTrackMatrix(TRACK(obj), &matrix);
return obj;
}

/*
call-seq: bounds() -> bounds_hash
Returns a hash of boundaries. The hash contains four keys: :left, :top,
:right, :bottom. Each holds an integer representing the pixel value.
*/
static VALUE track_bounds(VALUE obj)
{
VALUE bounds_hash = rb_hash_new();
RgnHandle region;
Rect bounds;
region = GetTrackDisplayBoundsRgn(TRACK(obj));
GetRegionBounds(region, &bounds);
DisposeRgn(region);
rb_hash_aset(bounds_hash, ID2SYM(rb_intern("left")), INT2NUM(bounds.left));
rb_hash_aset(bounds_hash, ID2SYM(rb_intern("top")), INT2NUM(bounds.top));
rb_hash_aset(bounds_hash, ID2SYM(rb_intern("right")), INT2NUM(bounds.right));
rb_hash_aset(bounds_hash, ID2SYM(rb_intern("bottom")), INT2NUM(bounds.bottom));
return bounds_hash;
}

void Init_quicktime_track()
{
VALUE mQuickTime;
Expand All @@ -270,4 +307,6 @@ void Init_quicktime_track()
rb_define_method(cTrack, "new_audio_media", track_new_audio_media, 0);
rb_define_method(cTrack, "new_text_media", track_new_text_media, 0);
rb_define_method(cTrack, "enable_alpha", track_enable_alpha, 0);
rb_define_method(cTrack, "scale", track_scale, 2);
rb_define_method(cTrack, "bounds", track_bounds, 0);
}
10 changes: 10 additions & 0 deletions lib/quicktime/track.rb
Expand Up @@ -26,5 +26,15 @@ def video?
def text?
media_type == :text
end

# Returns the bounding width of this track in number of pixels.
def width
bounds[:right] - bounds[:left]
end

# Returns the bounding height of this track in number of pixels.
def height
bounds[:bottom] - bounds[:top]
end
end
end
12 changes: 9 additions & 3 deletions spec/quicktime/track_spec.rb
Expand Up @@ -6,7 +6,7 @@
@movie = QuickTime::Movie.open(File.dirname(__FILE__) + '/../fixtures/example.mov')
end

describe "example.mov video track" do
describe "video track" do
before(:each) do
@track = @movie.video_tracks.first
end
Expand Down Expand Up @@ -49,9 +49,15 @@
@track.offset = 2.5
@track.offset.should == 2.5
end

it "should be able to scale size of track" do
@track.scale(0.5, 0.5)
@track.width.should == 30
@track.height.should == 25
end
end

describe "example.mov audio track" do
describe "audio track" do
before(:each) do
@track = @movie.audio_tracks.first
end
Expand Down

0 comments on commit 7604316

Please sign in to comment.