stlab.adobe.com Adobe Systems Incorporated

button_helper.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /****************************************************************************************************/
00008 
00009 #ifndef ADOBE_BUTTON_HELPER_HPP
00010 #define ADOBE_BUTTON_HELPER_HPP
00011 
00012 /****************************************************************************************************/
00013 
00014 #include <adobe/config.hpp>
00015 
00016 #include <adobe/any_regular.hpp>
00017 #include <adobe/dictionary.hpp>
00018 #include <adobe/widget_attributes.hpp>
00019 
00020 #include <boost/function.hpp>
00021 #include <boost/gil/gil_all.hpp>
00022 #include <boost/range/begin.hpp>
00023 #include <boost/range/end.hpp>
00024 
00025 #include <vector>
00026 #include <string>
00027 
00046 /****************************************************************************************************/
00047 
00048 namespace adobe {
00049 
00050 /****************************************************************************************************/
00051 
00060 typedef boost::function<void (const any_regular_t&, const dictionary_t&)> button_hit_proc_t;
00061 
00062 /****************************************************************************************************/
00063 
00079 struct button_state_descriptor_t
00080 {
00084     button_state_descriptor_t() : 
00085         modifier_set_m(modifiers_none_s)
00086     { }
00087 
00089     std::string name_m;
00090 
00092     std::string alt_text_m;
00093 
00095     modifiers_t modifier_set_m;
00096 
00098     button_hit_proc_t hit_proc_m;
00099 
00101     any_regular_t value_m;
00102 
00104     dictionary_t contributing_m;
00105 
00106     button_state_descriptor_t& operator=(const button_state_descriptor_t& x) 
00107     { /*REVISIT MOVE*/ 
00108         name_m = x.name_m; 
00109         alt_text_m = x.alt_text_m; 
00110         modifier_set_m = x.modifier_set_m; 
00111         hit_proc_m = x.hit_proc_m; 
00112         value_m = x.value_m; 
00113         contributing_m = x.contributing_m; 
00114         return *this;
00115     }
00116 
00117 };
00118 
00119 /****************************************************************************************************/
00120 
00127 typedef std::vector<button_state_descriptor_t> button_state_set_t;
00128 
00129 /****************************************************************************************************/
00130 
00134 struct image_button_state_descriptor_t
00135 {
00136     typedef boost::gil::rgba8_image_t image_type;
00137 
00141     image_button_state_descriptor_t() : 
00142         modifier_set_m(modifiers_none_s)
00143     { }
00144 
00146     image_type image_m;
00147 
00149     image_type disabled_image_m;
00150 
00152     image_type hover_image_m;
00153 
00155     image_type cursor_image_m;
00156 
00158     std::string alt_text_m;
00159 
00161     modifiers_t modifier_set_m;
00162 
00164     button_hit_proc_t hit_proc_m;
00165 
00167     any_regular_t value_m;
00168 
00170     dictionary_t contributing_m;
00171 };
00172 
00173 /****************************************************************************************************/
00174 
00181 typedef std::vector<image_button_state_descriptor_t> image_button_state_set_t;
00182 
00183 /****************************************************************************************************/
00184 
00195 template <typename ButtonStateRange>
00196 typename boost::range_iterator<ButtonStateRange>::type
00197 button_modifier_state(ButtonStateRange& range,
00198                       modifiers_t       modifier_mask,
00199                       modifiers_t       modifiers)
00200 {
00201     typedef typename boost::range_iterator<ButtonStateRange>::type iterator;
00202 
00203     modifiers &= modifier_mask;
00204 
00205     iterator first(boost::begin(range));
00206     iterator last(boost::end(range));
00207 
00208     for (; first != last; ++first)
00209         if ((first->modifier_set_m & modifiers) == modifiers)
00210             break;
00211 
00212     return first;
00213 }
00214 
00224 template <typename ButtonStateRange>
00225 typename boost::range_iterator<ButtonStateRange>::type
00226 button_default_state(ButtonStateRange& range)
00227 {
00228     typename boost::range_iterator<ButtonStateRange>::type
00229         result(button_modifier_state(range, modifiers_none_s, modifiers_none_s));
00230 
00231     if (result == boost::end(range))
00232         throw std::runtime_error("No default state specified for button");
00233 
00234     return result;
00235 }
00236 
00246 modifiers_t name_to_modifer(name_t name);
00247 
00256 modifiers_t value_to_modifier(const any_regular_t& modifier_set);
00257 
00258 /*************************************************************************************************/
00259 
00275 template <typename Control, typename UserData>
00276 struct display_compositor_t
00277 {
00279     typedef any_regular_t model_type;
00280 
00285     display_compositor_t(Control& control, UserData user_data) :
00286         control_m(control), user_data_m(user_data)
00287     { }
00288 
00292     void display(const any_regular_t& to_value)
00293     {
00294         control_m.set(user_data_m, to_value);
00295     }
00296 
00297 #ifndef ADOBE_NO_DOCUMENTATION
00298     friend bool operator==(const display_compositor_t& lhs, const display_compositor_t& rhs)
00299     {
00300         return lhs.control_m == rhs.control_m && lhs.user_data_m == rhs.user_data_m;
00301     }
00302 
00303     Control& control_m;
00304     UserData user_data_m;
00305 #endif
00306 };
00307 
00308 /*************************************************************************************************/
00309 
00318 template <typename Control, typename UserData>
00319 display_compositor_t<Control, UserData>* make_display_compositor(Control& control, UserData index)
00320 {
00321     return new display_compositor_t<Control, UserData>(control, index);
00322 }
00323 
00324 /****************************************************************************************************/
00325 
00326 } // namespace adobe
00327 
00328 /****************************************************************************************************/
00329 
00330 #endif
00331 
00332 /****************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google