summaryrefslogtreecommitdiff
path: root/ipl/gprogs/scroll.icn
blob: 968160a6e4ab2a0185c8f3468919d6ffd6df775e (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
############################################################################
#
#       File:	  scroll.icn
#
#       Subject:  Program to scroll image
#
#	Author:   Jon Lipp
#
#	Date:     November 22, 1996
#
##########################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This program displays an image, with scolling.
#
##########################################################################
#
#  Links:  options, vidgets, vscroll, wopen, xcompat
#
############################################################################
#
#  Requires:  Version 9 graphics
#
############################################################################

link options
link vidgets, vscroll
link wopen
link xcompat

global win, im_win, view_width, view_height
global scv, sch

procedure main(args)
   local opts, file, scrollbar_width, picw, pich, root

   opts := options(args, "f:w+h+")
   file := \opts["f"] | 
      stop("Usage: scroll -f file [-w window size/width] [-h window height]")
   view_width := \opts["w"] | 300
   view_height := \opts["h"] | view_width
   scrollbar_width := 15
#
#  Load in the bitmap; get the dimensions.
#
   im_win := WOpen("canvas=hidden", "image=" || file) |
      stop("Couldn't make temporary bitmap.")
   picw := WAttrib(im_win, "width")
   pich := WAttrib(im_win, "height")

   win := WOpen("label=" || file, "size=" ||
      (view_width + scrollbar_width + 1) || "," ||
      (view_height + scrollbar_width + 1) ) |
         stop("*** cannot open file")

   root := Vroot_frame(win)
#
#  Create two scrollbars.
#
   scv := Vvert_scrollbar(root, -1, 0, win, sl_cb, 1,
      view_height,scrollbar_width, pich, 0, , view_height)
   sch := Vhoriz_scrollbar(root, 0, -1, win, sl_cb, 2, view_width,
     scrollbar_width, 0, picw, , view_width)

   VResize(root)
#
#  Draw the initial view of the pixmap, based on the scrollbar's values.
#
   sl_cb(scv, scv.callback.value)
   sl_cb(sch, sch.callback.value)
# 
#  Now get events, pass control to the procedure quit() if an event is not
#  captured by a vidget.
#
   GetEvents(root, quit, , resize)
end

#
#  Terminate the program on a keypress of "q".
#
procedure quit(e)

   if e === "q" then stop("End scroll.")
end

procedure resize(root)

   VReformat(scv, WAttrib(scv.win, "height") - 15)
   VReformat(sch, WAttrib(sch.win, "width") - 15)
end
   
#
#  Copy a portion of the bitmap to the main
#  window based on the values of the scrollbars.
#  
procedure sl_cb(caller, val)
   static vpos, hpos
   initial vpos := hpos := 0

   (caller.id = 1, vpos := val) | hpos := val
   CopyArea(im_win, win, hpos, vpos, view_width, view_height, 0, 0)
end