cleaned all trailing white space from source files.
[sdk] / samples / guiAndGfx / curvyweb / curvyweb.ec
1 // CurvyWeb -- By Joey Adams
2 import "ecere"
3
4 class Form1 : Window
5 {
6    text = "Form1 Professional Edition";
7    background = activeBorder;
8    borderStyle = sizable;
9    hasMaximize = true;
10    hasMinimize = true;
11    hasClose = true;
12    size = { 400, 400 };
13    anchor = { horz = -19, vert = 44 };
14
15    int webDensity;
16    webDensity = 10;
17
18    Slider slider { this, size = { 25, 350 }, position = {375, 25}, direction=vertical, percent=(double)webDensity/200.0;
19
20       bool NotifySlide(Slider slider, double percent)
21       {
22          webDensity = (int)(percent*200);
23          Update(null);
24          return true;
25       }
26    };
27
28    void OnResize(int width, int height)
29    {
30       slider.position.x = width-25;
31       slider.size.h = height-50;
32    }
33
34    void OnRedraw(Surface surface)
35    {
36       int i,w,h,d;
37       w = this.clientSize.w-1;
38       h = this.clientSize.h-1;
39       d = webDensity;
40       if (d<=0)
41          d = 1;
42       for (i=0; i<=d; i++)
43          surface.DrawLine(0,i*h/d,i*w/d,h);
44    }
45
46    /*void OnRedraw(Surface surface)
47    {
48       int i,w,h,d;
49       w = this.clientSize.w-1;
50       h = this.clientSize.h-1;
51       d = webDensity;
52       if (d<=0)
53          d = 1;
54       for (i=0; i<=d; i++) {
55          surface.DrawLine(i*w/d,0,i*w/d,h);
56          surface.DrawLine(0,i*h/d,w,i*h/d);
57       }
58    }*/
59 }
60
61 //Ar, ye slider be pirated from Acovel Player!
62
63 class Gadget : Window
64 {
65    clickThrough = true;
66    inactive = true;
67
68    bool OnLeftButtonDown(int x, int y, Modifiers mods)
69    {
70
71       return true;
72    }
73 };
74
75 define skinBackground = Color { r = 40, g = 40, b = 40 };
76 define skinForeground = white;
77
78 class Slider : Gadget
79 {
80    ScrollDirection direction;
81    opacity = 0;
82    bool dragging;
83    double percent;
84    int offset;
85
86    void OnRedraw(Surface surface)
87    {
88       if(direction == horizontal)
89       {
90          int pos = (int)((clientSize.w-7) * percent + 0.5) + 3;
91          surface.SetBackground(skinForeground);
92          surface.Area(0, clientSize.h / 2 - 3, clientSize.w-1, clientSize.h/2 + 3);
93          surface.SetForeground(black);
94          surface.Rectangle(1, clientSize.h / 2 - 2, clientSize.w-2, clientSize.h/2 + 2);
95
96          surface.SetBackground(darkGray);
97          surface.Area(pos - 3, 0, pos + 3, clientSize.h-1);
98          surface.SetForeground(white);
99          surface.Rectangle(pos - 3, 0, pos + 3, clientSize.h-1);
100          surface.VLine(2, clientSize.h-3, pos);
101       }
102       else
103       {
104          int pos = (int)((clientSize.h-7) * (1.0-percent) + 0.5) + 3;
105          surface.SetBackground(skinForeground);
106          surface.Area(clientSize.w / 2 - 3, 0, clientSize.w/2 + 3, clientSize.h-1);
107          surface.SetForeground(black);
108          surface.Rectangle(clientSize.w / 2 - 2, 1, clientSize.w/2 + 2, clientSize.h-2);
109
110          surface.SetBackground(darkGray);
111          surface.Area(0, pos - 3, clientSize.w-1, pos + 3);
112          surface.SetForeground(white);
113          surface.Rectangle(0, pos - 3, clientSize.w-1, pos + 3);
114          surface.HLine(2, clientSize.w-3, pos);
115       }
116    }
117
118    bool OnLeftButtonDown(int x, int y, Modifiers mods)
119    {
120       dragging = true;
121       Capture();
122       OnMouseMove(x, y, mods);
123       return true;
124    }
125
126    bool OnMouseMove(int x, int y, Modifiers mods)
127    {
128       if(dragging)
129       {
130          if(direction == horizontal)
131             percent = ((double)x - offset - 3) / (double)(clientSize.w-7);
132          else
133             percent = 1.0-((double)y - offset - 3) / (double)(clientSize.h-7);
134          // TO FIX: Max(Min didn't work with double
135          if(percent < 0) percent = 0;
136          else if(percent > 1) percent = 1;
137          Update(null);
138          NotifySlide(master, this, percent);
139       }
140       return true;
141    }
142
143    void OnMouseCaptureLost()
144    {
145       OnLeftButtonUp(0,0,0);
146    }
147
148    bool OnLeftButtonUp(int x, int y, Modifiers mods)
149    {
150       if(dragging)
151       {
152          dragging = false;
153          ReleaseCapture();
154          NotifySlideUp(master, this, percent);
155       }
156       return true;
157    }
158
159 public:
160    virtual bool Window::NotifySlide(Slider slider, double percent);
161    virtual bool Window::NotifySlideUp(Slider slider, double percent);
162    property double percent
163    {
164       get { return percent; }
165       set { if(!dragging) { percent = value; Update(null); } }
166    }
167    property ScrollDirection direction
168    {
169       set { direction = value; }
170       get { return direction; }
171    };
172 }
173
174 Form1 form1 {};