Skip to content

Commit

Permalink
last changes before v4.2.4-beta2
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalazscs committed Mar 13, 2021
1 parent 55bd78a commit b8e223b
Show file tree
Hide file tree
Showing 99 changed files with 566 additions and 468 deletions.
14 changes: 10 additions & 4 deletions src/main/java/pixelitor/Canvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,31 @@ public Canvas(Canvas orig) {
/**
* Changes the size with values given in image space
*/
public void changeSize(int newWidth, int newHeight, View view) {
public void changeSize(int newWidth, int newHeight, View view, boolean notify) {
width = newWidth;
height = newHeight;

// also update the component space values
recalcCoSize(view);
recalcCoSize(view, notify);

activeCanvasSizeChanged(this);
}

/**
* Recalculates the component-space (zoomed) size
*/
public void recalcCoSize(View view) {
public void recalcCoSize(View view, boolean notify) {
double viewScale = view.getScaling();

int oldZoomedWidth = zoomedWidth;
int oldZoomedHeight = zoomedHeight;

zoomedWidth = (int) (viewScale * width);
zoomedHeight = (int) (viewScale * height);

view.canvasCoSizeChanged();
if (notify && (zoomedWidth != oldZoomedWidth || zoomedHeight != oldZoomedHeight)) {
view.canvasCoSizeChanged();
}
}

/**
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/pixelitor/Composition.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pixelitor.gui.PixelitorWindow;
import pixelitor.gui.View;
import pixelitor.gui.utils.Dialogs;
import pixelitor.gui.utils.ImagePreviewPanel;
import pixelitor.guides.Guides;
import pixelitor.guides.GuidesChangeEdit;
import pixelitor.history.*;
Expand Down Expand Up @@ -74,6 +75,8 @@ public class Composition implements Serializable {
@Serial
private static final long serialVersionUID = 1L;

private static long debugCounter = 0;

private String name;

private final List<Layer> layerList = new ArrayList<>();
Expand All @@ -90,6 +93,10 @@ public class Composition implements Serializable {
//
// transient variables from here
//

// useful for distinguishing between versions with the same name
private transient String debugName;

private transient File file;
private transient boolean dirty = false;

Expand Down Expand Up @@ -140,6 +147,7 @@ public static Composition fromImage(BufferedImage img, File file, String name) {
// one of the file and name arguments must be given
throw new IllegalArgumentException("no name could be set");
}
comp.createDebugName();
assert comp.getName() != null;
return comp;
}
Expand Down Expand Up @@ -194,6 +202,7 @@ public Composition copy(boolean forUndo, boolean copySelection) {
compCopy.guides = guides.copyForNewComp(view);
}
}
compCopy.createDebugName();

assert compCopy.checkInvariant();

Expand All @@ -211,6 +220,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
// init transient variables
compositeImage = null; // will be set when needed
file = null; // will be set later
debugName = null; // will be set later
dirty = false;
view = null; // will be set later
selection = null; // the selection is not saved
Expand All @@ -226,7 +236,7 @@ public View getView() {
public void setView(View view) {
this.view = view;
if (view != null) {
canvas.recalcCoSize(view);
canvas.recalcCoSize(view, true);
}

if (selection != null) { // can happen when duplicating
Expand Down Expand Up @@ -283,6 +293,15 @@ public void setName(String name) {
}
}

public String getDebugName() {
return debugName;
}

public void createDebugName() {
assert name != null;
this.debugName = name + " " + debugCounter++;
}

public String generateNewLayerName() {
return "layer " + newLayerCount++;
}
Expand Down Expand Up @@ -1045,7 +1064,7 @@ public void createSelectionFrom(Shape shape) {
public void setSelectionRef(Selection selection) {
this.selection = selection;
if (isActive()) {
SelectionActions.setEnabled(selection != null, this);
SelectionActions.update(this);
SelectionActions.getShowHide().updateTextFrom(selection);
}
}
Expand Down Expand Up @@ -1357,6 +1376,7 @@ public void afterSuccessfulSaveActions(File file, boolean addToRecentMenus) {
if (addToRecentMenus) {
RecentFilesMenu.getInstance().addFile(file);
}
ImagePreviewPanel.removeThumbFromCache(file);
Messages.showFileSavedMessage(file);
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/pixelitor/OpenImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ private static void onAllImagesClosed() {
setActiveView(null, false);
activationListeners.forEach(ViewActivationListener::allViewsClosed);
History.onAllImagesClosed();
SelectionActions.setEnabled(false, null);

SelectionActions.update(null);
PixelitorWindow.get().updateTitle(null);
FramesUI.resetCascadeIndex();
}
Expand Down Expand Up @@ -172,7 +171,7 @@ public static void viewActivated(View view) {

var comp = view.getComp();
setActiveView(view, false);
SelectionActions.setEnabled(comp.hasSelection(), comp);
SelectionActions.update(comp);
view.activateUI(true);

for (ViewActivationListener listener : activationListeners) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/pixelitor/Pixelitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ public static void main(String[] args) {
if (!Language.isCodeSupported(sysLangCode)) { // except if supported
Locale.setDefault(Locale.US);
}

Language.load();

System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Pixelitor");

// System.setProperty("sun.java2d.uiScale", "2.0");

if (JVM.isLinux) {
// doesn't seem to pick up good defaults
System.setProperty("awt.useSystemAAFontSettings", "lcd");
Expand Down Expand Up @@ -225,14 +226,14 @@ private static void afterStartTestActions() {

// SplashImageCreator.saveManySplashImages();

// Debug.addTestPath();

// Debug.keepSwitchingToolsRandomly();
// Debug.startFilter(new Marble());

// Navigator.showInDialog(pw);

// Tools.PEN.activate();
// Debug.addTestPath();
// Tools.PEN.startRestrictedMode(PenToolMode.TRANSFORM, false);
// Debug.addMaskAndShowIt();

// Debug.showAddTextLayerDialog();
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/pixelitor/colors/FgBgColorSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import javax.swing.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import static java.awt.Color.BLACK;
Expand Down Expand Up @@ -180,9 +179,9 @@ public void onClick() {
}

private void initResetDefaultsButton() {
resetToDefaultAction = new AbstractAction() {
resetToDefaultAction = new PAction() {
@Override
public void actionPerformed(ActionEvent e) {
public void onClick() {
setDefaultColors();
}
};
Expand All @@ -199,9 +198,9 @@ public void setDefaultColors() {
}

private void initSwapColorsButton() {
swapColorsAction = new AbstractAction() {
swapColorsAction = new PAction() {
@Override
public void actionPerformed(ActionEvent e) {
public void onClick() {
swapColors();
}
};
Expand All @@ -224,9 +223,9 @@ private void swapColors() {
}

private void initRandomizeButton() {
randomizeColorsAction = new AbstractAction() {
randomizeColorsAction = new PAction() {
@Override
public void actionPerformed(ActionEvent e) {
public void onClick() {
setFgColor(Rnd.createRandomColor(), false);
setBgColor(Rnd.createRandomColor(), true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/pixelitor/compactions/Crop.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public CompletableFuture<Composition> process(Composition oldComp) {
}
});

newCanvas.changeSize(cropRect.width, cropRect.height, view);
newCanvas.changeSize(cropRect.width, cropRect.height, view, false);

// The intersected selection, tool widgets etc. have to be moved
// into the coordinate system of the new, cropped image.
Expand Down Expand Up @@ -138,7 +138,7 @@ public CompletableFuture<Composition> process(Composition oldComp) {
view.replaceComp(newComp);

newComp.updateAllIconImages();
SelectionActions.setEnabled(newComp.hasSelection(), newComp);
SelectionActions.update(newComp);

newComp.imageChanged(FULL, true);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/compactions/EnlargeCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public boolean doesNothing() {
protected void changeCanvasSize(Canvas newCanvas, View view) {
newCanvasWidth = newCanvas.getWidth() + east + west;
newCanvasHeight = newCanvas.getHeight() + north + south;
newCanvas.changeSize(newCanvasWidth, newCanvasHeight, view);
newCanvas.changeSize(newCanvasWidth, newCanvasHeight, view, false);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/pixelitor/compactions/Resize.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Laszlo Balazs-Csiki and Contributors
* Copyright 2021 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -108,7 +108,7 @@ private static Composition afterResizeActions(Composition oldComp,
newComp.imCoordsChanged(canvasTransform, false);

View view = newComp.getView();
newCanvas.changeSize(newCanvasSize.width, newCanvasSize.height, view);
newCanvas.changeSize(newCanvasSize.width, newCanvasSize.height, view, false);

History.add(new CompositionReplacedEdit("Resize",
view, oldComp, newComp, canvasTransform, false));
Expand All @@ -117,7 +117,7 @@ private static Composition afterResizeActions(Composition oldComp,
// the view was active when the resize started, but since the
// resize was asynchronous, this could have changed
if (view.isActive()) {
SelectionActions.setEnabled(newComp.hasSelection(), newComp);
SelectionActions.update(newComp);
}

Guides oldGuides = oldComp.getGuides();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/compactions/Rotate.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void changeCanvasSize(Canvas canvas, View view) {
// switch width and height
int newWidth = canvas.getHeight();
int newHeight = canvas.getWidth();
canvas.changeSize(newWidth, newHeight, view);
canvas.changeSize(newWidth, newHeight, view, false);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/compactions/SimpleCompAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public CompletableFuture<Composition> process(Composition oldComp) {
History.add(new CompositionReplacedEdit(
getEditName(), view, oldComp, newComp, canvasAT, false));
view.replaceComp(newComp);
SelectionActions.setEnabled(newComp.hasSelection(), newComp);
SelectionActions.update(newComp);

Guides guides = oldComp.getGuides();
if (guides != null) {
Expand Down
Loading

0 comments on commit b8e223b

Please sign in to comment.