Subversion Repositories Kolibri OS

Rev

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

  1. #include<menuet/os.h>
  2. #define _WIN32
  3. #include "fitz.h"
  4. #include "mupdf.h"
  5. #include "muxps.h"
  6. #include "pdfapp.h"
  7. #include "icons/allbtns.h"
  8.  
  9.  
  10.  
  11. static char Title[] = "some title";
  12. static char * filename = "/hd0/1/yand.pdf";
  13. static pdfapp_t gapp;
  14.  
  15. void f65(unsigned x, unsigned y, unsigned w, unsigned h, char *d) //Вывод картинки
  16. {
  17. asm ("nop"::"c"(w*65536+h), "d"(x*65536+y), "b"(d));
  18. asm ("xor %eax, %eax");
  19. asm ("movl %eax, %ebp");
  20. asm ("pushl $32");
  21. asm ("popl %esi");
  22. asm ("int $0x40"::"a"(65));
  23.  
  24. }
  25.  
  26.         struct blit_call
  27. {
  28.    int dstx;      
  29.    int dsty;
  30.    int w;
  31.    int h;
  32.  
  33.    int srcx;
  34.    int srcy;
  35.    int srcw;
  36.    int srch;
  37.  
  38.    unsigned char *d;
  39.    int   stride;
  40. };
  41.  
  42. void blit(int dstx, int dsty, int w, int h, int srcx, int srcy,int srcw, int srch, int stride, char *d) //Вызов сисфункции Blitter
  43. {
  44.  
  45. struct blit_call image;
  46.         image.dstx=dstx;
  47.         image.dsty=dsty;
  48.         image.w=w;
  49.         image.h=h;
  50.         image.srcx=srcx;
  51.         image.srcy=srcy;
  52.         image.srcw=srcw;
  53.         image.srch=srch;
  54.         image.stride=stride;
  55.         image.d=d;
  56.        
  57.  
  58. asm ("int $0x40"::"a"(73),"b"(0),"c"(&image));
  59.  
  60. }
  61.  
  62. void winwarn(pdfapp_t *app, char *msg)
  63. {
  64.         fprintf(stderr, "mupdf: %s\n", msg);
  65. }
  66.  
  67. void winerror(pdfapp_t *app, fz_error error)
  68. {
  69.         fz_catch(error, "aborting");
  70.         exit(1);
  71. }
  72.  
  73. char *winpassword(pdfapp_t *app, char *filename)
  74. {
  75.         char *r = "";
  76.         return r;
  77. }
  78.  
  79.  
  80. void wincursor(pdfapp_t *app, int curs)
  81. {
  82.        
  83. }
  84.  
  85. void wintitle(pdfapp_t *app, char *s)
  86. {
  87.  
  88. sprintf(Title,"uPDF: %s", s);  
  89. }
  90.  
  91. void winhelp(pdfapp_t *app)
  92. {
  93.        
  94. }
  95.  
  96. void winresize(pdfapp_t *app, int w, int h)
  97. {
  98.         //here should be something!!!
  99.        
  100.        
  101. }
  102.  
  103.  
  104. void windocopy(pdfapp_t *app)
  105. {
  106. }
  107.  
  108. void winreloadfile(pdfapp_t *app)
  109. {
  110.         pdfapp_close(app);
  111.  
  112.  
  113.         pdfapp_open(app, filename, 0, 1);
  114. }
  115.  
  116. void winopenuri(pdfapp_t *app, char *buf)
  117. {
  118.         /* here can be browser!
  119.         char *browser = getenv("BROWSER");
  120.         if (!browser)
  121.                 browser = "open";
  122.         if (fork() == 0)
  123.                 execlp(browser, browser, buf, (char*)0);
  124.                 * */
  125.                
  126. }
  127.  
  128.  
  129.  
  130. void winclose(pdfapp_t *app)
  131. {
  132.         pdfapp_close(&gapp);
  133.         __menuet__sys_exit();
  134. }
  135.  
  136. void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
  137. {
  138. asm ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
  139. }
  140.  
  141.  
  142. static void winblit(pdfapp_t *app)
  143. {
  144.         char yoba[32];
  145.         int x0 = gapp.panx;
  146.         int y0 = gapp.pany;
  147.         int x1 = gapp.panx + gapp.image->w;
  148.         int y1 = gapp.pany + gapp.image->h;
  149. __menuet__debug_out(" Window blit\n");
  150. __menuet__bar(0,0,598,370,0xababab); //background of pics
  151. /*
  152.         XSetForeground(xdpy, xgc, xbgcolor.pixel);
  153.         fillrect(0, 0, x0, gapp.winh);
  154.         fillrect(x1, 0, gapp.winw - x1, gapp.winh);
  155.         fillrect(0, 0, gapp.winw, y0);
  156.         fillrect(0, y1, gapp.winw, gapp.winh - y1);*/
  157.         if (gapp.image->h-y0 > 0) {
  158.         kol_paint_bar(0, gapp.image->h-y0, 590, 368, 0xEFEFEF);
  159. }
  160.         /*kol_paint_bar(x1, 0, gapp.winw - x1, gapp.winh, 0x00FF00);
  161.         kol_paint_bar(0, 0, gapp.winw, y0, 0xFF0000);
  162.         kol_paint_bar(0, y1, gapp.winw, gapp.winh - y1, 0xFFFF);*/
  163.        
  164.  
  165.         /*XSetForeground(xdpy, xgc, xshcolor.pixel);
  166.         fillrect(x0+2, y1, gapp.image->w, 2);
  167.         fillrect(x1, y0+2, 2, gapp.image->h);*/
  168. sprintf (yoba, "%d x %d, %d x %d \n", gapp.image->w, gapp.image->h, gapp.winw, gapp.winh);
  169. __menuet__debug_out(yoba);
  170.  
  171.  
  172.         if (gapp.image->n == 4)
  173.                 /*ximage_blit(xwin, xgc,
  174.                         x0, y0,
  175.                         gapp.image->samples,
  176.                         0, 0,
  177.                         gapp.image->w,
  178.                         gapp.image->h,
  179.                         gapp.image->w * gapp.image->n);*/
  180.                 //      f65(x0,y0+32,gapp.image->w,gapp.image->h,gapp.image->samples);
  181.                          
  182.                         blit(6, 24, 588, 368, x0, y0,gapp.image->w, gapp.image->h, gapp.image->w * gapp.image->n, gapp.image->samples);
  183.                        
  184.                        
  185.         else if (gapp.image->n == 2)
  186.         {
  187.                 int i = gapp.image->w*gapp.image->h;
  188.                 unsigned char *color = malloc(i*4);
  189.                 if (color != NULL)
  190.                 {
  191.                         unsigned char *s = gapp.image->samples;
  192.                         unsigned char *d = color;
  193.                         for (; i > 0 ; i--)
  194.                         {
  195.                                 d[2] = d[1] = d[0] = *s++;
  196.                                 d[3] = *s++;
  197.                                 d += 4;
  198.                         }
  199.                         /*ximage_blit(xwin, xgc,
  200.                                 x0, y0,
  201.                                 color,
  202.                                 0, 0,
  203.                                 gapp.image->w,
  204.                                 gapp.image->h,
  205.                                 gapp.image->w * 4); */
  206.                         //f65(x0,y0,gapp.image->w,gapp.image->h,color);
  207.                         blit(6, 24, 588, 368, x0, y0,gapp.image->w, gapp.image->h, gapp.image->w * 4, color);
  208.                         free(color);
  209.                 }
  210.         }
  211.  
  212.  
  213.  __menuet__bar(0,0,598,34,0xe1e1e1); // bar on the top (buttons holder)
  214.  __menuet__bar(590,0,5,400,0xe1e1e1); // sidebar for scrolling
  215.  
  216.  __menuet__make_button(8,5,26,24,7,0xe1e1e1); //(posirion x, position y, width, height, id, color)
  217.  __menuet__putimage(8,5,26,24,folder.pixel_data);
  218.    
  219.  __menuet__make_button(42,5,26,24,6,0xe1e1e1); //magnify -
  220.  __menuet__putimage(42,5,26,24,minus.pixel_data);
  221.  
  222.  __menuet__make_button(68,5,26,24,5,0xe1e1e1); //magnify +
  223.  __menuet__putimage(68,5,26,24,plus.pixel_data);
  224.  
  225.  
  226. /* __menuet__make_button(100,0,20,20,10,0xe1e1e1); // rotate + 15 deg
  227.  __menuet__write_text(105,3,0xFFFFFF,"p",1);
  228.  
  229.  __menuet__make_button(120,0,20,20,11,0xe1e1e1); // rotate - 15 deg
  230.  __menuet__write_text(125,3,0xFFFFFF,"q",1); */
  231.  
  232.  __menuet__make_button(500,5,26,24,4,0xe1e1e1); //show help
  233.  __menuet__putimage(500,5,26,24,help.pixel_data);
  234.  
  235.  __menuet__make_button(534,5,24,24,2,0xe1e1e1); //prev page
  236.  __menuet__putimage(534,5,24,24,prev.pixel_data);
  237.  
  238.  __menuet__make_button(558,5,24,24,3,0xe1e1e1); //nex page
  239.  __menuet__putimage(558,5,24,24,next.pixel_data);
  240.  
  241.   __menuet__make_button(573,34,17,17,8,0xe1e1e1); // move up
  242.  __menuet__putimage(573,34,17,17,scrup.pixel_data);
  243.  
  244.  __menuet__make_button(573,363,17,17,9,0xe1e1e1); // move down
  245.  __menuet__putimage(573,363,17,17,scrdn.pixel_data);
  246.  
  247.  
  248. }
  249.  
  250. void paint(void)
  251. {
  252.  __menuet__window_redraw(1);
  253.  //__menuet__define_window(10,10,600,400,0x64CFCFCF,0x800000FF,Title);
  254.  __menuet__define_window(10,10,600,400,0x73CFCFCF,0x800000FF,Title);
  255.  __menuet__bar(0,0,600,400,0xFFFFFF);
  256.  winblit(&gapp);
  257.  __menuet__window_redraw(2);
  258.  }
  259.  
  260. void winrepaint(pdfapp_t *app)
  261. {
  262.         winblit(&gapp);
  263. }
  264.  
  265. void winrepaintsearch(pdfapp_t *app)
  266. {
  267.         paint();
  268.         //search!
  269. }
  270.  
  271.  
  272. int main (void)
  273. {
  274.        
  275.         char* original_command_line = *(char**)0x1C;
  276.         __menuet__debug_out(original_command_line);
  277.        
  278.         char buf[128];
  279.         int resolution = 72;
  280.                 int pageno = 1;
  281.                 __menuet__debug_out("\nStarted\n");
  282.                 fz_accelerate();
  283.                 __menuet__debug_out("PDF init\n");
  284.                 pdfapp_init(&gapp);
  285.         gapp.scrw = 600;
  286.         gapp.scrh = 400;
  287.         gapp.resolution = resolution;
  288.         gapp.pageno = pageno;
  289.         __menuet__debug_out("PDF Open\n");
  290.         pdfapp_open(&gapp, original_command_line, 0, 0);
  291.                 __menuet__debug_out("PDF Opened\n");
  292.        
  293.        
  294.  
  295.  int i;
  296.  int butt;
  297.  
  298.  __menuet__debug_out("Inital paint\n");
  299.    pdfapp_onresize(&gapp, 600, 400);
  300.  paint();
  301.  for(;;)
  302.  {
  303.  
  304.   i=__menuet__wait_for_event();
  305.   butt = __menuet__get_button_id();
  306.   if (gapp.image)
  307.                                 {
  308.                                        
  309.                                                 gapp.shrinkwrap = 0;
  310.                                 }
  311.   switch(i)
  312.   {
  313.    case 1:
  314.     paint();
  315.    
  316.     continue;
  317.    case 2:
  318.     buf[0]=__menuet__getkey();
  319.     pdfapp_onkey(&gapp, buf[0]);
  320.     continue;
  321.    case 3:
  322.     if(butt==1) __menuet__sys_exit();//browse file
  323.     if(butt==2) pdfapp_onkey(&gapp, '['); //previous page
  324.     if(butt==3) pdfapp_onkey(&gapp, ']'); __menuet__debug_out("\nStarted\n"); //next page
  325.     if(butt==4) pdfapp_onkey(&gapp, '?'); //show help window
  326.     if(butt==5) pdfapp_onkey(&gapp, '+'); //magnify +
  327.     if(butt==6) pdfapp_onkey(&gapp, '-'); //mag -
  328.     if(butt==7) ;//mag open file
  329.     if(butt==8) pdfapp_onkey(&gapp, 'j'); //move up
  330.     if(butt==9) pdfapp_onkey(&gapp, 'k'); //move down
  331.     if(butt==10) pdfapp_onkey(&gapp, 'a'); //rotate +15 deg
  332.     if(butt==11) pdfapp_onkey(&gapp, 's'); //rotate -15deg
  333.     continue;
  334.  
  335.   }
  336.  }
  337.  return 0;
  338. }
  339.  
  340.