2 * Copyright (c) 2014 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.
21 #include "radio-button-impl.h"
24 using namespace Dali::Toolkit::Internal;
30 const Property::Index RadioButton::PROPERTY_ACTIVE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 11;
31 const Property::Index RadioButton::PROPERTY_LABEL_ACTOR = Internal::Button::BUTTON_PROPERTY_END_INDEX + 12;
40 return Toolkit::RadioButton::New();
43 TypeRegistration typeRegistration(typeid (Toolkit::RadioButton ), typeid (Toolkit::Button ), Create);
45 PropertyRegistration property1(typeRegistration, "active", Toolkit::RadioButton::PROPERTY_ACTIVE, Property::BOOLEAN, &RadioButton::SetProperty, &RadioButton::GetProperty);
46 PropertyRegistration property2(typeRegistration, "label-actor", Toolkit::RadioButton::PROPERTY_LABEL_ACTOR, Property::MAP, &RadioButton::SetProperty, &RadioButton::GetProperty);
51 const char* const INACTIVE_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-inactive.png";
52 const char* const ACTIVE_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-active.png";
53 const Vector3 IMAGE_WIDTH(16.f, 0.f, 0.f);
54 const Vector3 DISTANCE_BETWEEN_IMAGE_AND_LABEL(5.f, 0.f, 0.f);
57 Dali::Toolkit::RadioButton RadioButton::New()
59 // Create the implementation, temporarily owned on stack
60 IntrusivePtr< RadioButton > internalRadioButton = new RadioButton();
62 // Pass ownership to CustomActor
63 Dali::Toolkit::RadioButton radioButton(*internalRadioButton);
65 // Second-phase init of the implementation
66 // This can only be done after the CustomActor connection has been made...
67 internalRadioButton->Initialize();
72 RadioButton::RadioButton()
76 mInactiveImage = Dali::Image::New(INACTIVE_BUTTON_IMAGE_DIR);
77 mActiveImage = Dali::Image::New(ACTIVE_BUTTON_IMAGE_DIR);
79 mImageActor = Dali::ImageActor::New(mInactiveImage);
80 mLabel = Actor::New();
83 RadioButton::~RadioButton()
87 void RadioButton::SetLabel(const std::string& label)
90 mLabel = Actor::New();
92 Toolkit::TextView textView = Toolkit::TextView::New(label);
93 textView.SetWidthExceedPolicy(Toolkit::TextView::ShrinkToFit); // Make sure our text always fits inside the button
94 textView.SetAnchorPoint(AnchorPoint::TOP_LEFT);
99 void RadioButton::SetLabel(Actor label)
101 if( mLabel != label )
103 Self().Remove(mLabel);
109 Actor RadioButton::GetLabel() const
114 void RadioButton::SetActive(bool active)
116 if( mActive != active )
120 Actor parent = Self().GetParent();
124 for( unsigned int i = 0; i < parent.GetChildCount(); ++i )
126 Dali::Toolkit::RadioButton rbChild = Dali::Toolkit::RadioButton::DownCast(parent.GetChildAt(i));
130 rbChild.SetActive(false);
135 mImageActor.SetImage(mActiveImage);
140 mImageActor.SetImage(mInactiveImage);
145 bool RadioButton::IsActive()const
150 void RadioButton::ToggleState()
155 void RadioButton::OnInitialize()
157 mImageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
158 Self().Add(mImageActor);
160 mLabel.SetAnchorPoint(AnchorPoint::TOP_LEFT);
161 mLabel.MoveBy(IMAGE_WIDTH + DISTANCE_BETWEEN_IMAGE_AND_LABEL);
165 void RadioButton::OnButtonUp()
170 void RadioButton::SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value)
172 Toolkit::RadioButton radioButton = Toolkit::RadioButton::DownCast(Dali::BaseHandle(object));
176 RadioButton & radioButtonImpl(GetImplementation(radioButton));
178 switch ( propertyIndex )
180 case Toolkit::RadioButton::PROPERTY_ACTIVE:
182 radioButtonImpl.SetActive(value.Get< bool >( ));
185 case Toolkit::RadioButton::PROPERTY_LABEL_ACTOR:
187 radioButtonImpl.SetLabel(Scripting::NewActor(value.Get< Property::Map >( )));
194 Property::Value RadioButton::GetProperty(BaseObject* object, Property::Index propertyIndex)
196 Property::Value value;
198 Toolkit::RadioButton radioButton = Toolkit::RadioButton::DownCast(Dali::BaseHandle(object));
202 RadioButton & radioButtonImpl(GetImplementation(radioButton));
204 switch ( propertyIndex )
206 case Toolkit::RadioButton::PROPERTY_ACTIVE:
208 value = radioButtonImpl.mActive;
211 case Toolkit::RadioButton::PROPERTY_LABEL_ACTOR:
214 Scripting::CreatePropertyMap(radioButtonImpl.mLabel, map);