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

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