Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IDATT2003 Mappevurdering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Håvard Johannes Versto Daleng
IDATT2003 Mappevurdering
Commits
a9b32376
Commit
a9b32376
authored
11 months ago
by
Magnus Eik
Browse files
Options
Downloads
Patches
Plain Diff
Add scaling fractal for window scaling.
parent
6c039314
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java
+39
-1
39 additions, 1 deletion
src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java
with
39 additions
and
1 deletion
src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java
+
39
−
1
View file @
a9b32376
...
...
@@ -39,6 +39,8 @@ public class ChaosGameGui implements ChaosGameObserver {
private
Stage
primaryStage
;
private
double
aspectRatio
;
private
Canvas
canvas
;
...
...
@@ -124,6 +126,8 @@ public class ChaosGameGui implements ChaosGameObserver {
private
GuiButtonController
controller
;
public
ChaosGameGui
(
Stage
primaryStage
)
throws
IOException
{
this
.
primaryStage
=
primaryStage
;
this
.
initializeComponents
();
...
...
@@ -135,7 +139,17 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
primaryStage
.
setScene
(
scene
);
primaryStage
.
setOnShown
(
event
->
this
.
imageView
.
requestFocus
());
primaryStage
.
show
();
}
// Initialize aspect ratio based on initial dimensions
this
.
aspectRatio
=
(
double
)
width
/
height
;
// Add listeners to handle window size changes
scene
.
widthProperty
().
addListener
((
observable
,
oldValue
,
newValue
)
->
{
resizeCanvas
();
});
scene
.
heightProperty
().
addListener
((
observable
,
oldValue
,
newValue
)
->
{
resizeCanvas
();
});}
/**
* Initialize the components of the GUI.
*/
...
...
@@ -220,6 +234,10 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
this
.
canvas
=
new
Canvas
(
width
,
height
);
//this.imageView.setImage(canvas.snapshot(null, null));
canvas
.
widthProperty
().
bind
(
imageView
.
fitWidthProperty
());
canvas
.
heightProperty
().
bind
(
imageView
.
fitHeightProperty
());
this
.
clearImageView
();
}
...
...
@@ -429,6 +447,8 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
rightVBox
.
setFocusTraversable
(
false
);
borderPane
.
setFocusTraversable
(
false
);
}
/**
...
...
@@ -569,4 +589,22 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
public
Window
getStage
()
{
return
this
.
primaryStage
;
}
private
void
resizeCanvas
()
{
double
newWidth
=
scene
.
getWidth
()
-
sideMenu
.
getWidth
();
double
newHeight
=
scene
.
getHeight
();
if
(
newWidth
/
newHeight
>
aspectRatio
)
{
newWidth
=
newHeight
*
aspectRatio
;
}
else
{
newHeight
=
newWidth
/
aspectRatio
;
}
// Update imageView size to new calculated dimensions
imageView
.
setFitWidth
(
newWidth
);
imageView
.
setFitHeight
(
newHeight
);
// Redraw the fractal to fit the new canvas size
controller
.
drawChaosGame
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment