Clean-up (debug features)
[scilab.git] / scilab / modules / graphics / macros / getmark.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA
3 // This file must be used under the terms of the CeCILL.
4 // This source file is licensed as described in the file COPYING, which
5 // you should have received as part of this distribution.  The terms
6 // are also available at
7 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
8
9
10 function [k1,k2]=getmark()
11
12     //returns the clicked markid (with a minus sign)
13     //and mark size.
14     [lhs,rhs]=argn(0)
15     k1=[];k2=[];
16
17     warnobsolete("ged", "5.5.0");
18
19     win=max(winsid()+1);
20     f=scf(win)
21
22
23
24     nbMarks = 14;
25     nbSizes = 6;
26
27     delmenu(win,_("&File"));
28     delmenu(win,_("&Edit"));
29     delmenu(win,_("&Tools"));
30     delmenu(win,_("&?"));
31
32     toolbar(win, "off");
33
34     //Event handler and menu definition
35
36     deff("evh(gwin,x,y,ibut)",..
37     ["global pos done"
38     "if or(ibut==(0:5)) then "
39     "   [x,y]=xchange(x,y,''i2f'')"
40     "   pos=[x,y],done=0,"
41     "end"
42     "if ibut==-1000 then ,done=3,end"
43     ])
44
45     deff("menu_ok(k,gwin)","global done;done=1")
46     deff("menu_cancel(k,gwin)","global done;done=2")
47     drawlater()
48     f.axes_size = [610,610]
49     f.auto_resize="off"
50
51     a=gca();
52
53     a.axes_visible="off";
54     a.data_bounds=[0 0;10 30];
55     a.font_size=2;
56     a.mark_size_unit="tabulated"
57     a.margins=[0.04 0.06 0.05 0.1];
58
59     a.title.text = " Select mark style k and mark size l";
60     a.title.font_size = 3;
61     for k=0:nbMarks
62         xstringb(0,2*k - 2,"k = "+msprintf("%2d",k),1.5,2)
63         xrect(0, 2*k, 1.5, 2);
64     end
65
66     for l=1:nbSizes
67         xstringb(l*1.5, 28,"l = "+msprintf("%2d",l-1),1.5,2)
68         xrect(l*1.5, 30, 1.5, 2);
69     end
70
71     H=[]
72     for x=1:nbSizes
73         Hc=[]
74         for k=(0:nbMarks)
75             xpoly(0.75+x*1.5,2*k - 1,"marks");
76             p=gce();p.mark_size=x-1;p.mark_style=k;
77             Hc=[Hc;p];
78         end
79         H=[H Hc]
80     end
81     drawnow()
82     seteventhandler("evh")
83
84     addmenu(win,"Ok",list(2,"menu_ok"));
85     addmenu(win,"Cancel",list(2,"menu_cancel"));
86
87     global pos done;done=-1;
88     ksel=9;xsel=1;
89     //H(k1+1,(k2+1)).mark_foreground=5;
90     while %t
91         select done
92         case 0 then //click somehere
93             seteventhandler("");drawlater()
94             cx=pos(1);cy=pos(2)
95             k1=round((cy + 1)/2);k1=min(k1,nbMarks);k1=max(0,k1);
96             k2=round((cx + 0.75)/1.5);k2=k2-2;k2=min(k2,nbSizes - 1);k2=max(0,k2);
97             H(ksel+1,xsel+1).mark_foreground=-1;
98             H(k1+1,k2+1).mark_foreground=5;
99             ksel=k1;xsel=k2;
100             done=-1;
101             xinfo("You have chosen mark_style = "+string(k1)+", mark_size = "+string(k2))
102             drawnow();seteventhandler("evh")
103         case 1 then  // ok button clicked
104             k1=k1;k=[k1,k2];break,
105         case 2 then   // cancel button clicked
106             k=[];break,
107         case 3 then //the window has been blosed
108             k=[],if argn(1)==1 then k1=k,end
109             clearglobal pos done
110             return
111         end
112         xpause(100)
113     end
114     if argn(1)==1 then k1=k,end
115     seteventhandler("")
116     xdel(win)
117     clearglobal pos done
118 endfunction