summaryrefslogtreecommitdiff
path: root/ipl/gpacks/weaving/mtrxedit.icn
blob: b712b5fa9561e2bae32cebf14063afb5966bebec (plain)
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
############################################################################
#
#	File:     mtrxedit.icn
#
#	Subject:  Program to create and edit binary arrays
#
#	Authors:  Ralph E. Griswold and Gregg M. Townsend
#
#	Date:     August 3, 2000
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This application provides a variety of facilities for creating and
#  editing binary arrays.  It is intended for use with weaving tie-ups
#  and liftplans.
#
############################################################################
#
#  Requires:  Version 9 graphics
#
############################################################################
#
#  Links: sort, patxform, vdialog, vsetup, dialog, wopen, xcompat
#
############################################################################

link sort
link patxform
link vdialog
link vsetup
link dialog
link wopen
link xcompat

$define MaxCell   	24			# maximum size of grid cell

$define GridSize	(32 * 8)		# size of area for edit grid
$define GridXoff	(32 * 5)		# x offset of grid area
$define GridYoff	(32 * 2 + 6)		# y offset of grid area

$define PattXoff	(32 * 14)		# x offset of pattern area
$define PattYoff	(32 * 2)		# y offset of pattern area
$define PattWidth	(32 * 8)		# width of pattern area
$define PattHeight	(32 * 8)		# heigth of pattern area

$define IconSize	16			# size of button icons

$define XformXoff	(16 * 2)		# x offset of xform area
$define XformYoff	(16 * 4)		# y offset of xform area

$define MaxPatt		128

$define InfoLength	40			# length of lines in info box

global allxform					# transform-all switch
global hbits					# number of bits horizontally
global vbits					# number of bits veritcally
global rows					# row repesentation of tile
global old_pat					# old pattern for undo
global cellsize					# size of cell in edit grid
global pattgc					# graphic context for pattern
global bordergc					# border for tile/pattern
global viewgc					# clipping area for viewing
global mode					# pattern/tile display mode
global tile_touched				# tile modification switch
global blank_pat				# 8x8 blank tile
global response					# switch for save dialog
global sym_state				# drawing state
global sym_image_current			# current drawing images
global sym_image_next				# next drawing images
global symmetries				# general symmetry state

global flip_right				# icon for right flip
global flip_left				# icon for left flip
global flip_vert				# icon for vertical flip
global flip_horiz				# icon for horizontal flip
global rotate_90				# icon for 90-degree rotation
global rotate_m90				# icon for -90-degree rotation
global rotate_180				# icon for 180-degree rotation
global ident					# icon for identity
global hi_ident					# highlighted icon for identity
global hi_left					# highlighted icon for l-flip
global hi_right					# highlighted icon for r-flip
global hi_vert					# highlighted icon for v-flip
global hi_horiz					# highlighted icon for h-flip
global hi_rot_90				# highlighted icon for 90-rot
global hi_rot_m90				# highlighted icon for -90 rot
global hi_rot_180				# highlighted icon for 180 rot
global SymmetXoff
global SymmetYoff

record pattrec(tile)

procedure main(args)
   local vidgets, e, i, j, x, y, v, h, input, mdigits

#  Initial state

   mdigits := '-' ++ &digits
   symmetries := 0				# initially no symmetries
   allxform := &null				# initially not all xforms

   sym_state := [				# initially no symmetries
      [1, -1, -1, -1],
      [-1, -1, -1, -1]
      ]

   blank_pat := "8,#0000000000000000"		# 8x8 blank tile

   tile_touched := &null

#  Set up vidgets

   vidgets := ui()

#  Set up graphic contexts

   pattgc := XBind(&window, "fillstyle=textured")	# for patterns
   bordergc := XBind(&window, "fg=red")			# for border
   viewgc := XBind(&window) 				# for tile view
   Clip(viewgc, PattXoff, PattYoff, PattWidth, PattHeight)
   Clip(bordergc, PattXoff - 1, PattYoff - 1, PattWidth + 2, PattHeight + 2)

   SymmetXoff := vidgets["symregion"].ux
   SymmetYoff := vidgets["symregion"].uy

#  Assign and draw the icons

   icons()

#  Initial and toggled editing images

   sym_image_next := [
      [ident, hi_rot_90, hi_rot_m90, hi_rot_180],
      [hi_right, hi_left, hi_vert, hi_horiz]
      ]
   sym_image_current := [
      [hi_ident, rotate_90, rotate_m90, rotate_180],
      [flip_right, flip_left, flip_vert, flip_horiz]
      ]

   rows := pat2rows(blank_pat)

#  Initial setup of grid and view areas

   setup() | stop("*** cannot set up pattern")

#  Enter event loop

   GetEvents(vidgets["root"], ,  shortcuts)
   
end

############################################################################
#
#	Callback procedures
#
############################################################################

#  file menu

procedure file_cb(vidget, menu)

   return case menu[1] of {
      "read  @R"  :  read_tile()
      "write @W"  :  write_tile()
      "copy  @C"  :  copy_tile()
      "paste @P"  :  paste_tile()
      "quit  @Q"  :  exit()
      }

end

procedure copy_tile()
   local output

   output := open("/tmp/tieup", "w") | {
      Notice("Cannot copy tile.")
      fail
      }

   write_pattern(output, pattrec(rows2pat(rows)))

   close(output)

   return

end

procedure paste_tile()
   local input, tile

   input := open("/tmp/tieup") | {
         Notice("Cannot paste tie-up file.")
         fail
         }

   tile := read_pattern(input) | {
      Notice("Cannot process matrix.")
      close(input)
      fail
      }

   close(input)

   rows := pat2rows(tile.tile)

   return setup()

end

#  editing grid

procedure grid_cb(vidget, e)
   local x, y, i, j

   if e === (&lpress | &rpress | &ldrag | &rdrag) then {
      j := (&x - GridXoff) / cellsize
      i := (&y - GridYoff) / cellsize
      if j < 0 | j >= hbits | i < 0 | i >= vbits then return

      if e === (&lpress | &ldrag) then setbit(i, j, "1")
      else setbit(i, j, "0")

      tile_touched := 1
      }

   return

end

#  symmetry buttons

procedure symmet_cb(vidget, e)
   local col, row, symcount

   if e === (&lpress | &rpress | &mpress) then {
      col := (&x - SymmetXoff) / IconSize + 1
      row := (&y - SymmetYoff) / IconSize + 1
      sym_state[row, col] *:= -1
      sym_image_current[row, col] :=: sym_image_next[row, col]
      place(SymmetXoff, SymmetYoff, col - 1, row - 1,
         sym_image_current[row, col])
      symcount := 0
      every symcount +:= !!sym_state
      if symcount = -8 then
         Notice("No drawing mode enabled; pattern cannot be edited")
      else if (sym_state[1, 1] = 1) & (symcount = -6) then symmetries := 0
      else symmetries := 1

      return
      }

   fail

end

#  tile menu

procedure tile_cb(vidget, value)
   local result

   case value[1] of {
      "new  @N"  :  new_tile()
      "info @I"  : tile_info()
      }

   return

end

procedure new_tile()

   case Dialog("New:", ["width", "height"], [*rows[1], *rows], 3,
      ["Okay", "Cancel"]) of {
         "Cancel"  :  fail
         "Okay"    :   {
            icheck(dialog_value) | fail
            rows := list(dialog_value[2], repl("0", dialog_value[1]))
            tile_touched := 1
            return setup()
            }
      }

   return

end

#  transformation buttons

procedure xform_cb(vidget, e)
   local col, row

   if e === (&lpress | &rpress | &mpress) then {
      old_pat := rows2pat(rows)
      col := (&x - XformXoff) / IconSize
      row := (&y - XformYoff) / IconSize
      rows := xform(col, row) | fail
      return setup()
      }

end

############################################################################
#
#  Support procedures
#
############################################################################

#  clear bits on current tile

procedure clear_tile()

   rows := list(vbits, repl("0", hbits))

   grid()

   return

end

#  draw editing grid

procedure grid()
   local x, y

   EraseArea(GridXoff, GridYoff, GridSize - 15, GridSize - 15)

   every x := 0 to hbits * cellsize by cellsize do
      DrawLine(GridXoff + x, GridYoff, GridXoff + x,
         GridYoff + vbits * cellsize)
   every y := 0 to vbits * cellsize by cellsize do
      DrawLine(GridXoff, GridYoff + y, GridXoff + hbits * cellsize,
         y + GridYoff)

   return

end

#  check for valid integers

procedure icheck(values)
   local i

   every i := !values do
      if not(integer(i)) | (i < 0) then {
         Notice("Invalid value")
         fail
         }

   return

end

#  assign and draw icons

procedure icons()
   local shift_up, shift_left, shift_right, shift_down, pixmap
   local clear, invert, scramble, trim, enlarge, resize, crop

   shift_up := "16,#3ffe6003408141c143e140814081408140814081408140_
      81408160033ffe0000"
   shift_left := "16,#3ffe6003400140014001401140195ffd40194011400140_
      01400160033ffe0000"
   shift_right := "16,#3ffe600340014001400144014c015ffd4c014401400140_
      01400160033ffe0000"
   shift_down := "16,#3ffe60034081408140814081408140814081408143e141_
      c1408160033ffe0000"
   flip_left := "16,#3ffe600340014079403940394049408149014e014e014f_
      01400160033ffe0000"
   flip_right := "16,#3ffe600340014f014e014e014901408140494039403940_
      79400160033ffe0000"
   flip_vert := "16,#3ffe6003408141c143e14081408140814081408143e141_
      c1408160033ffe0000"
   flip_horiz := "16,#3ffe600340014001400144114c195ffd4c194411400140_
      01400160033ffe0000"
   rotate_90 := "16,#3ffe6003400140f141014201420142014f814701420140_
      01400160033ffe0000"
   rotate_m90 := "16,#3ffe600340014781404140214021402140f94071402140_
      01400160033ffe0000"
   rotate_180 := "16,#3ffe6003400141c140214011401140114111432147c143_
      01410160033ffe0000"
   clear := "16,#3ffe600340014001400140014001400140014001400140_
      01400160033ffe0000"
   invert := "16,#3ffe60ff40ff40ff40ff40ff40ff7fff7f817f817f817f_
      817f817f833ffe0000"
   scramble := "16,#3ffe60034c014c0d418d41814001403159b1598140194c_
      194c0160033ffe0000"
   trim := "16,#3ffe60134011407d40394011400140fd48854c857e854c_
      8548fd60033ffe0000"
   enlarge := "16,#3ffe6083418143fd418148815c017efd48854885488548_
      8548fd60033ffe0000"
   resize := "16,#3ffe6093419943fd419948915c017efd488548857e855c_
      8548fd60033ffe0000"
   crop := "16,#3ffe60034011401147fd441144114411441144115ff144_
      01440160033ffe0000"

   ident := "16,#3ffe6003400140014001400141c141c141c14001400140_
      01400160033ffe0000"

   hi_ident := "16,#00001ffc3ffe3ffe3ffe3ffe3e3e3e3e3e3e3ffe3ffe3f_
      fe3ffe1ffc00000000"
   hi_rot_90 := "16,#00001ffc3ffe3f0e3efe3dfe3dfe3dfe307e38fe3dfe3f_
      fe3ffe1ffc00000000"
   hi_rot_m90 := "16,#00001ffc3ffe387e3fbe3fde3fde3fde3f063f8e3fde3f_
      fe3ffe1ffc00000000"
   hi_rot_180 := "16,#00001ffc3ffe3e3e3fde3fee3fee3fee3eee3cde383e3c_
      fe3efe1ffc00000000"
   hi_right := "16,#00001ffc3ffe30fe31fe31fe36fe3f7e3fb63fc63fc63f_
      863ffe1ffc00000000"
   hi_left := "16,#00001ffc3ffe3f863fc63fc63fb63f7e36fe31fe31fe30_
      fe3ffe1ffc00000000"
   hi_vert := "16,#00001ffc3f7e3e3e3c1e3f7e3f7e3f7e3f7e3f7e3c1e3e_
      3e3f7e1ffc00000000"
   hi_horiz := "16,#00001ffc3ffe3ffe3ffe3bee33e6200233e63bee3ffe3f_
      fe3ffe1ffc00000000"

#  now place the images

   place(XformXoff, XformYoff, 1, 0, shift_up)
   place(XformXoff, XformYoff, 0, 1, shift_left)
   place(XformXoff, XformYoff, 2, 1, shift_right)
   place(XformXoff, XformYoff, 1, 2, shift_down)
   place(XformXoff, XformYoff, 0, 4, flip_right)
   place(XformXoff, XformYoff, 0, 5, flip_left)
   place(XformXoff, XformYoff, 1, 4, flip_vert)
   place(XformXoff, XformYoff, 1, 5, flip_horiz)
   place(XformXoff, XformYoff, 0, 7, rotate_90)
   place(XformXoff, XformYoff, 0, 8, rotate_m90)
   place(XformXoff, XformYoff, 1, 7, rotate_180)
   place(XformXoff, XformYoff, 0, 10, clear)
   place(XformXoff, XformYoff, 1, 10, invert)
   place(XformXoff, XformYoff, 2, 10, scramble)
   place(XformXoff, XformYoff, 0, 12, trim)
   place(XformXoff, XformYoff, 1, 12, enlarge)
   place(XformXoff, XformYoff, 2, 12, resize)
   place(XformXoff, XformYoff, 0, 14, crop)

   place(SymmetXoff, SymmetYoff, 0, 0, hi_ident)
   place(SymmetXoff, SymmetYoff, 1, 0, rotate_90)
   place(SymmetXoff, SymmetYoff, 2, 0, rotate_m90)
   place(SymmetXoff, SymmetYoff, 3, 0, rotate_180)
   place(SymmetXoff, SymmetYoff, 0, 1, flip_right)
   place(SymmetXoff, SymmetYoff, 1, 1, flip_left)
   place(SymmetXoff, SymmetYoff, 2, 1, flip_vert)
   place(SymmetXoff, SymmetYoff, 3, 1, flip_horiz)

   return

end

#  invert bits on current pattern

procedure invert()

   rows := pinvert(rows)

   return

end

#  place icon

procedure place(xoff, yoff, col, row, pattern)

#  Pattern(pattgc, pattern)
#  FillRectangle(pattgc, xoff + col * IconSize, 
   DrawImage(pattgc, xoff + col * IconSize, 
     yoff + row * IconSize, pattern)

   return

end

#  terminate session

#  read pattern specification

procedure read_pattern(file)
   local line

   line := readpattline(file) | fail

   return pattrec(legaltile(getpatt(line)), getpattnote(line))

end

#  read and add tile to tile list

procedure read_tile()
   local input, tile
   static file, line

   initial line := "1"

   repeat {
      if TextDialog("Read tile:", ["file", "line"], [file, line], [60, 4]) == "Cancel" then fail
      input := open(dialog_value[1]) | {
         Notice("Cannot open file.")
         next
         }
      file := dialog_value[1]
      line := (0 < integer(dialog_value[2]))
      every 1 to line - 1 do
         read(input) | {
            Notice("Not that many lines in file.")
            close(input)
            next
            }
      tile := read_pattern(input) | {
         Notice("Cannot process matrix.")
         close(input)
         next
         }
      close(input)
      rows := pat2rows(tile.tile)
      return setup()
      }

end

#  scramble bits of current tile

procedure bscramble()

   rows := pscramble(rows, "b")

   return

end

#  set bits of tile

procedure setbit(i, j, c)
   local x, y, xu, yu, xv, yv, xt, yt, action

   if (symmetries = 0) & (rows[i + 1, j + 1] == c) then return	# optimization

   x := GridXoff + j * cellsize + 1		# the selected cell itself
   y := GridYoff + i * cellsize + 1
   xt := GridXoff + i * cellsize + 1
   yt := GridYoff + j * cellsize + 1

   i +:= 1					# for computational convenience
   j +:= 1

   xu := GridXoff + (hbits - j) * cellsize + 1	# opposite cells
   yu := GridYoff + (vbits - i) * cellsize + 1
   xv := GridXoff + (hbits - i) * cellsize + 1
   yv := GridYoff + (vbits - j) * cellsize + 1

   action := if c = 1 then FillRectangle else EraseArea

   if sym_state[1, 1] = 1 then {		# cell itself
      rows[i, j] := c
      action(x, y, cellsize - 1, cellsize - 1)
      }
   if sym_state[1, 2] = 1 then {		# 90 degrees
      if rows[j, -i] := c then			# may be out of bounds
         action(xv, yt, cellsize - 1, cellsize - 1)
      }
   if sym_state[1, 3] = 1 then {		# -90 degrees
      if rows[-j, i] := c then			# may be out of bounds
         action(xt, yv, cellsize - 1, cellsize - 1)
      }
   if sym_state[1, 4] = 1 then {		# 180 degrees
      rows[-i, -j] := c
      action(xu, yu, cellsize - 1, cellsize - 1)
      }
   if sym_state[2, 1] = 1 then {		# left diagonal
      if rows[j, i] := c then			# may be out of bounds
      action(xt, yt, cellsize - 1, cellsize - 1)
      }
   if sym_state[2, 2] = 1 then {		# right diagonal
      if rows[-j, -i] := c then			# may be out of bounds
      action(xv, yv, cellsize - 1, cellsize - 1)
      }
   if sym_state[2, 3] = 1 then {		# vertical
      rows[-i, j] := c
      action(x, yu, cellsize - 1, cellsize - 1)
      }
   if sym_state[2, 4] = 1 then {		# horizontal
      rows[i, -j] := c
      action(xu, y, cellsize - 1, cellsize - 1)
      }

   return

end

#  set up editing grid and view area

procedure setup()
   local i, j

   hbits := *rows[1]
   vbits := *rows

   if (hbits | vbits) > 80 then {		# based on cell size >= 3
      Notice("Dimensions too large")
      fail
      }
   if hbits > MaxPatt then mode := &null	# too large for pattern

   cellsize := MaxCell				# cell size on window
   cellsize >:= GridSize / (vbits + 4)
   cellsize >:= GridSize / (hbits + 4)

   grid()

   every i := 1 to hbits do
      every j := 1 to vbits do
         if rows[j, i] == "1" then
            FillRectangle(GridXoff + (i - 1) * cellsize,
               GridYoff + (j - 1) * cellsize, cellsize, cellsize)

   return

end

#  keyboard shortcuts

procedure shortcuts(e)

   if &meta then case map(e) of {
      "c"  :  copy_tile()
      "i"  :  tile_info()
      "n"  :  new_tile()
      "p"  :  paste_tile()
      "q"  :  exit()
      "r"  :  read_tile()
      "z"  :  undo_xform()
      "w"  :  write_tile()
      }

   return

end

#  return number of bits set in tile for sorting

procedure tile_bits(x)

   return tilebits(pat2rows(x.tile))

end

#  show information about tile

procedure tile_info()
   local line1, line2, pattern, bits, density

   pattern := rows2pat(rows)
   bits := tilebits(rows)
   density := left(bits / real(*rows[1] * *rows), 6)

   line1 := left(*rows[1] || "x" || *rows || " b=" || bits || " d=" ||
      density, InfoLength)
   line2 := if *pattern > InfoLength then pattern[1+:(InfoLength - 3)] ||
      "..." else left(pattern, InfoLength)

   Notice(line1, line2)

   return

end

#  return tile size for sorting

procedure tile_size(x)
   local dims

   dims := tiledim(x.tile)

   return dims.w * dims.h

end

#  undo transformation

procedure undo_xform()

   rows := pat2rows(old_pat)

   return setup()

end

#  write pattern

procedure write_pattern(file, pattern)

   write(file, pattern.tile)

   return

end

#  write tile

procedure write_tile()
   local output

   repeat {
      if SaveDialog("Write tie-up") == "Cancel" then fail
      output := open(dialog_value, "w") | {
         Notice("Cannot open file for writing.")
         next
         }
      write_pattern(output, pattrec(rows2pat(rows)))
      close(output)
      return
      }

end

#  handle transformation

procedure xform(col, row)
   local result
   static params

   tile_touched := 1

   return case col of {
      0:   case row of {
         1:   pshift(rows, -1, "h")
         4:   pflip(rows, "r")
         5:   pflip(rows, "l")
         7:   protate(rows, 90)
         8:   protate(rows, -90)
         10:  list(vbits, repl("0", hbits))
         12:  ptrim(rows)
         14:  {
              if /allxform then {
                 case Dialog("Crop:", ["left", "right", "top", "bottom"],
                    0, 3, ["Okay", "Cancel"]) of {
                       "Cancel":   fail
                        "Okay": {
                           icheck(dialog_value) | fail
                           result := copy(params := dialog_value)
                           push(result, rows)
                           pcrop ! result
                           }
                    }
                 }
            }
         default:   fail
         }
      1: case row of {
         0:   pshift(rows, -1, "v")
         2:   pshift(rows, 1, "v")
         4:   pflip(rows, "v")
         5:   pflip(rows, "h")
         7:   protate(rows, 180)
         10:  pinvert(rows)
         12:  {
              if /allxform then {
                 case Dialog("Enlarge:", ["left", "right", "top", "bottom"],
                    0, 3, ["Okay", "Cancel"]) of {
                       "Cancel":  fail
                       "Okay":  {
                           icheck(dialog_value) | fail
                           result := copy(params := dialog_value)
                           push(result, rows)
                           pborder ! result
                           }
                       }
                    }
                 }
         default:   fail
         }
      2: case row of {
         1:   pshift(rows, 1, "h")
         10:  pscramble(rows, "b")
         12:  {
              if /allxform then {
                 case Dialog("Center:", ["width", "height"], [*rows[1], *rows], 
                    3, ["Okay", "Cancel"]) of {
                    "Cancel":  fail
                    "Okay": {
                       icheck(dialog_value) | fail
                       result := copy(params := dialog_value)
                       push(result, rows)
                       pcenter ! result
                       }
                    }
                 }
              }
         default:   fail
         }
      default:   fail
      }

end

#===<<vib:begin>>===	modify using vib; do not remove this marker line
procedure ui_atts()
   return ["size=427,419", "bg=pale gray", "label=Penelope"]
end

procedure ui(win, cbk)
return vsetup(win, cbk,
   [":Sizer:::0,0,427,419:Penelope",],
   ["file:Menu:pull::0,0,36,21:file",file_cb,
      ["read  @R","write @W","copy  @C","paste @P","quit  @Q "]],
   ["line1:Line:::27,22,427,22:",],
   ["symmetries:Label:::25,340,70,13:symmetries",],
   ["tile:Menu:pull::38,0,36,21:tile",tile_cb,
      ["new  @N","info @I"]],
   ["transformations:Label:::5,33,105,13:transformations",],
   ["symregion:Rect:grooved::25,367,70,38:",symmet_cb],
   ["info:Rect:invisible::147,368,251,31:",],
   ["xform:Rect:grooved::26,58,58,256:",xform_cb],
   ["grid:Rect:grooved::145,58,251,256:",grid_cb],
   )
end
#===<<vib:end>>===	end of section maintained by vib