Subversion Repositories Kolibri OS

Rev

Rev 4198 | Rev 7421 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.     use32
  2.     org     0x0
  3. ;-------------------------------------------------------------------------------
  4.     db      "MENUET01"
  5.     dd      1, main, __dataend, __memend, __stackend, 0, sys_path
  6. ;-------------------------------------------------------------------------------
  7.     include "../../../macros.inc"
  8.     include "../../../proc32.inc"
  9.     include "../../../dll.inc"
  10.     include "../../../develop/libraries/box_lib/load_lib.mac"
  11.     ;include "../../../debug.inc"
  12.  
  13.     include "DATA.INC"
  14.     include "NAME.INC"
  15.  
  16.     @use_library_mem     \
  17.             mem.Alloc,   \
  18.             mem.Free,    \
  19.             mem.ReAlloc, \
  20.             dll.Load
  21. ;================================================================================
  22. main:
  23. ; ==== Init ====
  24.     mcall   18, 7
  25.     mov     [win.psid], eax
  26.  
  27.     mcall   40, 100101b
  28.  
  29. ; ==== Load libs ====
  30.     load_libraries load_lib_start, load_lib_end
  31.  
  32. ; ==== Config LibINI ====
  33.     invoke  ini.get_int, ini_data.file_name, ini_data.settings_name, ini_data.location_name, 1
  34.     mov     [dock_items.location], eax
  35.     invoke  ini.get_int, ini_data.file_name, ini_data.settings_name, ini_data.fsize_name, 0
  36.     mov     [dock_items.fsize], eax
  37.  
  38.     invoke  ini.sections, ini_data.file_name, sections_callback
  39.  
  40. ; ==== Load colors ====
  41.     mcall   48, 3, color
  42.     or      dword[color.bg],    0x10000000
  43.     or      dword[color.frame], 0x10000000
  44.     or      dword[color.text],  0x80000000
  45.  
  46. ; ==== Config LibIMG ====
  47.     mov     dword[fi.p00], 5
  48.     mov     dword[fi.p16], buf_128
  49.     mov     dword[fi.p21], img_data.file_name
  50.  
  51.     mcall   70, fi
  52.  
  53.     mov     edx, [buf_128 + 32]
  54.     imul    edx, 10
  55.  
  56.     stdcall mem.Alloc, edx
  57.     mov     [img_data.rgb_object], eax
  58.  
  59.     mov     dword[fi.p00], 0
  60.     mov     dword[fi.p12], edx
  61.     m2m     dword[fi.p16], dword[img_data.rgb_object]
  62.     mov     dword[fi.p21], img_data.file_name
  63.  
  64.     mcall   70, fi
  65.  
  66.     cmp     ebx, 0xFFFFFFFF
  67.     je      @f
  68.  
  69.     stdcall dword[img.decode], dword[img_data.rgb_object], ebx, 0
  70.     mov     dword[img_data.object], eax
  71.  
  72.   ; === ALPHA ===
  73.     mov     edi, eax
  74.     add     edi, 8
  75.     mov     edi, [edi]
  76.     imul    edi, 128
  77.     sub     edi, 4
  78.  
  79.     add     eax, 24
  80.     mov     eax, [eax]
  81.  .setalpha:
  82.     mov     ebx, [eax + edi]
  83.     shr     ebx, 24
  84.     cmp     ebx, 0
  85.     jne     .nonalpha
  86.  
  87.     mov     ecx, [color.bg]
  88.     mov     [eax + edi], ecx
  89.  .nonalpha:
  90.     sub     edi, 4
  91.     cmp     edi, 0
  92.     jne     .setalpha
  93.  
  94.   ; === CONVERTING TO BGR
  95.     stdcall dword[img.toRGB], dword[img_data.object], dword[img_data.rgb_object]
  96.     stdcall dword[img.destroy], dword[img_data.object]
  97.  
  98. ; ==== Config window ====
  99.     mov     eax, dword[dock_items.location]
  100.     and     eax, 1b
  101.     cmp     eax, 0
  102.     je      .vert
  103.     jmp     .setshape
  104.  
  105.  .vert:
  106.     mov     byte[win.isvert], 1
  107.  
  108.  .setshape:
  109.     cmp     byte[win.isvert], 1
  110.     je      .vert_sp
  111.  
  112.  .horz_sp:
  113.     call    .HORZ_WIDTH
  114.     call    .HORZ_X
  115.     call    .HORZ_HEIGHT
  116.     cmp     dword[dock_items.location], 1
  117.     je      .settop
  118.  
  119.  .setbottom:
  120.     call    .HORZ_Y_BOTTOM
  121.     jmp     .SETDEF
  122.  
  123.  .settop:
  124.     call    .HORZ_Y_TOP
  125.     jmp     .SETDEF
  126.  
  127.  
  128.  .vert_sp:
  129.     call    .VERT_WIDTH
  130.     call    .VERT_HEIGHT
  131.     call    .VERT_Y
  132.     cmp     dword[dock_items.location], 2
  133.     je      .setleft
  134.  
  135.  .setright:
  136.     call    .VERT_X_RIGHT
  137.     jmp     .SETDEF
  138.  
  139.  .setleft:
  140.     call    .VERT_X_LEFT
  141.     jmp     .SETDEF
  142.  
  143. ;-------------------------------------------------------------------------------
  144.  .HORZ_WIDTH:
  145.     cmp     [dock_items.fsize], byte 1
  146.     je      @f
  147.     mov     eax, BUTTON_SIZE
  148.     mov     ebx, [dock_items.count]
  149.     imul    eax, ebx
  150.     add     eax, 24
  151.     dec     eax
  152.     jmp     .set_hw
  153.   @@:
  154.     mcall   14
  155.     shr     eax, 16
  156.  .set_hw:
  157.     mov     [win.width_opn], eax
  158.     mov     [win.width_hdn], eax
  159.  
  160.     ret
  161.  
  162. ;-------------------------------------------------------------------------------
  163.  .HORZ_X:
  164.     mcall   14
  165.     shr     eax, 17
  166.     mov     ecx, [win.width_opn]
  167.     shr     ecx, 1
  168.     sub     eax, ecx
  169.     mov     [win.x_opn], eax
  170.     mov     [win.x_hdn], eax
  171.  
  172.     ret
  173.  
  174. ;-------------------------------------------------------------------------------
  175.  .HORZ_HEIGHT:
  176.     mov     dword[win.height_hdn], 3
  177.     mov     dword[win.height_opn], BUTTON_SIZE
  178.  
  179.     ret
  180.  
  181. ;-------------------------------------------------------------------------------
  182.  .HORZ_Y_BOTTOM:
  183.     mcall   14
  184.     and     eax, 0xFFFF
  185.     dec     eax
  186.     mov     [win.y_hdn], eax
  187.     sub     eax, 43
  188.     mov     [win.y_opn], eax
  189.  
  190.     ret
  191.  
  192.  .HORZ_Y_TOP:
  193.     mov     dword[win.y_opn], 0
  194.     mov     dword[win.y_hdn], 0
  195.  
  196.     ret
  197.  
  198. ;-------------------------------------------------------------------------------
  199.  .VERT_WIDTH:
  200.     mov     dword[win.width_opn], BUTTON_SIZE
  201.     mov     dword[win.width_hdn], 3
  202.  
  203.     ret
  204.  
  205. ;-------------------------------------------------------------------------------
  206.  .VERT_X_LEFT:
  207.     mov     dword[win.x_opn], 0
  208.     mov     dword[win.x_hdn], 0
  209.  
  210.     ret
  211.  
  212.  .VERT_X_RIGHT:
  213.     mcall   14
  214.     and     eax, 0xFFFF0000
  215.     shr     eax, 16
  216.     mov     [win.x_hdn], eax
  217.     sub     eax, BUTTON_SIZE
  218.     mov     [win.x_opn], eax
  219.  
  220.     ret
  221.  
  222. ;-------------------------------------------------------------------------------
  223.  .VERT_HEIGHT:
  224.     cmp     [dock_items.fsize], byte 1
  225.     je      @f
  226.     mov     eax, BUTTON_SIZE
  227.     mov     ebx, [dock_items.count]
  228.     imul    eax, ebx
  229.     dec     eax
  230.     jmp     .set_vh
  231.   @@:
  232.     mcall   14
  233.     and     eax, 0xFFFF
  234.  .set_vh:
  235.     mov     [win.height_opn], eax
  236.     mov     [win.height_hdn], eax
  237.  
  238.     ret
  239.  
  240. ;-------------------------------------------------------------------------------
  241.  .VERT_Y:
  242.     mcall   14
  243.     and     eax, 0xFFFF
  244.     shr     eax, 1
  245.  
  246.     mov     esi, [win.height_opn]
  247.     shr     esi, 1
  248.     sub     eax, esi
  249.  
  250.     mov     [win.y_hdn], eax
  251.     mov     [win.y_opn], eax
  252.  
  253.     ret
  254.  
  255. ;-------------------------------------------------------------------------------
  256.  .SETDEF:
  257.     mov     eax, [win.width_hdn]
  258.     mov     [win.width], eax
  259.  
  260.     mov     eax, [win.x_hdn]
  261.     mov     [win.x], eax
  262.  
  263.     mov     eax, [win.height_hdn]
  264.     mov     [win.height], eax
  265.  
  266.     mov     eax, [win.y_hdn]
  267.     mov     [win.y], eax
  268.  
  269. ;-------------------------------------------------------------------------------
  270. ; ==== START ====
  271.     mcall   9, win.procinfo, -1
  272.     mov     ecx, [win.procinfo + 30]
  273.     mcall   18, 21
  274.     and     eax, 0xFFFF
  275.     mov     [win.sid], eax
  276.  
  277.     call    main_loop
  278. ;-------------------------------------------------------------------------------
  279. exit:
  280.     stdcall mem.Free, [img_data.rgb_object]
  281.     mcall   18, 2, [nwin.sid]
  282.     mcall   -1
  283. ;-------------------------------------------------------------------------------
  284. main_loop:
  285.     mcall   10
  286.  
  287.     cmp     eax, EV_REDRAW
  288.     je      event_redraw
  289.  
  290.     cmp     eax, EV_BUTTON
  291.     je      event_button
  292.  
  293.     cmp     eax, EV_MOUSE
  294.     je      event_mouse
  295.  
  296.     jmp     main_loop
  297. ;-------------------------------------------------------------------------------
  298. event_redraw:
  299.     call    DRAW_WINDOW
  300.     jmp     main_loop
  301. ;-------------------------------------------------------------------------------
  302. DRAW_WINDOW:
  303.     mcall   12, 1
  304.  
  305.     mov     esi, [color.bg]
  306.     or      esi, 0x01000000
  307.     mcall   0, <[win.x], [win.width]>, <[win.y], [win.height]>, [color.bg], , [color.frame]
  308.  
  309.     mov     edi, 0
  310.   @@:
  311.     cmp     edi, [dock_items.count]
  312.     je      @f
  313.  
  314.     push    edi
  315.     mov     eax, 8
  316.     mov     edx, 0x60000002
  317.     mov     esi, [color.bg]
  318.     imul    edi, BUTTON_SIZE
  319.     add     edi, 12
  320.     shl     edi, 16
  321.     add     edi, BUTTON_SIZE
  322.     cmp     byte[win.isvert], 1
  323.     je      .vert_btn
  324.     mcall   , edi, <0, BUTTON_SIZE>
  325.     jmp     .endbtn
  326.  .vert_btn:
  327.     sub     edi, 12 shl 16
  328.     mcall   , <0, BUTTON_SIZE>, edi
  329.  .endbtn:
  330.     pop     edi
  331.  
  332.     cmp     byte[dock_items.separator + edi], 1
  333.     jne     .end_separator
  334.  
  335.  .draw_separator:
  336.     push    ebx
  337.     push    ecx
  338.  
  339.     mov     eax, 13
  340.     mov     ebx, edi
  341.     imul    ebx, BUTTON_SIZE
  342.     add     ebx, BUTTON_SIZE
  343.     add     ebx, 12
  344.     dec     ebx
  345.     shl     ebx, 16
  346.     add     ebx, 2
  347.  
  348.     cmp     byte[win.isvert], 1
  349.     je      .vert_draw_sep
  350.     mcall   , , <4,  36>, [color.frame]
  351.     jmp     .end_inner_sep
  352.  .vert_draw_sep:
  353.     sub     ebx, 12 shl 16
  354.     mov     ecx, ebx
  355.     mcall   , <4, 36>, , [color.frame]
  356.  .end_inner_sep:
  357.     pop     ecx
  358.     pop     ebx
  359.  .end_separator:
  360.  
  361.     cmp     byte[win.isvert], 1
  362.     je      .vert_dig
  363.     mov     edx, ebx
  364.     and     edx, 0xFFFF0000
  365.     add     edx, 0x00060006
  366.     jmp     .digend
  367.  .vert_dig:
  368.     mov     edx, ecx
  369.     and     edx, 0xFFFF0000
  370.     shr     edx, 16
  371.     add     edx, 0x00060006
  372.  .digend:
  373.  
  374.     imul    ebx, edi, 4
  375.     add     ebx, dock_items.icon
  376.     mov     ebx, [ebx]
  377.     imul    ebx, ICON_SIZE_BGR
  378.     add     ebx, [img_data.rgb_object]
  379.  
  380.     mcall   7, , <32, 32>
  381.  
  382.     inc     edi
  383.     jmp     @b
  384.   @@:
  385.  
  386.     mcall   12, 2
  387.  
  388.     ret
  389. ;-------------------------------------------------------------------------------
  390. event_button:
  391.     mcall   17
  392.  
  393.     cmp     ah, 1
  394.     je      .button_close
  395.  
  396.     cmp     ah, 2
  397.     je      .button_dock
  398.  
  399.     jmp     @f
  400.  
  401.  .button_close:
  402.     jmp     exit
  403.  
  404.  .button_dock:
  405.     mov     edi, [win.button_index]
  406.     imul    edi, 256
  407.  
  408.     mov     dword[fi.p00], 7
  409.  
  410.     mov     esi, edi
  411.     add     esi, dock_items.path
  412.     mov     dword[fi.p21], esi
  413.  
  414.     mov     esi, edi
  415.     add     esi, dock_items.param
  416.     mov     dword[fi.p08], esi
  417.  
  418.     mcall   70, fi
  419.  
  420.     mov     ecx, eax
  421.     mcall   18, 21
  422.     and     eax, 0xFFFF
  423.     mov     [win.psid], eax
  424.  
  425.     jmp     wnd_hide
  426.  
  427.   @@:
  428.     jmp     main_loop
  429. ;-------------------------------------------------------------------------------
  430. event_mouse:
  431.   ; ==== IS MOUSE INNER ====
  432.     mcall   37, 1
  433.     mov     edi, eax
  434.     mov     esi, eax
  435.     shr     edi, 16
  436.     and     esi, 0xFFFF
  437.  
  438.     cmp     edi, 0
  439.     jl      wnd_hide
  440.     dec     edi
  441.     cmp     edi, [win.width]
  442.     jg      wnd_hide
  443.     cmp     esi, 0
  444.     jl      wnd_hide
  445.     dec     esi
  446.     cmp     esi, [win.height]
  447.     jg      wnd_hide
  448.  
  449.   ; ==== COUNT INDEX ====
  450.  
  451.     mov     eax, [dock_items.location]
  452.     and     eax, 1b
  453.     cmp     eax, 1
  454.     jne     .vert
  455.     mov     eax, edi
  456.     jmp     .nxt
  457.  
  458.  .vert:
  459.     mov     eax, esi
  460.     add     eax, 12
  461.  
  462.  .nxt:
  463.     sub     eax, 12
  464.     mov     edx, 0
  465.     mov     ebx, BUTTON_SIZE
  466.     div     ebx
  467.  
  468.     cmp     eax, [dock_items.count]
  469.     jge     .set0
  470.     jmp     .nxtcmp
  471.  
  472.  .set0:
  473.     mov     eax, 100
  474.  
  475.  .nxtcmp:
  476.     cmp     [win.button_index], eax
  477.     je      .nxt2
  478.  
  479.     push    dword[win.button_index]
  480.     pop     dword[win.prev_index]
  481.  
  482.     mov     [win.button_index], eax
  483.  
  484.  ; ==== DRAW SELECTION ====
  485.     call    DRAW_SELECTION
  486.  
  487.  .nxt2:
  488.     mov     eax, [win.button_index]
  489.     imul    eax, BUTTON_SIZE
  490.     cmp     byte[win.isvert], 1
  491.     je      .vert_name
  492.     add     eax, [win.x]
  493.     mov     [nwin.x], eax
  494.     mov     byte[nwin.change_shape], 1
  495.     mcall   13, <0, [win.width]>, <[win.height], 1>, [color.frame]
  496.     jmp     .vert_end
  497.  .vert_name:
  498.     add     eax, [win.y]
  499.     add     eax, 14
  500.     mov     [nwin.y], eax
  501.     mov     byte[nwin.change_shape], 1
  502.     mcall   13, <[win.width], 1>, <0, [win.height]>, [color.frame]
  503.  .vert_end:
  504.  
  505.  ; ==== OPEN/CLOSE WINDOW ====
  506.     cmp     byte[win.state], 1
  507.     je      main_loop
  508.  
  509.     mov     edx, esp
  510.     add     edx, 512
  511.     mcall   51, 1, n_main
  512.  
  513.     mov     eax, 18
  514.  
  515.     mcall   , 7
  516.     mov     [win.psid], eax
  517.  
  518.     mcall   18, 3, [win.sid]
  519.  
  520.     mov     byte[win.state], 1
  521.  
  522.     mov     eax, [win.width_opn]
  523.     mov     [win.width], eax
  524.  
  525.     mov     eax, [win.x_opn]
  526.     mov     [win.x], eax
  527.  
  528.     mov     eax, [win.height_opn]
  529.     mov     [win.height], eax
  530.  
  531.     mov     eax, [win.y_opn]
  532.     mov     [win.y], eax
  533.  
  534.     mcall   67, [win.x], [win.y], [win.width], [win.height]
  535.  
  536.     call    DRAW_WINDOW
  537.     call    DRAW_SELECTION
  538.     jmp     main_loop
  539.  
  540. ;-------------------------------------------------------------------------------
  541. wnd_hide:
  542.     cmp     byte[win.state], 0
  543.     je      main_loop
  544.  
  545.     mov     byte[nwin.close], 1
  546.  
  547.     mcall   18, 3, [win.psid]
  548.  
  549.     mov     byte[win.state], 0
  550.     mov     byte[win.button_index], -1
  551.  
  552.     mov     eax, [win.width_hdn]
  553.     mov     [win.width], eax
  554.  
  555.     mov     eax, [win.x_hdn]
  556.     mov     [win.x], eax
  557.  
  558.     mov     eax, [win.height_hdn]
  559.     mov     [win.height], eax
  560.  
  561.     mov     eax, [win.y_hdn]
  562.     mov     [win.y], eax
  563.  
  564.     mcall   67, [win.x], [win.y], [win.width], [win.height]
  565.  
  566.     call    DRAW_WINDOW
  567.     jmp     main_loop
  568. ;-------------------------------------------------------------------------------
  569. DRAW_SELECTION:
  570.     mov     ebx, [win.prev_index]
  571.     imul    ebx, BUTTON_SIZE
  572.     add     ebx, 14
  573.     shl     ebx, 16
  574.     add     ebx, 40
  575.     mov     ecx, 0x00020028
  576.  
  577.     cmp     byte[win.isvert], 1
  578.     jne     @f
  579.     xchg    ebx, ecx
  580.     sub     ecx, 0x000C0000
  581.   @@:
  582.  
  583.     mcall   13, , , [color.bg]
  584.  
  585.     mov     edx, ebx
  586.     shr     ecx, 16
  587.     mov     dx, cx
  588.     add     edx, 0x00040004
  589.  
  590.     mov     ebx, [win.prev_index]
  591.     imul    ebx, 4
  592.     add     ebx, dock_items.icon
  593.     mov     ebx, [ebx]
  594.     imul    ebx, ICON_SIZE_BGR
  595.     add     ebx, [img_data.rgb_object]
  596.  
  597.     mcall   7, , <32, 32>
  598.  
  599.     mov     ebx, [win.button_index]
  600.     imul    ebx, BUTTON_SIZE
  601.     add     ebx, 14
  602.     shl     ebx, 16
  603.     add     ebx, 40
  604.     mov     ecx, 0x00020028
  605.  
  606.     cmp     byte[win.isvert], 1
  607.     jne     @f
  608.     xchg    ebx, ecx
  609.     sub     ecx, 0x000C0000
  610.   @@:
  611.  
  612.     mcall   13, , , [color.bt]
  613.  
  614.     mov     edx, ebx
  615.     shr     ecx, 16
  616.     mov     dx, cx
  617.     add     edx, 0x00040004
  618.  
  619.     mov     ecx, [win.button_index]
  620.     imul    ecx, 4
  621.     add     ecx, dock_items.icon
  622.     mov     ecx, [ecx]
  623.     imul    ecx, ICON_SIZE_BGR
  624.     add     ecx, [img_data.rgb_object]
  625.  
  626.     mov     ebx, sel_img
  627.  
  628.     mov     edi, 0
  629.   @@:
  630.     mov     al, byte[ecx + 2]
  631.     shl     eax, 8
  632.     mov     al, byte[ecx + 1]
  633.     shl     eax, 8
  634.     mov     al, byte[ecx + 0]
  635.  
  636.     or      eax, 0x10000000
  637.     cmp     eax, [color.bg]
  638.     jne     .notbg
  639.     mov     eax, [color.bt]
  640.  .notbg:
  641.  
  642.     mov     byte[ebx + 0], al
  643.     shr     eax, 8
  644.     mov     byte[ebx + 1], al
  645.     shr     eax, 8
  646.     mov     byte[ebx + 2], al
  647.  
  648.     add     ebx, 3
  649.     add     ecx, 3
  650.  
  651.     add     edi, 3
  652.  
  653.     cmp     edi, 1024 * 3
  654.     jne     @b
  655.  
  656.     mcall   7, sel_img, <32, 32>
  657.  
  658.     ret
  659. ;-------------------------------------------------------------------------------
  660. proc sections_callback, _file_name, _section_name
  661.     mov     eax, [_section_name]
  662.     cmp     byte[eax], '@'
  663.     jne     @f
  664.  
  665.     dec     dword[dock_items.count]
  666.     jmp     .endproc
  667.  
  668.   @@:
  669.     ; ==== GET NAME ====
  670.     mov     ebx, [dock_items.count]
  671.     imul    ebx, 16
  672.     add     ebx, dock_items.name
  673.  
  674.     mov     eax, [_section_name]
  675.  
  676.     mov     edi, 0
  677.   @@:
  678.     mov     cl, byte[eax]
  679.     mov     byte[ebx + edi], cl
  680.  
  681.     inc     eax
  682.     inc     edi
  683.     cmp     edi, 10
  684.     jne     @b
  685.  
  686.   ; ==== GET PATH ====
  687.     mov     ebx, [dock_items.count]
  688.     imul    ebx, 256
  689.     add     ebx, dock_items.path
  690.  
  691.     invoke  ini.get_str, [_file_name], [_section_name], ini_data.path_name, ebx, 256, 0
  692.  
  693.   ; === GET  PARAM ===
  694.     mov     ebx, [dock_items.count]
  695.     imul    ebx, 256
  696.     add     ebx, dock_items.param
  697.  
  698.     invoke  ini.get_str, [_file_name], [_section_name], ini_data.param_name, ebx, 256, 0
  699.  
  700.   ; ==== GET ICON ====
  701.     invoke  ini.get_int, [_file_name], [_section_name], ini_data.icon_name, 0
  702.  
  703.     mov     ebx, [dock_items.count]
  704.     imul    ebx, 4
  705.     mov     [dock_items.icon + ebx], eax
  706.  
  707.   ; ==== GET SEPARATOR ====
  708.     invoke  ini.get_int, [_file_name], [_section_name], ini_data.separator_name, 0
  709.  
  710.     mov     ebx, [dock_items.count]
  711.     mov     byte[dock_items.separator + ebx], al
  712.  
  713.   ; ====== END =======
  714.  .endproc:
  715.     mov     eax, 1
  716.     inc     dword[dock_items.count]
  717.     ret
  718. endp
  719. ;-------------------------------------------------------------------------------
  720.     include "MEMORY.INC"