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                         lead = trail = drop = rise = 0;
00055                 }
00056 
00057         // data fields
00058         int             lead;   ///< pixels to left of draw origin
00059         int             trail;  ///< pixels to right of draw origin
00060         int             drop;   ///< pixels below draw origin
00061         int             rise;   ///< pixels above draw origin
00062 };
00063 
00064 
00065 
00066 struct border_size_t {
00067         border_size_t(void) throw() { this->clear(); }
00068         void clear(void) throw() {
00069                         size = 0;
00070                 }
00071 
00072         // data fields
00073         int             size;   ///< border in x/y directions
00074 };
00075 
00076 
00077 
00078 /// types of elements that appear in a dialog
00079 enum eElementType {
00080         eElement_Button         = 1,  ///< a simple text-only button
00081         eElement_Label          = 2,  ///< read-only text
00082         eElement_Textbox        = 3,  ///< a box for inputting text
00083 
00084         eElement_Container      = 50, ///< contains a group of elements
00085         eElement_Dialog         = 60, ///< a top-level dialog object
00086 
00087         // keep this last!
00088         eElement_Invalid        = 0
00089 };
00090 
00091 
00092 
00093 /// This is the object that is capable of rendering dialogs.
00094 /// This library (core dialog library) does NOT render dialogs!  That is up to
00095 ///     a client-supplied library.
00096 /// This is the interface that the client must support to render dialogs.
00097 class Drawer {
00098 public:
00099         // virtual constructor -------------------------------------------------
00100         virtual ~Drawer(void) throw();
00101 
00102         // dialog::Drawer class interface methods ------------------------------
00103 
00104         /// return the pixel size of the given string (based on whatever font
00105         ///     the Drawer wants to use for this sort of element)
00106         virtual font_size_t getFontSizing(IN eElementType type,
00107                                 IN const char * text) = 0;
00108 
00109         /// return the border size (in pixels) for the given element type
00110         virtual border_size_t getBorderSizing(IN eElementType type) = 0;
00111 
00112         /// draw a string (using whatever font the Drawer wants to use for
00113         ///     this element type) at the given position.
00114         virtual void drawString(IN eElementType type,
00115                                 IN const point_t& pos,
00116                                 IN const char * text) = 0;
00117 
00118         /// draw a rect with a border at the given position.  The rect interior
00119         ///     AND the border should neatly fit within the specified rectangle.
00120         virtual void drawRectWithBorder(IN eElementType type,
00121                                 IN const rect_t& rect) = 0;
00122 
00123         /// draw a circle at the specified position
00124         virtual void drawCircle(IN const point_t& pos,
00125                                 IN float radius) = 0;
00126 };
00127 
00128 
00129 
00130 /// for testing, we provide a text-only drawer
00131 class TextDrawer : public Drawer {
00132 public:
00133         // virtual destructor --------------------------------------------------
00134         virtual ~TextDrawer(void) throw();
00135 
00136         // dialog::TextDrawer class interface methods --------------------------
00137         virtual void writeToStream(IO std::ostream& stream) = 0;
00138 
00139         // static factory methods ----------------------------------------------
00140         static smart_ptr<TextDrawer> create(IN int borderSize);
00141 };
00142 
00143 
00144 
00145 };      // dialog namespace
00146 
00147 #endif  // WAVEPACKET_DIALOG_DRAWER_H__
00148