1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2012 - 2016 - Scilab Enterprises
5 // This file is hereby licensed under the terms of the GNU GPL v2.0,
6 // pursuant to article 5.3.4 of the CeCILL v.2.1.
7 // This file was originally licensed under the terms of the CeCILL v2.1,
8 // and continues to be available under such terms.
9 // For more information, see the COPYING file which you should have received
10 // along with this program.
12 function [c] = getcolor(Title,cini)
20 if type(Title)~=10 then
21 error(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"), "getcolor", 1));
23 if size(Title, "*")~=1 then
24 error(msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"), "getcolor", 1));
28 if type(Title)~=10 then
29 error(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"), "getcolor", 1));
31 if size(Title, "*")~=1 then
32 error(msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"), "getcolor", 1));
35 error(msprintf(gettext("%s: Wrong type for input argument #%d: A real expected.\n"), "getcolor", 2));
37 if size(cini, "*")~=1 then
38 error(msprintf(gettext("%s: Wrong size for input argument #%d: A real expected.\n"), "getcolor", 2));
41 error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "getcolor", 2, 0, 2));
46 cmap = curFig.color_map;
47 curwin = curFig.figure_id;
53 // create the window for getcolor
76 H = m*45; // These numbers set the size of the getcolor window
78 fig.figure_size = [H,W];
82 delmenu(win,gettext("&File"))
83 delmenu(win,gettext("&Tools"))
84 delmenu(win,gettext("&Edit"))
85 delmenu(win,gettext("&?"))
91 R = [0;0;dx*0.95;dy*0.95];
94 if modulo(k,n)==1 then
98 rects = [rects,R+[x;y;0;0]];
103 xsetech([-1/8,0,1+1/6,1+1/6-1/8],[0,0,wdim(1),wdim(2)]);
105 xsetech([-1/8,-1/8,1+1/6,1+1/6],[0,0,wdim(1),wdim(2)]);
107 // rectangles with the colors
109 // frame around the colors
114 xpoly([-ddx,1,1,-ddx],[0,0,1+ddy,1+ddy],"lines",1);
116 xpoly([-ddx,1-1/n,1-1/n,1,1,-ddx],[0,0,r/m,r/m,1+ddy,1+ddy],"lines",1);
127 k1 = min(max(cini,1),N);
128 xrects(rects(eye(),k1),-k1);
131 rector.thickness = 4;
132 rector.foreground = color(255*(1-cmap(k1,1)),255*(1-cmap(k1,2)),255*(1-cmap(k1,3)));
134 //add a menu and its callback
136 Ok = "execstr("+gettext("Ok")+"_"+string(win)+"(1))";
137 Cancel = "execstr("+gettext("Cancel")+"_"+string(win)+"(1))";
139 addmenu(win, gettext("Ok"));
140 addmenu(win, gettext("Cancel"));
144 windowCloseButton = -1000;
147 [c_i,cx,cy,cw,str] = xclick();
148 if (c_i == windowCloseButton) then
149 // window has been closed
153 elseif (c_i== -2) then
154 if str==Ok then k = k1; c = k; break;end;
155 if str==Cancel then k = []; c = []; break;end;
161 if or(c_i==[0,3])&k<=N&k>0 then
163 move(rector,[rects(1,k)-rects(1,k1),rects(2,k)-rects(2,k1)]);
164 rector.foreground = color(255*(1-cmap(k,1)),255*(1-cmap(k,2)),255*(1-cmap(k,3)));
167 name = rgb2name(cmap(k,eye())*255);
168 fig.info_message = ..
169 gettext("Color number")+" "+string(k)+": R="+string(floor(cmap(k,1)*255))+" G="+string(floor(cmap(k,2)*255))+" B="+string(floor(cmap(k,3)*255))+" "+gettext("Name")+"="""+name(1)+"""";
175 if (c_i <> windowCloseButton) then