-
-
Notifications
You must be signed in to change notification settings - Fork 90
Library: Add Drawing area #261
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a623178
add DrawingArea
bazylevnik0 fece1a4
Update src/Library/demos/Drawing Area/main.blp
bazylevnik0 2d81db8
changed description in json
bazylevnik0 70fc811
Update src/Library/demos/Drawing Area/main.blp
bazylevnik0 110d91d
fixed format blp,js: names
bazylevnik0 001d646
js fixed .getValue
bazylevnik0 a5b3b14
Update src/Library/demos/Drawing Area/main.js
bazylevnik0 d0277f3
Update src/Library/demos/Drawing Area/main.js
bazylevnik0 ed8ffea
Update src/Library/demos/Drawing Area/main.js
bazylevnik0 c03cc7f
Update src/Library/demos/Drawing Area/main.js
bazylevnik0 b872ec3
Update src/Library/demos/Drawing Area/main.js
bazylevnik0 a70e4a7
Update src/Library/demos/Drawing Area/main.json
bazylevnik0 e5a6f43
js fixed .getValue
bazylevnik0 1a5aa08
css deleted
bazylevnik0 caa1c48
add links for related tutorials/docs
bazylevnik0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using Gtk 4.0; | ||
| using Adw 1; | ||
|
|
||
| Adw.StatusPage { | ||
| title: "Drawing Area"; | ||
| description: _("Programmatically draw onto a surface."); | ||
|
|
||
| Box { | ||
| halign: center; | ||
| orientation: vertical; | ||
|
|
||
| DrawingArea drawing_area { | ||
| content-width: 300; | ||
| content-height: 300; | ||
| } | ||
|
|
||
| Scale scale { | ||
| orientation: horizontal; | ||
| width-request: 300; | ||
| draw-value: true; | ||
| adjustment: Gtk.Adjustment { | ||
| lower: -25; | ||
| upper: 25; | ||
| value: 0; | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| //https://docs.gtk.org/gtk4/class.DrawingArea.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import Cairo from "cairo"; | ||
| import Gtk from "gi://Gtk?version=4.0"; | ||
| Gtk.init(); | ||
|
|
||
| const drawingArea = workbench.builder.get_object("drawing_area"); | ||
| const scaleRotate = workbench.builder.get_object("scale"); | ||
|
|
||
| let triangle = [3]; | ||
| triangle[0] = [2]; | ||
| triangle[0][0] = 100; | ||
| triangle[0][1] = 100; | ||
| triangle[1] = [2]; | ||
| triangle[1][0] = 0; | ||
| triangle[1][1] = -100; | ||
| triangle[2] = [2]; | ||
| triangle[2][0] = -100; | ||
| triangle[2][1] = 100; | ||
| let triangle_original = [3]; | ||
| for (let i = 0; i < 3; i++) { | ||
| let temp = [2]; | ||
| temp[0] = triangle[i][0]; | ||
| temp[1] = triangle[i][1]; | ||
| triangle_original[i] = temp; | ||
| } | ||
|
|
||
| drawingArea.set_draw_func((area, cr, width, height) => { | ||
| // Draw triangle in context | ||
| cr.moveTo(150 + triangle[0][0], 150 + triangle[0][1]); | ||
| cr.lineTo(150 + triangle[1][0], 150 + triangle[1][1]); | ||
| cr.lineTo(150 + triangle[2][0], 150 + triangle[2][1]); | ||
| cr.lineTo(150 + triangle[0][0], 150 + triangle[0][1]); | ||
|
|
||
| cr.setSourceRGBA(1, 0, 1, 1); | ||
| cr.stroke(); | ||
| // Freeing the context before returning from the callback | ||
| cr.$dispose(); | ||
| }); | ||
|
|
||
| scaleRotate.connect("value-changed", () => { | ||
| // Recalculate value of points of triangle | ||
| for (let i = 0; i < 3; i++) { | ||
| // Calculate original angle | ||
| let x = triangle_original[i][0]; | ||
| let y = triangle_original[i][1]; | ||
| let angle = Math.atan(Math.abs(y) / Math.abs(x)); | ||
| if (x > 0 && y > 0) { | ||
| angle = angle; | ||
| } | ||
| if (x < 0 && y > 0) { | ||
| angle = Math.PI - angle; | ||
| } | ||
| if (x < 0 && y < 0) { | ||
| angle = Math.PI + angle; | ||
| } | ||
| if (x > 0 && y < 0) { | ||
| angle = Math.PI * 2 - angle; | ||
| } | ||
| if (x === 0) { | ||
| if (y > 0) { | ||
| angle = angle; | ||
| } | ||
| if (y < 0) { | ||
| angle = -1 * angle; | ||
| } | ||
| } | ||
| if (y === 0) { | ||
| if (x > 0) { | ||
| angle = angle; | ||
| } | ||
| if (x < 0) { | ||
| angle = M_PI; | ||
| } | ||
| } | ||
| // Add to original angle scale value | ||
| angle += (scaleRotate.get_value() * Math.PI) / 180; | ||
| // Set new value to triangle | ||
| let radius = Math.sqrt(x * x + y * y); | ||
|
|
||
| triangle[i][0] = radius * Math.cos(angle); | ||
| triangle[i][1] = radius * Math.sin(angle); | ||
| } | ||
| // Redraw drawing_area | ||
| drawingArea.queue_draw(); | ||
| }); | ||
| //https://www.cairographics.org/tutorial/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "Drawing Area", | ||
| "category": "user_interface", | ||
| "description": "Programmatically draw onto a surface.", | ||
| "panels": [ | ||
| "ui", | ||
| "code" | ||
| ], | ||
| "autorun": true | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.