screen_rect.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "rve_render_client/screen_rect.h"
00031 #include "rve_render_client/texture.h"
00032 #include "rve_render_client/client_context.h"
00033 
00034 #include <rve_common/parse_resource_uri.h>
00035 
00036 #include <ros/assert.h>
00037 
00038 #include <rve_interfaces/ScreenRect.h>
00039 
00040 namespace rve_render_client
00041 {
00042 
00043 ScreenRect::ScreenRect(const rve_common::UUID& render_target_id, uint32_t zorder, float x0, float y0, float x1, float y1)
00044 : id_(rve_common::UUID::generate())
00045 , render_target_id_(render_target_id)
00046 , zorder_(zorder)
00047 , rect_(x0, y0, x1, y1)
00048 , context_(0)
00049 , proxy_handle_(NullHandle)
00050 , opacity_(1.0f)
00051 {}
00052 
00053 ScreenRect::~ScreenRect()
00054 {
00055 }
00056 
00057 rve_interfaces::ScreenRectProxy* ScreenRect::getProxy()
00058 {
00059   ROS_ASSERT(proxy_handle_ != NullHandle);
00060   ROS_ASSERT(context_);
00061   return context_->getInterface<rve_interfaces::ScreenRectProxy>(proxy_handle_);
00062 }
00063 
00064 void ScreenRect::create(ClientContext* context)
00065 {
00066   ROS_ASSERT(!context_);
00067   context_ = context;
00068   proxy_handle_ = context->lookupInterface("screen_rect");
00069 
00070   rve_interfaces::ScreenRectProxy* proxy = getProxy();
00071   proxy->createAsync(render_target_id_, getID(), zorder_, rect_.x0, rect_.y0, rect_.x1, rect_.y1);
00072   proxy->setOpacityAsync(render_target_id_, getID(), opacity_);
00073   if (texture_)
00074   {
00075     proxy->setTextureAsync(render_target_id_, getID(), texture_->getID());
00076   }
00077   else if (!texture_resource_.empty())
00078   {
00079     proxy->setTextureByResourceAsync(render_target_id_, getID(), texture_resource_);
00080   }
00081   else
00082   {
00083     proxy->setColorAsync(render_target_id_, getID(), color_);
00084   }
00085 }
00086 
00087 void ScreenRect::destroy(ClientContext* context)
00088 {
00089   ROS_ASSERT(context_);
00090 
00091   rve_interfaces::ScreenRectProxy* proxy = getProxy();
00092   proxy->destroyAsync(render_target_id_, id_);
00093 
00094   context_ = 0;
00095   proxy_handle_ = NullHandle;
00096 }
00097 
00098 void ScreenRect::setCorners(float x0, float y0, float x1, float y1)
00099 {
00100   rect_ = Rect(x0, y0, x1, y1);
00101   rve_interfaces::ScreenRectProxy* proxy = getProxy();
00102   if (proxy)
00103   {
00104     proxy->setCorners(render_target_id_, getID(), x0, y0, x1, y1);
00105   }
00106 }
00107 
00108 void ScreenRect::setZOrder(uint32_t zorder)
00109 {
00110   zorder_ = zorder;
00111   rve_interfaces::ScreenRectProxy* proxy = getProxy();
00112   if (proxy)
00113   {
00114     proxy->setZOrderAsync(render_target_id_, getID(), zorder);
00115   }
00116 }
00117 
00118 void ScreenRect::setOpacity(float opacity)
00119 {
00120   opacity_ = opacity;
00121   rve_interfaces::ScreenRectProxy* proxy = getProxy();
00122   if (proxy)
00123   {
00124     proxy->setOpacityAsync(render_target_id_, getID(), opacity_);
00125   }
00126 }
00127 
00128 void ScreenRect::setColor(Color c)
00129 {
00130   color_ = c;
00131   opacity_ = c.a;
00132   texture_.reset();
00133   texture_resource_.clear();
00134 
00135   rve_interfaces::ScreenRectProxy* proxy = getProxy();
00136   if (proxy)
00137   {
00138     proxy->setColorAsync(render_target_id_, getID(), color_);
00139     proxy->setOpacityAsync(render_target_id_, getID(), opacity_);
00140   }
00141 }
00142 
00143 void ScreenRect::setTexture(const TexturePtr& tex)
00144 {
00145   texture_ = tex;
00146   texture_resource_.clear();
00147   rve_interfaces::ScreenRectProxy* proxy = getProxy();
00148   if (proxy)
00149   {
00150     proxy->setTextureAsync(render_target_id_, getID(), texture_->getID());
00151   }
00152 }
00153 
00154 void ScreenRect::setTexture(const std::string& resource_path)
00155 {
00156   rve_common::ResourceURI uri;
00157   rve_common::parseResourceURI(resource_path, uri);
00158 
00159   rve_interfaces::ScreenRectProxy* proxy = getProxy();
00160 
00161   if (uri.scheme == "texture" || uri.scheme == "rtt")
00162   {
00163     texture_resource_ = resource_path;
00164     if (proxy)
00165     {
00166       proxy->setTextureByResourceAsync(render_target_id_, getID(), texture_resource_);
00167     }
00168   }
00169   else
00170   {
00171     setTexture(loadTexture(resource_path));
00172   }
00173 }
00174 
00175 }


rve_render_client
Author(s): Josh Faust
autogenerated on Wed Dec 11 2013 14:31:32