Skip to content

Commit

Permalink
Some fixes on the canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
lainsce committed Oct 12, 2023
1 parent 24b21e0 commit adaa819
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
36 changes: 18 additions & 18 deletions data/style.css
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
.editor-bg {
margin: 0;
padding: 0;
background-color: #7f7f7f;
background-color: @view_bg_color;
background-image: linear-gradient(
45deg,
#cccccc 25%,
alpha(@outline, 0.38) 25%,
transparent 25%
),
linear-gradient(
-45deg,
#cccccc 25%,
alpha(@outline, 0.38) 25%,
transparent 25%
),
linear-gradient(
45deg,
transparent 75%,
#cccccc 75%
alpha(@outline, 0.38) 75%
),
linear-gradient(
-45deg,
transparent 75%,
#cccccc 75%
alpha(@outline, 0.38) 75%
);
background-size: 20px 20px;
background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
Expand All @@ -34,8 +34,8 @@

.scrim .disclosure-button {
background: image(@osd_bg_color);
box-shadow: 0 2px 6px 2px rgba(0,0,0, 0.15),
0 1px 2px 0 rgba(0,0,0, 0.3);
box-shadow: 0 2px 6px 2px rgba(black, 0.15),
0 1px 2px 0 rgba(black, 0.3);
color: @osd_fg_color;
}
.scrim .disclosure-button:hover {
Expand All @@ -61,8 +61,8 @@
.scrim .minimize image,
.scrim .maximize image {
background: image(@osd_bg_color);
box-shadow: 0 2px 6px 2px rgba(0,0,0, 0.15),
0 1px 2px 0 rgba(0,0,0, 0.3);
box-shadow: 0 2px 6px 2px rgba(black, 0.15),
0 1px 2px 0 rgba(black, 0.3);
color: @osd_fg_color;
}
.scrim .close:hover image,
Expand All @@ -85,8 +85,8 @@

.viewer-bar button {
background: image(@osd_bg_color);
box-shadow: 0 2px 6px 2px rgba(0,0,0, 0.15),
0 1px 2px 0 rgba(0,0,0, 0.3);
box-shadow: 0 2px 6px 2px rgba(black, 0.15),
0 1px 2px 0 rgba(black, 0.3);
padding: 9px;
min-width: 24px;
min-height: 24px;
Expand All @@ -104,25 +104,25 @@

.props-view {
background: @osd_bg_color;
box-shadow: -2px 0 6px 2px rgba(0,0,0, 0.15),
-1px 0 2px 0 rgba(0,0,0, 0.3);
box-shadow: -2px 0 6px 2px rgba(black, 0.15),
-1px 0 2px 0 rgba(black, 0.3);
}

.props-view .mini-content-block {
background: shade(@osd_bg_color, 1.2);
color: @osd_fg_color;
}
.props-view .content-list row:first-child .mini-content-block {
border-top-left-radius: 18px;
border-top-right-radius: 18px;
border-top-left-radius: 26px;
border-top-right-radius: 26px;

}
.props-view .content-list row .mini-content-block {
border-radius: 8px;
}
.props-view .content-list row:last-child .mini-content-block {
border-bottom-left-radius: 18px;
border-bottom-right-radius: 18px;
border-bottom-left-radius: 26px;
border-bottom-right-radius: 26px;
}

.props-view .mini-content-block button {
Expand Down Expand Up @@ -178,4 +178,4 @@
.props-scrim .maximize:active image {
background: image(@osd_accent_color);
color: @osd_bg_color;
}
}
3 changes: 1 addition & 2 deletions data/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<object class="HeAppBar" id="main_bar">
<property name="show-back">0</property>
<property name="valign">start</property>
<property name="decoration-layout">:close</property>
<child>
<object class="GtkMenuButton">
<property name="icon-name">open-menu-symbolic</property>
Expand Down Expand Up @@ -45,4 +44,4 @@
</item>
</section>
</menu>
</interface>
</interface>
15 changes: 9 additions & 6 deletions src/Canvas.vala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
public class Modi.Canvas : Gtk.Box {
public PictureFile? project { get; set; }
// 0.5 is enough default zoom for most pictures
public float scale { get; set; default = 0.50f; }
public float scale { get; set; default = 0.25f; }
public int w = 0;
public int h = 0;

Expand All @@ -24,22 +23,26 @@ public class Modi.Canvas : Gtk.Box {
notify["project"].connect (update_zoom);
notify["scale"].connect (update_zoom);
notify["visible-rect"].connect (() => queue_draw ());

set_halign (Gtk.Align.CENTER);
set_valign (Gtk.Align.CENTER);
}

void update_zoom () {
if (scale > 0.0) {
if (scale >= 0.0) {
w = (int) (project.source.get_intrinsic_width () * scale);
h = (int) (project.source.get_intrinsic_height () * scale);
set_size_request (w, h);
}
}

public override void snapshot (Gtk.Snapshot snapshot) {
// The order of snapshot events here is from the end of this block, to here, the start.
if (project == null) {
base.snapshot (snapshot);
return;
}
project.start_snapshot (snapshot, visible_rect, this);
project.end_snapshot (snapshot, visible_rect, this);
snapshot.append_texture (project.source, target_rect);
var w = (int) (this.get_width ());
var h = (int) (this.get_height ());
Expand All @@ -66,6 +69,6 @@ public class Modi.Canvas : Gtk.Box {
snapshot.scale (scale, scale);

snapshot.restore ();
project.end_snapshot (snapshot, visible_rect, this);
project.start_snapshot (snapshot, visible_rect, this);
}
}
}
8 changes: 4 additions & 4 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public class Modi.MainWindow : He.ApplicationWindow {
public class MainWindow (He.Application app) {
Object (
application: app,
default_width: 800,
default_height: 600,
width_request: 360,
height_request: 360
height_request: 280
);

present ();
on_project_changed ();

set_default_size (800, 600);
}

void on_project_changed () {
Expand Down Expand Up @@ -100,4 +100,4 @@ public class Modi.MainWindow : He.ApplicationWindow {

editor.imgsize_mcb.subtitle = project.source.get_intrinsic_width ().to_string () + "×" + project.source.get_intrinsic_height ().to_string () + " px";
}
}
}
6 changes: 4 additions & 2 deletions src/Viewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Modi.Viewer : He.Bin {
canvas.notify["scale"].connect (() => {
if (canvas.scale == 0.25) {
zoomout.sensitive = false;
} else if (canvas.scale == 0.75) {
} else if (canvas.scale == 2.0) {
zoomin.sensitive = false;
} else {
zoomout.sensitive = true;
Expand Down Expand Up @@ -96,6 +96,8 @@ public class Modi.Viewer : He.Bin {

stack.visible_child_name = is_empty ? "empty" : "canvas";

window.set_default_size (canvas.w, canvas.h);

if (is_empty)
this.remove_css_class ("editor-bg");
else
Expand All @@ -107,7 +109,7 @@ public class Modi.Viewer : He.Bin {
}

public void zoom_out () {
if (canvas.scale > 0.0) {
if (canvas.scale >= 0.0) {
canvas.scale -= float.parse("0.25");
} else {
canvas.scale = float.parse("0.25");
Expand Down

0 comments on commit adaa819

Please sign in to comment.