home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / database / pk4pak.zip / COLORPAL.SC < prev    next >
Text File  |  1993-02-04  |  8KB  |  212 lines

  1. ;============================================================================
  2. ; (c) Copyright Elect Software International Inc., 1992, Toronto. Anyone can
  3. ; use this code for anything as long as it is not resold as a software
  4. ; development resource, as long as the copyright notice isn't removed, as
  5. ; long as changes are clearly marked as to authorship, and as long as users
  6. ; indemnify Elect from any liability.
  7. ; Comments welcome. Henrik Bechmann, CIS:72701,3717; Tel:416-534-8176.
  8. ;============================================================================
  9.  
  10. ; ColorPal Version 1.00 January, 1993.
  11.  
  12. ;==============================================================================
  13. ;                       COLORPAL DESCRIPION
  14. ;==============================================================================
  15. ; Puts up a color palette and provides facilities for changing the selected
  16. ; color by arrow key or mouse. Can be dragged by mouse.
  17. ;==============================================================================
  18. ;                       COLORPAL INTERFACE
  19. ;==============================================================================
  20. ; METHODS:
  21. ; ColorPal.Constructor()
  22. ; ColorPal.Destructor()
  23. ; ColorPal.MakePalette()
  24. ; ColorPal.DestoryPalette()
  25. ; ColorPal.ShowAttribute(ColorAttribute)
  26. ; ColorPal.SelectAttribute(EventBag) ; Arrow key or mouse down on the palette
  27. ;                                    ; window
  28. ; PROPERTIES:
  29. ; ColorPal.WindowHandle ; the window handle of the palette after MakePalette()
  30. ; ColorPal.ColorAttribute ; The attribute resulting from showAttribute() or
  31. ;                         ; selectAttribute()
  32. ; ColorPal.IsActive       ; if the color palette constructor has been run.
  33. ;                         ; Check isWindow(ColorPal.WindowHandle) to make sure
  34. ;                         ; that MakePalette has been run.
  35. ;==============================================================================
  36. ;                       COLORPAL IMPLEMENTATION
  37. ;==============================================================================
  38.  
  39. Proc ColorPal.Constructor()
  40.    ColorPal.WindowHandle = 0
  41.    ColorPal.BackGround = 4 * 16
  42.    ColorPal.ForeGround = 7
  43.    ColorPal.ColorAttribute = ColorPal.ForeGround +
  44.                              ColorPal.BackGround
  45.    ColorPal.IsActive = True
  46. EndProc ; ColorPal.Constructor
  47.  
  48. Proc ColorPal.Destructor()
  49.    Release Vars
  50.       ColorPal.WindowHandle,
  51.       ColorPal.ColorAttribute,
  52.       ColorPal.Background,
  53.       ColorPal.Foreground,
  54.       ColorPal.IsActive
  55. EndProc ; ColorPal.Destructor
  56.  
  57. Proc ColorPal.MakePalette()
  58.    Private
  59.       WindowBag,
  60.       i,j
  61.    Dynarray WindowBag[]
  62.    WindowBag["Style"] = 112 + 8
  63.    WindowBag["HasFrame"] = False
  64.    WindowBag["CanvasHeight"] = 11
  65.    WindowBag["CanvasWidth"] = 18
  66.    Window Create Floating Attributes WindowBag To ColorPal.WindowHandle
  67.    SetCanvas ColorPal.WindowHandle
  68.    @0,0 PaintCanvas Fill " " Background 0,0,0,17
  69.    Frame Single From 1,0 To 10,17
  70.    For i From 0 to 7
  71.       For j From 0 to 15
  72.          PaintCanvas Fill "■" Attribute (i * 16) + j
  73.             i + 2,j + 1,i + 2 ,j + 1
  74.       EndFor
  75.    EndFor
  76.    ColorPal.SetColorBlinking(ColorPal.BackGround,ColorPal.ForeGround)
  77. EndProc ; ColorPal.MakePalette
  78.  
  79. Proc ColorPal.DestroyPalette()
  80.    Window Select ColorPal.WindowHandle
  81.    Window Close
  82. EndProc
  83.  
  84. Proc ColorPal.ShowAttribute(ColorAttribute)
  85.    While ColorAttribute > 127
  86.       ColorAttribute = ColorAttribute - 128
  87.    EndWhile
  88.    ColorPal.SetColorNormal(ColorPal.Background,ColorPal.ForeGround)
  89.    ColorPal.BackGround = Int(ColorAttribute/16) * 16
  90.    ColorPal.ForeGround = Mod(ColorAttribute,16)
  91.    ColorPal.SetColorBlinking(ColorPal.Background,ColorPal.ForeGround)
  92. EndProc ; ColorPal.SetAttribute
  93.  
  94. Proc ColorPal.SelectAttribute(EventBag)
  95.    Private
  96.       CRow,
  97.       CCol,
  98.       MRow,
  99.       MCol,
  100.       Keycode,
  101.       ReturnVal
  102.    ReturnVal = True
  103.    ColorPal.SetColorNormal(ColorPal.Background,ColorPal.Foreground)
  104.    ColorPal.BackGround = ColorPal.BackGround / 16
  105.    Switch
  106.       Case EventBag["Type"] = "KEY":
  107.          KeyCode = EventBag["KeyCode"]
  108.          Switch
  109.             Case Keycode = Asc("Up"):
  110.                ColorPal.Background = ColorPal.Background - 1
  111.                If ColorPal.Background < 0 Then
  112.                   ColorPal.Background = 7
  113.                Endif
  114.             Case Keycode = Asc("Down"):
  115.                ColorPal.Background = ColorPal.Background + 1
  116.                If ColorPal.Background > 7 Then
  117.                   ColorPal.Background = 0
  118.                Endif
  119.             Case Keycode = Asc("Left"):
  120.                ColorPal.Foreground = ColorPal.Foreground - 1
  121.                If ColorPal.Foreground < 0 Then
  122.                   ColorPal.Foreground = 15
  123.                Endif
  124.             Case Keycode = Asc("Right"):
  125.                ColorPal.Foreground = ColorPal.Foreground + 1
  126.                If ColorPal.Foreground > 15 Then
  127.                   ColorPal.Foreground = 0
  128.                Endif
  129.             OtherWise:
  130.                ReturnVal = False
  131.          EndSwitch
  132.       Case EventBag["Type"] = "MOUSE":
  133.          Crow = EventBag["Row"]
  134.          Ccol = EventBag["Col"]
  135.          LocalizeEvent EventBag
  136.          MRow = EventBag["Row"]
  137.          MCol = EventBag["Col"]
  138.          EventBag["Row"] = CRow
  139.          EventBag["Col"] = Ccol
  140.          If MRow > 1 And MRow < 10
  141.             And MCol > 0 And MCol < 17 Then
  142.             ColorPal.BackGround = MRow - 2
  143.             ColorPal.ForeGround = MCol - 1
  144.             ReturnVal = True
  145.          Else
  146.             If MRow = 0 Then
  147.                ColorPal!MouseMovePalette(EventBag)
  148.             Endif
  149.             ReturnVal = False
  150.          Endif
  151.    EndSwitch
  152.    ColorPal.BackGround = ColorPal.Background * 16
  153.    ColorPal.SetColorBlinking(ColorPal.Background,ColorPal.Foreground)
  154.    ColorPal.ColorAttribute = ColorPal.BackGround + ColorPal.ForeGround
  155.    Return ReturnVal
  156. EndProc ; ColorPal.SelectAttribute
  157.  
  158. Proc ColorPal!MouseMovePalette(MouseEventBag)
  159.    Private
  160.       EventBar,
  161.       WindowBag,
  162.       OriginRow,
  163.       OriginCol,
  164.       MosueRow,
  165.       MouseCol
  166.  
  167.    Window GetAttributes ColorPal.WindowHandle To WindowBag
  168.    OriginRow = WindowBag["OriginRow"]
  169.    OriginCol = WindowBag["OriginCol"]
  170.    MouseRow = MouseEventBag["Row"]
  171.    MouseCol = MouseEventBag["Col"]
  172.    While True
  173.       GetEvent To EventBag
  174.       If EventBag["Type"] = "MOUSE" Then
  175.          If EventBag["Action"] = "MOVE" Then
  176.             Window Move ColorPal.WindowHandle To
  177.                OriginRow + (EventBag["Row"] - MouseRow),
  178.                OriginCol + (EventBag["Col"] - MouseCol)
  179.          Endif
  180.          If EventBag["Action"] = "UP" Then
  181.             Quitloop
  182.          Endif
  183.       Endif
  184.    EndWhile
  185.    Window GetAttributes ColorPal.WindowHandle To WindowBag
  186.    If WindowBag["OriginRow"] < 1 Then
  187.       WindowBag["OriginRow"] = 1
  188.       Window SetAttributes ColorPal.WindowHandle From WindowBag
  189.    Endif
  190. EndProc ; ColorPal!MouseMovePalette
  191.  
  192. Proc ColorPal.SetColorBlinking(BackGround,ForeGround)
  193.    Private
  194.       CRow,
  195.       CCol
  196.    CRow = (BackGround / 16) + 2
  197.    CCol = ForeGround + 1
  198.    SetCanvas ColorPal.WindowHandle
  199.    PaintCanvas Attribute BackGround + ForeGround + 128
  200.       Crow,CCol,Crow,Ccol
  201. EndProc ; ColorPal.SetColorBlinking
  202.  
  203. Proc ColorPal.SetColorNormal(BackGround,ForeGround)
  204.    Private
  205.       CRow,
  206.       CCol
  207.    CRow = (BackGround / 16) + 2
  208.    CCol = ForeGround + 1
  209.    SetCanvas ColorPal.WindowHandle
  210.    PaintCanvas Attribute BackGround + ForeGround
  211.       Crow,CCol,Crow,Ccol
  212. EndProc