Skip to content

Commit 7f6016e

Browse files
committed
javadoc for splitscreen renderer
1 parent 43f709f commit 7f6016e

File tree

1 file changed

+73
-24
lines changed

1 file changed

+73
-24
lines changed

jplotter/src/main/java/hageldave/jplotter/renderers/SplitScreenRenderer.java

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,130 @@
11
package hageldave.jplotter.renderers;
22

3-
import java.awt.geom.Rectangle2D;
4-
53
import org.lwjgl.opengl.GL11;
64
import org.w3c.dom.Document;
75
import org.w3c.dom.Element;
86
import org.w3c.dom.Node;
97

108
import hageldave.jplotter.svg.SVGUtils;
119

12-
public class SplitScreenRenderer implements Renderer, AdaptableView {
10+
/**
11+
* The SplitScreenRenderer is a space dividing renderer which defines two separate
12+
* view ports for two other renderers.
13+
* The space can be divided either vertically or horizontally ({@link #setVerticalSplit(boolean)}).
14+
* The location of the divider is defined by a relative value determining the area ratio between
15+
* the first view port and the whole area (0.5 is equally split, divider in the middle).
16+
* ({@link #setDividerLocation(double)}).
17+
* The first renderer will be put on top/left, the second on bottom/right.
18+
*
19+
* @author hageldave
20+
*/
21+
public class SplitScreenRenderer implements Renderer {
1322

1423
Renderer r1;
1524
Renderer r2;
16-
double spaceRatio;
25+
double dividerLocation;
1726
boolean verticalSplit;
1827
boolean isEnabled = true;
1928

29+
/**
30+
* Creates a new SplitScreenRenderer that is horizontally and equally split.
31+
*/
2032
public SplitScreenRenderer() {
2133
this(0.5,false);
2234
}
2335

24-
public SplitScreenRenderer(double ratio, boolean vertical) {
25-
this(null,null,ratio,vertical);
36+
/**
37+
* Creates a new SplitScreenRenderer.
38+
* @param divider relative location of the divider
39+
* @param vertical splitting vertically (true) or horizontally (false)
40+
*/
41+
public SplitScreenRenderer(double divider, boolean vertical) {
42+
this(null,null,divider,vertical);
2643
}
2744

28-
public SplitScreenRenderer(Renderer r1, Renderer r2, double ratio, boolean vertical) {
45+
/**
46+
* Creates a new {@link SplitScreenRenderer}
47+
* @param r1 left/top renderer
48+
* @param r2 right/bottom renderer
49+
* @param divider relative location of the divider
50+
* @param vertical splitting vertically (true) or horizontally (false)
51+
*/
52+
public SplitScreenRenderer(Renderer r1, Renderer r2, double divider, boolean vertical) {
2953
this.r1=r1;
3054
this.r2=r2;
31-
this.spaceRatio=ratio;
55+
this.dividerLocation=divider;
3256
this.verticalSplit=vertical;
3357
}
3458

35-
public SplitScreenRenderer setSpaceRatio(double spaceRatio) {
36-
this.spaceRatio = spaceRatio;
59+
/**
60+
* Sets the dividers relative location. This determines the viewport sizes for the split.
61+
* @param location value in [0.0 .. 1.0], 0.5 is equal, 0.75 uses 3/4 of the space for renderer 1.
62+
* @return this for chaining.
63+
*/
64+
public SplitScreenRenderer setDividerLocation(double location) {
65+
this.dividerLocation = location;
3766
return this;
3867
}
3968

69+
/**
70+
* Sets the split orientation.
71+
* @param verticalSplit, when true the renderers are put left and right,
72+
* when false they are put top and bottom.
73+
* @return this for chaining
74+
*/
4075
public SplitScreenRenderer setVerticalSplit(boolean verticalSplit) {
4176
this.verticalSplit = verticalSplit;
4277
return this;
4378
}
4479

80+
/**
81+
* Sets the top/left renderer.
82+
* @param r1 renderer to render in the top/left view port.
83+
* @return this for chaining
84+
*/
4585
public SplitScreenRenderer setR1(Renderer r1) {
4686
this.r1 = r1;
4787
return this;
4888
}
4989

90+
/**
91+
* Sets the bottom/right renderer.
92+
* @param r2 renderer to render in the bottom/right view port.
93+
* @return this for chaining
94+
*/
5095
public SplitScreenRenderer setR2(Renderer r2) {
5196
this.r2 = r2;
5297
return this;
5398
}
5499

100+
/**
101+
* @return the top/left renderer.
102+
*/
55103
public Renderer getR1() {
56104
return r1;
57105
}
58106

107+
/**
108+
* @return the bottom/right renderer.
109+
*/
59110
public Renderer getR2() {
60111
return r2;
61112
}
62113

63-
public double getSpaceRatio() {
64-
return spaceRatio;
114+
/**
115+
* @return the relative location of the divider.
116+
*/
117+
public double getDividerLocation() {
118+
return dividerLocation;
65119
}
66120

121+
/**
122+
* @return whether the split orientation is vertical
123+
*/
67124
public boolean isVerticalSplit() {
68125
return verticalSplit;
69126
}
70127

71-
@Override
72-
public void setView(Rectangle2D view) {
73-
if(r1 instanceof AdaptableView)
74-
((AdaptableView) r1).setView(view);
75-
if(r2 instanceof AdaptableView)
76-
((AdaptableView) r2).setView(view);
77-
}
78-
79128
@Override
80129
public void glInit() {
81130
if(r1 != null)
@@ -91,8 +140,8 @@ public void render(int vpx, int vpy, int w, int h) {
91140

92141
glInit();
93142

94-
int w1 = verticalSplit ? (int)Math.round(w*spaceRatio):w;
95-
int h1 = verticalSplit ? h:(int)Math.round(h*spaceRatio);
143+
int w1 = verticalSplit ? (int)Math.round(w*dividerLocation):w;
144+
int h1 = verticalSplit ? h:(int)Math.round(h*dividerLocation);
96145
int w2 = verticalSplit ? w-w1:w;
97146
int h2 = verticalSplit ? h:h-h1;
98147
int x1 = 0;
@@ -116,8 +165,8 @@ public void renderSVG(Document doc, Element parent, int w, int h) {
116165
if(!isEnabled())
117166
return;
118167

119-
int w1 = verticalSplit ? (int)Math.round(w*spaceRatio):w;
120-
int h1 = verticalSplit ? h:(int)Math.round(h*spaceRatio);
168+
int w1 = verticalSplit ? (int)Math.round(w*dividerLocation):w;
169+
int h1 = verticalSplit ? h:(int)Math.round(h*dividerLocation);
121170
int w2 = verticalSplit ? w-w1:w;
122171
int h2 = verticalSplit ? h:h-h1;
123172
int x1 = 0;

0 commit comments

Comments
 (0)