Merge remote-tracking branch 'origin/6.1'
[scilab.git] / scilab / modules / scicos_blocks / macros / Sources / tkscaleblk.sci
1 //  Scicos
2 //
3 // Copyright (C) DIGITEO - ClĂ©ment DAVID <clement.david@scilab.org>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 //
19 // See the file ../license.txt
20 //
21
22 function block=tkscaleblk(block,flag)
23     if flag == 1 then
24         // Output update
25         slider = get(block.uid + "#slider");
26
27         if slider <> [] then
28             // calculate real value
29             value = get(slider,"value") / block.rpar(3);
30
31             w = get(block.uid);
32             if w <> [] then
33                 set(w, "info_message", string(value));
34             end
35
36             block.outptr(1) = value;
37         end
38     elseif flag == 4 then
39         // Initialization
40
41         // if already exists (stopped) then reuse
42         f = get(block.uid);
43         if f <> [] then
44             return;
45         end
46
47         if length(block.label) == 0 then
48             tk_label = string(curblock());
49         else
50             tk_label = block.label;
51         end
52
53         f = figure("Figure_name", _("TK Source: ") + tk_label, ...
54         "dockable", "off", ...
55         "infobar_visible" , "on", ...
56         "toolbar", "none", ...
57         "menubar_visible", "off", ...
58         "menubar", "none", ...
59         "backgroundcolor", [1 1 1], ...
60         "default_axes", "off", ...
61         "figure_size", [180 350], ...
62         "layout", "border", ...
63         "figure_position", [40 40], ...
64         "Tag", block.uid);
65
66         frame_slider = uicontrol(f, ...
67         "style", "frame", ...
68         "constraints", createConstraints("border", "left", [180, 0]), ...
69         "border", createBorder("line", "lightGray", 1), ...
70         "backgroundcolor", [1 1 1], ...
71         "layout", "gridbag");
72
73         // slider
74         bounds = block.rpar(1:2);
75         initial = mean(bounds);
76         uicontrol(frame_slider, ...
77         "Style", "slider", ...
78         "Tag", block.uid + "#slider", ...
79         "Min", bounds(1), ...
80         "Max", bounds(2), ...
81         "Value", initial, ...
82         "Position", [0 0 10 20], ...
83         "SliderStep", [block.rpar(3) 2*block.rpar(3)]);
84
85         frame_label = uicontrol(frame_slider, ...
86         "style", "frame", ...
87         "constraints", createConstraints("border", "right"), ...
88         "backgroundcolor", [1 1 1], ...
89         "layout", "gridbag");
90
91         // labels
92         labels = string([bounds(2) ; ...
93         mean([bounds(2) initial])  ; ...
94         initial                    ; ...
95         mean([bounds(1) initial])  ; ...
96         bounds(1)]);
97         labels = "<html>" + strcat(labels, "<br /><br /><br />") + "</html>";
98
99         uicontrol(frame_label, ...
100         "Style", "text", ...
101         "String", labels(1), ...
102         "FontWeight", "bold", ...
103         "backgroundcolor", [1 1 1]);
104
105         // update default value
106         block.outptr(1) = initial / block.rpar(3);
107     elseif flag == 5 then
108         // Ending
109         f = get(block.uid);
110         if f <> [] then
111             close(f);
112         end
113     end
114 endfunction
115