source: trunk/src/org/expeditee/agents/ScaleFrameset.java@ 636

Last change on this file since 636 was 636, checked in by jts21, 10 years ago

Don't scale lower than minimum size (to stop crashing/breaking item sizes)

File size: 2.2 KB
Line 
1package org.expeditee.agents;
2
3import java.util.Collection;
4
5import org.expeditee.gui.Frame;
6import org.expeditee.gui.FrameIO;
7import org.expeditee.gui.FrameKeyboardActions;
8import org.expeditee.gui.Vector;
9import org.expeditee.items.Item;
10import org.expeditee.items.Line;
11import org.expeditee.items.Text;
12import org.expeditee.items.UserAppliedPermission;
13
14public class ScaleFrameset extends DefaultAgent {
15 private int _firstFrame = 1;
16
17 private float _scale = 1F;
18
19 private int _maxFrame = Integer.MAX_VALUE;
20
21 public ScaleFrameset(float scale, int firstFrame, int maxFrame) {
22 super();
23 _firstFrame = firstFrame;
24 _maxFrame = maxFrame;
25 _scale = scale;
26 }
27
28 public ScaleFrameset(float scale) {
29 this(scale, 1, Integer.MAX_VALUE);
30 }
31
32 @Override
33 protected Frame process(Frame frame) {
34 String framesetName = frame.getFramesetName();
35
36 _maxFrame = Math.min(FrameIO.getLastNumber(framesetName), _maxFrame);
37
38 // Scale each of the frames
39 for (int i = _firstFrame; i <= _maxFrame; i++) {
40 scaleFrame(FrameIO.LoadFrame(framesetName + i), _scale);
41 }
42 // TODO fix this so it actually works properly!!
43 // TODO figure out why it doesnt repaint correctly sometimes
44
45 // TODO make this thread safe!
46 FrameKeyboardActions.Refresh();
47
48 return null;
49 }
50
51 public static void scaleFrame(Frame frame, float scaleFactor) {
52
53 if (frame == null) {
54 return;
55 }
56
57 for (Vector v : frame.getVectors()) {
58 v.Source.scale(scaleFactor, 0, 0);
59 }
60
61 Collection<Item> items = frame.getVisibleItems();
62
63 for(Item item : items) {
64 if(item instanceof Text && item.getSize() <= Text.MINIMUM_FONT_SIZE && scaleFactor < 1) {
65 return;
66 }
67 }
68
69 for (Item item : items) {
70 // This line is only needed for circles!!
71 // Need to really fix up the way this works!!
72 if (item.hasEnclosures())
73 continue;
74 if (!item.hasPermission(UserAppliedPermission.full))
75 continue;
76 item.invalidateAll();
77 if (!(item instanceof Line)) {
78 item.scale(scaleFactor, 0, 0);
79 }
80 }
81
82 for (Item item : items) {
83 if (!item.hasPermission(UserAppliedPermission.full))
84 continue;
85 // if (!(item instanceof Line))
86 item.updatePolygon();
87
88 if (item instanceof Line) {
89 ((Line) item).refreshStroke(item.getThickness());
90 }
91
92 item.invalidateAll();
93 }
94 }
95}
Note: See TracBrowser for help on using the repository browser.