-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.ml
More file actions
102 lines (84 loc) · 2.62 KB
/
Copy pathwindow.ml
File metadata and controls
102 lines (84 loc) · 2.62 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
open GL
open Draw
open Rect
open BatFloat
type window = {
mutable pos : Rect.t;
mutable children : window list;
mutable painter : Rect.t -> unit;
}
let default_painter _ = ()
let default rect = { pos = rect;
children = [];
painter = default_painter }
let empty_window () = default Rect.o
let desktop = default Rect.o
let shelf rect = desktop.pos <- rect
open BatInt
let with_scisor rect f =
let open BatInt in
let screen_width, screen_height = Display.display_size () in
let coords { Rect.x; y; w; h; } =
(x, screen_height-y-h, w, h)
in
glMatrixMode GL_MODELVIEW;
glLoadIdentity ();
let x, y, width, height = coords rect in
glScissor ~x ~y ~width ~height;
glEnable GL_SCISSOR_TEST;
f ();
glDisable GL_SCISSOR_TEST
let desktop_rect () = Rect.rect (0,0) (Display.display_size ())
let rec draw_window window =
let rec draw_client_window rect { pos; children; painter } =
let client_rect = Rect.place_in pos rect in
with_scisor rect (fun () ->
painter client_rect;
List.iter (draw_client_window (together rect client_rect)) children)
in
draw_client_window (desktop_rect ()) window
let draw_desktop () =
Texgen.update_texture();
draw_window desktop
let window_path window =
let bool_of_option = function Some _ -> true | None -> false in
let rec find_loop path ({ children; } as window') =
if window' == window
then Some path
else
match children with
| [] -> None
| windows ->
try List.find bool_of_option
(List.map (fun w -> find_loop (w :: path) w) windows)
with _ -> None
in
match find_loop [] desktop with
| None -> []
| Some path -> List.rev path
let abs_pos window =
let path = window_path window in
List.fold_left
(fun rect { pos } ->
Rect.place_in pos rect) desktop.pos path
let find_window position =
let rec loop rect window =
let rect = Rect.place_in window.pos rect in
(if Rect.is_in rect position then
[window] @ List.concat (List.map (loop rect) window.children)
else
[])
in
List.rev (loop (Rect.rect (0,0) (0,0)) desktop)
let add parent window =
parent.children <- parent.children @ [window];
()
let remove parent window =
parent.children <- BatList.remove_if ((==) window) parent.children;
()
let relative_pos window_relative window =
let window_relative_pos = abs_pos window_relative in
let window_pos = abs_pos window in
Rect.subr window_relative_pos window_pos
let client_pos window global_pos =
Pos.sub global_pos (pos (abs_pos window))