00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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 }