00001 /* 00002 * layout_2d.h 00003 * 00004 * Copyright (C) 2007 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 #ifndef WAVEPACKET_LAYOUT_2D_H__ 00032 #define WAVEPACKET_LAYOUT_2D_H__ 00033 00034 // includes -------------------------------------------------------------------- 00035 #include "common/common.h" 00036 00037 00038 /// \ingroup geometric 00039 /*@{*/ 00040 00041 //////////////////////////////////////////////////////////////////////////////// 00042 /// 00043 /// \defgroup layout Layout API 00044 /// 00045 /// This is an extremely primitive API for performing basic object layout. I 00046 /// only have 2D layouts for now and have no plans for higher dimensions :) 00047 /// 00048 /// This isn't much code but felt better abstracted to a general library 00049 /// rather than put in the application. 00050 /// 00051 //////////////////////////////////////////////////////////////////////////////// 00052 00053 /*@{*/ 00054 00055 00056 namespace layout { 00057 00058 enum eLayoutType { 00059 eLayout_Horizontal = 1, 00060 eLayout_Vertical = 2, 00061 00062 eLayout_Invalid = 0 00063 }; 00064 00065 struct layout_info_t { 00066 // constructor, manipulators 00067 layout_info_t(void) throw() { this->clear(); } 00068 void clear(void) throw() { 00069 type = eLayout_Invalid; 00070 spacing = 0.0; 00071 } 00072 00073 // data fields 00074 eLayoutType type; // what sort of layout? 00075 float spacing;// spacing between objects 00076 }; 00077 00078 00079 struct object_t { 00080 // constructor, manipulators 00081 object_t(void) throw() { this->clear(); } 00082 void clear(void) throw() { 00083 id = ""; 00084 width = height = x = y = 0.0; 00085 } 00086 00087 // data fields 00088 std::string id; // opaque ID for client 00089 float width; 00090 float height; 00091 float x; 00092 float y; 00093 }; 00094 00095 typedef std::vector<object_t> vec_obj_t; // order matters! 00096 00097 00098 //////////////////////////////////////////////////////////////////////////////// 00099 // 00100 // API 00101 // 00102 //////////////////////////////////////////////////////////////////////////////// 00103 00104 /// the only function in the 2D layout library! 00105 /// 00106 /// Given the layout instructions (layout_info_t object), and the list 00107 /// of objects to be laid out (vec_obj_t vector), this routine calculates 00108 /// the proper position for each object. 00109 /// - On input, each object_t in the vector must have id, width and height set. 00110 /// - On output, each object_t will be provided with x/y coordinates. 00111 void performLayout(IN const layout_info_t& info, 00112 IO vec_obj_t& objects); 00113 00114 00115 }; // layout namespace 00116 00117 #endif // WAVEPACKET_LAYOUT_2D_H__ 00118