Rev 1858 | Rev 2097 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1528 | jag | 1 | /* |
2 | * slit.h |
||
3 | * slit in Mondrian |
||
2009 | jag | 4 | * DIN Is Noise is copyright (c) 2006-2023 Jagannathan Sampath |
1528 | jag | 5 | * For more information, please visit http://dinisnoise.org/ |
6 | */ |
||
7 | |||
8 | #ifndef __slit__ |
||
9 | #define __slit__ |
||
10 | |||
11 | #include <list> |
||
12 | #include "fader.h" |
||
13 | |||
14 | struct rect; |
||
15 | |||
16 | struct slit { // a slit on an edge of a box |
||
17 | |||
18 | rect* boxes [2]; // slit can be on 2 boxes |
||
19 | int edges [2]; // edges of the boxes that has the slit |
||
20 | |||
21 | int type; |
||
22 | enum {INVALID=-1, VERTICAL, HORIZONTAL}; |
||
23 | |||
24 | float start, mid, end; |
||
25 | static float HALF_SIZE; |
||
26 | static float MIN_HALF_SIZE; |
||
27 | static float MIN_SIZE; // 2 * MIN_HALF_SIZE |
||
28 | |||
29 | static int ref; // log |
||
30 | |||
31 | double animt; // animation duration |
||
32 | fader* fdr; // to animate slit |
||
33 | static const double INITIAL_OPEN_CLOSE_TIME; |
||
34 | |||
35 | slit (); |
||
36 | slit (rect** bxs, float x, float y, float sz, fader* fdr = 0); |
||
37 | ~slit (); |
||
38 | int is_too_small (); |
||
39 | inline void calc_mid () { mid = (start+end) / 2.0; } |
||
40 | |||
41 | float anim_start, anim_end; // start,end at start of animation |
||
42 | void toggle_anim (); |
||
43 | void eval_anim (); |
||
44 | |||
45 | int select; // selected? |
||
46 | |||
47 | }; |
||
48 | |||
49 | struct slit_info { |
||
50 | float x, y, half_size; |
||
51 | int anim; |
||
52 | fader fdr; |
||
53 | slit_info (); |
||
54 | }; |
||
55 | |||
56 | struct slit_lip_t { // for editing slit |
||
57 | slit* slitt; |
||
58 | float* lip; |
||
59 | float* prev; |
||
60 | float* cur; |
||
61 | float low, high; |
||
62 | slit_lip_t () { clear ();} |
||
63 | void edit (); |
||
64 | void clear (); |
||
65 | void set_high (float h); |
||
66 | void set_low (float l); |
||
67 | }; |
||
68 | |||
69 | struct slit_drawer { // for drawing |
||
70 | static const int MAX_LINES = 512; |
||
71 | float* verts; |
||
72 | int cur; |
||
73 | int last; |
||
74 | slit_drawer (int n = MAX_LINES); |
||
75 | ~slit_drawer (); |
||
76 | void add (float x, float y); |
||
77 | void draw (); |
||
78 | }; |
||
79 | |||
80 | void draw_slits (float start, float end, float level, int type, std::list<slit*>& _slits, slit_drawer& slit_drawerr); |
||
81 | rect* get_other_rect_of_slit (rect* ir, int e, float v, slit** os); |
||
82 | slit* slit_hit (rect* b, int e, float v); |
||
83 | slit* slit_hit (rect** bxs, float x, float y); |
||
84 | int get_slit_lip (slit_lip_t& sl, rect* R, int e, float v); |
||
85 | |||
86 | typedef std::list<slit*>::iterator slit_iterator; |
||
87 | |||
88 | #endif |