File: clicktile.input

package info (click to toggle)
wims 2%3A4.29a%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 185,704 kB
  • sloc: xml: 366,687; javascript: 120,570; ansic: 62,341; java: 62,170; sh: 7,744; perl: 3,937; yacc: 3,217; cpp: 1,915; lex: 1,805; makefile: 1,084; lisp: 914; pascal: 601; python: 520; php: 318; asm: 7
file content (299 lines) | stat: -rw-r--r-- 10,099 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
!reset xsize ysize background_color return_all_objects
!set appletdir=java/Clicktile
!set anstype=yes
!set anstyle=dprompt
!set ans_require=clicktile

!reset tmp
!if $wims_read_parm=def
  !exit
!endif

!! Clicktile sample here :
!! http://localhost/wims/?module=U3/algebra/oefpartition.fr&exo=schensted1&cmd=new

!!########################

!default name_colorlabel=brush color
!if $lang=fr
  !set name_colorlabel=couleur du pinceau
!endif
!if $lang=it
  !set name_colorlabel=cambia colore
!endif


!!###traitement des options (qui se trouvent dans \embed)
!set oef_applet_option=!replace internal $	$ by $\
$ in $inputsize

!set oef_applet_option=!replace internal ; by $\
$ in $oef_applet_option
!set oef_applet_option=!nonempty lines $oef_applet_option
!set Inputsize=!line 1 of $oef_applet_option
!set test=!text remove 0123456789x in $Inputsize
!if $test issametext $empty
  !set Inputsize=!replace internal x by , in $Inputsize
  !set oef_applet_option=!line 2 to -1 of $oef_applet_option
  !set oef_applet_option=!declosing $oef_applet_option
  !distribute items $Inputsize into xsize,ysize
!endif
!set oef_applet_option=!translate [] to $  $ in $oef_applet_option
!set list=
!set oef_applet_option_cnt=!linecnt $oef_applet_option

!reset applet_parm applet_image
!set cmt=0
!for a=1 to $oef_applet_option_cnt
  !set line=!line $a of $oef_applet_option
  !set w=!word 1 of $line
  !set l=!word 2 to -1 of $line
  !set l1=!nospace $(l[2..-1])
  !if xrange isin $w
    !distribute item $[$(l[1])],$[$(l[2])-$(l[1])] into  xmin, xn
  !endif
  !if yrange isin $w
    !distribute item $[$(l[1])],$[$(l[2])-$(l[1])+1] into ymin, yn
  !endif
  !if square isin $w
    !set click_color=!append item "$(l[1])" to $click_color
    !set l1cnt=!itemcnt $l1
    !for pp=1 to $l1cnt
      !set point=!item $pp of $l1
      !set point=!replace : by , in $point
      !set id=$[$(point[1])-($xmin) + 1000*$[$(point[2])-($ymin)]]
      !set list=!append item "$id" to $list
      !set applet_parm=!append line var obj=document.getElementById($id);\
   obj.setAttributeNS(null,"fill","$(l[1])");\
    to $applet_parm
    !next
  !else
    !if $w iswordof text segment line point
      !increase cmt
      !set ll=!replace internal : by , in $(l[2..-1])
      !if $w iswordof line segment
        !set tmp=var obj$cmt = document.createElementNS('http://www.w3.org/2000/svg', 'line');\
     obj$cmt.setAttribute('x1', $[$(ll[1])-($xmin)]*w);\
     obj$cmt.setAttribute('y1',($[$(ll[2])+($ymin)]+yn)*h);\
     obj$cmt.setAttribute('x2', $[$(ll[3])-($xmin)]*w);\
     obj$cmt.setAttribute('y2',($[$(ll[4])+($ymin)]+yn)*h);\
     obj$cmt.setAttribute('stroke', '$(l[1])');\
     obj$cmt.setAttribute('stroke-width', 3);
      !endif
      !if $w iswordof point
        !set tmp=var obj$cmt = document.createElementNS('http://www.w3.org/2000/svg', 'circle');\
     obj$cmt.setAttributeNS(null, 'cx', $[$(ll[1])-($xmin)]*w);\
     obj$cmt.setAttributeNS(null, 'cy', ($[$(ll[2])+($ymin)]+yn)*h);\
     obj$cmt.setAttributeNS(null, 'r',  3);\
     obj$cmt.setAttributeNS(null,'fill', '$(l[1])');
      !endif
      !if $w iswordof text
        !set ll=!replace : by , in $(ll)
        !set tmp=var obj$cmt = document.createElementNS('http://www.w3.org/2000/svg', 'text');\
          obj$cmt.setAttributeNS(null, 'x', $[$(ll[1])-($xmin)]*w);\
          obj$cmt.setAttributeNS(null, 'y', ($[-$(ll[2])+($ymin)+1]+yn)*h);\
          obj$cmt.setAttributeNS(null, 'font-size', 22);\
          obj$cmt.setAttributeNS(null,'fill', '$(l[1])');\
          obj$cmt.innerHTML='$(ll[3])';
      !endif
      !set applet_parm=!append line $tmp\
      wims_svg$i.appendChild(obj$cmt);\
      to $applet_parm
    !else
      !if $w iswordof return_all_objects background_color colors
        !set $w=$l
        !if $l=yes
          !set $w=1
        !endif
      !else
        !if $w iswordof copy
          !set image=$(l[3])
          !set l1=!nospace $(l[1..2])
          !set applet_image=!append line \
          <image xlink:href="$image" x="$(l1[1])" y="$(l1[2])" width="100%" height="100%"></image>\
           to $applet_image
          !set stroke_opacity=0.70
          !set fill_opacity=0.50
        !endif
     !endif
    !endif
  !endif
!next
!if $colors!=$empty
  !set colors=!makelist "x" for x in $colors
!endif
!set click_color=!append item $colors to $click_color

!default background_color=green
!default oef_applet_option=xrange 0,10\
yrange 0,1\
colors red,blue\
background_color $background_color
!set listtotal=!makelist p + 1000*q for p=0 to $xn
!set listtotal=!values $listtotal for q=1 to $yn
!set listtotal=!makelist "x" for x in $listtotal
!set listc=!listcomplement $list in $listtotal
!set listc_cnt=!itemcnt $listc_cnt
!default xsize=200
!default ysize=30
!set xsize=$[(ceil($xsize/$xn))*$xn]
!set ysize=$[(ceil($ysize/$yn))*$yn]
!set Inputsize=$xsize,$ysize
!default return_all_objects=0

!default stroke_opacity=0.99
!default fill_opacity=0.99
!!############################
!!####partie importante
<style>
/*<![CDATA[*/
  .clicktile_button{
    min-width: 3em;
    text-shadow: 0 0 3px black;
    background-image: none;
    border-top-color: rgba(0,0,0,.25);
  }
  .clicktile_active{
    width: 100%;
  }
  .active_tile{
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 512 512'%3E%3C!--! Font Awesome Pro 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --%3E%3Cpath d='M0 64C0 28.7 28.7 0 64 0H352c35.3 0 64 28.7 64 64v64c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V64zM160 352c0-17.7 14.3-32 32-32V304c0-44.2 35.8-80 80-80H416c17.7 0 32-14.3 32-32V160 69.5c37.3 13.2 64 48.7 64 90.5v32c0 53-43 96-96 96H272c-8.8 0-16 7.2-16 16v16c17.7 0 32 14.3 32 32V480c0 17.7-14.3 32-32 32H192c-17.7 0-32-14.3-32-32V352z'/%3E%3C/svg%3E"), pointer;
  }
  .active_tile:hover,
  .active_tile:focus{
    opacity: .6;
    stroke: var(--wims_hlink_color);
    stroke-width: 2;
  }
/*]]>*/
</style>
<input type="hidden" name="reply$i" id="Clicktilereply$i" value="">

<div id="Clicktile$i" class="clicktile_active" style="height:$[$ysize+30]px;">
  <svg version="1.1" baseProfile="full"
   xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
   id="svgClicktile$i" width="$xsize" height="$ysize"
   viewBox="0 0 $xsize,$ysize">
   <g id="svg_transformClicktile$i">
$applet_image
   </g>
  </svg>
  <div>
  <label for="colorchange$i">$name_colorlabel</label>
  <button type="button" class="clicktile_button wims_button" style="background-color:$background_color;"
  onclick="javascript:change_color();" id="colorchange$i" name="change" title="$background_color">&nbsp;</button>
  </div>
</div>
<script>
/*<![CDATA[*/
var num = 0;
var xmin=$xmin;var ymin=$ymin;
var return_all_objects=$return_all_objects;
var wims_svg$i = document.getElementById("svgClicktile$i");
wims_svg$i.addEventListener("click", svg_mouse, false);
var xn = $xn;
var yn = $yn;
var w = $[$xsize/($xn+1)];
var h = $[$ysize/$yn];
var x,y;
var line_width = 1;
var stroke_color = "black";
var fill_color = "$background_color";
var stroke_opacity = $stroke_opacity;
var fill_opacity = $fill_opacity;

!set click_color=!listuniq $click_color
!set click_color_cnt=!itemcnt $click_color

var num_colors =$[$click_color_cnt];
var click_color = new Array("$background_color",$click_color);
var listc=new Array($listc);
var start_color = click_color[0];
for(var p = 0 ; p < xn ; p = p+1){
  for(var q = 1 ; q < yn; q = q+1){
    var id=p+1000*q;
    var rect = document.createElementNS('http://www.w3.org/2000/svg','rect');
    rect.setAttributeNS(null,"x",p*w);
    rect.setAttributeNS(null,"y",(yn-q)*h);
    rect.setAttributeNS(null,"width",w);
    rect.setAttributeNS(null,"height",h);
    rect.setAttributeNS(null,"id",id);
    rect.setAttributeNS(null,"stroke-width",line_width);
    rect.setAttributeNS(null,"stroke",stroke_color);
    rect.setAttributeNS(null,"stroke-opacity",stroke_opacity);
    rect.setAttributeNS(null,"fill-opacity",fill_opacity);
    for(var a = 0 ; a < listc.length ; a = a+1){
      var b=listc[a];
      if(b==id){
        rect.setAttributeNS(null,"class","active_tile");
        rect.setAttributeNS(null,"fill",start_color);
        rect.setAttributeNS(null,"onmousedown","javascript:paint_color("+id+")");
        break;}
    }
    wims_svg$i.appendChild(rect);
  }
}

$applet_parm

function paint_color(myid) {
  var obj = document.getElementById(myid);
  obj.setAttributeNS(null,"fill",click_color[num]);
  return;
}

function change_color(myid) {
  num++;
  if(num > num_colors){num = 0;}
  const colorbutton = document.getElementById("colorchange$i");
  colorbutton.style.backgroundColor=click_color[num];
  //colorbutton.textContent=click_color[num];
  colorbutton.setAttribute('title',click_color[num]);
  return(num);
}
function svg_mouse(action) {
  return 0;
}

function read_svg$i() {
  var reply=" ";
  for(var pr = 0 ; pr < xn; pr = pr+1){
    for(var qr = 1 ; qr < yn; qr = qr+1){
      var id1=pr + 1000*qr;
      if (return_all_objects==1) {
        var obj=document.getElementById(id1);
        var bb=obj.getAttributeNS(null,'fill');
        if(bb != click_color[0]){
          var pr1 = pr + xmin;
          var qr1 = qr + ymin;
          reply += bb + "@" + pr1  + ":" + qr1 + ";";
        }
      } else {
        for(var a = 0 ; a < listc.length ; a = a+1){
          var b=listc[a];
          if(b==id1){
           var obj=document.getElementById(id1);
           var bb=obj.getAttributeNS(null,'fill');
            if(bb != click_color[0]){
              var pr1 = pr + xmin;
              var qr1 = qr + ymin;
              reply += bb + "@" + pr1  + ":" + qr1 + ";";
            };
            break
          }
        }
      }
    }
  };
  document.getElementById("Clicktilereply$i").value=reply;
}

/*]]>*/
</script>


!!###on garde les options pour le retour, variable de nom impos oef_applet_option
!set oef_answer_option$i=$Inputsize\
$oef_applet_option

!set oef_js_submit=$oef_js_submit read_svg$i();