[LON-CAPA-cvs] cvs: loncom /homework imagechoice.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 24 Feb 2004 00:14:01 -0000


albertel		Mon Feb 23 19:14:01 2004 EDT

  Modified files:              
    /loncom/homework	imagechoice.pm 
  Log:
  - converted to new randomlylabe syntax
  
  
Index: loncom/homework/imagechoice.pm
diff -u loncom/homework/imagechoice.pm:1.4 loncom/homework/imagechoice.pm:1.5
--- loncom/homework/imagechoice.pm:1.4	Tue Feb 17 17:02:05 2004
+++ loncom/homework/imagechoice.pm	Mon Feb 23 19:14:01 2004
@@ -1,4 +1,4 @@
-# $Id: imagechoice.pm,v 1.4 2004/02/17 22:02:05 albertel Exp $
+# $Id: imagechoice.pm,v 1.5 2004/02/24 00:14:01 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -144,60 +144,59 @@
     return int(scalar(split(':',$ENV{"imagechoice.$id.coords"}))/2);
 }
 
+sub add_obj {
+    my ($x,$id,$type,$args,$extra)=@_;
+
+    $$x{"cgi.$id.OBJTYPE"}.=$type.':';
+    my $i=$$x{"cgi.$id.OBJCOUNT"}++;
+    $$x{"cgi.$id.OBJ$i"}=$args;
+    if (defined($extra)) { $$x{"cgi.$id.OBJEXTRA$i"}=$extra; }
+}
+
 sub drawX {
-    my ($imid,$x,$y)=@_;
-    my %x;
-    $x{"cgi.$imid.LINECOUNT"}=4;
+    my ($data,$imid,$x,$y)=@_;
     my $length = 6;
     my $width = 1;
     my $extrawidth = 2;
-    $x{"cgi.$imid.LINE0"}=
-	join(':',(($x-$length),($y-$length),($x+$length),($y+$length),
-		  "FFFFFF",($width+$extrawidth)));
-    $x{"cgi.$imid.LINE1"}=
+    &add_obj($data,$imid,'LINE',
+	     join(':',(($x-$length),($y-$length),($x+$length),($y+$length),
+		       "FFFFFF",($width+$extrawidth))));
+    &add_obj($data,$imid,'LINE',
 	join(':',(($x-$length),($y+$length),($x+$length),($y-$length),
-		  "FFFFFF",($width+$extrawidth)));
-    $x{"cgi.$imid.LINE2"}=
+		  "FFFFFF",($width+$extrawidth))));
+    &add_obj($data,$imid,'LINE',
 	join(':',(($x-$length),($y-$length),($x+$length),($y+$length),
-		  "FF0000",($width)));
-    $x{"cgi.$imid.LINE3"}=
+		  "FF0000",($width))));
+    &add_obj($data,$imid,'LINE',
 	join(':',(($x-$length),($y+$length),($x+$length),($y-$length),
-		  "FF0000",($width)));
-    return %x;
+		  "FF0000",($width))));
 }
 
 sub drawPolygon {
-    my ($id,$imid)=@_;
+    my ($data,$id,$imid)=@_;
     my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"});
     my $coordstr;
     while (@coords) {
 	$coordstr.='('.shift(@coords).','.shift(@coords).')-';
     }
     chop($coordstr);
-    my %x;
     my $width = 1;
     my $extrawidth = 2;
-    my $i=$x{"cgi.$imid.POLYCOUNT"}++;
-    $x{"cgi.$imid.POLYOPT$i"}=join(':',("FFFFFF",($width+$extrawidth)),'1');
-    $x{"cgi.$imid.POLY$i"}=$coordstr;
-    $i=$x{"cgi.$imid.POLYCOUNT"}++;
-    $x{"cgi.$imid.POLYOPT$i"}=join(':',("00FF00",$width),'1');
-    $x{"cgi.$imid.POLY$i"}=$coordstr;
-    return %x;
+    &add_obj($data,$imid,'POLYGON',
+	     join(':',("FFFFFF",($width+$extrawidth)),'1'),$coordstr);
+    &add_obj($data,$imid,'POLYGON',
+	     join(':',("00FF00",($width)),'1'),$coordstr);
 }
 
 sub drawBox {
-    my ($id,$imid)=@_;
+    my ($data,$id,$imid)=@_;
     my (undef,@coords)=split(':',$ENV{"imagechoice.$id.coords"});
-    my %x;
-    if (scalar(@coords) < 4) { return %x; }
+    if (scalar(@coords) < 4) { return ''; }
     my $width = 1;
     my $extrawidth = 2;
-    my $i=$x{"cgi.$imid.BOXCOUNT"}++;
-    $x{"cgi.$imid.BOX$i"}=join(':',(@coords,"FFFFFF",($width+$extrawidth)));
-    $i=$x{"cgi.$imid.BOXCOUNT"}++;
-    $x{"cgi.$imid.BOX$i"}=join(':',(@coords,"00FF00",$width));
-    return %x;
+    &add_obj($data,$imid,'RECTANGLE',
+	     join(':',(@coords,"FFFFFF",($width+$extrawidth))));
+    &add_obj($data,$imid,'RECTANGLE',join(':',(@coords,"00FF00",$width)));
 }
 
 sub drawimage {
@@ -209,9 +208,9 @@
     $data{"cgi.$imid.BGIMG"}=$filename;
     my $x=$coords[-2];
     my $y=$coords[-1];
-    %data=(%data,&drawX($imid,$x,$y));
-    if ($type eq "polygon") { %data=(%data,&drawPolygon($id,$imid)); }
-    if ($type eq "box") { %data=(%data,&drawBox($id,$imid)); }
+    &drawX(\%data,$imid,$x,$y);
+    if ($type eq "polygon") { &drawPolygon(\%data,$id,$imid); }
+    if ($type eq "box") { &drawBox(\%data,$id,$imid); }
     &Apache::lonnet::appenv(%data);
     return "/adm/randomlabel.png?token=$imid"
 }