Subversion Repositories Kolibri OS

Rev

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

  1. ; windows.inc
  2. ; Copyright (c) 2002 Thomas Mathys
  3. ; killer@vantage.ch
  4. ;
  5. ; This program is free software; you can redistribute it and/or modify
  6. ; it under the terms of the GNU General Public License as published by
  7. ; the Free Software Foundation; either version 2 of the License, or
  8. ; (at your option) any later version.
  9. ;
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ; GNU General Public License for more details.
  14. ;
  15. ; You should have received a copy of the GNU General Public License
  16. ; along with this program; if not, write to the Free Software
  17. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19. %ifndef _WINDOWS_INC
  20. %define _WINDOWS_INC
  21.  
  22.  
  23. WND_CENTER                      equ     (1 << 0)
  24. WND_DEFAULT_WORKCOLOR           equ     (1 << 1)
  25. WND_DEFAULT_GRABCOLOR           equ     (1 << 2)
  26. WND_DEFAULT_FRAMECOLOR          equ     (1 << 3)
  27. WND_DEFAULT_CAPTIONCOLOR        equ     (1 << 4)
  28. WND_DEFAULT_COLORS              equ     (WND_DEFAULT_WORKCOLOR | WND_DEFAULT_GRABCOLOR | WND_DEFAULT_FRAMECOLOR | WND_DEFAULT_CAPTIONCOLOR)
  29.  
  30.  
  31. struc WND
  32.         .xposandsize    resd    1       ; x position and size (like syscall)
  33.         .yposandsize    resd    1       ; y position and size (like syscall)
  34.         .workcolor      resd    1       ; work area color (like syscall)
  35.         .grabcolor      resd    1       ; grab bar color (like syscall)
  36.         .framecolor     resd    1       ; frame color (like syscall)
  37.         .caption        resd    1       ; pointer to caption (zero terminated)
  38.                                         ; can be zero, if no caption is desired.
  39.         .captioncolor   resd    1       ; caption color
  40.         .flags          resd    1       ; combination of WND_xxx flags, or zero.
  41. endstruc
  42.  
  43.  
  44. BUTTON_COLOR_GRAB               equ     0x01000000
  45. BUTTON_COLOR_WORK               equ     0x02000000
  46.  
  47.  
  48. struc BUTTON
  49.         .xposandsize    resd    1       ; x position and size (like syscall)
  50.         .yposandsize    resd    1       ; y position and size (like syscall)
  51.         .id             resd    1       ; button id
  52.         .color          resd    1       ; button color. can be a real color
  53.                                         ; or one of the BUTTON_COLOR_xxx constants
  54. endstruc
  55.  
  56.  
  57. LABEL_COLOR_GRABBUTTON  equ     0x01000000      ; use grab button text default color
  58. LABEL_COLOR_GRAB        equ     0x02000000      ; use grab text default color
  59. LABEL_COLOR_WORKBUTTON  equ     0x03000000      ; use work button text default color
  60. LABEL_COLOR_WORK        equ     0x04000000      ; use work text default color
  61. LABEL_BGCOLOR_TRANSPARENT equ   0x01000000      ; transparent
  62. LABEL_BGCOLOR_WORK      equ     0x02000000      ; use work area color
  63.  
  64.  
  65. struc LABEL
  66.         .position       resd    1       ; position, x in upper word, y in lower word
  67.         .caption        resd    1       ; pointer to caption (zero terminated)
  68.                                         ; if this is field is zero, the label will
  69.                                         ; not be drawn.
  70.         .color          resd    1       ; text color, or a LABEL_COLOR_xxx constant
  71.         .bgcolor        resd    1       ; background color, or a LABEL_BGCOLOR_xxx constant
  72. endstruc
  73.  
  74.  
  75.         section .text
  76.  
  77.  
  78. ;***********************************************************
  79. ; draw a window
  80. ;
  81. ; input:        edi = pointer to a WND structure
  82. ; output:       nothing
  83. ; destroys:     nothing
  84. ; notes:        you must call begin redraw/end redraw
  85. ;               yourself, before and after calling
  86. ;               this function.
  87. ;***********************************************************
  88.        
  89. drawWindow:
  90.  
  91. %define WNDCOLORS ebp-MOS_WNDCOLORS_size
  92.  
  93.         enter MOS_WNDCOLORS_size,0
  94.         pushfd
  95.         pushad
  96.  
  97.         ; get default window colors
  98.         mov ebx,3
  99.         lea ecx,[WNDCOLORS]
  100.         mov edx,MOS_WNDCOLORS_size
  101.         mov eax,MOS_SC_WINDOWPROPERTIES
  102.         int 0x40
  103.  
  104.         ;
  105.         ; window position
  106.         ;
  107.         test dword [edi + WND.flags],WND_CENTER         ; center window ?
  108.         jnz short .center
  109.         mov ebx,[edi + WND.xposandsize]                 ; nope -> just load dimensions
  110.         mov ecx,[edi + WND.yposandsize]
  111.         jmp short .positionok
  112. .center:                                                ; so let's center this window...
  113.         MOS_GETSCREENMAX                                ; get screen dimensions
  114.         mov ebx,eax                                     ; xpos = (screenx-width)/2
  115.         shr ebx,16
  116.         sub bx,[edi + WND.xposandsize]
  117.         jns short .xok
  118.         xor ebx,ebx
  119. .xok:
  120.         shl ebx,15                                      ; / 2, move result to hi-word
  121.         mov bx,[edi + WND.xposandsize]
  122.         movzx ecx,ax                                    ; same for ypos
  123.         sub cx,[edi + WND.yposandsize]
  124.         jns short .yok
  125.         xor ecx,ecx
  126. .yok:
  127.         shl ecx,15
  128.         mov cx,[edi + WND.yposandsize]
  129. .positionok:                                            ; ebx/ecx contain dimensions
  130.  
  131.         push edi
  132.  
  133.         ; define window
  134.         mov eax,MOS_SC_DEFINEWINDOW
  135.         mov edx,[edi + WND.workcolor]
  136.         mov edi,windowtitle
  137.         int 0x40
  138.         pop edi
  139.  
  140.         popad
  141.         popfd
  142.         leave
  143.         ret
  144. %undef WNDCOLORS
  145.  
  146.  
  147. ;***********************************************************
  148. ; draw a bunch of buttons
  149. ;
  150. ; input:        edi = pointer to an array of BUTTON structs
  151. ;               ecx = # of buttons to draw
  152. ; output:       nothing
  153. ; destroys:     nothing
  154. ; notes:        you must call begin redraw/end redraw yourself
  155. ;***********************************************************
  156.  
  157. drawButtons:
  158.  
  159. %define WNDCOLORS ebp-MOS_WNDCOLORS_size
  160.  
  161.         or ecx,ecx
  162.         jnz short .ok
  163.         ret
  164. .ok:
  165.         enter MOS_WNDCOLORS_size,0
  166.         pushfd
  167.         pushad
  168.        
  169.         ; get default window colors
  170.         push ecx
  171.         mov ebx,3
  172.         lea ecx,[WNDCOLORS]
  173.         mov edx,MOS_WNDCOLORS_size
  174.         mov eax,MOS_SC_WINDOWPROPERTIES
  175.         int 0x40
  176.         pop ecx
  177.        
  178. .drawall:
  179.         push ecx
  180.         mov ebx,[edi + BUTTON.xposandsize]
  181.         mov ecx,[edi + BUTTON.yposandsize]
  182.         mov edx,[edi + BUTTON.id]
  183.         mov esi,[edi + BUTTON.color]   
  184.         cmp esi,BUTTON_COLOR_GRAB                       ; use a default color ?
  185.         jne .ok1
  186.         mov esi,[WNDCOLORS + MOS_WNDCOLORS.grabButton]
  187. .ok1:
  188.         cmp esi,BUTTON_COLOR_WORK
  189.         jne .ok2
  190.         mov esi,[WNDCOLORS + MOS_WNDCOLORS.workButton]
  191. .ok2:  
  192.         mov eax,MOS_SC_DEFINEBUTTON
  193.         int 0x40
  194.         add edi,BUTTON_size
  195.         pop ecx
  196.         loop .drawall
  197.        
  198.         popad
  199.         popfd
  200.         leave
  201.         ret
  202. %undef WNDCOLORS
  203.  
  204.  
  205. ;***********************************************************
  206. ; draw a bunch of labels
  207. ;
  208. ; input:        edi = pointer to an array of LABEL structs
  209. ;               ecx = # of labels to draw
  210. ; output:       nothing
  211. ; destroys:     nothing
  212. ;***********************************************************
  213.  
  214. drawLabels:
  215.  
  216. %define WNDCOLORS ebp-MOS_WNDCOLORS_size
  217.  
  218.         or ecx,ecx
  219.         jnz short .ok
  220.         ret
  221. .ok:
  222.         enter MOS_WNDCOLORS_size,0
  223.         pushfd
  224.         pushad
  225.        
  226.         ; get default window colors
  227.         push ecx
  228.         mov ebx,3
  229.         lea ecx,[WNDCOLORS]
  230.         mov edx,MOS_WNDCOLORS_size
  231.         mov eax,MOS_SC_WINDOWPROPERTIES
  232.         int 0x40
  233.         pop ecx
  234.        
  235. .drawall:
  236.         push ecx
  237.        
  238.         cmp dword [edi + LABEL.caption],0
  239.         jne short .notnull
  240.         jmp .next
  241. .notnull:
  242.        
  243.         ; get caption length
  244.         push edi
  245.         mov edi,[edi + LABEL.caption]
  246.         mov ecx,-1
  247.         xor al,al
  248.         repne scasb                             ; search for zero byte
  249.         mov esi,edi
  250.         pop edi
  251.         sub esi,[edi + LABEL.caption]
  252.         dec esi                                 ; esi = string length
  253.        
  254.         ; clear background, if necessary
  255.         cmp dword [edi + LABEL.bgcolor],LABEL_BGCOLOR_TRANSPARENT
  256.         je .clearok
  257.         mov ebx,[edi + LABEL.position]          ; ebx = xstart/width
  258.         mov eax,esi                             ; width = stringlength * 6
  259.         mov edx,6
  260.         mul edx
  261.         mov bx,ax
  262.         mov ecx,[edi + LABEL.position]          ; ecx = ystart/height
  263.         shl ecx,16
  264.         mov cx,8       
  265.         mov edx,[edi + LABEL.bgcolor]
  266.         cmp edx,LABEL_BGCOLOR_WORK
  267.         jne short .bgcolorok
  268.         mov edx,[WNDCOLORS + MOS_WNDCOLORS.work]
  269. .bgcolorok:
  270.         mov eax,MOS_SC_DRAWBAR
  271.         int 0x40
  272. .clearok:      
  273.  
  274.         ; draw label   
  275.         mov ebx,[edi + LABEL.position]          ; ebx = label position
  276.         mov edx,[edi + LABEL.caption]           ; edx -> caption
  277.         mov ecx,[edi + LABEL.color]             ; ecx = color
  278.         cmp ecx,LABEL_COLOR_GRABBUTTON
  279.         jne short .ok1
  280.         mov ecx,[WNDCOLORS + MOS_WNDCOLORS.grabButtonText]
  281. .ok1:
  282.         cmp ecx,LABEL_COLOR_GRAB
  283.         jne short .ok2
  284.         mov ecx,[WNDCOLORS + MOS_WNDCOLORS.grabText]
  285. .ok2:
  286.         cmp ecx,LABEL_COLOR_WORKBUTTON
  287.         jne short .ok3
  288.         mov ecx,[WNDCOLORS + MOS_WNDCOLORS.workButtonText]
  289. .ok3:
  290.         cmp ecx,LABEL_COLOR_WORK
  291.         jne short .ok4
  292.         mov ecx,[WNDCOLORS + MOS_WNDCOLORS.workText]
  293. .ok4:
  294.         mov eax,MOS_SC_WRITETEXT
  295.         int 0x40
  296.  
  297. .next:
  298.         add edi,LABEL_size                      ; next label
  299.         pop ecx
  300.         dec ecx
  301.         jz .done
  302.         jmp .drawall
  303. .done:
  304.  
  305.         popad
  306.         popfd
  307.         leave
  308.         ret
  309. %undef WNDCOLORS
  310.  
  311.  
  312. %endif