Subversion Repositories Kolibri OS

Rev

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

  1. macro use_progressbar
  2. {
  3. pb equ [ebp + 4 + 8*4]
  4. align 16
  5. progressbar_draw:
  6.         pushad
  7.                                 mov    ebp, esp                        
  8. ; draw frame
  9.         push   ebp
  10.         mov    [.last_esp], esp
  11.         mov    eax, pb
  12.         mov    esi, [eax + PB_LEFT]
  13.         mov    edi, [eax + PB_TOP]
  14.         mov    ebp, [eax + PB_WIDTH]
  15.         add    ebp, esi
  16.                                 dec    ebp
  17.         mov    esp, [eax + PB_HEIGHT]
  18.         add    esp, edi
  19.                                 dec    esp
  20.         mov    edx, [eax + PB_FRAME_COLOR]
  21.         mov    eax, 38
  22.         mov    ebx, esi
  23.         shl    ebx, 16
  24.         add    ebx, ebp
  25.         mov    ecx, edi
  26.         shl    ecx, 16
  27.         add    ecx, edi
  28.         int    64
  29.         mov    ecx, esp
  30.         shl    ecx, 16
  31.         add    ecx, esp
  32.         int    64              
  33.         mov    bx, si
  34.         mov    ecx, edi
  35.         shl    ecx, 16
  36.         add    ecx, esp
  37.         int    64              
  38.         mov    ebx, ebp
  39.         shl    ebx, 16
  40.         add    ebx, ebp
  41.         int    64                      
  42.         mov    esp, [.last_esp]
  43.         pop    ebp
  44. ; if min > max then .skip
  45.         mov    eax, pb
  46.                                 mov    edx, [eax + PB_MAX]
  47.                                 mov    ecx, [eax + PB_MIN]
  48.                                 cmp    ecx, edx
  49.                                 ; jg     .skip
  50.                                 jne    .min_no_eq_max
  51.                                 dec    edx
  52. .min_no_eq_max:                        
  53. ; draw all progress rectangle
  54.                                 call   get_progress_width
  55.                                 mov    edi, eax
  56.         mov    eax, pb                         
  57.         mov    ebx, [eax + PB_LEFT]
  58.                                 inc    ebx
  59.         shl    ebx, 16
  60.         add    ebx, edi
  61.         mov    ecx, [eax + PB_TOP]
  62.                                 inc    ecx
  63.         shl    ecx, 16
  64.         add    ecx, [eax + PB_HEIGHT]
  65.                                 dec    ecx
  66.                                 dec    ecx
  67.         mov    edx, [eax + PB_PROGRESS_COLOR]
  68.                                 mov    eax, 13
  69.         int    64
  70. ; draw last part of non-progress rectangle
  71. ; edi = pW, esi = W - 2
  72.         sub    esi, edi ; width
  73.                                 shr    ebx, 16
  74.         add    ebx, edi
  75.         shl    ebx, 16
  76.         add    ebx, esi
  77.                                 mov    esi, pb
  78.         mov    edx, [esi + PB_BACK_COLOR]
  79.         int    64                              
  80. ; .skip:
  81.                                 popad
  82.         ret    4
  83. .last_esp dd 0
  84.  
  85.  
  86. align 16
  87. get_progress_width:
  88. ; pW = (W-2)(value - min) / (max - min)
  89.         mov    esi, [eax + PB_WIDTH]
  90.         dec    esi
  91.         dec    esi
  92.         mov    eax, [eax + PB_VALUE]
  93.         sub    eax, ecx
  94.         imul   eax, esi
  95.         neg    ecx
  96.         add    ecx, edx
  97.         xor    edx, edx
  98.         div    ecx
  99.         ret
  100.  
  101.  
  102. align 16
  103. progressbar_progress:
  104.         pushad
  105.                                 mov    ebp, esp
  106. ; if min > max then .skip
  107.         mov    eax, pb
  108.                                 mov    edx, [eax + PB_MAX]
  109.                                 mov    ecx, [eax + PB_MIN]
  110.                                 cmp    ecx, edx
  111.                                 ; jg     .skip         
  112.                                 jne    .min_no_eq_max1
  113.                                 dec    edx
  114. .min_no_eq_max1:       
  115.                                 call   get_progress_width
  116.                                 mov    edi, eax                        
  117. ; increase value
  118.         mov    eax, pb
  119.                                 mov    edx, [eax + PB_MAX]
  120.                                 mov    ecx, [eax + PB_VALUE]
  121.                                 inc    ecx
  122. ; if value > max then value = max
  123.         cmp    ecx, edx
  124.                                 jng    .next
  125.                                 mov    ecx, edx
  126. .next:         
  127.                     mov    [eax + PB_VALUE], ecx
  128. ; draw new part of progress rectangle
  129.         mov    eax, pb
  130.                                 mov    ecx, [eax + PB_MIN]
  131.                                 cmp    ecx, edx
  132.                                 jne    .min_no_eq_max2
  133.                                 dec    edx
  134. .min_no_eq_max2:       
  135.         call   get_progress_width
  136.                                 mov    esi, eax
  137. ; edi = last pW, esi = new pW                          
  138.         mov    eax, pb                         
  139.         mov    ebx, [eax + PB_LEFT]
  140.                                 inc    ebx
  141.                           add    ebx, edi      
  142.         shl    ebx, 16
  143.         add    ebx, esi
  144.                           sub    ebx, edi
  145.         mov    ecx, [eax + PB_TOP]
  146.                                 inc    ecx
  147.         shl    ecx, 16
  148.         add    ecx, [eax + PB_HEIGHT]
  149.                                 dec    ecx
  150.                                 dec    ecx
  151.         mov    edx, [eax + PB_PROGRESS_COLOR]
  152.                                 mov    eax, 13
  153.         int    64                              
  154. ; .skip:
  155.                                 popad
  156.         ret    4
  157. restore pb                             
  158. }