Subversion Repositories Kolibri OS

Rev

Rev 4116 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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