summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2017-09-27 21:24:10 +0200
committerJoel Klinghed <the_jk@yahoo.com>2017-09-27 21:24:10 +0200
commitfae61cdbbee3fdd6846ff34f976e5aa37d1c5218 (patch)
treee040782eda08baf8e98dfdd944c4800f4cc0a6a1 /src
parentb9e17cb1bda94c9c24a574547dc303c650125395 (diff)
Draw the machines in columns if the window is wider than it's high
Diffstat (limited to 'src')
-rw-r--r--src/main.cc31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/main.cc b/src/main.cc
index 2870e51..2b9086a 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -611,11 +611,12 @@ private:
}
cairo_rectangle(cairo_.get(), 0, 0, w_, h_);
cairo_fill(cairo_.get());
- auto pad_x = std::min(9.0, w_ / 20.0), pad_y = pad_x;
- auto margin_x = std::min(7.5, w_ / 20.0), margin_y = margin_x;
+ auto const pad_x = std::min(9.0, w_ / 20.0), pad_y = pad_x;
+ auto const margin_x = std::min(7.5, w_ / 20.0), margin_y = margin_x;
auto y = pad_y;
- auto box_width = w_ - pad_x * 2;
- auto box_height = box_height_ + margin_y * 2;
+ auto const columns = std::max(1, w_ / h_);
+ auto const box_width = (w_ - pad_x) / columns - pad_x;
+ auto const box_height = box_height_ + margin_y * 2;
if (!job_pattern_) {
job_pattern_.reset(cairo_pattern_create_linear(0.0, 0.0, box_width, 0.0));
cairo_pattern_add_color_stop_rgb(job_pattern_.get(), 0.000000,
@@ -631,10 +632,12 @@ private:
}
pango_layout_set_width(layout_.get(),
(box_width - margin_x * 2) * PANGO_SCALE);
+ auto col = 0;
for (auto const& machine : machines_) {
pango_layout_set_text(layout_.get(), machine.data.name.data(),
machine.data.name.size());
- rounded_path(cairo_.get(), pad_x, y, box_width, box_height);
+ auto x = pad_x + col * (box_width + pad_x);
+ rounded_path(cairo_.get(), x, y, box_width, box_height);
cairo_set_source_rgba(cairo_.get(), 0.1, 0.1, 0.1, 0.7);
if (machine.x > 0.0) {
@@ -642,10 +645,13 @@ private:
auto old = std::unique_ptr<cairo_path_t, CairoPathDelete>(
cairo_copy_path(cairo_.get()));
cairo_new_path(cairo_.get());
- cairo_rectangle(cairo_.get(), pad_x, y,
+ cairo_rectangle(cairo_.get(), x, y,
machine.x * box_width, box_height);
cairo_clip(cairo_.get());
cairo_append_path(cairo_.get(), old.get());
+ cairo_matrix_t matrix;
+ cairo_matrix_init_translate(&matrix, -x, 0);
+ cairo_pattern_set_matrix(job_pattern_.get(), &matrix);
cairo_set_source(cairo_.get(), job_pattern_.get());
cairo_fill(cairo_.get());
cairo_reset_clip(cairo_.get());
@@ -656,7 +662,7 @@ private:
auto radius = box_height / 10.0;
cairo_set_line_width(cairo_.get(), 1.5);
cairo_new_path(cairo_.get());
- cairo_move_to(cairo_.get(), pad_x + box_width - radius, y);
+ cairo_move_to(cairo_.get(), x + box_width - radius, y);
cairo_rel_line_to(cairo_.get(),
-(machine.requests * (box_width - radius * 2))
/ requests_, 0);
@@ -664,17 +670,20 @@ private:
cairo_stroke(cairo_.get());
}
- cairo_move_to(cairo_.get(), pad_x + margin_x, y + margin_y);
+ cairo_move_to(cairo_.get(), x + margin_x, y + margin_y);
pango_cairo_layout_path(cairo_.get(), layout_.get());
cairo_set_source_rgb(cairo_.get(), 0.0, 0.0, 0.0);
cairo_set_line_cap(cairo_.get(), CAIRO_LINE_CAP_ROUND);
cairo_set_line_width(cairo_.get(), 2.0);
cairo_stroke(cairo_.get());
cairo_set_source_rgb(cairo_.get(), 1.0, 1.0, 1.0);
- cairo_move_to(cairo_.get(), pad_x + margin_x, y + margin_y);
+ cairo_move_to(cairo_.get(), x + margin_x, y + margin_y);
pango_cairo_show_layout(cairo_.get(), layout_.get());
- y += box_height + pad_y * 2;
- if (y >= h_) break;
+ if (++col == columns) {
+ col = 0;
+ y += box_height + pad_y * 2;
+ if (y >= h_) break;
+ }
}
cairo_surface_flush(surface_.get());
xcb_copy_area(wnd_.conn(), pixmap_.get(), wnd_.get(), gcontext_.get(),