Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef __KLIB_H__
  2. #define __KLIB_H__
  3.  
  4. /********* C library *********/
  5.    
  6. get_event()
  7. {
  8. #asm
  9.   mov  eax,10
  10.   int  0x40
  11. #endasm
  12. }
  13.    
  14. get_key()
  15. {
  16. #asm
  17.   mov  eax,2
  18.   int  0x40
  19.   and  eax,0x0000ff00
  20.   shr  eax,8
  21. #endasm
  22. }
  23.    
  24. get_button()
  25. {
  26. #asm
  27.   mov  eax,17
  28.   int  0x40
  29.   shr  eax,8
  30. #endasm
  31. }
  32.    
  33. begin_draw()
  34. {
  35. #asm
  36.   mov  ebx,1
  37.   mov  eax,12
  38.   int  0x40
  39. #endasm
  40. }
  41.    
  42. end_draw()
  43. {
  44. #asm
  45.   mov  ebx,2
  46.   mov  eax,12
  47.   int  0x40
  48. #endasm
  49. }
  50.    
  51. window(x1,y1,w,h,c_area,c_grab,c_fram)
  52. int x1,y1,w,h;            /* esp +32 +28 +24 +20 */
  53. int c_area,c_grab,c_fram; /* esp +16 +12 +8 */
  54. {
  55. #asm
  56.   ; color of frames
  57.   mov  edi,[esp+8]
  58.    
  59.   ; color of grab bar bit 8->color gl
  60.   mov  esi,[esp+12]
  61.    
  62.   ; color of work area bit 8-> color gl
  63.   mov  edx,[esp+16]
  64.    
  65.   ;left / width
  66.   mov  ebx,[esp+32]
  67.   shl  ebx,16
  68.   mov  bx,[esp+24]
  69.   ;top / height
  70.   mov  ecx,[esp+28]
  71.   shl  ecx,16
  72.   mov  cx,[esp+20]
  73.    
  74.   ;execute
  75.   mov  eax,0
  76.   int  0x40
  77. #endasm
  78. }
  79.    
  80. label(x,y,color,p_string)
  81. int x,y,color;  /* esp +20 +16 +12 */
  82. char *p_string; /* esp +8 */
  83. {
  84. #asm
  85.   mov  ebx,[esp+20]
  86.   shl  ebx,16
  87.   mov  bx,[esp+16]
  88.   mov  ecx,[esp+12]
  89.   mov  edx,[esp+8]
  90.    
  91.   ;find text lenght
  92.   xor  esi,esi
  93. .next:
  94.   cmp  byte [edx+esi],0
  95.   jz   .good
  96.   inc  esi
  97.   jmp  .next
  98. .good:
  99.    
  100.   mov  eax,4
  101.   int  0x40
  102. #endasm
  103. }
  104.  
  105.  
  106.  
  107. // Button + Text
  108. buttonT(x1,y1,w,h,color,id,p_string, str_color)
  109. int x1,y1,w,h;  /* esp +28 +24 +20 +16 */
  110. int color,id;
  111. char *p_string;
  112. int str_color;
  113.  
  114. {
  115.         button(x1,y1,w,h,color,id);
  116.         label(x1+4,y1+2,str_color,p_string);
  117. }
  118.    
  119. // Button
  120. button(x1,y1,w,h,color,id)
  121. int x1,y1,w,h;  /* esp +28 +24 +20 +16 */
  122. int color,id;   /* esp +12 +8 */
  123. {
  124. #asm
  125.   ;left / width
  126.   mov  ebx,[esp+28]
  127.   shl  ebx,16
  128.   mov  bx,[esp+20]
  129.   ;top / height
  130.   mov  ecx,[esp+24]
  131.   shl  ecx,16
  132.   mov  cx,[esp+16]
  133.    
  134.   mov  edx,[esp+8]
  135.   mov  esi,[esp+12]
  136.    
  137.   mov  eax,8
  138.   int  0x40
  139. #endasm
  140. }
  141. // CONTROLS:
  142. #define CheckBox        1
  143.  
  144. /* CheckBox
  145. array[ ]:
  146. 0       int type
  147. 1       int id
  148. 2       int x,
  149. 3       int y,
  150. 4       int color,
  151. 5       int colorText
  152. 6       int checked
  153. */
  154. char cbt[2] = " ";
  155. checkbox(cb)
  156. int *cb;
  157. {    
  158.         if (cb[6] == 1) // cheked is set
  159.                 cbt[0] = 'X';
  160.         else
  161.                 cbt[0] = ' ';
  162.        
  163.         buttonT(cb[2], cb[3], 12,10,cb[4],cb[1],cbt,cb[5]);
  164. }
  165.  
  166. eventControls(control,count,id)
  167. int* control;
  168. int count;
  169. int id;
  170. {
  171.         int i;
  172.         int *cont;
  173.         for (i=0; i<count; i++)
  174.         {
  175.                 cont = control[i];
  176.                 switch (cont[0])
  177.                 {
  178.                         case CheckBox:
  179.                                 if (cont[1]==id)
  180.                                 {
  181.                                         cont[6] = 1 - cont[6];
  182.                                         renderControls(control,count);
  183.                                         return 1;
  184.                                 }
  185.                         break;
  186.                 }
  187.         }
  188.         return 0;
  189. }
  190.  
  191. renderControls(control, count)
  192. int* control;
  193. int count;
  194. {
  195.         int i;
  196.         int *cont;
  197.        
  198.         for (i=0; i<count; i++)
  199.         {
  200.                 cont = control[i];
  201.                 switch (cont[0])
  202.                 {
  203.                         case CheckBox:
  204.                                 checkbox(cont)
  205.                         break;
  206.                 }
  207.         }
  208. }
  209.  
  210.    
  211. s_quit()
  212. {
  213. #asm
  214.   mov  eax,-1
  215.   int  0x40
  216. #endasm
  217. }  
  218.  
  219.    
  220.  
  221. #endif