9fcc26be1a1abac8c8d1724159dd9f4e680fdcaa
[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         scr.Present();
19         sleep(5);
20         scr.ScreenShot(output);
21 }
22
23 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))
24 {
25         View view(doc,bounds, c);
26         Screen scr;
27         scr.SetMouseHandler([&](int x, int y, int buttons, int wheel) // [?] wtf
28         {
29                 static bool oldButtonDown = false;
30                 static int oldx, oldy;
31                 if (buttons && !oldButtonDown)
32                 {
33                         // We're beginning a drag.
34                         oldButtonDown = true;
35                         oldx = x;
36                         oldy = y;
37                         scr.SetMouseCursor(Screen::CursorMove);
38                 }
39                 if (buttons)
40                 {
41                         view.Translate(Real(oldx-x)/Real(scr.ViewportWidth()), Real(oldy-y)/Real(scr.ViewportHeight()));
42                 }
43                 else
44                 {
45                         oldButtonDown = false;
46                         scr.SetMouseCursor(Screen::CursorArrow);
47                 }
48                 oldx = x;
49                 oldy = y;
50                 
51                 if (wheel)
52                 {
53                         view.ScaleAroundPoint(Real(x)/Real(scr.ViewportWidth()),Real(y)/Real(scr.ViewportHeight()), expf(-wheel/20.f));
54                 }
55         }
56         );
57
58         while (scr.PumpEvents())
59         {
60                 scr.Clear();
61                 view.Render();
62                 scr.Present();
63         }
64 }

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