1 //------------------------------------------------------------------------
2 //  Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net>
3 //
4 //  This file is part of the ZBar Bar Code Reader.
5 //
6 //  The ZBar Bar Code Reader is free software; you can redistribute it
7 //  and/or modify it under the terms of the GNU Lesser Public License as
8 //  published by the Free Software Foundation; either version 2.1 of
9 //  the License, or (at your option) any later version.
10 //
11 //  The ZBar Bar Code Reader is distributed in the hope that it will be
12 //  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 //  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU Lesser Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser Public License
17 //  along with the ZBar Bar Code Reader; if not, write to the Free
18 //  Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 //  Boston, MA  02110-1301  USA
20 //
21 //  http://sourceforge.net/projects/zbar
22 //------------------------------------------------------------------------
23 #ifndef _ZBAR_WINDOW_H_
24 #define _ZBAR_WINDOW_H_
25 
26 /// @file
27 /// Output Window C++ wrapper
28 
29 #ifndef _ZBAR_H_
30 # error "include zbar.h in your application, **not** zbar/Window.h"
31 #endif
32 
33 #include "Image.h"
34 
35 namespace zbar {
36 
37 /// mid-level output window abstraction.
38 /// displays images to user-specified platform specific output window
39 
40 class Window {
41 public:
42     /// constructor.
43     Window (zbar_window_t *window = NULL)
44     {
45         if(window)
46             _window = window;
47         else
48             _window = zbar_window_create();
49     }
50 
51     /// constructor.
Window(void * x11_display_w32_hwnd,unsigned long x11_drawable)52     Window (void *x11_display_w32_hwnd,
53             unsigned long x11_drawable)
54     {
55         _window = zbar_window_create();
56         attach(x11_display_w32_hwnd, x11_drawable);
57     }
58 
~Window()59     ~Window ()
60     {
61         zbar_window_destroy(_window);
62     }
63 
64     /// cast to C window object.
65     operator zbar_window_t* () const
66     {
67         return(_window);
68     }
69 
70     /// associate reader with an existing platform window.
71     /// see zbar_window_attach()
72     void attach (void *x11_display_w32_hwnd,
73                  unsigned long x11_drawable = 0)
74     {
75         if(zbar_window_attach(_window,
76                                x11_display_w32_hwnd, x11_drawable) < 0)
77             throw_exception(_window);
78     }
79 
80     /// control content level of the reader overlay.
81     /// see zbar_window_set_overlay()
set_overlay(int level)82     void set_overlay (int level)
83     {
84         zbar_window_set_overlay(_window, level);
85     }
86 
87     /// retrieve current content level of reader overlay.
88     /// see zbar_window_get_overlay()
89 
90     /// draw a new image into the output window.
91     /// see zbar_window_draw()
draw(Image & image)92     void draw (Image& image)
93     {
94         if(zbar_window_draw(_window, image) < 0)
95             throw_exception(_window);
96     }
97 
98     /// clear the image from the output window.
99     /// see zbar_window_draw()
clear()100     void clear ()
101     {
102         if(zbar_window_draw(_window, NULL) < 0)
103             throw_exception(_window);
104     }
105 
106     /// redraw the last image.
107     /// zbar_window_redraw()
redraw()108     void redraw ()
109     {
110         if(zbar_window_redraw(_window) < 0)
111             throw_exception(_window);
112     }
113 
114     /// resize the image window.
115     /// zbar_window_resize()
resize(unsigned width,unsigned height)116     void resize (unsigned width, unsigned height)
117     {
118         if(zbar_window_resize(_window, width, height) < 0)
119             throw_exception(_window);
120     }
121 
122 private:
123     zbar_window_t *_window;
124 };
125 
126 /// select a compatible format between video input and output window.
127 /// see zbar_negotiate_format()
negotiate_format(Video & video,Window & window)128 static inline void negotiate_format (Video& video, Window& window)
129 {
130     if(zbar_negotiate_format(video, window) < 0)
131         throw_exception(video);
132 }
133 
134 }
135 
136 #endif
137