Subversion Repositories Kolibri OS

Rev

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

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ft2build.h>
  4. #include FT_FREETYPE_H
  5. #include FT_GLYPH_H
  6. #include <kos32sys.h>
  7. #include <pixlib2.h>
  8.  
  9. typedef struct
  10. {
  11.   int  l;
  12.   int  t;
  13.   int  r;
  14.   int  b;
  15. }rect_t;
  16.  
  17. typedef struct
  18. {
  19.     FT_Face face;
  20.     int     height;
  21.     int     base;
  22.  
  23.     FT_Glyph glyph[256];
  24.  
  25. }font_t;
  26.  
  27. typedef struct
  28. {
  29.     bitmap_t bitmap;
  30.     font_t   *font;
  31.  
  32.     char    *text;
  33.     char   **line;
  34.     int      lines;
  35.     int      txlines;
  36.     int      startline;
  37.     int      endline;
  38.     int      w;
  39.     int      h;
  40. }tview_t;
  41.  
  42. int init_tview(tview_t *txv, int width, int height, char *text, int size);
  43. int txv_scroll_up(tview_t *txv);
  44. int txv_scroll_down(tview_t *txv);
  45.  
  46. void* init_fontlib();
  47. int draw_text_ext(bitmap_t *winbitmap, FT_Face face, char *text, int len, rect_t *rc, int color);
  48.  
  49. void draw_window(void)
  50. {
  51.     BeginDraw();
  52.     DrawWindow(0,0,0,0,NULL,0,0x74);
  53.     EndDraw();
  54. }
  55.  
  56. tview_t txv;
  57.  
  58. int main(int argc, char *argv[])
  59. {
  60.     ufile_t uf;
  61.     oskey_t   key;
  62.  
  63.     __asm__ __volatile__(
  64.     "int $0x40"
  65.     ::"a"(40), "b"(0xc0000027));
  66.  
  67.     if(argc < 2)
  68.         uf = load_file("/RD/1/EXAMPLE.ASM");
  69.     else uf = load_file(argv[1]);
  70.  
  71.     if(uf.data == NULL ||
  72.        uf.size == 0)
  73.        return 0;
  74.  
  75.     init_pixlib(0);
  76.     init_fontlib();
  77.  
  78.     init_tview(&txv, 480, 600, uf.data, uf.size);
  79.  
  80.     BeginDraw();
  81.     DrawWindow(10, 40, txv.w+TYPE_3_BORDER_WIDTH*2,
  82.                txv.h+TYPE_3_BORDER_WIDTH+get_skin_height(), "Text example", 0x000000, 0x74);
  83.     blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0);
  84.  
  85.     EndDraw();
  86.  
  87.         for (;;)
  88.         {
  89.         uint32_t wheels;
  90.         int      buttons;
  91.         pos_t    pos;
  92.  
  93.         switch (get_os_event())
  94.                 {
  95.                 case 1:
  96.                         draw_window();
  97.             blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0);
  98.                         break;
  99.                 case 2:
  100.             key = get_key();
  101.             switch(key.code)
  102.             {
  103.                 case 27:
  104.                     return;
  105.  
  106.                 case 177:
  107.                     if( txv_scroll_up(&txv) )
  108.                         blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0);
  109.                     break;
  110.  
  111.                 case 178:
  112.                     if( txv_scroll_down(&txv) )
  113.                         blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0);
  114.                     break;
  115.             }
  116.             break;
  117.  
  118.         case 3:
  119.                         // button pressed; we have only one button, close
  120.                         return;
  121.  
  122.         case 6:
  123. //            pos = get_mouse_pos();
  124. //            buttons = get_mouse_buttons();
  125.             wheels = get_mouse_wheels();
  126.  
  127.             if( wheels & 0xFFFF)
  128.             {
  129.                 int r;
  130.  
  131.                 if((short)wheels > 0)
  132.                     r = txv_scroll_up(&txv);
  133.                 else
  134.                     r = txv_scroll_down(&txv);
  135.  
  136.                 if( r )
  137.                     blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0);
  138.             }
  139.                 }
  140.         }
  141.     return 0;
  142. }
  143.