f1a0172902fbe24bb5d381bb8b1a9a8cc187dd96
[ipdf/code.git] / src / main.h
1 #include "common.h"
2
3 #include "document.h"
4 #include "view.h"
5 #include "screen.h"
6 #include <unistd.h>
7
8
9 using namespace std;
10 using namespace IPDF;
11
12 inline void OverlayBMP(Document & doc, const char * input, const char * output, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f))
13 {
14         View view(doc, bounds, c);
15         Screen scr;
16         scr.RenderBMP(input);
17         view.Render();
18         sleep(1);
19         scr.ScreenShot(output);
20         scr.Present();
21         
22         sleep(1);
23 }
24
25 inline void MainLoop(Document & doc, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f))
26 {
27         View view(doc,bounds, c);
28         Screen scr;
29         scr.SetMouseHandler([&](int x, int y, int buttons, int wheel) // [?] wtf
30         {
31                 static bool oldButtonDown = false;
32                 static int oldx, oldy;
33                 if (buttons && !oldButtonDown)
34                 {
35                         // We're beginning a drag.
36                         oldButtonDown = true;
37                         oldx = x;
38                         oldy = y;
39                         scr.SetMouseCursor(Screen::CursorMove);
40                 }
41                 if (buttons)
42                 {
43                         view.Translate(Real(oldx-x)/Real(scr.ViewportWidth()), Real(oldy-y)/Real(scr.ViewportHeight()));
44                 }
45                 else
46                 {
47                         oldButtonDown = false;
48                         scr.SetMouseCursor(Screen::CursorArrow);
49                 }
50                 oldx = x;
51                 oldy = y;
52                 
53                 if (wheel)
54                 {
55                         view.ScaleAroundPoint(Real(x)/Real(scr.ViewportWidth()),Real(y)/Real(scr.ViewportHeight()), expf(-wheel/20.f));
56                 }
57         }
58         );
59
60         while (scr.PumpEvents())
61         {
62                 scr.Clear();
63                 view.Render();
64                 scr.Present();
65         }
66 }

UCC git Repository :: git.ucc.asn.au