Subversion Repositories Kolibri OS

Rev

Rev 5824 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;  COLORREF.ASM - COLOR REFERENCE
  2. ;
  3. ;  Compile with FASM for Menuet
  4. ;
  5.  
  6. use32
  7.          org  0x0
  8.  
  9.          db  'MENUET01'            ; 8 byte id
  10.          dd   0x01                 ; header version
  11.          dd   start                ; start of code
  12.          dd   finis                ; size of image
  13.          dd   0x1000               ; memory for app
  14.          dd   0x1000               ; esp
  15.          dd   0x0,0x0              ; I_Param , I_Icon
  16.  
  17. include 'lang.inc'
  18. include '..\..\..\macros.inc'
  19. wide:    dd   0                    ; screen pixels width
  20. mouse:   dd   0                    ; 1=right,2=left [mouse click]
  21.  
  22.  
  23. start:
  24.  
  25.     mov  eax,14                    ; get screen size
  26.     mcall
  27.     shr  eax,16                    ; get width into AX
  28.     inc  eax                       ; not 0 based
  29.     mov  [wide],eax
  30.  
  31.     call draw_window
  32.  
  33. still:
  34.     mov  eax,23                    ; wait for event w/timeout
  35.     mov  ebx,5                     ; delay in hundredths
  36.     mcall
  37.  
  38.     cmp  eax,1                     ; redraw request ?
  39.     jne  s1
  40.     jmp  red
  41. s1: cmp  eax,2                     ; key in buffer ?
  42.     jne  s2
  43.     jmp  key
  44. s2: cmp  eax,3                     ; button in buffer ?
  45.     jne  s3
  46.     jmp   button
  47. s3: mov  eax,9                     ; process info function
  48.     mov  ebx,stat_table            ; return data table
  49.     mov  ecx,-1                    ; who am i
  50.     mcall
  51.     cmp  ax,[stat_table+4]         ; are we active?
  52.     je   active                    ; yep
  53.     jmp  still
  54.  
  55.   active:
  56.     mov  eax,37                    ; mouse info function
  57.     mov  ebx,2                     ; get buttons
  58.     mcall
  59.     cmp  eax,0                     ; mouse click?
  60.     jne  click
  61.     jmp  still
  62.   click:
  63.     mov  [mouse],eax               ; save mouse click
  64.     mov  eax,37                    ; mouse info
  65.     xor  ebx,ebx                   ; get screen pos for mouse
  66.     mcall                      ; into EAX
  67.     xor  ebx,ebx
  68.     mov  bx,ax                     ; BX=y screen position
  69.     shr  eax,16                    ; AX=x screen position
  70.     xchg eax,ebx                   ; EAX=y, EBX=x
  71.     dec  eax                       ; don't calc mouse scanline
  72.     mov  ecx,[wide]                ; get pixels wide
  73.     mul  ecx
  74.     add  ebx,eax                   ; add x
  75.     mov  eax,35                    ; get mouse pos pixel
  76.     mcall                      ; EAX=mouse pixel color
  77.     mov  ebx,eax                   ; EBX has color
  78.     mov  esi,colors                ; color table
  79.     mov  ecx,72                    ; total colors
  80.     xor  edx,edx                   ; init a counter
  81.   check:
  82.     lodsd
  83.     inc  edx                       ; update counter
  84.     cmp  ebx,eax                   ; color match?
  85.     je   _match                     ; yep
  86.     loop check                     ; check all colors
  87.     jmp still                      ; no match
  88.   _match:
  89.     cmp  [mouse],dword 1           ; right click?
  90.     je   right                     ; yep
  91.   left:
  92.     cmp  [picks],edx               ; changed left color yet?
  93.     jne  l1                        ; no, do it
  94.     jmp  still
  95. l1: mov  [picks],edx               ; update left pick color
  96.     call draw_picks                ; redraw colors and text
  97.     jmp  still
  98.   right:
  99.     cmp  [picks+4],edx             ; changed right color yet?
  100.     jne  r1                        ; no, do it
  101.     jmp  still
  102. r1: mov  [picks+4],edx             ; update right pick color
  103.     call draw_picks                ; redraw colors and text
  104.     jmp  still
  105.  
  106.   red:                             ; redraw
  107.     call draw_window
  108.     jmp  still
  109.  
  110.   key:                             ; key
  111.     mov  eax,2                     ; just read it and ignore
  112.     mcall
  113.     cmp  al,0                      ; key in buffer?
  114.     je   .k1                       ; yep
  115.     jmp  still
  116. .k1:cmp  ah,'H'                    ; cap H ?
  117.     je   .k2                       ; yep
  118.     cmp  ah,'h'                    ; locase h ?
  119.     je   .k2                       ; yep
  120.     jmp  still
  121. .k2:call help                      ; show help screen
  122.     jmp  still
  123.  
  124.   button:                          ; button
  125.     mov  eax,17                    ; get id
  126.     mcall
  127.     cmp  ah,1                      ; button id=1 ?
  128.     je   close
  129.     jmp  still
  130.  
  131.   close:
  132.     mov  eax,-1                    ; close this program
  133.     mcall
  134.  
  135.  
  136. ;   *********************************************
  137. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  138. ;   *********************************************
  139.  
  140.  
  141. draw_window:
  142.  
  143.     mcall 12,1
  144.  
  145.     mov  eax,0                     ; DRAW WINDOW
  146.     mov  ebx,1*65536+(200-1)       ; [x start] *65536 + [x size]
  147.     mov  ecx,200*65536+240         ; [y start] *65536 + [y size]
  148.     mov  edx,0x14000000            ; work area color (type II)
  149.     mov  edi,title                ; frame color
  150.     mcall
  151.    
  152.     call palette                   ; display color palette
  153.  
  154.     mcall 12, 2
  155.  
  156.     ret
  157.  
  158.  
  159. ;   *********************************************
  160. ;   *******  COLOR PALETTE LAYOUT ROUTINES ******
  161. ;   *********************************************
  162.  
  163.  
  164. palette:
  165.     mov  ebx,15*65536+18           ; LAYOUT: start x and width
  166.     mov  edx,32*65536+18           ; LAYOUT: start y and depth
  167.     mov  ecx,8                     ; 8 rows
  168.     mov  ebp,colors                ; color table
  169. p1: push ecx
  170.     mov  ecx,9                     ; 9 columns
  171. p2: push ecx
  172.     push edx
  173.     mov  ecx,edx                   ; y coord
  174.     mov  edx,[ebp]                 ; color
  175.     mov  eax,13                    ; draw bar function
  176.     mcall
  177.     pop  edx
  178.     pop  ecx
  179.     add  ebx,19*65536              ; next column
  180.     add  ebp,4                     ; next color
  181. p3: loop p2
  182.     pop  ecx
  183.     mov  ebx,15*65536+18           ; restart x
  184.     add  edx,19*65536              ; next row
  185.     loop p1
  186.     call draw_picks
  187.  
  188.     ret
  189.  
  190. draw_picks:
  191.     mov  ebx,64*65536+24           ; draw x and width
  192.     mov  ecx,188*65536+42          ; draw y and depth
  193.     mov  edx,0xc0c0c0              ; color grey
  194.     mov  eax,13                    ; draw bar function
  195.     mcall
  196.     mov  eax,[picks]               ; first picked color
  197.     mov  esi,22*65536+196          ; print at x and y
  198.     call do_hex                    ; print color number
  199.     mov  eax,[picks+4]             ; second picked color
  200.     mov  esi,22*65536+215          ; print at x and y
  201.     call do_hex                    ; print color number
  202.     mov  eax,[picks]               ; first picked color
  203.     mov  ebx,67*65536+18           ; x and width
  204.     mov  esi,191*65536+18          ; y and depth
  205.     call do_color                  ; paint color 1 square
  206.     mov  eax,[picks+4]             ; second picked color
  207.     mov  ebx,67*65536+18           ; x and width
  208.     mov  esi,209*65536+18          ; y and depth
  209.     call do_color                  ; paint color 2 square
  210.     mov  eax,[picks]               ; first picked color
  211.     mov  ebx,96*65536+196          ; x and y
  212.     call do_name                   ; print color's name
  213.     mov  eax,[picks+4]             ; second picked color
  214.     mov  ebx,96*65536+215          ; x and y
  215.     call do_name                   ; print color's name
  216.  
  217.     ret
  218.  
  219. do_hex:
  220.     dec  eax                       ; use 0 base
  221.     mov  ecx,4                     ; dword length
  222.     mul  ecx                       ; calc pointer
  223.     mov  edi,colors                ; color table
  224.     add  edi,eax                   ; add offset
  225.     mov  ecx,[edi]                 ; save color 1
  226.     mov  ebx,0x60100               ; print 6 hex digits
  227.     mov  edx,esi                   ; copy color
  228.     mov  esi,0x40e1e1e1            ; use white
  229.     xor  edi, edi
  230.     mov  eax,47                    ; print number function
  231.     mcall
  232.  
  233.     ret
  234.  
  235. do_color:
  236.     dec  eax                       ; use 0 base
  237.     mov  ecx,4                     ; dword length
  238.     mul  ecx                       ; calc pointer
  239.     mov  edi,colors                ; color table
  240.     add  edi,eax                   ; add offset
  241.     mov  edx,[edi]                 ; color
  242.     mov  ecx,esi                   ; recover y an depth
  243.     mov  eax,13                    ; draw bar function
  244.     mcall
  245.  
  246.     ret
  247.  
  248. do_name:
  249.     dec  eax                       ; use 0 base
  250.     mov  ecx,15                    ; string length
  251.     mul  ecx                       ; calc pointer
  252.     mov  edx,names                 ; color table
  253.     add  edx,eax                   ; add offset
  254.     mov  ecx,0x40e1e1e1            ; color
  255.     mov  esi,15
  256.     xor  edi, edi
  257.     mov  eax,4                     ; print text function
  258.     mcall
  259.  
  260.     ret
  261.  
  262.  
  263. help:
  264.         mcall 48,4
  265.         mov ecx, eax
  266.         shl ecx, 16
  267.         add ecx, 236
  268.         sub ecx, eax
  269.  
  270.        
  271.     mov  ebx,5*65536+190           ; x and width
  272.     mov  edx,0x465e8f              ; dark denim color
  273.     mov  eax,13                    ; write text funx
  274.     mcall
  275.     mov  ebx,20*65536+40           ; starting x and y
  276.     mov  edx,text                  ; start of text
  277.     mov  esi,27                    ; width of text
  278.     mov  ecx,14                    ; 14 text lines to do
  279.     mov  eax,4                     ; write text funx
  280. h1: push ecx
  281.     sub  ebx,65537                 ; drop shadow x and y
  282.     mov  ecx,0x000000              ; black shadow
  283.     mcall
  284.     add  ebx,65537                 ; original x and y
  285.     mov  ecx,0xefefef              ; white text
  286.     mcall
  287.     add  edx,27                    ; next line of text
  288.     add  bx,12                     ; next row
  289.     pop  ecx
  290.     loop h1
  291.     mov  eax,10                    ; wait on event
  292.     mcall
  293.     cmp  eax,2                     ; got a key?
  294.     jne  h2                        ; nope
  295.     mov  eax,2                     ; yep, burn it
  296.     mcall
  297. h2:
  298.         call draw_window
  299.  
  300.     ret
  301.  
  302.  
  303. ;   *********************************************
  304. ;   **********  DATA DEFINITIONS AREA ***********
  305. ;   *********************************************
  306.  
  307. title    db   'COLOR REFERENCE H>HELP',0
  308.  
  309. picks:
  310.     dd   31,2           ; selected top/bot colors
  311.  
  312. colors:
  313.     dd   0xe0e0e0       ; white
  314.     dd   0xe7e6a0       ; pale yellow
  315.     dd   0xe7e05a       ; lemon yellow
  316.     dd   0xe7c750       ; mustard
  317.     dd   0xe7b850       ; cadium yellow
  318.     dd   0xbfa461       ; yellow ocre
  319.     dd   0xe0c090       ; cream
  320.     dd   0xe0b27b       ; peach
  321.     dd   0xe2986d       ; dark peach
  322.     dd   0xebb2c0       ; pink
  323.     dd   0xe0b0a0       ; flesh
  324.     dd   0xc79790       ; artificial arm
  325.     dd   0xb88688       ; deep blush
  326.     dd   0xc4a077       ; washed khaki
  327.     dd   0xb69269       ; khaki
  328.     dd   0xa8845b       ; dark khaki
  329.     dd   0xab937a       ; beige
  330.     dd   0xa39370       ; poupon
  331.     dd   0x988c00       ; camouflage
  332.     dd   0x98a024       ; pale olive
  333.     dd   0x838b00       ; olive
  334.     dd   0x6d7600       ; dark olive
  335.     dd   0x5b6200       ; black olive
  336.     dd   0x94946a       ; washed army
  337.     dd   0x74744a       ; army
  338.     dd   0x66a696       ; pale teal
  339.     dd   0x409b90       ; faded teal
  340.     dd   0x008d8d       ; pastel teal
  341.     dd   0x007c7c       ; teal
  342.     dd   0x006464       ; dark teal
  343.     dd   0x00b8ca       ; light turquoise
  344.     dd   0x00a0b2       ; turquoise
  345.     dd   0x00889a       ; dark turquoise
  346.     dd   0x575f8c       ; medium cobalt
  347.     dd   0x4e4e7c       ; cobalt
  348.     dd   0x00459a       ; ultramarine
  349.     dd   0x400088       ; navy blue
  350.     dd   0x4e00e7       ; true blue
  351.     dd   0x508cec       ; sky blue
  352.     dd   0x6a73d0       ; mountain blue
  353.     dd   0x677ab0       ; faded jeans
  354.     dd   0x576fa0       ; denim
  355.     dd   0xd048c8       ; fuschia
  356.     dd   0xb800e7       ; lavendar
  357.     dd   0xa800a8       ; light violet
  358.     dd   0x780078       ; violet
  359.     dd   0x520064       ; purple
  360.     dd   0xb800b8       ; magenta
  361.     dd   0xa4307a       ; rose
  362.     dd   0x90207f       ; mauve
  363.     dd   0xe76e83       ; salmon
  364.     dd   0xea7a7d       ; pastel orange
  365.     dd   0xe26830       ; orange
  366.     dd   0xac5800       ; burnt sienna
  367.     dd   0xcc0000       ; red orange
  368.     dd   0xac0000       ; cadium red
  369.     dd   0x880040       ; brick red
  370.     dd   0x780000       ; rust
  371.     dd   0x683020       ; terra cotta
  372.     dd   0x7f4658       ; light maroon
  373.     dd   0x702050       ; maroon
  374.     dd   0x7a5b5f       ; umber blush
  375.     dd   0x584838       ; burnt umber
  376.     dd   0x8a5d1a       ; cigar brown
  377.     dd   0x64504a       ; ice brown
  378.     dd   0x564242       ; dark chocolate
  379.     dd   0x00aa66       ; celery stalk
  380.     dd   0x107a30       ; forest green
  381.     dd   0x365800       ; hooker's green
  382.     dd   0x8beb88       ; pastel lime
  383.     dd   0x7bbb64       ; lime
  384.     dd   0x4ba010       ; dark lime
  385.  
  386. names:
  387.     db   'WHITE          '
  388.     db   'PALE YELLOW    '
  389.     db   'LEMON YELLOW   '
  390.     db   'MUSTARD        '
  391.     db   'CADIUM YELLOW  '
  392.     db   'YELLOW OCRE    '
  393.     db   'CREAM          '
  394.     db   'PEACH          '
  395.     db   'DARK PEACH     '
  396.     db   'PINK           '
  397.     db   'FLESH          '
  398.     db   'ARTIFICIAL ARM '
  399.     db   'DEEP BLUSH     '
  400.     db   'WASHED KHAKI   '
  401.     db   'KHAKI          '
  402.     db   'DARK KHAKI     '
  403.     db   'BEIGE          '
  404.     db   'POUPON         '
  405.     db   'CAMOUFLAGE     '
  406.     db   'PALE OLIVE     '
  407.     db   'OLIVE          '
  408.     db   'DARK OLIVE     '
  409.     db   'BLACK OLIVE    '
  410.     db   'WASHED ARMY    '
  411.     db   'ARMY           '
  412.     db   'PALE TEAL      '
  413.     db   'FADED TEAL     '
  414.     db   'PASTEL TEAL    '
  415.     db   'TEAL           '
  416.     db   'DARK TEAL      '
  417.     db   'LIGHT TURQUOISE'
  418.     db   'TURQUOISE      '
  419.     db   'DARK TURQUOISE '
  420.     db   'MEDIUM COBALT  '
  421.     db   'COBALT         '
  422.     db   'ULTRAMARINE    '
  423.     db   'NAVY BLUE      '
  424.     db   'TRUE BLUE      '
  425.     db   'SKY BLUE       '
  426.     db   'MOUNTAIN BLUE  '
  427.     db   'FADED JEANS    '
  428.     db   'DENIM          '
  429.     db   'FUSHIA         '
  430.     db   'LAVENDAR       '
  431.     db   'LIGHT VIOLET   '
  432.     db   'VIOLET         '
  433.     db   'PURPLE         '
  434.     db   'MAGENTA        '
  435.     db   'ROSE           '
  436.     db   'MAUVE          '
  437.     db   'SALMON         '
  438.     db   'PASTEL ORANGE  '
  439.     db   'ORANGE         '
  440.     db   'BURNT SIENNA   '
  441.     db   'RED ORANGE     '
  442.     db   'CADIUM RED     '
  443.     db   'BRICK RED      '
  444.     db   'RUST           '
  445.     db   'TERRA COTTA    '
  446.     db   'LIGHT MAROON   '
  447.     db   'MAROON         '
  448.     db   'UMBER BLUSH    '
  449.     db   'BURNT UMBER    '
  450.     db   'CIGAR BROWN    '
  451.     db   'ICE BROWN      '
  452.     db   'DARK CHOCOLATE '
  453.     db   'CELERY STALK   '
  454.     db   'FOREST GREEN   '
  455.     db   "HOOKER'S GREEN "
  456.     db   'PASTEL LIME    '
  457.     db   'LIME           '
  458.     db   'DARK LIME      '
  459.  
  460.  
  461. text:
  462.     db   'TO SEE HOW COLORS COMPARE  '
  463.     db   'TO ONE ANOTHER, LEFT CLICK '
  464.     db   'THE FIRST COLOR AND RIGHT  '
  465.     db   'CLICK THE SECOND. TO GET   '
  466.     db   "A SENSE OF A COLOR'S TRUE  "
  467.     db   'HUE, RIGHT AND LEFT CLICK  '
  468.     db   'THE SAME COLOR TO SEE IT   '
  469.     db   'ON THE NEUTRAL BACKGROUND. '
  470.     db   'TO USE A LIGHTER OR DARKER '
  471.     db   'VALUE OF A COLOR, ADD OR   '
  472.     db   'SUBTRACT 0x10 OR 0x20 FROM '
  473.     db   'EACH BYTE OF ITS HEX VALUE.'
  474.     db   '                           '
  475.     db   '       ANY KEY ...         '
  476.  
  477. stat_table:
  478.  
  479.  
  480. finis:
  481.