Skip to content

Commit

Permalink
added export zoom setting
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Oct 14, 2021
1 parent d62d9c3 commit c8de770
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 80 deletions.
36 changes: 36 additions & 0 deletions repository/OpenPonk-Roassal2/OPRTCanvasExporter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Class {
#name : #OPRTCanvasExporter,
#superclass : #RTCanvasExporter,
#category : #'OpenPonk-Roassal2'
}

{ #category : #accessing }
OPRTCanvasExporter class >> maxWidthAndHeight [

^ 10000
]

{ #category : #private }
OPRTCanvasExporter >> scaleToMorphLimits [

"scale down to estimated morph (maxWidthAndHeight) and exporter (maxArea) size limits"

| scaledDown |
scaledDown := false.
self extent x > self class maxWidthAndHeight ifTrue: [
scaledDown := true.
self scale:
self class maxWidthAndHeight / self extent x * self cameraScale ].
self extent y > self class maxWidthAndHeight ifTrue: [
scaledDown := true.
self scale:
self class maxWidthAndHeight / self extent y * self cameraScale ].
scaledDown ifTrue: [
GrowlMorph
openWithLabel: 'Warning'
contents: 'Image was forced to scale down to '
, (self cameraScale * 100 printShowingDecimalPlaces: 0)
, ' % zoom due to technical restrictions (max resolution).'
backgroundColor: GrowlMorph theme warningBackgroundColor
labelColor: GrowlMorph theme textColor ]
]
36 changes: 27 additions & 9 deletions repository/OpenPonk-Spec/OPCanvasPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,50 @@ OPCanvasPresenter >> ensureKeyBindingsFor: aWidget [

{ #category : #toolbar }
OPCanvasPresenter >> exportAsPng [
FDSaveFileDialog new
whenSelected: [ :file | self exportCanvasTo: file ];
extensionFilters: {'Images' -> #(png)};
defaultName: self editor diagramController model name asFileName , '.png';

OPExportCanvasDialog new
whenSelected: [ :file :zoom | self exportCanvasTo: file zoom: zoom ];
extensionFilters: { ('Images' -> #( png )) };
defaultName:
self editor diagramController model name asFileName , '.png';
open
]

{ #category : #toolbar }
OPCanvasPresenter >> exportCanvasTo: aFile [

| gridShape gridColor selectedElements |
self exportCanvasTo: aFile zoom: TRCamera new defaultCameraScale
]

{ #category : #toolbar }
OPCanvasPresenter >> exportCanvasTo: aFileReference zoom: aNumber [

| gridShape gridColor selectedElements zoom |
zoom := aNumber = 1
ifTrue: [ roassalView canvas camera defaultCameraScale ]
ifFalse: [ aNumber ].
gridShape := roassalView canvas shapes detect: [ :each |
each isKindOf: TRCanvasGridShape ].
gridColor := gridShape color.
selectedElements := self selectedElements.
self diagramController deselectAll.
[
gridShape color: Color transparent.
(RTCanvasExporter canvas: roassalView canvas)
(OPRTCanvasExporter canvas: roassalView canvas)
format: #png;
whole;
defaultScale;
scale: zoom;
oversizedBy: 20 @ 20;
fileName: aFile;
fileName: aFileReference;
export.
self inform: 'Saved to ' , aFile pathString ] ensure: [
UIManager default
inform: (String streamContents: [ :s |
s << 'Saved to ' << aFileReference pathString.
s
cr;
cr.
s << 'Click to open location' ])
actionOnClick: [ aFileReference openInOSFileBrowser ] ] ensure: [
gridShape color: gridColor.
selectedElements do: [ :each | "self diagramController selectFigure: "
each announce: TRMouseLeftClick new ] ]
Expand Down
102 changes: 102 additions & 0 deletions repository/OpenPonk-Spec/OPExportCanvasDialog.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
Class {
#name : #OPExportCanvasDialog,
#superclass : #FDSaveFileDialog,
#instVars : [
'zoomLabel',
'zoomText',
'zoomPercentageLabel'
],
#category : #'OpenPonk-Spec'
}

{ #category : #specs }
OPExportCanvasDialog class >> defaultSpec [

^ SpecColumnLayout composed
newRow: [ :r |
r
newColumn: [ :c | c add: #bookmarksList ] width: 150;
newColumn: [ :c |
c add: #currentFolderLabel height: self toolbarHeight.
c add: #filesList ] ];
newRow: [ :r |
r
add: #nameLabel width: 50;
add: #nameText;
add: #filtersDropList width: 200 ]
height: self toolbarHeight;
newRow: [ :r |
r
add: #zoomLabel width: 50;
add: #zoomText width: 40;
add: #zoomPercentageLabel.
r newColumn: [ :c | ].
self dialogButtonsLayout: r ]
height: self toolbarHeight;
yourself
]

{ #category : #actions }
OPExportCanvasDialog >> confirm [

| zoomNumber file |
file := self selectedEntry.
file ifNil: [ ^ self ].
zoomNumber := (NumberParser
parse: zoomText text
onError: [ TRCamera new defaultCameraScale * 100 ])
/ 100.
zoomNumber < 0.01 ifTrue: [
zoomNumber := TRCamera new defaultCameraScale ].
onConfirmBlock cull: file cull: zoomNumber.
self delete
]

{ #category : #initialization }
OPExportCanvasDialog >> initializePresenter [

super initializePresenter.
self initializeZoom
]

{ #category : #initialization }
OPExportCanvasDialog >> initializeWidgets [

super initializeWidgets.
(zoomLabel := self newLabel) label: 'Zoom: '.
(zoomText := self newTextInput) autoAccept: true.
(zoomPercentageLabel := self newLabel) label: ' %'.
self focusOrder: {
nameText.
filtersDropList.
zoomText.
cancelButton.
confirmButton }
]

{ #category : #initialization }
OPExportCanvasDialog >> initializeZoom [

zoomText
text: '100';
whenTextIsAccepted: [ :text |
zoomText text: ((text select: #isDigit) takeFirst: 4) ]
]

{ #category : #accessing }
OPExportCanvasDialog >> zoomLabel [

^ zoomLabel
]

{ #category : #accessing }
OPExportCanvasDialog >> zoomPercentageLabel [

^ zoomPercentageLabel
]

{ #category : #accessing }
OPExportCanvasDialog >> zoomText [

^ zoomText
]
71 changes: 0 additions & 71 deletions repository/OpenPonk-Spec/OPExportDiagramWizard.class.st

This file was deleted.

0 comments on commit c8de770

Please sign in to comment.