home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume19 / xruler / part01 < prev    next >
Encoding:
Text File  |  1993-04-27  |  10.5 KB  |  380 lines

  1. Newsgroups: comp.sources.x
  2. From: mmm@cetia.fr (Mark Martin)
  3. Subject: v19i042:  xruler - xruler - vertical/horizontal transparent ruler or grid, Part01/01
  4. Message-ID: <1993Mar12.145737.25896@sparky.imd.sterling.com>
  5. X-Md4-Signature: 238cd7c86491cd0f94ff2d91056185c0
  6. Date: Fri, 12 Mar 1993 14:57:37 GMT
  7. Approved: chris@sparky.imd.sterling.com
  8.  
  9. Submitted-by: mmm@cetia.fr (Mark Martin)
  10. Posting-number: Volume 19, Issue 42
  11. Archive-name: xruler/part01
  12. Environment: X11, Shape, xbiff, atobm, awk
  13.  
  14. xruler creates a shaped window in the form of a horizontal or vertical
  15. ruler, or as a transparent grid which can be placed over other windows
  16. to aid with taking measurements and so on.
  17.  
  18. It is a (bourne) shell script needing awk, atobm, and xbiff from X11
  19. Release 4 or 5.  The server must implement shaped windows.
  20.  
  21. The awk script is a little slow when creating horizontal rulers.
  22. Give it time...
  23.  
  24. Copyright 1992 Mark M Martin. Cetia. France. 
  25. Anyone may use, copy, distribute, sell this script provided the above
  26. copyright is kept in it.  No implied warranty or fitness for purpose.
  27.  
  28. email: mmm@cetia.fr
  29. --
  30. Mark M Martin            mmm@cetia.fr
  31. Cetia, France.
  32.  
  33.  
  34. #! /bin/sh
  35. # This is a shell archive, meaning:
  36. # 1. Remove everything above the #! /bin/sh line.
  37. # 2. Save the resulting text in a file.
  38. # 3. Execute the file with /bin/sh (not csh) to create the files:
  39. #    xruler/README
  40. #    xruler/xruler
  41. #    xruler/xruler.man
  42. #    xruler/Imakefile
  43. #    xruler/Makefile.std
  44. #    xruler/patchlevel.h
  45. # This archive created: Fri Sep 11 19:21:14 FDT 1992
  46. # By: mmm
  47. # Part 1 of 1
  48. PATH=/bin:$PATH export PATH
  49. mkdir xruler
  50. if test -f 'xruler/README'
  51. then    echo "shar: will not overwrite existing file xruler/README"
  52. else    echo "shar: extracting xruler/README (604 chars)"
  53.     sed 's/^X//' <<\END-OF-FILE! >'xruler/README'
  54. Xxruler creates a shaped window in the form of a horizontal or vertical
  55. Xruler, or as a transparent grid which can be placed over other windows
  56. Xto aid with taking measurements and so on.
  57. X
  58. XIt is a (bourne) shell script needing awk, atobm, and xbiff from X11
  59. XRelease 4 or 5.  The server must implement shaped windows.
  60. X
  61. XThe awk script is a little slow when creating horizontal rulers.
  62. XGive it time...
  63. X
  64. XCopyright 1992 Mark M Martin. Cetia. France. 
  65. XAnyone may use, copy, distribute, sell this script provided the above
  66. Xcopyright is kept in it.  No implied warranty or fitness for purpose.
  67. X
  68. Xemail: mmm@cetia.fr
  69. END-OF-FILE!
  70.     if test 604 -ne "`wc -c <'xruler/README'`"
  71.     then    echo "shar: error transmitting xruler/README (604 characters)"
  72.     fi
  73. fi
  74. if test -f 'xruler/xruler'
  75. then    echo "shar: will not overwrite existing file xruler/xruler"
  76. else    echo "shar: extracting xruler/xruler (3494 chars)"
  77.     sed 's/^X//' <<\END-OF-FILE! >'xruler/xruler'
  78. X#!/bin/sh
  79. X# xruler: create a vertical transparent ruler. 11sep1992
  80. X# Copyright 1992 Mark M Martin. Cetia. France. 
  81. X# Anyone may use, copy, distribute, sell this script provided the above
  82. X# copyright is kept in it.  No implied warranty or fitness for purpose.
  83. X
  84. Xusage="usage: $0 -h height -w width -grid -l linewidth -tl ticklength -t tickinterval..."
  85. X
  86. X# --- some default sizes. The corner is an handle making it easier to
  87. X# --- grip the ruler if no window manager title bar.
  88. X
  89. Xcorner=15 linewidth= ticklen=20 grid=0
  90. Xdefaultticks='50 25' defaultheight=700
  91. Xheight= width= debug=false
  92. X
  93. Xwhile    case $1 in
  94. X    -h|-height)    shift
  95. X            height=$1 ;;
  96. X    -w|-width)    shift
  97. X            width=$1 ;;
  98. X    -tl|-ticklength)shift
  99. X            ticklen=$1 ;;
  100. X    -grid)        grid=1 ;;
  101. X    -l|-linewidth)    shift
  102. X            linewidth=$1 ;;
  103. X    -t|-ticks)    while    case $2 in
  104. X                [0-9]*)    allticks="$allticks $2" ;;
  105. X                *)    break ;;
  106. X                esac
  107. X            do    shift
  108. X            done ;;
  109. X    -debug)        debug=true ;;
  110. X    '')        break ;;
  111. X    *)        echo "$usage"
  112. X            exit 1 ;;
  113. X    esac
  114. Xdo    shift
  115. Xdone
  116. X
  117. Xif [ -z "$allticks" ]
  118. Xthen    allticks=$defaultticks
  119. Xfi
  120. Xcase "$height+$width+$grid" in
  121. X++0)        height=$defaultheight ;;
  122. X+*+1|*++1)    echo "height and width must be given for -grid"
  123. X        exit 1;;
  124. Xesac
  125. Xif [ -z "$linewidth" ]
  126. Xthen    if [ $grid = 1 ]
  127. X    then    linewidth=1
  128. X    else    linewidth=2
  129. X    fi
  130. Xfi
  131. X
  132. Xtmp=/tmp/rule$$
  133. Xtrap 'rm -f $tmp;exit' 1 2 3 15
  134. X
  135. Xawk '
  136. XBEGIN{    vert = '"0$height"'; horiz = '"0$width"'; corner = '"$corner"'
  137. X    linewidth = '"$linewidth"'; ticklen = '"$ticklen"'; grid = '"$grid"'
  138. X    numticks = split("'"$allticks"'",ticks," ")
  139. X    t = ticklen
  140. X    for(i = 1;i<=numticks;i++){
  141. X        ticklength[i] = int(t)
  142. X        t = t*.75
  143. X    }
  144. X    maxlen = ticklen
  145. X    if(vert)height = vert+linewidth
  146. X    else height = ticklen
  147. X    if(maxlen<corner)maxlen = corner
  148. X    width = horiz+linewidth
  149. X    if(horiz && maxlen<width)maxlen = width
  150. X    # precompute the (non full) horizontal lines all alike for a grid
  151. X    if(grid){
  152. X        str = ""
  153. X        for(w = linewidth;w<width;w++){
  154. X        mark = 0
  155. X        for(i = 1;i<=numticks && !mark;i++)
  156. X            if((w%ticks[i])<linewidth)
  157. X            mark++
  158. X        if(mark)str = str "#"
  159. X        else str = str "-"
  160. X        }
  161. X    }
  162. X    for(l = -corner;l<height;l++){
  163. X        tl = linewidth;
  164. X        if(l<-1)tl = corner;
  165. X        else if(l==-1)tl = 0;
  166. X        else if(horiz && l<linewidth)tl = width
  167. X        else if(vert){
  168. X            for(i = 1;i<=numticks;i++)
  169. X            if((l%ticks[i])<linewidth){
  170. X                if(grid){ tl = width; break }
  171. X                else if(tl<ticklength[i])tl = ticklength[i]
  172. X            }
  173. X        }
  174. X        for(w = 0;w<tl;w++)printf("#");
  175. X        if(grid && tl==linewidth){
  176. X            printf("%s",str)
  177. X            w = width
  178. X        }
  179. X        else if(l>0 && horiz && l<ticklen){
  180. X            for(;w<width;w++){
  181. X                mark = 0
  182. X            for(i = 1;i<=numticks && !mark;i++)
  183. X                if((w%ticks[i])<linewidth)
  184. X                if(l<ticklength[i])mark++
  185. X            if(mark)printf("#");
  186. X            else printf("-")
  187. X            }
  188. X        }
  189. X        for(;w<maxlen;w++)printf("-");
  190. X        printf("\n");
  191. X    }
  192. X}
  193. X' </dev/null |
  194. Xif $debug
  195. Xthen    cat
  196. Xelse    atobm >$tmp
  197. Xfi
  198. X
  199. X# --- there are weird effects if the geometry isnt bigger than actual bitmap
  200. X
  201. Xcase "$height+$width" in
  202. X+*)    height=$ticklen ;;
  203. X*+)    width=$ticklen ;;
  204. Xesac
  205. Xheight=`expr $height + $corner + $linewidth + 10`
  206. Xwidth=`expr $width + $linewidth + 10`
  207. X
  208. Xif $debug
  209. Xthen    echo ${width}x$height
  210. X    exit
  211. Xfi
  212. X
  213. Xxbiff    -name xruler \
  214. X    -xrm "xruler.Geometry:${width}x$height-1+1" \
  215. X    -xrm "xruler*shapeWindow:true" \
  216. X    -xrm "xruler*flip:false" \
  217. X    -xrm "xruler*fullPixmap:$tmp" \
  218. X    -xrm "xruler*fullPixmapMask:$tmp" \
  219. X    -xrm "xruler*emptyPixmap:$tmp" \
  220. X    -xrm "xruler*emptyPixmapMask:$tmp" \
  221. X    -xrm "xruler*file:/dev/null" \
  222. X    -xrm "xruler*update:9999999" &
  223. X
  224. X# --- give it time to read file then remove it.
  225. X
  226. X(    sleep 60
  227. X    rm -f $tmp
  228. X) &
  229. END-OF-FILE!
  230.     chmod +x xruler/xruler
  231.     if test 3494 -ne "`wc -c <'xruler/xruler'`"
  232.     then    echo "shar: error transmitting xruler/xruler (3494 characters)"
  233.     fi
  234. fi
  235. if test -f 'xruler/xruler.man'
  236. then    echo "shar: will not overwrite existing file xruler/xruler.man"
  237. else    echo "shar: extracting xruler/xruler.man (1703 chars)"
  238.     sed 's/^X//' <<\END-OF-FILE! >'xruler/xruler.man'
  239. X.\"xruler man
  240. X.TH XRULER 1X
  241. X.SH NAME
  242. Xxruler \- a vertical or horizontal transparent ruler or grid
  243. X.SH SYNOPSIS
  244. X.B
  245. Xxruler
  246. X.RB [ -h
  247. X.IR height ]
  248. X.RB [ -w
  249. X.IR width ]
  250. X.RB [ -l
  251. X.IR linewidth ]
  252. X.RB [ -tl
  253. X.IR ticklength ]
  254. X.RB [ -grid ]
  255. X.RB [ -t
  256. X.IR "tickinterval ..." ]
  257. X.SH DESCRIPTION
  258. X.B xruler
  259. Xcreates a shaped window in the form of a ruler with intervals marked
  260. Xby ticks.
  261. XThe ruler can be vertical, horizontal or both, or be a rectangular grid.
  262. XThe window can be positioned over other windows to ease measuring
  263. Xestimates.
  264. X.P
  265. XA foreground colour can be specified, for example, by the resource line
  266. X
  267. X    xruler*foreground: red
  268. X
  269. Xin the .Xdefaults file or xrdb database.
  270. X.SH OPTIONS
  271. XAll values are in pixels.
  272. X.TP
  273. X-h
  274. Xis followed by the height of the vertical ruler.
  275. X.TP
  276. X-w
  277. Xis followed by the width of the horizontal ruler.
  278. X.TP
  279. X-l
  280. Xis followed by the width of the lines used to draw the ruler.
  281. XThis defaults to 2 for rulers and 1 for grids.
  282. X.TP
  283. X-t
  284. Xis followed by a list of tick intervals.
  285. XThe default is 50 and 25.
  286. XWhen more than one interval is specified the length of the later ones
  287. Xis 75% of the previous one.
  288. X.TP
  289. X-tl
  290. Xis followed by the length of the largest tick.
  291. XIf more than one tick interval is specified, the length of later ones
  292. Xis 75% of the previous one.
  293. X.TP
  294. X-grid
  295. XThe ticklength is ignored and a grid of the given height and width
  296. Xis produced.
  297. XNeither height nor width can be defaulted.
  298. X.SH LIMITATIONS
  299. XThe shape extension must exist in the server.
  300. Xxbiff and atobm must be in the PATH.
  301. X.SH AUTHOR
  302. XCopyright 1992 Mark M Martin. Cetia. France. 
  303. X
  304. XAnyone may use, copy, distribute, sell this script provided the above
  305. Xcopyright is kept in it.
  306. XNo implied warranty or fitness for purpose.
  307. X
  308. Xemail: mmm@cetia.fr
  309. END-OF-FILE!
  310.     if test 1703 -ne "`wc -c <'xruler/xruler.man'`"
  311.     then    echo "shar: error transmitting xruler/xruler.man (1703 characters)"
  312.     fi
  313. fi
  314. if test -f 'xruler/Imakefile'
  315. then    echo "shar: will not overwrite existing file xruler/Imakefile"
  316. else    echo "shar: extracting xruler/Imakefile (117 chars)"
  317.     sed 's/^X//' <<\END-OF-FILE! >'xruler/Imakefile'
  318. XXCOMM Imakefile for xruler script
  319. X
  320. Xall::
  321. X
  322. XInstallNamedProg(xruler,xruler,$(BINDIR))
  323. XInstallManPage(xruler,$(MANDIR))
  324. END-OF-FILE!
  325.     if test 117 -ne "`wc -c <'xruler/Imakefile'`"
  326.     then    echo "shar: error transmitting xruler/Imakefile (117 characters)"
  327.     fi
  328. fi
  329. if test -f 'xruler/Makefile.std'
  330. then    echo "shar: will not overwrite existing file xruler/Makefile.std"
  331. else    echo "shar: extracting xruler/Makefile.std (475 chars)"
  332.     sed 's/^X//' <<\END-OF-FILE! >'xruler/Makefile.std'
  333. X
  334. X           BINDIR = /usr/bin/X11
  335. X     INSTBINFLAGS = -m 0755 -o bin -g bin
  336. X          INSTALL = install
  337. X           MANDIR =  /usr/catman/man1
  338. X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* 
  339. X               RM = rm -f
  340. X
  341. X
  342. Xall::
  343. X
  344. Xinstall:: xruler
  345. X    $(INSTALL) -c $(INSTBINFLAGS) xruler $(DESTDIR)$(BINDIR)/xruler
  346. X
  347. Xinstall.man:: xruler.man
  348. X    $(INSTALL) -c $(INSTMANFLAGS) xruler.man $(DESTDIR)$(MANDIR)/xruler.$(MANSUFFIX)
  349. X
  350. Xclean::
  351. X    $(RM_CMD) "#"*
  352. END-OF-FILE!
  353.     if test 475 -ne "`wc -c <'xruler/Makefile.std'`"
  354.     then    echo "shar: error transmitting xruler/Makefile.std (475 characters)"
  355.     fi
  356. fi
  357. if test -f 'xruler/patchlevel.h'
  358. then    echo "shar: will not overwrite existing file xruler/patchlevel.h"
  359. else    echo "shar: extracting xruler/patchlevel.h (85 chars)"
  360.     sed 's/^X//' <<\END-OF-FILE! >'xruler/patchlevel.h'
  361. X/*
  362. X * xruler:
  363. X * level 0: initial release to comp.sources.x
  364. X */
  365. X#define PATCHLEVEL 0
  366. END-OF-FILE!
  367.     if test 85 -ne "`wc -c <'xruler/patchlevel.h'`"
  368.     then    echo "shar: error transmitting xruler/patchlevel.h (85 characters)"
  369.     fi
  370. fi
  371. echo 'end of shar part 1 of 1'
  372. exit 0
  373.  
  374. exit 0 # Just in case...
  375. -- 
  376.   // chris@IMD.Sterling.COM            | Send comp.sources.x submissions to:
  377. \X/  Amiga - The only way to fly!      |
  378.  "It's intuitively obvious to the most |    sources-x@imd.sterling.com
  379.   casual observer..."                  |
  380.