Commit 82d42056 authored by Jim Nelson's avatar Jim Nelson

Cleanup. Thumbnails now bottom-aligned with white text.

parent 3b70ad9d
......@@ -86,6 +86,9 @@ public class AppWindow : Gtk.Window {
if (mainWindow == null) {
mainWindow = this;
}
enter_notify_event += on_mouse_enter;
leave_notify_event += on_mouse_exit;
}
private void on_about() {
......@@ -100,18 +103,23 @@ public class AppWindow : Gtk.Window {
private void import(File file) {
FileType type = file.query_file_type(FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
if(type == FileType.REGULAR) {
message("File %s", file.get_path());
message("Importing file %s", file.get_path());
collectionPage.add_photo(file);
return;
} else if (type != FileType.DIRECTORY) {
message("Skipping file %s (not directory or file)", file.get_path());
return;
}
message("Importing directory %s", file.get_path());
import_dir(file);
}
private void import_dir(File dir) {
assert(dir.query_file_type(FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null) == FileType.DIRECTORY);
try {
FileEnumerator enumerator = dir.enumerate_children("*",
FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
......@@ -129,17 +137,18 @@ public class AppWindow : Gtk.Window {
FileType type = info.get_file_type();
if (type == FileType.REGULAR) {
message("File %s", file.get_path());
message("Importing file %s", file.get_path());
collectionPage.add_photo(file);
} else if (type == FileType.DIRECTORY) {
message("Dir %s", file.get_path());
message("Importing directory %s", file.get_path());
import_dir(file);
} else {
message("Skipped %s", file.get_path());
}
}
} catch (Error err) {
error("%s", err.message);
// TODO: Better error reporting
error("Error importing: %s", err.message);
}
}
......@@ -154,5 +163,17 @@ public class AppWindow : Gtk.Window {
import(File.new_for_uri(uri));
}
}
private bool on_mouse_enter(AppWindow aw, Gdk.EventCrossing crossing) {
message("on_mouse_enter");
return false;
}
private bool on_mouse_exit(AppWindow aw, Gdk.EventCrossing crossing) {
message("on_mouse_exit");
return false;
}
}
......@@ -6,22 +6,34 @@ Gdk.Color parse_color(string color) {
}
public class CollectionPage : Gtk.ScrolledWindow {
public static const int THUMB_X_PADDING = 20;
public static const int THUMB_Y_PADDING = 20;
public static const string BG_COLOR = "#777";
private Gtk.Viewport viewport = new Gtk.Viewport(null, null);
private Gtk.Table layoutTable = new Gtk.Table(0, 0, false);
private List<Thumbnail> thumbnailList = new List<Thumbnail>();
private int currentX = 0;
private int currentY = 0;
private int cols = 1;
private int cols = 0;
private int thumbCount = 0;
construct {
// scrollbar policy
set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
size_allocate += on_resize;
Gtk.Viewport viewport = new Gtk.Viewport(null, null);
// set table column and row padding ... this is done globally rather than per-thumbnail
layoutTable.set_col_spacings(THUMB_X_PADDING);
layoutTable.set_row_spacings(THUMB_Y_PADDING);
// need to manually build viewport to set its background color
viewport.add(layoutTable);
viewport.modify_bg(Gtk.StateType.NORMAL, parse_color("#777"));
viewport.modify_bg(Gtk.StateType.NORMAL, parse_color(BG_COLOR));
// notice that this is capturing the viewport's resize, not the scrolled window's,
// as that's what interesting when laying out the photos
viewport.size_allocate += on_resize;
add(viewport);
}
......@@ -32,35 +44,39 @@ public class CollectionPage : Gtk.ScrolledWindow {
Thumbnail thumbnail = new Thumbnail(file);
thumbnailList.append(thumbnail);
thumbCount++;
layoutTable.attach(thumbnail, currentX, currentX + 1, currentY, currentY + 1,
Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.EXPAND,
Gtk.AttachOptions.SHRINK,
20, 20);
attach_thumbnail(thumbnail);
layoutTable.show_all();
}
private void attach_thumbnail(Thumbnail thumbnail) {
layoutTable.attach(thumbnail, currentX, currentX + 1, currentY, currentY + 1,
Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.EXPAND,
Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL,
0, 0);
if (++currentX >= cols) {
if(++currentX >= cols) {
currentX = 0;
currentY++;
}
thumbCount++;
show_all();
}
private void on_resize(CollectionPage s, Gdk.Rectangle allocation) {
int newCols = allocation.width / (Thumbnail.THUMB_WIDTH + 20 + 20);
private void on_resize(Gtk.Viewport v, Gdk.Rectangle allocation) {
message("v.width=%d width=%d", v.allocation.width, allocation.width);
int newCols = allocation.width / (Thumbnail.THUMB_WIDTH + THUMB_X_PADDING + THUMB_X_PADDING);
if (newCols < 1)
newCols = 1;
if (cols == newCols)
return;
int rows = (thumbCount / newCols) + 1;
message("rows=%d cols=%d", rows, newCols);
cols = newCols;
int rows = (thumbCount / cols) + 1;
message("rows=%d cols=%d", rows, cols);
layoutTable.resize(rows, cols);
......@@ -69,14 +85,7 @@ public class CollectionPage : Gtk.ScrolledWindow {
foreach (Thumbnail thumbnail in thumbnailList) {
layoutTable.remove(thumbnail);
layoutTable.attach(thumbnail, currentX, currentX + 1, currentY, currentY + 1,
Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.EXPAND,
Gtk.AttachOptions.SHRINK,
20, 20);
if(++currentX >= cols) {
currentX = 0;
currentY++;
}
attach_thumbnail(thumbnail);
}
}
}
......
all: photo
TARGET = photo
VALAC_OPTS = -g --enable-checking
SRC_FILES = \
main.vala \
AppWindow.vala \
CollectionPage.vala \
Thumbnail.vala \
PhotoTable.vala
PKGS = \
gtk+-2.0 \
sqlite3
all: $(TARGET)
clean:
rm -f photo
rm -f $(TARGET)
photo: main.vala AppWindow.vala CollectionPage.vala Thumbnail.vala Makefile
valac -g --enable-checking --pkg gtk+-2.0 main.vala AppWindow.vala CollectionPage.vala Thumbnail.vala -o photo
$(TARGET): $(SRC_FILES) Makefile
valac $(VALAC_OPTS) $(foreach pkg,$(PKGS),--pkg $(pkg)) $(SRC_FILES) -o $(TARGET)
public class Thumbnail : Gtk.VBox {
public class Thumbnail : Gtk.Alignment {
public static const int THUMB_WIDTH = 128;
public static const int THUMB_HEIGHT = 128;
public static const int LABEL_PADDING = 4;
public static const string TEXT_COLOR = "#FFF";
private File file;
private Gtk.Image image;
private Gtk.Label label;
private Gtk.Label title;
construct {
}
......@@ -13,24 +15,31 @@ public class Thumbnail : Gtk.VBox {
public Thumbnail(File file) {
this.file = file;
// bottom-align everything
set(0, 1, 0, 0);
Gdk.Pixbuf pixbuf = null;
try {
pixbuf = new Gdk.Pixbuf.from_file(file.get_path());
} catch (Error err) {
error("%s", err.message);
error("Error loading image: %s", err.message);
return;
}
pixbuf = scale(pixbuf, THUMB_WIDTH, THUMB_HEIGHT);
label = new Gtk.Label(file.get_basename());
label.set_use_underline(false);
image = new Gtk.Image.from_pixbuf(pixbuf);
pack_start(image, true, true, 0);
pack_end(label, false, false, 4);
title = new Gtk.Label(file.get_basename());
title.set_use_underline(false);
title.modify_fg(Gtk.StateType.NORMAL, parse_color(TEXT_COLOR));
Gtk.VBox vbox = new Gtk.VBox(false, 0);
vbox.pack_start(image, false, false, 0);
vbox.pack_end(title, false, false, LABEL_PADDING);
add(vbox);
}
public Gdk.Pixbuf scale(Gdk.Pixbuf pixbuf, int maxWidth, int maxHeight) {
......@@ -46,7 +55,7 @@ public class Thumbnail : Gtk.VBox {
} else {
ratio = (double) maxHeight / (double) height;
}
int newWidth = (int) ((double) width * ratio);
int newHeight = (int) ((double) height * ratio);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment