From 5ce6add42f153896f53fa3e4e3ae7c13bd674f01 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Wed, 6 Mar 2013 23:36:28 -0600 Subject: [PATCH] Added gravity to the TextReader, so text can be easily anchored to the corners. --- include/TextReader.h | 4 +++- src/Main.cpp | 14 +++++++------- src/TextReader.cpp | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/include/TextReader.h b/include/TextReader.h index 89c1479c..3efa4735 100644 --- a/include/TextReader.h +++ b/include/TextReader.h @@ -17,6 +17,7 @@ #include #include "Magick++.h" #include "Cache.h" +#include "Clip.h" #include "Exceptions.h" using namespace std; @@ -43,11 +44,12 @@ namespace openshot tr1::shared_ptr image; list lines; bool is_open; + GravityType gravity; public: /// Constructor for TextReader. - TextReader(int width, int height, int x_offset, int y_offset, string text, string font, double size, string text_color, string background_color); + TextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, string text, string font, double size, string text_color, string background_color); /// Close Reader void Close(); diff --git a/src/Main.cpp b/src/Main.cpp index 064e3faa..adbbb30e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -18,13 +18,13 @@ void FrameReady(int number) int main() { -// FFmpegReader r("/home/jonathan/Videos/sintel_trailer-1080p.mp4"); -// r.Open(); -// tr1::shared_ptr f = r.GetFrame(300); -// f->Display(); -// r.Close(); -// -// return 0; + TextReader r(720, 480, 10, 10, GRAVITY_TOP_RIGHT, "What's Up!", "Courier", 30, "Blue", "Black"); + r.Open(); + tr1::shared_ptr f = r.GetFrame(1); + f->Display(); + r.Close(); + + return 0; diff --git a/src/TextReader.cpp b/src/TextReader.cpp index aeb279cb..ae2c39a0 100644 --- a/src/TextReader.cpp +++ b/src/TextReader.cpp @@ -2,8 +2,8 @@ using namespace openshot; -TextReader::TextReader(int width, int height, int x_offset, int y_offset, string text, string font, double size, string text_color, string background_color) -: width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), size(size), text_color(text_color), background_color(background_color), is_open(false) +TextReader::TextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, string text, string font, double size, string text_color, string background_color) +: width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), size(size), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity) { // Init FileInfo struct (clear all values) InitFileInfo(); @@ -25,6 +25,38 @@ void TextReader::Open() // Give image a transparent background color image->backgroundColor(Magick::Color("none")); + // Set gravity (map between OpenShot and ImageMagick) + switch (gravity) + { + case GRAVITY_TOP_LEFT: + lines.push_back(Magick::DrawableGravity(Magick::NorthWestGravity)); + break; + case GRAVITY_TOP: + lines.push_back(Magick::DrawableGravity(Magick::NorthGravity)); + break; + case GRAVITY_TOP_RIGHT: + lines.push_back(Magick::DrawableGravity(Magick::NorthEastGravity)); + break; + case GRAVITY_LEFT: + lines.push_back(Magick::DrawableGravity(Magick::WestGravity)); + break; + case GRAVITY_CENTER: + lines.push_back(Magick::DrawableGravity(Magick::CenterGravity)); + break; + case GRAVITY_RIGHT: + lines.push_back(Magick::DrawableGravity(Magick::EastGravity)); + break; + case GRAVITY_BOTTOM_LEFT: + lines.push_back(Magick::DrawableGravity(Magick::SouthWestGravity)); + break; + case GRAVITY_BOTTOM: + lines.push_back(Magick::DrawableGravity(Magick::SouthGravity)); + break; + case GRAVITY_BOTTOM_RIGHT: + lines.push_back(Magick::DrawableGravity(Magick::SouthEastGravity)); + break; + } + // Set stroke properties lines.push_back(Magick::DrawableStrokeColor(Magick::Color("none"))); lines.push_back(Magick::DrawableStrokeWidth(0.0));