Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ; $$$$$$$$$$$$$$$$$$$ ABAKIS $$$$$$$$$$$$$$$$$$$$$
  2. ; *************** STAR^2 SOFTWARE ****************
  3. ; ??????????????????? BOX.INC ????????????????????
  4.  
  5. screen.w equ [!screen.w] ; forward reference
  6. screen.h equ [!screen.h] ; restore at end
  7.  
  8. macro BOX [p] {
  9.  forward p: integer p#.x, p#.y, p#.w, p#.h
  10. }
  11.  
  12. ;;;;;;;;;;;;;;;;;; VISIBILITY ;;;;;;;;;;;;;;;;;;;;
  13.  
  14. ; is visible or partially? return 0 if
  15. ; completely invisible
  16.  
  17. function visible, x, y, w, h
  18.   if w<=0, go .0, end
  19.   if h<=0, go .0, end
  20.   . r0=x, r1=y
  21.   if r0>=screen.w, go .0, end
  22.   if r1>=screen.h, go .0, end
  23.   . r0+w, r1+h
  24.   if r0<0, go .0, end
  25.   if r1<0, go .0, end
  26.   return 1
  27.   .0:
  28. endf 0
  29.  
  30. ;;;;;;;;;;;;;;; POINT INSIDE BOX? ;;;;;;;;;;;;;;;;
  31.  
  32. ; x>=bx and x<bx+bw and y>=by and y<by+bh
  33.  
  34. function point.inside, b, x, y
  35.   locals b.x, b.y, b.w, b.h
  36.   . r0=b,\
  37.    b.x=[?box.x+r0], b.y=[?box.y+r0],\
  38.    b.w=[?box.w+r0], b.h=[?box.h+r0],\
  39.    r1=x, r2=b.x
  40.   cmp r1, r2
  41.   jl .r0
  42.   add r2, b.w
  43.   cmp r1, r2
  44.   jge .r0
  45.   . r1=y, r2=b.y
  46.   cmp r1, r2
  47.   jl .r0
  48.   add r2, b.h
  49.   cmp r1, r2
  50.   jge .r0
  51.   return 1
  52.   .r0: . r0=0
  53. endf
  54.  
  55. ;;;;;;;;;;;;;;;;;;;;;; CLIP ;;;;;;;;;;;;;;;;;;;;;;
  56.  
  57. ; "clipping"; to exclude invisible sections of
  58. ; imagery before drawing
  59.  
  60. ; clip.pixel x, y. if invisible, return 0
  61.  
  62. function clip.pixel, x, y
  63.   . r0=x, r1=y
  64.   if r0<0, go .0, end
  65.   if r0>=screen.w, go .0, end
  66.   if r1<0, go .0, end
  67.   if r1>=screen.h, go .0, end
  68.   return 1
  69.   .0:
  70. endf 0
  71.  
  72. ; 2-DO: convert to ABAKIS...
  73.  
  74. ; clip.line o, &x, &y, &n. return 0 if
  75. ; completely invisible or adjust x/y/n
  76. ; if partially in/visible. o/rientation=
  77. ; 'h'/'v'. n=w/h. parameters sent by
  78. ; reference
  79.  
  80. function clip.line, o, x, y, n
  81.   push r6 r7 r3
  82.   . r6=x, r7=y, r3=n,\
  83.    r0=[r6], r2=[r7], r1=[r3]
  84.  
  85.   ; if invisible, return 0
  86.  
  87.   cmp r0, screen.w      ; x>=screen.w?
  88.   jge .0
  89.   cmp r2, screen.h      ; y>=screen.h?
  90.   jge .0
  91.   cmp r1, 0             ; w/h<=0?
  92.   jle .0
  93.   cmp o, 0              ; orientation?
  94.   jne .vertical
  95.   .horizontal:
  96.   cmp r2, 0             ; y<0?
  97.   jl .0
  98.   cmp r2, screen.h      ; y>=screen.h?
  99.   jge .0
  100.   . r2=r0, r2+r1        ; x+w<0?
  101.   cmp r2, 0
  102.   jl .0
  103.   if r0<0               ; if x<0
  104.    . r0+r1,\            ; { w=x+w, x=0 }
  105.     [r3]=r0,\
  106.     dword [r6]=0
  107.   end
  108.   cmp r2, screen.w      ; if x+w>=screen.w
  109.   jl @f                 ; { w=screen.w-x }
  110.   . r0=screen.w,\
  111.    r0-[r6], [r3]=r0
  112.   @@:
  113.   jmp .yes
  114.   .vertical:
  115.   cmp r0, 0             ; x<0?
  116.   jl .0
  117.   cmp r0, screen.w      ; x>=screen.w?
  118.   jge .0
  119.   . r1=r2,\
  120.   r1+[r3]               ; y+h<0?
  121.   cmp r1, 0
  122.   jl .0
  123.   if r2<0               ; if y<0
  124.     . [r3]=r1,\         ; { h=y+h, y=0 }
  125.     dword [r7]=0
  126.   end
  127.   cmp r1, screen.h      ; if y+h>=screen.h
  128.   jl .yes               ; { h=screen.h-y }
  129.   . r0=screen.h,\
  130.    r0-[r7], [r3]=r0
  131.   .yes: . r0=YES
  132.   jmp .e
  133.   .0: . r0=NO
  134.   .e:
  135.   pop r3 r7 r6
  136. endf
  137.  
  138. ; clip.scanline &s, &x, &y, &w does the same
  139. ; as clip.line but sets the s/tart offset of
  140. ; pixels and adjusts w correctly. this only
  141. ; applies to scanlines, not one-color lines
  142.  
  143. function clip.scanline, s, x, y, w
  144.   push r3
  145.   . r3=s,\
  146.    dword [r3]=0,\         ; offset=0 initially
  147.    r0=x, r0=[r0]
  148.   cmp r0, screen.w        ; x>=screen.w?
  149.   jge .0
  150.   . r2=y, r2=[r2]
  151.   cmp r2, screen.h        ; y>=screen.h?
  152.   jge .0
  153.   cmp r2, 0               ; y<0?
  154.   jl .0
  155.   cmp r2, screen.h        ; y>=screen.h?
  156.   jge .0
  157.   . r1=w, r1=[r1],\
  158.    r3=r0, r3+r1           ; x+w<0?
  159.   cmp r3, 0
  160.   jl .0
  161.   cmp r3, screen.w        ; if x+w>=screen.w
  162.   jl @f                   ; w=screen.w-x
  163.   . r1=screen.w,\
  164.    r1-r0, r3=w,\
  165.    [r3]=r1
  166.   @@:
  167.   cmp r0, 0               ; if x<0, clip
  168.   jg .e
  169.   . r2=r0, -r2, r2*4      ; index=-x * scale
  170.   . r3=s, [r3]=r2,\
  171.    r1=w, [r1]+r0,\        ; w+=x
  172.    r3=x, dword [r3]=0     ; x=0
  173.   . r0=YES
  174.   jmp .e
  175.   .0: . r0=NO
  176.   .e:
  177.   pop r3
  178. endf
  179.  
  180. ;;;;;;;;;;;;;;;;;;;;;;; BOX ;;;;;;;;;;;;;;;;;;;;;;
  181.  
  182. ; BOX structure...
  183.  
  184. virtual at 0
  185.   ?box:
  186.   .x dd 0
  187.   .y dd 0
  188.   .w dd 0
  189.   .h dd 0
  190. END virtual
  191.  
  192. align
  193.  
  194. box:
  195.  integer .x, .y, .w, .h
  196.  
  197. macro set.box box, x, y, w, h {
  198.  . box#.x=x, box#.y=y,\
  199.    box#.w=w, box#.h=h
  200. }
  201.  
  202. function move.box.right, b, n
  203.   . r0=b, r1=n, r0+?box.x, [r0]+r1
  204. endf
  205.  
  206. function move.box.down, b, n
  207.   . r0=b, r1=n, r0+?box.y, [r0]+r1
  208. endf
  209.  
  210. function move.box.r, b
  211.   . r0=b, r1=[?box.w+r0], r0+?box.x, [r0]+r1
  212. endf
  213.  
  214. function move.box.d, b
  215.   . r0=b, r1=[?box.h+r0], r0+?box.y, [r0]+r1
  216. endf
  217.  
  218. restore screen.w, screen.h