2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "image-channel-control-impl.h"
18 #include <dali-toolkit/dali-toolkit.h>
19 #include <dali/public-api/object/type-registry-helper.h>
20 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
22 using namespace Dali; // Needed for macros
32 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
33 varying mediump vec2 vTexCoord;\n
34 uniform sampler2D sTexture;\n
35 uniform mediump vec4 uColor;\n
36 uniform mediump vec3 uChannels;\n
40 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4(uChannels, 1.0) ;\n
44 Dali::BaseHandle Create()
46 return Demo::ImageChannelControl::New();
49 DALI_TYPE_REGISTRATION_BEGIN( ImageChannelControl, Dali::Toolkit::Control, Create );
51 DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "url", STRING, RESOURCE_URL );
52 DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "redChannel", FLOAT, RED_CHANNEL );
53 DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "greenChannel", FLOAT, GREEN_CHANNEL );
54 DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "blueChannel", FLOAT, BLUE_CHANNEL );
56 DALI_TYPE_REGISTRATION_END();
58 } // anonymous namespace
61 Internal::ImageChannelControl::ImageChannelControl()
62 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
63 mChannels( 1.0f, 1.0f, 1.0f )
67 Internal::ImageChannelControl::~ImageChannelControl()
71 Demo::ImageChannelControl Internal::ImageChannelControl::New()
73 IntrusivePtr<Internal::ImageChannelControl> impl = new Internal::ImageChannelControl();
74 Demo::ImageChannelControl handle = Demo::ImageChannelControl( *impl );
79 void ImageChannelControl::SetImage( const std::string& url )
85 Property::Map properties;
87 shader[Dali::Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = FRAGMENT_SHADER;
88 properties[Dali::Toolkit::Visual::Property::TYPE] = Dali::Toolkit::Visual::IMAGE;
89 properties[Dali::Toolkit::Visual::Property::SHADER]=shader;
90 properties[Dali::Toolkit::ImageVisual::Property::URL] = url;
92 Dali::Toolkit::InitializeVisual( self, mVisual, properties );
97 void ImageChannelControl::OnInitialize()
100 mChannelIndex = self.RegisterProperty( "uChannels", Vector3(1.0f, 1.0f, 1.0f) );
103 void ImageChannelControl::OnStageConnection( int depth )
105 Control::OnStageConnection( depth );
109 CustomActor self = Self();
110 mVisual.SetOnStage( self );
114 void ImageChannelControl::OnStageDisconnection()
118 CustomActor self = Self();
119 mVisual.SetOffStage( self );
122 Control::OnStageDisconnection();
125 void ImageChannelControl::OnSizeSet( const Vector3& targetSize )
127 Control::OnSizeSet( targetSize );
131 Vector2 size( targetSize );
132 mVisual.SetSize( size );
136 Vector3 ImageChannelControl::GetNaturalSize()
141 mVisual.GetNaturalSize(naturalSize);
142 return Vector3(naturalSize);
144 return Vector3::ZERO;
148 ///////////////////////////////////////////////////////////
153 void ImageChannelControl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
155 Demo::ImageChannelControl imageChannelControl = Demo::ImageChannelControl::DownCast( Dali::BaseHandle( object ) );
157 if ( imageChannelControl )
159 ImageChannelControl& impl = GetImpl( imageChannelControl );
160 Actor self = impl.Self();
163 case Demo::ImageChannelControl::Property::RED_CHANNEL:
165 impl.mChannels[0] = value.Get<float>();
166 self.SetProperty( impl.mChannelIndex, impl.mChannels );
169 case Demo::ImageChannelControl::Property::GREEN_CHANNEL:
171 impl.mChannels[1] = value.Get<float>();
172 self.SetProperty( impl.mChannelIndex, impl.mChannels );
175 case Demo::ImageChannelControl::Property::BLUE_CHANNEL:
177 impl.mChannels[2] = value.Get<float>();
178 self.SetProperty( impl.mChannelIndex, impl.mChannels );
185 Property::Value ImageChannelControl::GetProperty( BaseObject* object, Property::Index propertyIndex )
187 Property::Value value;
189 Demo::ImageChannelControl imageChannelControl = Demo::ImageChannelControl::DownCast( Dali::BaseHandle( object ) );
191 if ( imageChannelControl )
193 ImageChannelControl& impl = GetImpl( imageChannelControl );
194 switch ( propertyIndex )
196 case Demo::ImageChannelControl::Property::RED_CHANNEL:
198 value = impl.mChannels[0];
201 case Demo::ImageChannelControl::Property::GREEN_CHANNEL:
203 value = impl.mChannels[1];
206 case Demo::ImageChannelControl::Property::BLUE_CHANNEL:
208 value = impl.mChannels[2];