]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/scout/lib/src/main.cc
fd9feae12292e8799661e7981f4c9f86a8e11644
[l4.git] / l4 / pkg / scout / lib / src / main.cc
1 /*
2  * \brief   Scout tutorial browser main program
3  * \date    2005-10-24
4  * \author  Norman Feske <norman.feske@genode-labs.com>
5  */
6
7 /*
8  * Copyright (C) 2005-2009
9  * Genode Labs, Feske & Helmuth Systementwicklung GbR
10  *
11  * This file is part of the Genode OS framework, which is distributed
12  * under the terms of the GNU General Public License version 2.
13  */
14
15 /**
16  * Local includes
17  */
18 #include "config.h"
19 #include "factory.h"
20 #include "platform.h"
21 #include <l4/cxx/exceptions>
22 #include <l4/cxx/iostream>
23
24 #include <l4/scout-gfx/tick>
25 #include <l4/scout-gfx/redraw_manager>
26 #include <l4/scout-gfx/user_state>
27 #include <l4/scout-gfx/factory>
28 #include <l4/scout-gfx/redraw_manager>
29
30 #include "browser_window.h"
31
32 using Scout_gfx::Document;
33
34 extern Document *create_document(Scout_gfx::Factory *f);
35
36
37 /**
38  * Runtime configuration
39  */
40 namespace Config
41 {
42         int iconbar_detail    = 1;
43         int background_detail = 1;
44         int mouse_cursor      = 0;
45         int browser_attr      = 0;
46 }
47
48
49 #define POINTER_RGBA  _binary_pointer_rgba_start
50
51 extern unsigned char POINTER_RGBA[];
52
53 enum
54 {
55   Browser_width  = 540,
56   Browser_height = 660,
57 };
58
59 /**
60  * Main program
61  */
62 int main() //int argc, char **argv)
63 {
64 try {
65   /* init platform */
66   Platform *pf = Platform::get(Rect(Point(0,0), Area(Browser_width, Browser_height)));
67
68   ::Factory *f = dynamic_cast< ::Factory* >(::Factory::set.find(*pf->pixel_info()));
69
70   Document *doc = create_document(f);
71
72   Scout_gfx::View *view = pf->create_view(Rect(Point(0,0), Area(Browser_width, Browser_height)));
73   /* create instance of browser window */
74   Scout_gfx::Window *browser = 
75     new Browser_window(f, 
76         doc,    /* initial document       */
77         view,   /* platform               */
78         view->geometry().area(),  /* max size of window     */
79         Config::browser_attr
80         );
81
82   /* initialize mouse cursor */
83 #if 0
84   int mx = 0, my = 0;
85   static Icon<Pixel_rgb565, 32, 32> mcursor;
86   if (Config::mouse_cursor) {
87       mcursor.geometry(mx, my, 32, 32);
88       mcursor.rgba(POINTER_RGBA);
89       mcursor.alpha(255);
90       mcursor.findable(0);
91       browser.append(&mcursor);
92   }
93 #endif
94   /* create user state manager */
95
96   /* assign browser as root element to redraw manager */
97   pf->root()->append(browser);
98   browser->set_geometry(view->geometry());
99   //browser->scroll_pos(Point(0, 0));
100   browser->refresh();
101   pf->process_redraws();
102
103   using Scout_gfx::Event;
104
105   browser->top();
106   /* enter main loop */
107   Event ev;
108   unsigned long curr_time, old_time;
109   curr_time = old_time = pf->timer_ticks();
110   do {
111       pf->get_event(&ev);
112
113       if (ev.type != Event::WHEEL) {
114 #if 0
115           /* update mouse cursor */
116           if (Config::mouse_cursor && (ev.mx != mx || ev.my != my)) {
117               int x1 = min(ev.mx, mx);
118               int y1 = min(ev.my, my);
119               int x2 = max(ev.mx + mcursor.w() - 1, mx + mcursor.w() - 1);
120               int y2 = max(ev.my + mcursor.h() - 1, my + mcursor.h() - 1);
121
122               mcursor.geometry(ev.mx, ev.my, mcursor.w(), mcursor.h());
123               redraw.request(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
124
125               mx = ev.mx; my = ev.my;
126           }
127 #endif
128       }
129
130       pf->root()->handle_event(ev);
131 #if 0
132       if (ev.type == Event::REFRESH)
133         pf->scr_update(Rect(Point(0, 0), pf->scr_size()));
134 #endif
135
136       if (ev.type == Event::TIMER)
137         Scout_gfx::Tick::handle(pf->timer_ticks());
138
139       /* perform periodic redraw */
140       curr_time = pf->timer_ticks();
141       if (!pf->event_pending() && ((curr_time - old_time > 20) || (curr_time < old_time))) {
142           old_time = curr_time;
143           pf->process_redraws();
144       }
145
146   } while (ev.type != Event::QUIT);
147
148   return 0;
149 } catch (L4::Runtime_error const &e) {
150     L4::cerr << "Fatal exception: " << e.str() << " '" << e.extra_str()
151              << "'\n" << e;
152 }
153 return 1;
154 }