-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ml
More file actions
212 lines (196 loc) · 8 KB
/
Copy pathexample.ml
File metadata and controls
212 lines (196 loc) · 8 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
open Widget
open Window
open Draw
open Blocks
let id a = a
let center_rect = Rect.lift4 id
open BatFloat
(* class sphere_view xw yw zw ww = object ( self : 'self ) *)
(* inherit graphics *)
(* method draw rect = *)
(* (\* Gl.disable `scissor_test; *\) *)
(* Gl.enable `depth_test ; *)
(* (\* Gl.disable `cull_face ; *\) *)
(* let x,y,w,h = center_rect rect in *)
(* (\* print_endline (string_of_float (float w/. float h)); *\) *)
(* GlDraw.viewport ~x ~y ~w ~h; *)
(* GlMat.mode `projection; *)
(* GlMat.push (); *)
(* GlMat.load_identity (); *)
(* GluMat.perspective ~fovy:40. ~aspect:(float w/. float h) ~z:(0.1,100.0); *)
(* GlMat.mode `modelview; *)
(* (\* Gl.enable `light0; *\) *)
(* (\* Gl.enable `lighting; *\) *)
(* (\* GlMat.push (); *\) *)
(* GlMat.load_identity (); *)
(* let x, y, z,w = xw#value, yw#value, zw#value, ww#value in *)
(* let h = w in *)
(* GluMat.look_at *)
(* ~eye:(x, y, z) *)
(* ~center:(0.0, 0.0, 0.0) *)
(* ~up: (0.0, 1.0, 0.); *)
(* (\* GlDraw.begins `quads; *\) *)
(* (\* GlDraw.color (0.,1.,0.); *\) *)
(* (\* GlDraw.vertex ~x ~y (); *\) *)
(* (\* GlDraw.vertex ~x:(x + w) ~y (); *\) *)
(* (\* GlDraw.vertex ~x:(x + w) ~y:(y + h) (); *\) *)
(* (\* GlDraw.vertex ~x ~y:(y + h) (); *\) *)
(* (\* GlDraw.vertex ~x:0. ~y:0. ~z:1.1; *\) *)
(* (\* GlDraw.vertex ~x:10. ~y:0. ~z:1.1; *\) *)
(* (\* GlDraw.vertex ~x:10. ~y:10. ~z:1.1; *\) *)
(* (\* GlDraw.vertex ~x:0. ~y:10. ~z:1.1; *\) *)
(* (\* GlDraw.ends (); *\) *)
(* Glut.glutSolidCube ~size:1.0; *)
(* GlMat.mode `projection; *)
(* GlMat.pop (); *)
(* (\* GlMat.mode `modelview; *\) *)
(* (\* GlMat.pop (); *\) *)
(* let w,h = Display. display_size in *)
(* GlDraw.viewport ~x:0 ~y:0 ~w ~h; *)
(* (\* Gl.enable `scissor_test *\) *)
(* () *)
(* end *)
let project_name = ref (Sys.argv.(1))
open Blocks
let texture_generator_view() =
let kont = ref None in
let open Texgen in
let control_pane = new texture_preview(* frame (Layout.fixed_vertical 5 25) *) in
let generate graphical_pane =
let op_of_properties edit_pane =
let ws = edit_pane # widgets in
let params =
List.map (fun (_,w) ->
w # key, w # value) ws
in
params
in
let start_rect =
BatOption.map (fun (_,b) -> (b # window.pos))
(BatList.Exceptionless.find (fun (_,b) -> b # get_state == Selected) graphical_pane#widgets) in
let rec find_all_macros = function
| (_,w) :: xs ->
if Pervasives.(w # key = "MACRO") then
let rect = w # window.pos in
let tree = graphical_pane#layout (Some rect) in
(match tree with
| Tree ((prop, block), lst) ->
let params = op_of_properties prop in
let i name = let Event.Int v = List.assoc name params in v in
i "id", List.hd lst) :: find_all_macros xs
else find_all_macros xs
| [] -> [] in
let macros = find_all_macros graphical_pane#widgets in
let tree = graphical_pane#layout start_rect in
let rec loop = function
| Tree ((prop, block), lst) ->
let params = op_of_properties prop in
let f name = let Event.Float v = List.assoc name params in v in
let i name = let Event.Int v = List.assoc name params in v in
(match block # key with
| "perlin" ->
Clouds { octaves = i "octaves";
persistence = f "persistence";
seed = i "seed" }
| "glow" -> Glow { x0 = f "x0";
y0 = f "y0";
atten = f "atten";
xr = f "xr";
yr = f "yr";}
| "phi" -> Phi ({ scale = f "scale";
base = f "base"; }, loop (List.hd lst))
| "flat" -> Flat { fx = f "fx";
fy = f "fy";
fw = f "fw";
fh = f "fh";
fg = f "fg";
bg = f "bg"; }
| "add" ->
Add (List.map loop lst)
| "light" ->
Light ({ lx = f "lx";
ly = f "ly";
ldx = f "ldx";
ldy = f "ldy"; }, loop (List.hd lst))
| "distort" ->
let op1::op2::op3::_ = lst in
Distort ({ dtype=Radial;
dscale = f "dscale"},
loop op1, loop op2, loop op3)
| "rgb" -> Printf.printf "lst::%d\n" (List.length lst); let r::g::b::_ = lst in
Rgb ({ rp = f "rp";
gp = f "gp";
bp = f "bp";}, loop r, loop g, loop b)
| "hsv" -> let r::g::b::_ = lst in
Hsv ({ hp = f "hp";
sp = f "sp";
vp = f "vp";}, loop r, loop g, loop b)
| "phi3" -> Phi3 ({ scale1 = f "scale1";
base1 = f "base1";
scale2 = f "scale2";
base2 = f "base2";
scale3 = f "scale3";
base3 = f "base3";
},
loop (List.hd lst))
| "MACRO" -> loop (List.hd lst)
| "CALL" -> loop (List.assoc (i "id") macros)
| "modulate" ->
Modulate (List.map loop lst)
| "invert" ->
Invert (loop (List.hd lst)))
in
let op2 = loop tree in
Texgen.operator := Some op2;
Texgen.reset ();
()
in
let prev_tid = ref None in
let draw w rect =
let tid = Texture.Tga.gl_maketex !prev_tid Texgen.ar in
prev_tid := Some tid;
control_pane # set_image tid;
Texgen.update_texture ();
w # draw;
in
let graphical_pane = block_canvas ~draw ~generate () in
let (_, edit_properties) :: _ = properties_definition in
let edit_pane = properties edit_properties in
let split_control = splitter ~first:control_pane ~second:property_pane Widget.Vertical in
property_pane # add (edit_pane :> fixed);
let main_view = splitter ~first:split_control ~second:graphical_pane Widget.Horizontal in
let main_frame = new frame (Layout.vertical_fixed ~sizes:[25]) in
main_frame#add ((menu_bar
[Entry ("Save",
(fun () -> graphical_pane # write !project_name;
save_texture (!project_name ^ ".tga");
));
Entry ("Open",
(fun () -> graphical_pane # read !project_name));
]) :> draggable);
main_frame#add (main_view :> draggable);
(* main_frame#add (completion_box ()); *)
(try
graphical_pane # read !project_name
with Sys_error _ -> ());
main_frame
let commandline_spec =
let open Arg in
[ "-project", Set_string project_name,"Filename of a project to work with. Default project is \"canvas.txt\"."]
let b () =
Arg.parse commandline_spec;
let open BatInt in
let g = new desktop in
let tgv = ((texture_generator_view()) :> graphical) in
Gui.init
(fun () ->
(* Png_loader.load_img (Filename "ala"); *)
g#add tgv;
())
(fun ~width ~height ->
Window.shelf (Rect.rect (0,0) (width,height));
tgv#invalidate (Rect.rect (10,10) (width-20,height-20));
g#invalidate (Rect.rect (0,0) (width,height)))
;;
b()
;;