Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ft2build.h>
  5. #include FT_FREETYPE_H
  6. #include FT_GLYPH_H
  7. #include <kos32sys.h>
  8.  
  9. #include "winlib.h"
  10.  
  11.  
  12. typedef struct tview *tview_t;
  13.  
  14. tview_t *create_tview(ctx_t *ctx, int width, int height);
  15. void txv_get_margins(const tview_t *txv, rect_t *margins);
  16. void txv_set_margins(tview_t *txv, const rect_t *margins);
  17. void txv_set_size(tview_t *txv, int txw, int txh);
  18. void txv_set_font_size(tview_t *txv, int size);
  19. int  txv_get_font_size(tview_t *txv);
  20. void txv_set_text(tview_t *txv, char *text, int size);
  21. int txv_scroll_up(tview_t *txv);
  22. int txv_scroll_down(tview_t *txv);
  23. int txv_page_up(tview_t *txv);
  24. int txv_page_down(tview_t *txv);
  25.  
  26. typedef struct
  27. {
  28.     volatile int lock;
  29.     unsigned int handle;
  30. }mutex_t;
  31.  
  32.  
  33. void* init_fontlib();
  34.  
  35. void draw_window(void)
  36. {
  37.     BeginDraw();
  38.     DrawWindow(0,0,0,0,NULL,0,0x73);
  39.     EndDraw();
  40. }
  41.  
  42. tview_t *txv;
  43.  
  44.  
  45.  
  46. int main(int argc, char *argv[])
  47. {
  48.     ufile_t  uf;
  49.     oskey_t  key;
  50.     ctx_t   *ctx;
  51.     rect_t   margins = {4,2,20,0};
  52.  
  53.     int clw = 640;
  54.     int clh = 480;
  55.  
  56.  
  57.     __asm__ __volatile__(
  58.     "int $0x40"
  59.     ::"a"(40), "b"(0xc0000027));
  60.  
  61.     if(argc < 2)
  62.         uf = load_file("/RD/1/EXAMPLE.ASM");
  63.     else uf = load_file(argv[1]);
  64.  
  65.     if(uf.data == NULL ||
  66.         uf.size == 0)
  67.         return 0;
  68.  
  69.     ctx = create_context(TYPE_3_BORDER_WIDTH, get_skin_height(), clw, clh);
  70.  
  71.     init_fontlib();
  72.  
  73.     txv = create_tview(ctx, clw, clh);
  74.     txv_set_margins(txv, &margins);
  75.     txv_set_text(txv, uf.data, uf.size);
  76.  
  77.     BeginDraw();
  78.     DrawWindow(10, 40, clw+TYPE_3_BORDER_WIDTH*2,
  79.                clh+TYPE_3_BORDER_WIDTH+get_skin_height(), "Text example", 0x000000, 0x73);
  80.     show_context(ctx);
  81.     EndDraw();
  82.  
  83.         for (;;)
  84.         {
  85.         uint32_t wheels;
  86.         int      buttons;
  87.         pos_t    pos;
  88.  
  89.         switch (get_os_event())
  90.                 {
  91.             case 1:
  92.             {
  93.                 char proc_info[1024];
  94.                 int winx, winy, winw, winh;
  95.                 int txw, txh;
  96.                 char state;
  97.  
  98.                 draw_window();
  99.  
  100.                 get_proc_info(proc_info);
  101.                 state  = *(char*)(proc_info+70);
  102.                 if(state & (WIN_STATE_MINIMIZED|WIN_STATE_ROLLED))
  103.                     continue;
  104.  
  105.                 winx = *(uint32_t*)(proc_info+34);
  106.                 winy = *(uint32_t*)(proc_info+38);
  107.                 winw = *(uint32_t*)(proc_info+42)+1;
  108.                 winh = *(uint32_t*)(proc_info+46)+1;
  109.  
  110.                 txw = winw - TYPE_3_BORDER_WIDTH*2;
  111.                 txh = winh - TYPE_3_BORDER_WIDTH - get_skin_height();
  112.  
  113.                 if( (txw != clw) ||
  114.                     (txh != clh) )
  115.                 {
  116.                     resize_context(ctx, txw, txh);
  117.                     txv_set_size(txv, txw, txh);
  118.                     clw = txw;
  119.                     clh = txh;
  120.                 };
  121.  
  122.                 show_context(ctx);
  123.                 break;
  124.             }
  125.                 case 2:
  126.             key = get_key();
  127. //            printf("key %d\n", key.code);
  128.             switch(key.code)
  129.             {
  130.                 case 27:
  131.                     return 0;
  132.  
  133.                 case 45:
  134.                     txv_set_font_size(txv, txv_get_font_size(txv) - 2);
  135.                     show_context(ctx);
  136.                     break;
  137.  
  138.                 case 61:
  139.                     txv_set_font_size(txv, txv_get_font_size(txv) + 2);
  140.                     show_context(ctx);
  141.                     break;
  142.  
  143.                 case 177:
  144.                     if( txv_scroll_down(txv) )
  145.                         show_context(ctx);
  146.                     break;
  147.  
  148.                 case 178:
  149.                     if( txv_scroll_up(txv) )
  150.                         show_context(ctx);
  151.                     break;
  152.                 case 183:
  153.                     if( txv_page_down(txv) )
  154.                         show_context(ctx);
  155.                     break;
  156.                 case 184:
  157.                     if( txv_page_up(txv) )
  158.                         show_context(ctx);
  159.                     break;
  160.             }
  161.             break;
  162.  
  163.         case 3:
  164.                         // button pressed; we have only one button, close
  165.             return 0;
  166.  
  167.         case 6:
  168. //            pos = get_mouse_pos();
  169. //            buttons = get_mouse_buttons();
  170.             wheels = get_mouse_wheels();
  171.  
  172.             if( wheels & 0xFFFF)
  173.             {
  174.                 int r = 0;
  175.  
  176.                 if((short)wheels > 0)
  177.                     r = txv_scroll_down(txv);
  178.                 else if((short)wheels < 0)
  179.                     r = txv_scroll_up(txv);
  180.  
  181.                 if( r )
  182.                     show_context(ctx);
  183.             }
  184.                 }
  185.         }
  186.     return 0;
  187. }
  188.