[gnome-characters/bilelmoussaoui/gtk4] characters: port remaining rendering code to snapshot api
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters/bilelmoussaoui/gtk4] characters: port remaining rendering code to snapshot api
- Date: Wed, 24 Nov 2021 07:27:36 +0000 (UTC)
commit 4c8ebbdffa8ba78b9b7e58dac80136558ffb07b5
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Wed Nov 24 08:27:30 2021 +0100
characters: port remaining rendering code to snapshot api
src/charactersView.js | 82 +++++++++++++++++++++++++--------------------------
1 file changed, 41 insertions(+), 41 deletions(-)
---
diff --git a/src/charactersView.js b/src/charactersView.js
index c5224ee..a38052d 100644
--- a/src/charactersView.js
+++ b/src/charactersView.js
@@ -17,7 +17,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-const { Gc, Gdk, GLib, Gio, GObject, Gtk, Pango, Graphene, PangoCairo } = imports.gi;
+const { Gc, Gdk, GLib, Gio, GObject, Gtk, Pango, Graphene } = imports.gi;
const Main = imports.main;
const Util = imports.util;
@@ -54,7 +54,6 @@ const CharacterListRow = GObject.registerClass({
// Draw characters. Do centering and attach to the baseline.
let cellSize = getCellSize(this._fontDescription);
for (let i in this._characters) {
- snapshot.save();
let character = this._characters[i];
let cellRect = new Gdk.Rectangle({
x: x + cellSize * i,
@@ -62,12 +61,14 @@ const CharacterListRow = GObject.registerClass({
width: cellSize,
height: cellSize,
});
+
if (Gc.character_is_invisible(character)) {
- // this._drawBoundingBox(cr, cellRect, character);
- // this._drawCharacterName(cr, cellRect, character);
+ this._drawBoundingBox(snapshot, pangoContext, cellRect, character);
+ this._drawCharacterName(snapshot, pangoContext, cellRect, character);
} else {
layout.set_text(character, -1);
if (layout.get_unknown_glyphs_count() === 0) {
+ snapshot.save();
let layoutBaseline = layout.get_baseline();
let logicalRect = layout.get_extents()[0];
snapshot.translate(new Graphene.Point({
@@ -75,23 +76,19 @@ const CharacterListRow = GObject.registerClass({
y: y + BASELINE_OFFSET * cellSize - layoutBaseline / Pango.SCALE,
}));
- let textColor = this._styleContext.lookup_color('foreground_color')[1];
+ let textColor = this._styleContext.lookup_color('window_fg_color')[1];
snapshot.append_layout(layout, textColor);
+ snapshot.restore();
} else {
- // this._drawBoundingBox(cr, cellRect, character);
- // this._drawCharacterName(cr, cellRect, character);
+ this._drawBoundingBox(snapshot, pangoContext, cellRect, character);
+ this._drawCharacterName(snapshot, pangoContext, cellRect, character);
}
}
- snapshot.restore();
}
}
- _computeBoundingBox(cr, cellRect, uc) {
- let layout = PangoCairo.create_layout(cr);
- layout.set_font_description(this._fontDescription);
- layout.set_text(uc, -1);
-
+ _computeBoundingBox(layout, cellRect, uc) {
let shapeRect;
let layoutBaseline;
if (layout.get_unknown_glyphs_count() === 0) {
@@ -129,33 +126,38 @@ const CharacterListRow = GObject.registerClass({
return shapeRect;
}
- _drawBoundingBox(cr, cellRect, uc) {
- cr.save();
- cr.rectangle(cellRect.x, cellRect.y, cellRect.width, cellRect.height);
- cr.clip();
+ _drawBoundingBox(snapshot, pangoContext, cellRect, uc) {
+ snapshot.save();
- let layout = PangoCairo.create_layout(cr);
+ let layout = Pango.Layout.new(pangoContext);
layout.set_font_description(this._fontDescription);
layout.set_text(uc, -1);
- let shapeRect = this._computeBoundingBox(cr, cellRect, uc);
+ let shapeRect = this._computeBoundingBox(layout, cellRect, uc);
let borderWidth = 1;
- cr.rectangle(shapeRect.x - borderWidth * 2,
- shapeRect.y - borderWidth * 2,
- shapeRect.width + borderWidth * 2,
- shapeRect.height + borderWidth * 2);
- cr.setSourceRGBA(239.0 / 255.0, 239.0 / 255.0, 239.0 / 255.0, 1.0);
- cr.fill();
- cr.restore();
+ let accentColor = this._styleContext.lookup_color('accent_color')[1];
+ accentColor.alpha = 0.1;
+
+ snapshot.append_color(accentColor,
+ new Graphene.Rect({
+ origin: new Graphene.Point({
+ x: shapeRect.x - borderWidth * 2,
+ y: shapeRect.y - borderWidth * 2,
+ }),
+ size: new Graphene.Size({
+ width: shapeRect.width + borderWidth * 2,
+ height: shapeRect.height + borderWidth * 2,
+ }),
+ }),
+ );
+ snapshot.restore();
}
- _drawCharacterName(cr, cellRect, uc) {
- cr.save();
- cr.rectangle(cellRect.x, cellRect.y, cellRect.width, cellRect.height);
- cr.clip();
+ _drawCharacterName(snapshot, pangoContext, cellRect, uc) {
+ snapshot.save();
- let layout = PangoCairo.create_layout(cr);
+ let layout = Pango.Layout.new(pangoContext);
layout.set_width(cellRect.width * Pango.SCALE * 0.8);
layout.set_height(cellRect.height * Pango.SCALE * 0.8);
layout.set_wrap(Pango.WrapMode.WORD);
@@ -166,16 +168,14 @@ const CharacterListRow = GObject.registerClass({
let text = name === null ? _('Unassigned') : Util.capitalize(name);
layout.set_text(text, -1);
let logicalRect = layout.get_extents()[0];
- cr.moveTo(cellRect.x - logicalRect.x / Pango.SCALE +
- (cellRect.width - logicalRect.width / Pango.SCALE) / 2,
- cellRect.y - logicalRect.y / Pango.SCALE +
- (cellRect.height - logicalRect.height / Pango.SCALE) / 2);
-
- let textColor = this._styleContext.lookup_color('foreground_color')[1];
- Gdk.cairo_set_source_rgba(cr, textColor);
- PangoCairo.show_layout(cr, layout);
-
- cr.restore();
+ snapshot.translate(new Graphene.Point({
+ x: cellRect.x - logicalRect.x / Pango.SCALE + (cellRect.width - logicalRect.width / Pango.SCALE)
/ 2,
+ y: cellRect.y - logicalRect.y / Pango.SCALE + (cellRect.height - logicalRect.height /
Pango.SCALE) / 2,
+ }));
+
+ let textColor = this._styleContext.lookup_color('window_fg_color')[1];
+ snapshot.append_layout(layout, textColor);
+ snapshot.restore();
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]