Commit 9ea8b72401a81c565b5c956a188728e040a792f5
1 parent
6f348bec
Add TiltSensor demo
Signed-off-by: suhyung Eom <suhyung.eom@samsung.com> Change-Id: I9e367f4140f18566526ea917da8e571403bd046c
Showing
4 changed files
with
113 additions
and
0 deletions
com.samsung.dali-demo.xml
| @@ -136,4 +136,7 @@ | @@ -136,4 +136,7 @@ | ||
| 136 | <ui-application appid="homescreen-benchmark.example" exec="/usr/apps/com.samsung.dali-demo/bin/homescreen-benchmark.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | 136 | <ui-application appid="homescreen-benchmark.example" exec="/usr/apps/com.samsung.dali-demo/bin/homescreen-benchmark.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 137 | <label>Homescreen Benchmark</label> | 137 | <label>Homescreen Benchmark</label> |
| 138 | </ui-application> | 138 | </ui-application> |
| 139 | + <ui-application appid="tilt.example" exec="/usr/apps/com.samsung.dali-demo/bin/tilt.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | ||
| 140 | + <label>Tilt sensor</label> | ||
| 141 | + </ui-application> | ||
| 139 | </manifest> | 142 | </manifest> |
demo/dali-demo.cpp
| @@ -72,6 +72,7 @@ int main(int argc, char **argv) | @@ -72,6 +72,7 @@ int main(int argc, char **argv) | ||
| 72 | demo.AddExample(Example("image-view-pixel-area.example", DALI_DEMO_STR_TITLE_IMAGE_VIEW_PIXEL_AREA)); | 72 | demo.AddExample(Example("image-view-pixel-area.example", DALI_DEMO_STR_TITLE_IMAGE_VIEW_PIXEL_AREA)); |
| 73 | demo.AddExample(Example("image-view-alpha-blending.example", DALI_DEMO_STR_TITLE_IMAGE_VIEW_ALPHA_BLENDING)); | 73 | demo.AddExample(Example("image-view-alpha-blending.example", DALI_DEMO_STR_TITLE_IMAGE_VIEW_ALPHA_BLENDING)); |
| 74 | demo.AddExample(Example("super-blur-bloom.example", DALI_DEMO_STR_TITLE_SUPER_BLUR_BLOOM)); | 74 | demo.AddExample(Example("super-blur-bloom.example", DALI_DEMO_STR_TITLE_SUPER_BLUR_BLOOM)); |
| 75 | + demo.AddExample(Example("tilt.example", DALI_DEMO_STR_TITLE_TILT_SENSOR)); | ||
| 75 | 76 | ||
| 76 | demo.SortAlphabetically( true ); | 77 | demo.SortAlphabetically( true ); |
| 77 | 78 |
examples/tilt/tilt-example.cpp
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2016 Samsung Electronics Co., Ltd. | ||
| 3 | + * | ||
| 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 | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 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. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 19 | +#include <dali/devel-api/adaptor-framework/tilt-sensor.h> | ||
| 20 | + | ||
| 21 | +using namespace Dali; | ||
| 22 | +using Dali::Toolkit::TextLabel; | ||
| 23 | + | ||
| 24 | +// This example shows how to use sensor using a simple TextLabel | ||
| 25 | +// | ||
| 26 | +class TiltController : public ConnectionTracker | ||
| 27 | +{ | ||
| 28 | +public: | ||
| 29 | + TiltController( Application& application ) | ||
| 30 | + : mApplication( application ) | ||
| 31 | + { | ||
| 32 | + // Connect to the Application's Init signal | ||
| 33 | + mApplication.InitSignal().Connect( this, &TiltController::Create ); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + ~TiltController() | ||
| 37 | + { | ||
| 38 | + // Nothing to do here; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + // The Init signal is received once (only) during the Application lifetime | ||
| 42 | + void Create( Application& application ) | ||
| 43 | + { | ||
| 44 | + // Get a handle to the stage | ||
| 45 | + Stage stage = Stage::GetCurrent(); | ||
| 46 | + stage.SetBackgroundColor( Color::BLUE); | ||
| 47 | + | ||
| 48 | + mTextLabel = TextLabel::New( "Tilt Sensor Demo" ); | ||
| 49 | + mTextLabel.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 50 | + mTextLabel.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 51 | + mTextLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); | ||
| 52 | + mTextLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); | ||
| 53 | + mTextLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); | ||
| 54 | + mTextLabel.SetProperty( TextLabel::Property::POINT_SIZE, 15.0f ); | ||
| 55 | + mTextLabel.SetName( "tiltLabel" ); | ||
| 56 | + stage.Add( mTextLabel ); | ||
| 57 | + | ||
| 58 | + // Respond to a click anywhere on the stage | ||
| 59 | + stage.GetRootLayer().TouchedSignal().Connect( this, &TiltController::OnTouch ); | ||
| 60 | + | ||
| 61 | + CreateSensor(); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + void CreateSensor() | ||
| 65 | + { | ||
| 66 | + mTiltSensor = TiltSensor::Get(); | ||
| 67 | + if ( mTiltSensor.Enable() ) | ||
| 68 | + { | ||
| 69 | + // Get notifications when the device is tilted | ||
| 70 | + mTiltSensor.TiltedSignal().Connect( this, &TiltController::OnTilted ); | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + bool OnTouch( Actor actor, const TouchEvent& touch ) | ||
| 75 | + { | ||
| 76 | + // quit the application | ||
| 77 | + mApplication.Quit(); | ||
| 78 | + return true; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + void OnTilted(const TiltSensor& sensor) | ||
| 82 | + { | ||
| 83 | + Quaternion pitchRot(Radian(Degree(sensor.GetPitch() * 90.0f)), Vector3(1, 0, 0)); | ||
| 84 | + Quaternion rollRot(Radian(Degree(sensor.GetRoll() * 90.0f)), Vector3(0, 1, 0)); | ||
| 85 | + | ||
| 86 | + mTextLabel.SetOrientation(Quaternion()); | ||
| 87 | + mTextLabel.RotateBy(rollRot); | ||
| 88 | + mTextLabel.RotateBy(pitchRot);; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | +private: | ||
| 92 | + Application& mApplication; | ||
| 93 | + TiltSensor mTiltSensor; | ||
| 94 | + TextLabel mTextLabel; | ||
| 95 | +}; | ||
| 96 | + | ||
| 97 | +// Entry point for Linux & Tizen applications | ||
| 98 | +// | ||
| 99 | +int main( int argc, char **argv ) | ||
| 100 | +{ | ||
| 101 | + Application application = Application::New( &argc, &argv ); | ||
| 102 | + TiltController test( application ); | ||
| 103 | + | ||
| 104 | + application.MainLoop(); | ||
| 105 | + return 0; | ||
| 106 | +} |
shared/dali-demo-strings.h
| @@ -104,6 +104,9 @@ extern "C" | @@ -104,6 +104,9 @@ extern "C" | ||
| 104 | 104 | ||
| 105 | #endif | 105 | #endif |
| 106 | 106 | ||
| 107 | +#define DALI_DEMO_STR_TITLE_TILT_SENSOR "Tilt Sensor" | ||
| 108 | + | ||
| 109 | + | ||
| 107 | #ifdef __cplusplus | 110 | #ifdef __cplusplus |
| 108 | } | 111 | } |
| 109 | #endif // __cplusplus | 112 | #endif // __cplusplus |