/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
// EXTERNAL INCLUDES
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
-#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
+#include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
-#include <fstream>
#include <sstream>
#include <limits>
+#include <cctype>
// INTERNAL INCLUDES
#include "shared/view.h"
// The Init signal is received once (only) during the Application lifetime
void Create(Application& application)
{
- Stage stage = Stage::GetCurrent();
- Vector2 stageSize = stage.GetSize();
+ Window window = application.GetWindow();
+ Vector2 windowSize = window.GetSize();
- stage.KeyEventSignal().Connect(this, &RefractionEffectExample::OnKeyEvent);
+ window.KeyEventSignal().Connect(this, &RefractionEffectExample::OnKeyEvent);
// Creates a default view with a default tool bar.
- // The view is added to the stage.
+ // The view is added to the window.
Toolkit::ToolBar toolBar;
Toolkit::Control view;
mContent = DemoHelper::CreateView( application,
// Add a button to change background. (right of toolbar)
mChangeTextureButton = Toolkit::PushButton::New();
- mChangeTextureButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON );
- mChangeTextureButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON_SELECTED );
+ mChangeTextureButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON );
+ mChangeTextureButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON_SELECTED );
mChangeTextureButton.ClickedSignal().Connect( this, &RefractionEffectExample::OnChangeTexture );
toolBar.AddControl( mChangeTextureButton,
DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
// Add a button to change mesh pattern. ( left of bar )
mChangeMeshButton = Toolkit::PushButton::New();
- mChangeMeshButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON );
- mChangeMeshButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON_SELECTED );
+ mChangeMeshButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON );
+ mChangeMeshButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON_SELECTED );
mChangeMeshButton.ClickedSignal().Connect( this, &RefractionEffectExample::OnChangeMesh );
toolBar.AddControl( mChangeMeshButton,
DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
mShaderFlat = Shader::New( VERTEX_SHADER_FLAT, FRAGMENT_SHADER_FLAT );
mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] );
- Texture texture = DemoHelper::LoadStageFillingTexture( TEXTURE_IMAGES[mCurrentTextureId] );
+ Texture texture = DemoHelper::LoadWindowFillingTexture( window.GetSize(), TEXTURE_IMAGES[mCurrentTextureId] );
mTextureSet = TextureSet::New();
mTextureSet.SetTexture( 0u, texture );
mMeshActor = Actor::New();
mMeshActor.AddRenderer( mRenderer );
- mMeshActor.SetSize( stageSize );
- mMeshActor.SetParentOrigin(ParentOrigin::CENTER);
+ mMeshActor.SetProperty( Actor::Property::SIZE, windowSize );
+ mMeshActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
mContent.Add( mMeshActor );
// Connect the callback to the touch signal on the mesh actor
mEffectStrengthIndex = mMeshActor.RegisterProperty( "uEffectStrength", 0.f );
- Vector3 lightPosition( -stageSize.x*0.5f, -stageSize.y*0.5f, stageSize.x*0.5f ); // top_left
+ Vector3 lightPosition( -windowSize.x*0.5f, -windowSize.y*0.5f, windowSize.x*0.5f ); // top_left
mMeshActor.RegisterProperty( "uLightPosition", lightPosition );
Property::Index lightSpinOffsetIndex = mMeshActor.RegisterProperty( "uLightSpinOffset", Vector2::ZERO );
mSpinAngleIndex = mMeshActor.RegisterProperty("uSpinAngle", 0.f );
- Constraint constraint = Constraint::New<Vector2>( mMeshActor, lightSpinOffsetIndex, LightOffsetConstraint(stageSize.x*0.1f) );
+ Constraint constraint = Constraint::New<Vector2>( mMeshActor, lightSpinOffsetIndex, LightOffsetConstraint(windowSize.x*0.1f) );
constraint.AddSource( LocalSource(mSpinAngleIndex) );
constraint.Apply();
bool OnChangeTexture( Toolkit::Button button )
{
mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES;
- Texture texture = DemoHelper::LoadStageFillingTexture( TEXTURE_IMAGES[mCurrentTextureId] );
+ Texture texture = DemoHelper::LoadWindowFillingTexture( mApplication.GetWindow().GetSize(), TEXTURE_IMAGES[mCurrentTextureId] );
mTextureSet.SetTexture( 0u, texture );
return true;
}
- bool OnTouch( Actor actor, const TouchData& event )
+ bool OnTouch( Actor actor, const TouchEvent& event )
{
switch( event.GetState( 0 ) )
{
std::vector<Vector3>& vertexPositions,
Vector<unsigned int>& faceIndices)
{
- std::ifstream ifs( objFileName.c_str(), std::ios::in );
+ std::streampos bufferSize = 0;
+ Dali::Vector<char> fileBuffer;
+ if( !Dali::FileLoader::ReadFile( objFileName, bufferSize, fileBuffer, Dali::FileLoader::FileType::TEXT ) )
+ {
+ DALI_LOG_WARNING( "file open failed for: \"%s\"", objFileName.c_str() );
+ return;
+ }
+
+ fileBuffer.PushBack( '\0' );
+
+ std::stringstream iss( &fileBuffer[0], std::ios::in );
boundingBox.Resize( 6 );
boundingBox[0]=boundingBox[2]=boundingBox[4] = std::numeric_limits<float>::max();
boundingBox[1]=boundingBox[3]=boundingBox[5] = -std::numeric_limits<float>::max();
std::string line;
- while( std::getline( ifs, line ) )
+ while( std::getline( iss, line ) )
{
if( line[0] == 'v' && std::isspace(line[1])) // vertex
{
}
std::istringstream iss(line.substr(2), std::istringstream::in);
-
- std::vector<unsigned int> indices( numOfInt );
-
+ Dali::Vector<unsigned int> indices;
+ indices.Resize(numOfInt);
unsigned int i=0;
while( iss >> indices[i++] && i < numOfInt);
unsigned int step = (i+1) / 3;
faceIndices.PushBack( indices[2*step]-1 );
}
}
-
- ifs.close();
}
void ShapeResizeAndTexureCoordinateCalculation( const Vector<float>& boundingBox,
Vector3 bBoxSize( boundingBox[1] - boundingBox[0], boundingBox[3] - boundingBox[2], boundingBox[5] - boundingBox[4]);
Vector3 bBoxMinCorner( boundingBox[0], boundingBox[2], boundingBox[4] );
- Vector2 stageSize = Stage::GetCurrent().GetSize();
- Vector3 scale( stageSize.x / bBoxSize.x, stageSize.y / bBoxSize.y, 1.f );
+ Vector2 windowSize = mApplication.GetWindow().GetSize();
+ Vector3 scale( windowSize.x / bBoxSize.x, windowSize.y / bBoxSize.y, 1.f );
scale.z = (scale.x + scale.y)/2.f;
textureCoordinates.reserve(vertexPositions.size());