Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All merged #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions area.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import Gtk from 'gi://Gtk';
import Pango from 'gi://Pango';
import Shell from 'gi://Shell';
import St from 'gi://St';
import Cogl from 'gi://Cogl';

const Color = Clutter.Color ?? Cogl.Color;

import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as Screenshot from 'resource:///org/gnome/shell/ui/screenshot.js';
Expand Down Expand Up @@ -1164,7 +1167,7 @@ export const DrawingArea = GObject.registerClass({
}

_onColorPicked(color) {
if (color instanceof Clutter.Color)
if (color instanceof Color)
color = color.to_string().slice(0, -2);

this.currentColor = this.getColorFromString(color);
Expand Down Expand Up @@ -1209,7 +1212,7 @@ export const DrawingArea = GObject.registerClass({

if (pickPixel.pickAsync) {
pickPixel.pickAsync().then(result => {
if (result instanceof Clutter.Color) {
if (result instanceof Color) {
// GS 3.38+
this._onColorPicked(result);
} else {
Expand Down Expand Up @@ -1472,7 +1475,7 @@ export const DrawingArea = GObject.registerClass({
// toString provides a string suitable for displaying the color name to the user.
getColorFromString(string, fallback) {
let [colorString, displayName] = string.split(':');
let [success, color] = Clutter.Color.from_string(colorString);
let [success, color] = Color.from_string(colorString);
color.toJSON = () => colorString;
color.toString = () => displayName || colorString;
if (success)
Expand Down
7 changes: 7 additions & 0 deletions data/icons/tool-arrow-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 38 additions & 10 deletions elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ import Clutter from 'gi://Clutter';
import GObject from 'gi://GObject';
import Pango from 'gi://Pango';
import PangoCairo from 'gi://PangoCairo';
import Cogl from 'gi://Cogl';

import { CURATED_UUID as UUID } from './utils.js';

const Color = Clutter.Color ?? Cogl.Color;

export const StaticColor = {
WHITE: Clutter.Color.new(255, 255, 255, 255),
BLUE: Clutter.Color.new(0, 0, 255, 255),
TRANSPARENT: Clutter.Color.new(0, 0, 0, 0),
BLACK: Clutter.Color.new(0, 0, 0, 255),
GRAY: Clutter.Color.new(160, 160, 164, 255),
RED: Clutter.Color.new(255, 0, 0, 255)
}
WHITE: Color.from_string('#ffffff'),
BLUE: Color.from_string('#0000ff'),
TRANSPARENT: Color.from_string('#00000000'),
BLACK: Color.from_string('#000000'),
GRAY: Color.from_string('#a0a0a4'),
RED: Color.from_string('#ff0000')
};

export const Shape = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6, IMAGE: 7 };
export const Shape = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6, IMAGE: 7, ARROW: 8 };
export const TextAlignment = { LEFT: 0, CENTER: 1, RIGHT: 2 };
export const Transformation = { TRANSLATION: 0, ROTATION: 1, SCALE_PRESERVE: 2, STRETCH: 3, REFLECTION: 4, INVERSION: 5, SMOOTH: 100 };

Expand Down Expand Up @@ -255,8 +258,7 @@ const _DrawingElement = GObject.registerClass({
cr.moveTo(points[0][0], points[0][1]);
for (let j = 1; j < points.length; j++) {
cr.lineTo(points[j][0], points[j][1]);
}

}
} else if (shape == Shape.ELLIPSE && points.length >= 2) {
let radius = Math.hypot(points[1][0] - points[0][0], points[1][1] - points[0][1]);
let ratio = 1;
Expand Down Expand Up @@ -284,6 +286,21 @@ const _DrawingElement = GObject.registerClass({
if (shape == Shape.POLYGON)
cr.closePath();

} else if (shape == Shape.ARROW && points.length >= 2) {
// Draw the main line
cr.moveTo(points[0][0], points[0][1]);
cr.lineTo(points[1][0], points[1][1]);

// Draw arrowhead
let angle = Math.atan2(points[1][1] - points[0][1], points[1][0] - points[0][0]);
let arrowSize = this.line.lineWidth * 5; // Adjust this multiplier to change arrow size

cr.moveTo(points[1][0], points[1][1]);
cr.lineTo(points[1][0] - arrowSize * Math.cos(angle - Math.PI/6),
points[1][1] - arrowSize * Math.sin(angle - Math.PI/6));
cr.moveTo(points[1][0], points[1][1]);
cr.lineTo(points[1][0] - arrowSize * Math.cos(angle + Math.PI/6),
points[1][1] - arrowSize * Math.sin(angle + Math.PI/6));
}
}

Expand Down Expand Up @@ -427,6 +444,17 @@ const _DrawingElement = GObject.registerClass({
row += ` ${points[i][0]},${points[i][1]}`;
row += `"${transAttribute}/>`;

} else if (this.shape == Shape.ARROW && points.length >= 2) {
let angle = Math.atan2(points[1][1] - points[0][1], points[1][0] - points[0][0]);
let arrowSize = this.line.lineWidth * 5; // Should match the Cairo version

row += `<path ${attributes} d="M${points[0][0]},${points[0][1]} `;
row += `L${points[1][0]},${points[1][1]} `;
row += `M${points[1][0]},${points[1][1]} `;
row += `L${points[1][0] - arrowSize * Math.cos(angle - Math.PI/6)},${points[1][1] - arrowSize * Math.sin(angle - Math.PI/6)} `;
row += `M${points[1][0]},${points[1][1]} `;
row += `L${points[1][0] - arrowSize * Math.cos(angle + Math.PI/6)},${points[1][1] - arrowSize * Math.sin(angle + Math.PI/6)}"`;
row += `${transAttribute}/>`;
}

return row;
Expand Down
2 changes: 1 addition & 1 deletion files.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Icons {
constructor(extension) {
const ICON_NAMES = [
'arc', 'color', 'dashed-line', 'document-export', 'fillrule-evenodd', 'fillrule-nonzero', 'fill', 'full-line', 'linecap', 'linejoin', 'palette', 'smooth', 'stroke',
'tool-ellipse', 'tool-line', 'tool-mirror', 'tool-move', 'tool-none', 'tool-polygon', 'tool-polyline', 'tool-rectangle', 'tool-resize',
'tool-ellipse', 'tool-line', 'tool-mirror', 'tool-move', 'tool-none', 'tool-polygon', 'tool-polyline', 'tool-rectangle', 'tool-resize', 'tool-arrow',
];
const ICON_DIR = extension.dir.get_child('data').get_child('icons');
const THEMED_ICON_NAMES = {
Expand Down
Binary file modified locale/de/LC_MESSAGES/draw-on-your-screen.mo
Binary file not shown.
7 changes: 7 additions & 0 deletions locale/de/LC_MESSAGES/draw-on-your-screen.po
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ msgctxt "drawing-tool"
msgid "Line"
msgstr "Linie"

msgctxt "drawing-tool"
msgid "Arrow"
msgstr "Pfeil"

msgctxt "drawing-tool"
msgid "Ellipse"
msgstr "Ellipse"
Expand Down Expand Up @@ -643,6 +647,9 @@ msgstr "Werkzeug Bild auswählen"
msgid "Select line tool"
msgstr "Werkzeug Linie auswählen"

msgid "Select arrow tool"
msgstr "Werkzeug Pfeil auswählen"

msgid "Select mirror tool"
msgstr "Werkzeug Spiegeln auswählen"

Expand Down
7 changes: 7 additions & 0 deletions locale/draw-on-your-screen.po
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ msgctxt "drawing-tool"
msgid "Line"
msgstr ""

msgctxt "drawing-tool"
msgid "Arrow"
msgstr ""

msgctxt "drawing-tool"
msgid "Ellipse"
msgstr ""
Expand Down Expand Up @@ -648,6 +652,9 @@ msgstr ""
msgid "Select line tool"
msgstr ""

msgid "Select arrow tool"
msgstr ""

msgid "Select mirror tool"
msgstr ""

Expand Down
Binary file added locale/es_ES/LC_MESSAGES/draw-on-your-screen.mo
Binary file not shown.
Loading