image.Add( stencil );
}
- TextView text = TextView::New( title );
- text.SetAnchorPoint( AnchorPoint::CENTER );
- text.SetParentOrigin( ParentOrigin::CENTER );
- text.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit );
- text.SetMultilinePolicy( Toolkit::TextView::SplitByWord );
- text.SetLineJustification( Toolkit::TextView::Center );
- text.SetTextAlignment( Toolkit::Alignment::Type( Alignment::HorizontalCenter | Alignment::VerticalCenter ) );
- text.SetColor( Color::WHITE );
- text.SetZ( 1 );
- // make the text 90% of tile
- text.SetSize( 0.9f * parentSize.width, 0.9f * parentSize.height );
- text.SetStyleToCurrentText( GetTableTextStyle() );
- text.SetSnapshotModeEnabled( false );
- tile.Add( text );
+ TextLabel label = TextLabel::New();
+ label.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ label.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- label.SetProperty( TextLabel::PROPERTY_MULTI_LINE, true );
- label.SetProperty( TextLabel::PROPERTY_TEXT, title );
++ label.SetProperty( TextLabel::Property::MULTI_LINE, true );
++ label.SetProperty( TextLabel::Property::TEXT, title );
+ label.SetColor( Color::BLACK );
+ tile.Add( label );
+
+ // FIXME - This is a kludge because size negotiation is not finished
+ label.SetSize( parentSize );
// Set the tile to be keyboard focusable
tile.SetKeyboardFocusable(true);
// Nothing to do here.
}
- /**
- * One-time setup in response to Application InitSignal.
- */
- void Create( Application& application )
+ /*
+ * Create a control composed of a label and an slider
+ * @param[in] label The text to be displayed ny the label
+ * @param[in] size The size of the slider
+ * @param[in] callback Pointer to the callback function to be called when user moves the slider
+ */
+ Actor CreateVectorComponentControl( const std::string& label, const Vector3& size, bool(PathController::*callback)(Slider,float) )
{
- // Get a handle to the stage:
- Stage stage = Stage::GetCurrent();
-
- // Connect to input event signals:
- stage.KeyEventSignal().Connect(this, &PathController::OnKeyEvent);
-
- // Create a default view with a default tool bar:
- Toolkit::View view; ///< The View instance.
- Toolkit::ToolBar toolBar; ///< The View's Toolbar.
- mContentLayer = DemoHelper::CreateView( mApplication,
- view,
- toolBar,
- BACKGROUND_IMAGE,
- TOOLBAR_IMAGE,
- "" );
-
- mContentLayer.TouchedSignal().Connect(this, &PathController::OnTouchLayer);
- Dali::TextActor textActor = TextActor::New(label);
- textActor.SetColor( Vector4(0.0f,0.0f,0.0f,1.0f));
- textActor.SetSize(size.y,size.y,0.0f);
--
- //Path
- mPath = Dali::Path::New();
- mPath.AddPoint( Vector3( 10.0f, stage.GetSize().y*0.5f, 0.0f ));
- mPath.AddPoint( Vector3( stage.GetSize().x*0.5f, stage.GetSize().y*0.3f, 0.0f ));
- mPath.GenerateControlPoints(0.25f);
- DrawPath( 200u );
- Slider slider = Slider::New();
- slider.SetAnchorPoint( AnchorPoint::CENTER_LEFT);
- slider.SetParentOrigin( ParentOrigin::CENTER_RIGHT);
- slider.SetProperty(Slider::Property::LOWER_BOUND, -1.0f );
- slider.SetProperty(Slider::Property::UPPER_BOUND, 1.0f );
--
- //Actor
- ImageAttributes attributes;
- Image img = ResourceImage::New(ACTOR_IMAGE, attributes );
- mActor = ImageActor::New( img );
- mActor.SetPosition( Vector3( 10.0f, stage.GetSize().y*0.5f, 0.0f ) );
- mActor.SetAnchorPoint( AnchorPoint::CENTER );
- mActor.SetSize( 100, 50, 1 );
- stage.Add( mActor );
- Property::Array marks;
- float mark = -1.0f;
- for(unsigned short i(0); i<21; ++i )
- {
- marks.push_back( mark );
- mark += 0.1f;
- }
--
- mForward = Vector3::XAXIS;
- CreateAnimation();
- slider.SetProperty(Slider::Property::MARKS, marks);
- slider.SetProperty(Slider::Property::SNAP_TO_MARKS, true );
- slider.SetSize(size);
- slider.SetScale( 0.5f );
- slider.ValueChangedSignal().Connect(this,callback);
- textActor.Add( slider );
- return textActor;
++ return Actor(); // TODO
}
/**
DrawPath( 200u );
CreateAnimation();
}
- else
- {
- if( mDragActor )
- {
- const TouchPoint& point = event.GetPoint(0);
- Vector3 newPosition = Vector3(point.screen.x, point.screen.y, 0.0f);
+ }
- std::string actorName(mDragActor.GetName());
+ return true;
+ }
- if( actorName.compare(0, 4, "Knot") == 0)
- {
- int index = actorName[4];
- mPath.GetPoint(index) = newPosition;
- }
- else
- {
- int index = actorName[12];
- mPath.GetControlPoint(index) = newPosition;
- }
+ bool OnTouchGuiLayer(Actor actor, const TouchEvent& event)
+ {
+ mDragActor.Reset();
+ return false;
+ }
+ /**
+ * Callback called when user changes slider X
+ * @param[in] slider The slider that has generated the signal
+ * @param[in] value The new value
+ */
+ bool OnSliderXValueChange( Slider s, float value)
+ {
+ if( fabs( value ) - Math::MACHINE_EPSILON_1000 < 0.0f )
+ {
+ mForward.x = 0.0f;
+ }
+ else
+ {
+ mForward.x = value;
+ }
- DrawPath( 200u );
- CreateAnimation();
- }
- }
+ CreateAnimation();
+ return true;
+ }
+
- /**
- * Callback called when user changes slider Y
- * @param[in] slider The slider that has generated the signal
- * @param[in] value The new value
- */
+ bool OnSliderYValueChange( Slider s, float value)
+ {
+ if( fabs( value ) - Math::MACHINE_EPSILON_1000 < 0.0f )
+ {
+ mForward.y = 0.0f;
}
- return false;
+ else
+ {
+ mForward.y = value;
+ }
+ CreateAnimation();
+ return true;
}
- /**
- * Main key event handler.
- * Quit on escape key.
- */
+ /**
- * Callback called when user changes slider Z
- * @param[in] slider The slider that has generated the signal
- * @param[in] value The new value
++ * Create the path animation.
+ */
+ bool OnSliderZValueChange( Slider s, float value)
+ {
+ if( fabs( value ) - Math::MACHINE_EPSILON_1000 < 0.0f )
+ {
+ mForward.z = 0.0f;
+ }
+ else
+ {
+ mForward.z = value;
+ }
+
+ CreateAnimation();
+ return true;
+ }
+
+ /**
+ * Main key event handler.
+ * Quit on escape key.
+ */
void OnKeyEvent(const KeyEvent& event)
{
if( event.state == KeyEvent::Down )
}
/**
- * Create the path animation.
+ * One-time setup in response to Application InitSignal.
*/
- void CreateAnimation()
+ void Create( Application& application )
{
- if( !mAnimation )
- {
- mAnimation = Animation::New( 2.0f );
- }
- else
- {
- mAnimation.Pause();
- mAnimation.Clear();
- mActor.SetRotation( Quaternion() );
- }
+ // Get a handle to the stage:
+ Stage stage = Stage::GetCurrent();
- mAnimation.Animate( mActor, mPath, mForward );
- mAnimation.SetLooping( true );
- mAnimation.Play();
+ // Connect to input event signals:
+ stage.KeyEventSignal().Connect(this, &PathController::OnKeyEvent);
+
+ // Create a default view with a default tool bar:
+ Toolkit::View view; ///< The View instance.
+ Toolkit::ToolBar toolBar; ///< The View's Toolbar.
+ mContentLayer = DemoHelper::CreateView( mApplication,
+ view,
+ toolBar,
+ BACKGROUND_IMAGE,
+ TOOLBAR_IMAGE,
+ "" );
+
+ mContentLayer.TouchedSignal().Connect(this, &PathController::OnTouchLayer);
+
- //Title
- TextView title = TextView::New();
- toolBar.AddControl( title, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
- Font font = Font::New();
- title.SetText( APPLICATION_TITLE );
- title.SetSize( font.MeasureText( APPLICATION_TITLE ) );
- title.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle());
-
+ //Path
+ mPath = Dali::Path::New();
+ mPath.AddPoint( Vector3( 10.0f, stage.GetSize().y*0.5f, 0.0f ));
+ mPath.AddPoint( Vector3( stage.GetSize().x*0.5f, stage.GetSize().y*0.5f, 0.0f ));
+ mPath.GenerateControlPoints(0.25f);
+ DrawPath( 200u );
+
+ //Actor
+ ImageAttributes attributes;
+ Image img = ResourceImage::New(ACTOR_IMAGE, attributes );
+ mActor = ImageActor::New( img );
+ mActor.SetAnchorPoint( AnchorPoint::CENTER );
+ mActor.SetSize( 100, 50, 1 );
+ stage.Add( mActor );
+
+ CreateAnimation();
+ CreateControls();
}
private:
--- /dev/null
- field.SetProperty( TextField::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @file text-field-example.cpp
+ * @brief Basic usage of TextField control
+ */
+
+// EXTERNAL INCLUDES
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali/public-api/text-abstraction/text-abstraction.h>
+
+// INTERNAL INCLUDES
+#include "edit-layout.h"
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+namespace
+{
+
+const float BORDER_WIDTH = 4.0f;
+
+} // unnamed namespace
+
+/**
+ * @brief The main class of the demo.
+ */
+class TextFieldExample : public ConnectionTracker
+{
+public:
+
+ TextFieldExample( Application& application )
+ : mApplication( application )
+ {
+ // Connect to the Application's Init signal
+ mApplication.InitSignal().Connect( this, &TextFieldExample::Create );
+ }
+
+ ~TextFieldExample()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * One-time setup in response to Application InitSignal.
+ */
+ void Create( Application& application )
+ {
+ Stage stage = Stage::GetCurrent();
+
+ stage.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent);
+
+ Vector2 stageSize = stage.GetSize();
+
+ EditLayout layout = EditLayout::New();
+ layout.SetParentOrigin( ParentOrigin::CENTER );
+ layout.SetAnchorPoint( AnchorPoint::CENTER );
+ layout.SetSize( stageSize.width - BORDER_WIDTH*2.0f, stageSize.height*0.2f );
+ stage.Add( layout );
+
+ TextField field = TextField::New();
+ field.SetParentOrigin( ParentOrigin::CENTER );
+ field.SetBackgroundColor( Color::BLACK );
+ layout.SetTopPanel( field );
+
- //Property::Value fieldText = field.GetProperty( TextField::PROPERTY_TEXT );
++ field.SetProperty( TextField::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
+
+ // TODO
++ //Property::Value fieldText = field.GetProperty( TextField::Property::TEXT );
+ //std::cout << "Got text from field: " << fieldText.Get< std::string >() << std::endl;
+ }
+
+ /**
+ * Main key event handler
+ */
+ void OnKeyEvent(const KeyEvent& event)
+ {
+ if(event.state == KeyEvent::Down)
+ {
+ if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
+ {
+ mApplication.Quit();
+ }
+ }
+ }
+
+private:
+
+ Application& mApplication;
+};
+
+void RunTest( Application& application )
+{
+ TextFieldExample test( application );
+
+ application.MainLoop();
+}
+
+/** Entry point for Linux & Tizen applications */
+int main( int argc, char **argv )
+{
+ Application application = Application::New( &argc, &argv );
+
+ RunTest( application );
+
+ return 0;
+}
--- /dev/null
- label.SetProperty( TextLabel::PROPERTY_MULTI_LINE, true );
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @file text-label-example.cpp
+ * @brief Basic usage of TextLabel control
+ */
+
+// INTERNAL INCLUDES
+#include "vertical-layout.h"
+#include "shared/multi-language-strings.h"
+
+// EXTERNAL INCLUDES
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali/public-api/text-abstraction/text-abstraction.h>
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+using namespace MultiLanguageStrings;
+
+/**
+ * @brief The main class of the demo.
+ */
+class TextLabelMultiLanguageExample : public ConnectionTracker
+{
+public:
+
+ TextLabelMultiLanguageExample( Application& application )
+ : mApplication( application ),
+ mLastPoint( 0.f )
+ {
+ // Connect to the Application's Init signal
+ mApplication.InitSignal().Connect( this, &TextLabelMultiLanguageExample::Create );
+ }
+
+ ~TextLabelMultiLanguageExample()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * One-time setup in response to Application InitSignal.
+ */
+ void Create( Application& application )
+ {
+ Stage stage = Stage::GetCurrent();
+
+ stage.KeyEventSignal().Connect(this, &TextLabelMultiLanguageExample::OnKeyEvent);
+
+ mLayout = VerticalLayout::New();
+ mLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+ stage.Add( mLayout );
+
+ for( unsigned int index = 0u; index < NUMBER_OF_LANGUAGES; ++index )
+ {
+ const Language& language = LANGUAGES[index];
+
+ TextLabel label = TextLabel::New();
+ label.SetParentOrigin( ParentOrigin::CENTER );
+
- label.SetProperty( TextLabel::PROPERTY_TEXT, text );
++ label.SetProperty( TextLabel::Property::MULTI_LINE, true );
+
+ const std::string text = language.languageName + " " + language.languageRomanName + " " + language.text;
+
++ label.SetProperty( TextLabel::Property::TEXT, text );
+ mLayout.AddLabel( label );
+
+ mLayout.TouchedSignal().Connect( this, &TextLabelMultiLanguageExample::OnTouchEvent );
+ }
+
+ const Vector2& size = Stage::GetCurrent().GetSize();
+ const float height = mLayout.GetHeightForWidth( size.width );
+ mLayout.SetSize( Size( size.width, height ) );
+ }
+
+ bool OnTouchEvent( Actor actor, const TouchEvent& event )
+ {
+ if( 1u == event.GetPointCount() )
+ {
+ const TouchPoint::State state = event.GetPoint(0u).state;
+
+ // Clamp to integer values; this is to reduce flicking due to pixel misalignment
+ const float localPoint = static_cast<float>( static_cast<int>( event.GetPoint( 0 ).local.y ) );
+
+ if( TouchPoint::Down == state )
+ {
+ mLastPoint = localPoint;
+ mAnimation = Animation::New( 0.25f );
+ }
+ else if( TouchPoint::Motion == state )
+ {
+ if( mAnimation )
+ {
+ mAnimation.MoveBy( mLayout, Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear );
+ mAnimation.Play();
+ mLastPoint = localPoint;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Main key event handler
+ */
+ void OnKeyEvent(const KeyEvent& event)
+ {
+ if(event.state == KeyEvent::Down)
+ {
+ if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
+ {
+ mApplication.Quit();
+ }
+ }
+ }
+
+private:
+
+ Application& mApplication;
+ VerticalLayout mLayout;
+ Animation mAnimation;
+ float mLastPoint;
+};
+
+void RunTest( Application& application )
+{
+ TextLabelMultiLanguageExample test( application );
+
+ application.MainLoop();
+}
+
+/** Entry point for Linux & Tizen applications */
+int main( int argc, char **argv )
+{
+ Application application = Application::New( &argc, &argv );
+
+ RunTest( application );
+
+ return 0;
+}
--- /dev/null
- mLabel.SetProperty( TextLabel::PROPERTY_MULTI_LINE, true );
- mLabel.SetProperty( TextLabel::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @file text-label-example.cpp
+ * @brief Basic usage of TextLabel control
+ */
+
+// EXTERNAL INCLUDES
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali/public-api/text-abstraction/text-abstraction.h>
+
+// INTERNAL INCLUDES
+#include "center-layout.h"
+#include "shared/multi-language-strings.h"
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+using namespace MultiLanguageStrings;
+
+namespace
+{
+ const unsigned int KEY_ZERO = 10;
+ const unsigned int KEY_ONE = 11;
+ const unsigned int KEY_M = 58;
+ const unsigned int KEY_L = 46;
+}
+
+/**
+ * @brief The main class of the demo.
+ */
+class TextLabelExample : public ConnectionTracker
+{
+public:
+
+ TextLabelExample( Application& application )
+ : mApplication( application ),
+ mLanguageId( 0u )
+ {
+ // Connect to the Application's Init signal
+ mApplication.InitSignal().Connect( this, &TextLabelExample::Create );
+ }
+
+ ~TextLabelExample()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * One-time setup in response to Application InitSignal.
+ */
+ void Create( Application& application )
+ {
+ Stage stage = Stage::GetCurrent();
+
+ stage.SetBackgroundColor( Color::BLUE );
+ stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
+ Vector2 stageSize = stage.GetSize();
+
+ CenterLayout centerLayout = CenterLayout::New();
+ centerLayout.SetParentOrigin( ParentOrigin::CENTER );
+ centerLayout.SetSize( stageSize.width*0.6f, stageSize.width*0.6f );
+ stage.Add( centerLayout );
+
+ mLabel = TextLabel::New();
+ mLabel.SetBackgroundColor( Color::BLACK );
+ centerLayout.Add( mLabel );
+
- Property::Value labelText = mLabel.GetProperty( TextLabel::PROPERTY_TEXT );
++ mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
++ mLabel.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
+
- mLabel.SetProperty( TextLabel::PROPERTY_RENDERING_BACKEND, event.keyCode - 10 );
++ Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT );
+ std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
+ }
+
+ /**
+ * Main key event handler
+ */
+ void OnKeyEvent(const KeyEvent& event)
+ {
+ if(event.state == KeyEvent::Down)
+ {
+ if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
+ {
+ mApplication.Quit();
+ }
+ else if( event.IsCtrlModifier() )
+ {
+ switch( event.keyCode )
+ {
+ case KEY_ZERO: // fall through
+ case KEY_ONE:
+ {
- bool multiLine = mLabel.GetProperty<bool>( TextLabel::PROPERTY_MULTI_LINE );
- mLabel.SetProperty( TextLabel::PROPERTY_MULTI_LINE, !multiLine );
++ mLabel.SetProperty( TextLabel::Property::RENDERING_BACKEND, event.keyCode - 10 );
+ break;
+ }
+ case KEY_M:
+ {
- mLabel.SetProperty( TextLabel::PROPERTY_TEXT, language.text );
++ bool multiLine = mLabel.GetProperty<bool>( TextLabel::Property::MULTI_LINE );
++ mLabel.SetProperty( TextLabel::Property::MULTI_LINE, !multiLine );
+ break;
+ }
+ case KEY_L:
+ {
+ const Language& language = LANGUAGES[ mLanguageId ];
+
++ mLabel.SetProperty( TextLabel::Property::TEXT, language.text );
+
+ if( ++mLanguageId >= NUMBER_OF_LANGUAGES )
+ {
+ mLanguageId = 0u;
+ }
+ }
+ }
+ }
+ }
+ }
+
+private:
+
+ Application& mApplication;
+
+ TextLabel mLabel;
+
+ unsigned int mLanguageId;
+};
+
+void RunTest( Application& application )
+{
+ TextLabelExample test( application );
+
+ application.MainLoop();
+}
+
+/** Entry point for Linux & Tizen applications */
+int main( int argc, char **argv )
+{
+ Application application = Application::New( &argc, &argv );
+
+ RunTest( application );
+
+ return 0;
+}