forked from ivangrozny/TexTuring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.pde
More file actions
126 lines (110 loc) · 6.81 KB
/
gui.pde
File metadata and controls
126 lines (110 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class GuiWindow {
ArrayList<GuiElement> elements;
String state = "";
ArrayList<File> listOfFiles;
GuiWindow() {
elements = new ArrayList<GuiElement>();
listOfFiles = new ArrayList<File>();
}
void setupGui(){
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } // platform specific UI
surface.setLocation(int(displayWidth*0.1), int(displayHeight*0.1));
surface.setResizable(true);
surface.setIcon( loadImage("logo.png") );
colorMode(HSB); for (int i=0;i<=25;i++) C[i] = color(123,270-i*13,100+i*5); // create UI color shades
background( bg );
noStroke();
PFont font = loadFont("PixelOperator-16.vlw"); textFont(font, 16);
int guiWidth = 350;
Rect guiRect = new Rect(d, d, 100, 22 );
elements.add(new Menu (new Rect(guiRect), new String[]{ "Parameters", "Save settings", "Load settings" } ));
guiRect.size.x = 113;
guiRect.pos.x += 190; elements.add(new Menu (new Rect(guiRect), new String[]{ "Input image", "Select file", "Select folder" } ));
guiRect.pos.x += 118; elements.add(new Menu (new Rect(guiRect), new String[]{ "Seeding mode", "noise", "monochrome", "regular" } ));
guiRect.pos.x += 118; elements.add(new Button(new Rect(guiRect), "Export image"));
elements.add(0,new ViewPort(new Rect( d+200+350+90 , b+35, width-200-350-90-d-d, height -3*b-35 )));
guiRect.pos.x = d+200+350+90; elements.add(new Button(new Rect(guiRect) , "Render"));
guiRect.size.x = 22; guiRect.size.y = 22;
guiRect.pos.x +=118; elements.add(new Button(new Rect(guiRect), " +"));
guiRect.pos.x += 28; elements.add(new Button(new Rect(guiRect), " -"));
guiRect.pos.x += 30+5;
guiRect.size.x=width-guiRect.pos.x-50-d; elements.add(1,new StatusBar(new Rect(guiRect), "status"));
guiRect.size.x=45;
guiRect.pos.x = width-d-45; elements.add(new Button(new Rect(guiRect), "About"));
guiRect = new Rect( 200, d, guiWidth, 23);
guiRect.pos.y += 100; elements.add(new Slider(new Rect(guiRect), "iterations","Growing time", 5000));
guiRect.pos.y += 55; elements.add(new Slider(new Rect(guiRect), "resolution","Size", 255));
guiRect.pos.y += 55;
guiRect.size.x-= 30; elements.add(new Slider(new Rect(guiRect), "threshold","Threshold", 255));
guiRect.pos.x += guiRect.size.x+10;
guiRect.size.x = 22; elements.add(new CheckBox(new Rect(guiRect), "check threshold"));
guiRect = new Rect( 200+50, guiRect.pos.y, 250, 250 );
guiRect.pos.y += 50; elements.add(2,new DiSlider(new Rect(guiRect), "From Growing bay to shades of grey"));
guiRect.size.x = guiWidth+10; guiRect.size.y = 60; guiRect.pos.x= 200;
guiRect.pos.y += 300; elements.add(new BiSlider(new Rect(guiRect), "reaction","Feed rate"));
guiRect.pos.y += 68; elements.add(new BiSlider(new Rect(guiRect), "diffusion", "Kill rate"));
for (int i = 0; i<7; i++) {
elements.add( i+2, new Snap( new Rect( d , d+100+ i*(80+b) , 100, 80 ) , "snap" ));
}
elements.get(7).flag = "beginAnimation";
elements.get(8).flag = "endAnimation";
// debug : list elements position
for (int i = 0; i < gui.elements.size(); ++i) println(i + "---" + gui.elements.get(i) );
}
void injectMouseMoved() { for (GuiElement elem : elements) { elem.moved(); } }
void injectMouseDragged() { for (GuiElement elem : elements) { if(elem.isOver()) { elem.dragged(); return; } } }
void injectMouseReleased() { for (GuiElement elem : elements) { if(elem.isOver()) { elem.released(); return; } } }
void injectMousePressed() { for (GuiElement elem : elements) { if(elem.isOver() ) { elem.pressed(); return; } } }
void injectMouseWheel(int scroll){ for (GuiElement elem : elements) { if(elem.isOver() ) { elem.scroll(scroll); return; } } }
void update(){
initDrop();
gui.elements.get(9).updateMapImg();
viewing = true ;
for (GuiElement elem : elements)
elem.update();
fill(colorFont); text("Samples", d, d+100 -10 );
}
void resize(){ for (GuiElement elem:elements) elem.resize(); }
void message(String msg){ elements.get(1).message(msg); }
void about(){
JPanel aboutPane = new JPanel(new BorderLayout());
String txt = "<html><h2>TexTuring 2.1</h2>2017 - General Public Licence - GNU GPL<br><br>Dithering tool based on natural patterns.<br>TexTuring is a tool to ease the use of reaction-diffusion model.<br><br><br>Project initiated in 2015 by <a href='www.ivan-murit.fr'>www.ivan-murit.fr</a><br>Special thanks to the crowd-founders for the initial support !<br><br></html>";
aboutPane.add(new JLabel(txt));
int aboutResult = JOptionPane.showConfirmDialog(null, aboutPane, "About", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE);
}
}
void loadFile( File _file ){ params.loadFile( _file ); }
void saveFile( File _file ){ params.saveFile( _file ); }
void keyPressed(){
if (key=='+') gui.elements.get(0).scroll(-1);
if (key=='-') gui.elements.get(0).scroll(1);
if (key==' ') gui.elements.get(0).renderView();
if (key==ENTER) gui.elements.get(0).renderView();
if ( keyCode == CONTROL) control = true;
}
void buttonPressed( GuiElement _elem ){
if ( _elem.name == "Select file" ) { selectInput("Select a new image", "fileSelected"); }
if ( _elem.name == "Select folder" ) { selectFolder("Select a folder to process:", "folderSelected");}
if ( _elem.name == "Export image" ) { exportImage(); }
if ( _elem.name == "Load settings" ) { selectInput( "Select TexTuring settings file", "loadFile"); viewing = true ; }
if ( _elem.name == "Save settings" ) { selectOutput("Name your TexTuring settings file", "saveFile"); }
if ( _elem.name == "specimen" ) { }
if ( _elem.name == "check threshold" ) { threshold = !threshold ; viewing=true; }
if ( _elem.name == "Render"){ gui.elements.get(0).renderView(); }
if ( _elem.name == " +" ) { gui.elements.get(0).scroll(-1); }
if ( _elem.name == " -" ) { gui.elements.get(0).scroll(1); }
if ( _elem.name == "About" ) { gui.about(); }
if ( _elem.name == "noise" ) { params.iniState = 0; viewing=true; synchroScroll = true ; gui.update(); }
if ( _elem.name == "regular" ) { params.iniState = 1; viewing=true; synchroScroll = true ; gui.update(); }
if ( _elem.name == "monochrome" ) { params.iniState = 2; viewing=true; synchroScroll = true ; gui.update(); }
mousePressed = false ;
}
color[] C = new color[26];
color bg = color(225);
//color colorOver = color();
color colorActive = color(255, 142, 9);
color colorFont = color(0, 38, 69);
int a = 200, b = 5, c = 20, d = 10, haut = 60, gauche = 65;
void styleSelecStroke(){ stroke(C[15]); noFill(); }
void styleSelec(){ fill(C[15]); noStroke(); }
void fontColor(){ fill(#002666); }