dialog/drawer.h

Go to the documentation of this file.
00001 /*
00002  * drawer.h
00003  *
00004  * Copyright (C) 2009  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  */
00031 
00032 #ifndef WAVEPACKET_DIALOG_DRAWER_H__
00033 #define WAVEPACKET_DIALOG_DRAWER_H__
00034 
00035 // includes --------------------------------------------------------------------
00036 #include "geometry/geometry_2d.h"
00037 #include "threadsafe/smart_ptr.h"
00038 
00039 
00040 namespace dialog {
00041 
00042 /// \ingroup dialog
00043 /*@{*/
00044 
00045 
00046 typedef point2d_t<int> point_t;
00047 typedef rect2d_t<int> rect_t;
00048 
00049 
00050 /// sizing information about how a font is rendered
00051 struct font_size_t {
00052         font_size_t(void) throw() { this->clear(); }
00053         void clear(void) throw() {
00054                         width = height = 0;
00055                 }
00056 
00057         // data fields
00058         int             width;   ///< width of text in pixels
00059         int             height;  ///< height of text in pixels
00060 };
00061 
00062 
00063 
00064 struct border_size_t {
00065         border_size_t(void) throw() { this->clear(); }
00066         void clear(void) throw() {
00067                         size = 0;
00068                 }
00069 
00070         // data fields
00071         int             size;   ///< border in x/y directions
00072 };
00073 
00074 
00075 
00076 /// types of elements that appear in a dialog
00077 enum eElementType {
00078         eElement_Button         = 1,  ///< a simple text-only button
00079         eElement_Label          = 2,  ///< read-only text
00080         eElement_Textbox        = 3,  ///< a box for inputting text
00081 
00082         eElement_Container      = 50, ///< contains a group of elements
00083         eElement_Dialog         = 60, ///< a top-level dialog object
00084 
00085         // keep this last!
00086         eElement_Invalid        = 0
00087 };
00088 
00089 
00090 
00091 /// This is the object that is capable of rendering dialogs.
00092 /// This library (core dialog library) does NOT render dialogs!  That is up to
00093 ///     a client-supplied library.
00094 /// This is the interface that the client must support to render dialogs.
00095 class Drawer {
00096 public:
00097         // virtual constructor -------------------------------------------------
00098         virtual ~Drawer(void) throw();
00099 
00100         // dialog::Drawer class interface methods ------------------------------
00101 
00102         /// return the pixel size of the given string (based on whatever font
00103         ///     the Drawer wants to use for this sort of element)
00104         virtual font_size_t getFontSizing(IN eElementType type,
00105                                 IN const char * text) = 0;
00106 
00107         /// return the border size (in pixels) for the given element type
00108         virtual border_size_t getBorderSizing(IN eElementType type) = 0;
00109 
00110         /// draw a string (using whatever font the Drawer wants to use for
00111         ///     this element type) at the given position.
00112         virtual void drawString(IN eElementType type,
00113                                 IN const point_t& pos,
00114                                 IN const char * text) = 0;
00115 
00116         /// draw a rect with a border at the given position.  The rect interior
00117         ///     AND the border should neatly fit within the specified rectangle.
00118         virtual void drawRectWithBorder(IN eElementType type,
00119                                 IN const rect_t& rect) = 0;
00120 
00121         /// draw a circle at the specified position
00122         virtual void drawCircle(IN const point_t& pos,
00123                                 IN float radius) = 0;
00124 };
00125 
00126 
00127 
00128 /// for testing, we provide a text-only drawer
00129 class TextDrawer : public Drawer {
00130 public:
00131         // virtual destructor --------------------------------------------------
00132         virtual ~TextDrawer(void) throw();
00133 
00134         // dialog::TextDrawer class interface methods --------------------------
00135         virtual void writeToStream(IO std::ostream& stream) = 0;
00136 
00137         // static factory methods ----------------------------------------------
00138         static smart_ptr<TextDrawer> create(IN int borderSize);
00139 };
00140 
00141 
00142 
00143 };      // dialog namespace
00144 
00145 #endif  // WAVEPACKET_DIALOG_DRAWER_H__
00146