1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2017 - Samuel GOUGEON
5 // Copyright (C) 2012 - 2016 - Scilab Enterprises
7 // This file is hereby licensed under the terms of the GNU GPL v2.0,
8 // pursuant to article 5.3.4 of the CeCILL v.2.1.
9 // This file was originally licensed under the terms of the CeCILL v2.1,
10 // and continues to be available under such terms.
11 // For more information, see the COPYING file which you should have received
12 // along with this program.
14 function [c] = getcolor(Title,cini)
22 if type(Title)~=10 then
23 msg = gettext("%s: Wrong type for input argument #%d: string expected.\n")
24 error(msprintf(msg, "getcolor", 1));
26 if size(Title, "*")~=1 then
27 msg = gettext("%s: Wrong size for input argument #%d: string expected.\n")
28 error(msprintf(msg, "getcolor", 1));
32 if type(Title)~=10 then
33 msg = gettext("%s: Wrong type for input argument #%d: string expected.\n")
34 error(msprintf(msg, "getcolor", 1));
36 if size(Title, "*")~=1 then
37 msg = gettext("%s: Wrong size for input argument #%d: string expected.\n")
38 error(msprintf(msg, "getcolor", 1));
41 msg = gettext("%s: Wrong type for input argument #%d: A real expected.\n")
42 error(msprintf(msg, "getcolor", 2));
44 if size(cini, "*")~=1 then
45 msg = gettext("%s: Wrong size for input argument #%d: A real expected.\n")
46 error(msprintf(msg, "getcolor", 2));
49 msg = gettext("%s: Wrong number of input arguments: %d to %d expected.\n")
50 error(msprintf(msg, "getcolor", 2, 0, 2));
55 cmap = curFig.color_map;
56 curwin = curFig.figure_id;
62 // create the window for getcolor
67 sdf; // quite agressive. Not sure it is actually useful
80 H = m*45; // These numbers set the size of the getcolor window
82 fig.figure_size = [H,W];
86 delmenu(win, gettext("&File"))
87 delmenu(win, gettext("&Tools"))
88 delmenu(win, gettext("&Edit"))
89 delmenu(win, gettext("&?"))
95 R = [0;0;dx*0.95;dy*0.95];
98 if modulo(k,n)==1 then
102 rects = [rects,R+[x;y;0;0]];
107 xsetech([-1/8,0,1+1/6,1+1/6-1/8],[0,0,wdim(1),wdim(2)]);
109 xsetech([-1/8,-1/8,1+1/6,1+1/6],[0,0,wdim(1),wdim(2)]);
111 // rectangles with the colors
113 // frame around the colors
118 xpoly([-ddx,1,1,-ddx],[0,0,1+ddy,1+ddy],"lines",1);
120 xpoly([-ddx,1-1/n,1-1/n,1,1,-ddx],[0,0,r/m,r/m,1+ddy,1+ddy],"lines",1);
131 k1 = min(max(cini,1),N);
132 xrects(rects(eye(),k1),-k1);
135 rector.thickness = 4;
136 rector.foreground = color(255*(1-cmap(k1,1)),255*(1-cmap(k1,2)),255*(1-cmap(k1,3)));
138 //add a menu and its callback
140 Ok = "execstr("+gettext("Ok")+"_"+string(win)+"(1))";
141 Cancel = "execstr("+gettext("Cancel")+"_"+string(win)+"(1))";
143 addmenu(win, gettext("Ok"));
144 addmenu(win, gettext("Cancel"));
149 windowCloseButton = -1000;
152 [c_i,cx,cy,cw,str] = xclick();
153 if (c_i == windowCloseButton) then
154 // window has been closed
158 elseif (c_i== -2) then
159 if str==Ok then k = k1; c = k; break;end;
160 if str==Cancel then k = []; c = []; break;end;
166 if or(c_i==[0,3])&k<=N&k>0 then
168 move(rector,[rects(1,k)-rects(1,k1),rects(2,k)-rects(2,k1)]);
169 rector.foreground = color(255*(1-cmap(k,1)),255*(1-cmap(k,2)),255*(1-cmap(k,3)));
172 name = rgb2name(cmap(k,eye())*255);
173 txt = msprintf("RGB(%d)=[%d %d %d]",k,cmap(k,1:3)*255);
175 txt = txt + " : """ + name(1) + """"
177 fig.info_message = txt
181 if (c_i <> windowCloseButton) then