Updated Files
libbirdfont/BackgroundImage.vala |
libbirdfont/BackgroundTool.vala |
libbirdfont/ScaledBackgrounds.vala |
libbirdfont/ScaledImage.vala |
--- a/libbirdfont/BackgroundImage.vala
+++ b/libbirdfont/BackgroundImage.vala
@@ -54,6 +54,7 @@
private double img_scale_y_size = 1;
public double img_rotation = 0;
+ private double preview_img_rotation = 0;
private int size = -1;
@@ -383,21 +384,23 @@
return get_scaled_backgrounds ();
}
+ public void start_rotation_preview () {
+ preview_img_rotation = img_rotation;
+ }
+
public void preview_img_rotation_from_coordinate (double x, double y, double view_zoom) {
double rotation;
- ScaledBackgrounds backgounds;
+ ScaledBackgrounds backgrounds;
+ ScaledBackground backgound;
- if (get_img_rotation_from_coordinate (x, y, out rotation)) {
- img_rotation = rotation;
- backgounds = get_image ();
- ImageSurface rotated;
+ if (get_img_rotation_from_coordinate (x, y, out rotation)) {
+ backgrounds = get_scaled_backgrounds ();
+ backgound = backgrounds.get_image (view_zoom * img_scale_x); // FIXME: y
img_rotation = rotation;
if (!high_contrast) {
- rotated = rotate ((ImageSurface) get_padded_image ());
- // FIXME: y
- scaled = new ScaledBackgrounds.single_size (rotated, img_scale_x * view_zoom);
+ backgound.rotate (rotation - preview_img_rotation);
} else {
contrast_image = null;
}
@@ -408,9 +411,15 @@
double rotation;
if (get_img_rotation_from_coordinate (x, y, out rotation)) {
img_rotation = rotation;
- scaled = null;
- contrast_image = null;
+ Task task = new Task (cache_scaled_image); // cache all sizes
+ MainWindow.run_blocking_task (task);
}
+ }
+
+ void cache_scaled_image () {
+ scaled = null;
+ contrast_image = null;
+ get_image ();
}
public bool get_img_rotation_from_coordinate (double x, double y, out double rotation) {
@@ -526,7 +535,7 @@
scaled_context.set_source_surface (part.get_image (), scaled_x, scaled_y);
scaled_context.paint ();
- } else {
+ } else {
ImageSurface contrast = get_contrast_image ();
image_scale_x = img_scale_x * ((double) size_margin / contrast.get_width ());
--- a/libbirdfont/BackgroundTool.vala
+++ b/libbirdfont/BackgroundTool.vala
@@ -79,6 +79,8 @@
img_width = background.get_img ().get_width () * background.img_scale_x;
img_height = background.get_img ().get_height () * background.img_scale_y;
+
+ background.start_rotation_preview ();
move_bg = true;
--- a/libbirdfont/ScaledBackgrounds.vala
+++ b/libbirdfont/ScaledBackgrounds.vala
@@ -33,14 +33,6 @@
image = scale (scale_factor);
scaled.add (image);
}
- }
-
- public ScaledBackgrounds.single_size (ImageSurface original, double scale_factor) {
- this.original = original;
- scaled = new ArrayList<ScaledBackground> ();
-
- ScaledBackground image = scale (scale_factor);
- scaled.add (image);
}
public ScaledBackground get_image (double scale) {
@@ -63,8 +55,9 @@
scale_factor = 1;
}
- int width = (int) (scale_factor * original.get_width ());
- int height = (int) (scale_factor * original.get_height ());
+ int width = (int) (original.get_width () * scale_factor);
+ int height = (int) (original.get_height () * scale_factor);
+
scaled_image = new ImageSurface (Format.ARGB32, width, height);
Context context = new Context (scaled_image);
context.scale (scale_factor, scale_factor);
--- a/libbirdfont/ScaledImage.vala
+++ b/libbirdfont/ScaledImage.vala
@@ -20,7 +20,7 @@
public class ScaledBackground : GLib.Object {
ImageSurface image;
- ImageSurface rotated;
+ ImageSurface original;
ArrayList<ImageSurface> parts;
int size;
int part_width;
@@ -33,11 +33,16 @@
scale = 1;
}
+ original = image;
this.image = image;
- rotated = image;
this.scale = scale;
parts = new ArrayList<ImageSurface> ();
+ create_parts ();
+ }
+
+ public void rotate (double angle) {
+ image = BackgroundImage.rotate_image (original, angle);
create_parts ();
}
@@ -65,16 +70,15 @@
ImageSurface next_part;
next_part = new ImageSurface (Format.ARGB32, part_width, part_height);
Context context = new Context (next_part);
- context.set_source_surface (rotated, -x * part_width, -y * part_width);
+ context.set_source_surface (image, -x * part_width, -y * part_width);
context.paint ();
parts.add (next_part);
}
}
}
- public void rotate (double angle) {
- rotated = BackgroundImage.rotate_image (image, angle);
- create_parts ();
+ public void set_scale (double s) {
+ scale = s;
}
public double get_scale () {
@@ -141,12 +145,12 @@
stop_y = size;
}
- int assembled_width = (int) ((stop_x - start_x) * image_width);
- int assembled_height = (int) ((stop_y - start_y) * image_height);
+ int assembled_width = (int) ((stop_x - start_x) * part_width);
+ int assembled_height = (int) ((stop_y - start_y) * part_height);
- image = new ImageSurface (Format.ARGB32, assembled_width, assembled_height);
+ ImageSurface assembled_image = new ImageSurface (Format.ARGB32, assembled_width, assembled_height);
- Context context = new Context (image);
+ Context context = new Context (assembled_image);
int start_offset_x = start_x * part_width;
int start_offset_y = start_y * part_height;
@@ -168,10 +172,10 @@
}
}
- return new ScaledBackgroundPart (image, scale,
+ return new ScaledBackgroundPart (assembled_image, scale,
start_offset_x, start_offset_y);
}
}
}