Subversion Repositories Kolibri OS

Rev

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

  1. ; FRMWRK.ASM
  2. ; ----------
  3. ; A set of common GUI code used in uFMOD examples for KolibriOS.
  4. ; Feel free to reuse it in your own projects if you like it ;)
  5.  
  6. ; ---------------------------------------------------------------
  7. ; void _cdecl _MessageBox  (szCap, lpString, cbString);
  8. ; void _cdecl _MessageBoxCB(szCap, lpString, cbString, cbProc);
  9. ; ---------------------------------------------------------------
  10.  
  11. ; This is similar to a Win32 MessageBox. The box is centered
  12. ; on screen. It contains a single-line text message and an
  13. ; "OK" button. This function returns when user closes the
  14. ; box (via the X button or via the OK button). An optional
  15. ; callback subroutine may be specified to be called when no
  16. ; events are pending in the event queue.
  17.  
  18. ; NOTE: Doesn't work if you already have defined a window
  19. ; in the current process! Doesn't modify the event mask. So,
  20. ; make sure keyboard events are enabled before calling this
  21. ; function. This function doesn't check the validity of the
  22. ; supplied parameters!
  23.  
  24. ; Parameters:
  25. ; szCap     - A pointer to the ASCIIz string containing the
  26. ;             caption. A trailing zero char IS required.
  27. ; lpString  - A pointer to an ASCII string containing a single
  28. ;             line message to pop up in the box. No trailing
  29. ;             zero char is required.
  30. ; cbString  - number of characters in string.
  31. ; cbProc    - Address of the callback subroutine. Can be NULL.
  32.  
  33. sOK db "OK"
  34. if FRMWRK_CALLBACK_ON
  35. _MessageBoxCB:
  36. else
  37. _MessageBox:
  38. end if
  39.         push ebp
  40.         push esi
  41.         push edi
  42.         push ebx
  43.         xor ebp,ebp      ; global 0
  44.         mov esi,[esp+28] ; cbString
  45.         mov edi,[esp+20] ; szCap
  46.  
  47.         ; Get screen metrics.
  48.         lea eax,[ebp+14]
  49.         int 40h
  50.         mov ecx,eax
  51.         movzx eax,ax
  52.         shr ecx,16         ; screen w
  53.         xchg eax,edx       ; screen h
  54.         lea ebx,[esi*2+esi]
  55.         lea ebx,[ebx*2+28] ; w = string len * 6 + 28
  56.         sub ecx,ebx
  57.         shr ecx,1
  58.         shl ecx,16
  59.         or ebx,ecx
  60.         lea ecx,[ebp+52h]  ; h = 52h
  61.         sub edx,ecx
  62.         shr edx,1
  63.         shl edx,16
  64.         or ecx,edx         ; y = (screen h - window h) / 2
  65.         mov edx,ebx        ; x = (screen w - window w) / 2
  66.  
  67. _MessageBoxCB_redraw:
  68.         ; Start redraw.
  69.         push edx
  70.         lea eax,[ebp+12]
  71.         lea ebx,[ebp+1]
  72.         int 40h
  73.  
  74.         ; Define and draw window.
  75.         xor eax,eax
  76.         mov ebx,edx        ; x, w (ECX: y, h)
  77.         mov edx,34C0C0C0h  ; style and BG color
  78.         int 40h
  79.  
  80.         ; Define the OK button.
  81.         push esi
  82.         lea eax,[ebp+8]
  83.         sub ebx,28+0Ah
  84.         shr bx,1
  85.         shl ebx,16         ; x = (window w - button w) / 2
  86.         mov bx,18+0Ah      ; w = 18 + 0Ah
  87.         mov ecx,001C0012h  ; y = 1Ch, h = 12h
  88.         lea edx,[ebp+1]    ; ID = close
  89.         mov esi,0C0C0C0h   ; color
  90.         int 40h
  91.  
  92.         ; Draw the OK label.
  93.         lea eax,[ebp+4]
  94.         add ebx,90000h     ; x = button x + 9
  95.         mov bx,22h         ; y = 22h
  96.         xor ecx,ecx        ; style, font and color
  97.         mov edx,sOK        ; string
  98.         lea esi,[ebp+2]    ; length
  99.         int 40h
  100.         pop esi
  101.  
  102.         ; Draw text string.
  103.         lea eax,[ebp+4]
  104.         mov ebx,000A000Ah  ; x = 0Ah, y = 0Ah
  105.         xor ecx,ecx        ; style, font and color
  106.         mov edx,[esp+28]   ; lpString
  107.         int 40h
  108.  
  109.         ; End redraw.
  110.         lea eax,[ebp+12]
  111.         lea ebx,[ebp+2]
  112.         int 40h
  113.  
  114. if FRMWRK_CALLBACK_ON
  115. _MessageBoxCB_eventloop:
  116.         mov edx,[esp+36]   ; cbProc
  117.         test edx,edx
  118.         lea eax,[ebp+10]
  119.         jz _MessageBoxCB_peekevent
  120.  
  121.         ; Invoke the callback.
  122.         call edx
  123.  
  124.         lea eax,[ebp+23]
  125.         lea ebx,[ebp+10] ; wait for at most 0.1 sec
  126. _MessageBoxCB_peekevent:
  127.         int 40h
  128.         dec eax
  129.         js _MessageBoxCB_eventloop
  130. else
  131.         lea eax,[ebp+10]
  132.         int 40h
  133.         dec eax
  134. end if
  135.         pop edx
  136.         jz _MessageBoxCB_redraw
  137.  
  138.         pop ebx
  139.         pop edi
  140.         pop esi
  141.         pop ebp
  142.         ret
  143.