From 0575db7ba91c81638a9670ce54664aa024782c14 Mon Sep 17 00:00:00 2001 From: o_ggy Date: Wed, 21 Jul 2010 13:56:46 -0700 Subject: [PATCH] moftmp --- moftmp/AbstractScene.cpp | 112 ++++ moftmp/AmbientLight.cpp | 74 +++ moftmp/AmbientLight.hpp | 32 ++ moftmp/Application.cpp | 111 ++++ moftmp/Application.hpp | 34 ++ moftmp/Board.cpp | 110 ++++ moftmp/Board.hpp | 41 ++ moftmp/CSVFile.cpp | 177 ++++++ moftmp/CSVFile.h | 28 + moftmp/Camera.cpp | 108 ++++ moftmp/Camera.hpp | 44 ++ moftmp/Captor.cpp | 48 ++ moftmp/Captor.hpp | 19 + moftmp/Color.cpp | 155 +++++ moftmp/Color.hpp | 43 ++ moftmp/ColorComponent.hpp | 50 ++ moftmp/Component2D.cpp | 0 moftmp/Component2D.h | 24 + moftmp/Component2D.hpp | 104 ++++ moftmp/Component3D.cpp | 7 + moftmp/Component3D.hpp | 22 + moftmp/ConsoleIO.cpp | 3 + moftmp/ConsoleIO.hpp | 80 +++ moftmp/Container2D.cpp | 162 ++++++ moftmp/Container2D.h | 45 ++ moftmp/Container3D.cpp | 62 ++ moftmp/Container3D.h | 27 + moftmp/DataRow.cpp | 12 + moftmp/DataRow.h | 47 ++ moftmp/DataTable.cpp | 104 ++++ moftmp/DataTable.h | 41 ++ moftmp/Deleter.hpp | 23 + moftmp/DeviceInputReceiver.cpp | 133 +++++ moftmp/DirectionalLight.cpp | 44 ++ moftmp/DirectionalLight.h | 22 + moftmp/Drawable.hpp | 11 + moftmp/EventCondition.hpp | 14 + moftmp/EventScheduler.cpp | 83 +++ moftmp/EventScheduler.hpp | 30 + moftmp/FactoryMethod.hpp | 137 +++++ moftmp/FilePath.cpp | 68 +++ moftmp/FilePath.hpp | 22 + moftmp/FileTextureBuilder.cpp | 37 ++ moftmp/Finalizer.hpp | 53 ++ moftmp/Font.cpp | 183 ++++++ moftmp/Font.hpp | 29 + moftmp/Graphics3D.hpp | 21 + moftmp/GraphicsDevice.cpp | 506 ++++++++++++++++ moftmp/GraphicsDevice.hpp | 56 ++ moftmp/GraphicsObject.cpp | 15 + moftmp/GraphicsSchedule.cpp | 66 +++ moftmp/GraphicsSchedule.h | 37 ++ moftmp/GraphicsUnit.hpp | 17 + moftmp/InputDevice.cpp | 310 ++++++++++ moftmp/InputDevice.hpp | 23 + moftmp/InputEventCondition.cpp | 24 + moftmp/InputEventCondition.hpp | 27 + moftmp/InputReceiver.hpp | 28 + moftmp/InstructionSet.hpp | 47 ++ moftmp/Interpolation.hpp | 79 +++ moftmp/Interpreter.cpp | 167 ++++++ moftmp/Interpreter.hpp | 63 ++ moftmp/KeyPressedEventCondition.cpp | 29 + moftmp/KeyPressedEventCondition.hpp | 29 + moftmp/Light.cpp | 22 + moftmp/Light.hpp | 25 + moftmp/Line3D.cpp | 20 + moftmp/Line3D.h | 22 + moftmp/LoggedInputReceiver.cpp | 21 + moftmp/LoggedInputReceiver.hpp | 24 + moftmp/LoggingInputReceiver.cpp | 33 ++ moftmp/LoggingInputReceiver.hpp | 22 + moftmp/LuaScript.cpp | 67 +++ moftmp/LuaScript.hpp | 25 + moftmp/Material.hpp | 45 ++ moftmp/MaterialBuilder.cpp | 134 +++++ moftmp/MaterialBuilder.hpp | 50 ++ moftmp/Matrix2D.cpp | 175 ++++++ moftmp/Matrix2D.hpp | 50 ++ moftmp/Matrix3D.cpp | 227 ++++++++ moftmp/Matrix3D.hpp | 49 ++ moftmp/Mesh.cpp | 91 +++ moftmp/MeshBuilder.cpp | 115 ++++ moftmp/MeshBuilder.hpp | 24 + moftmp/MeshResource.h | 12 + moftmp/OnceEventCondition.cpp | 36 ++ moftmp/OnceEventCondition.hpp | 20 + moftmp/PixelMap.hpp | 11 + moftmp/PixelMapTextureBuilder.cpp | 70 +++ moftmp/PlainWidgetView.cpp | 128 +++++ moftmp/PlainWidgetView.hpp | 29 + moftmp/Rectangle.hpp | 72 +++ moftmp/ResourceManager.hpp | 134 +++++ moftmp/SceneGraph.hpp | 23 + moftmp/SelectionModel.cpp | 73 +++ moftmp/SelectionModel.h | 34 ++ moftmp/Sprite.cpp | 192 +++++++ moftmp/Sprite.hpp | 69 +++ moftmp/TextCompiler.cpp | 42 ++ moftmp/TextCompiler.hpp | 18 + moftmp/TextView.cpp | 184 ++++++ moftmp/TextView.hpp | 44 ++ moftmp/Texture.cpp | 53 ++ moftmp/Texture.hpp | 28 + moftmp/TextureComponent.hpp | 45 ++ moftmp/TextureResource.h | 18 + moftmp/Timer.cpp | 76 +++ moftmp/Timer.hpp | 22 + moftmp/Vector2D.cpp | 75 +++ moftmp/Vector2D.hpp | 34 ++ moftmp/Vector3D.cpp | 72 +++ moftmp/Vector3D.hpp | 28 + moftmp/VertexBuffer.cpp | 102 ++++ moftmp/VertexBuffer.hpp | 30 + moftmp/VertexTypes.hpp | 104 ++++ moftmp/Window.cpp | 128 +++++ moftmp/Window.hpp | 27 + moftmp/graphics/utilities.hpp | 11 + moftmp/graphics/utilities.hpp~ | 11 + moftmp/mofGraphics.hpp | 15 + moftmp/mofInput.hpp | 7 + moftmp/moflib.vcproj | 665 ++++++++++++++++++++++ moftmp/moflib.vcproj.TOMOHIRO.TomohiroYasuda.user | 65 +++ moftmp/private/DeviceInputReceiver.hpp | 27 + moftmp/private/DirectInput.hpp | 8 + moftmp/private/FileTextureBuilder.cpp | 32 ++ moftmp/private/FileTextureBuilder.hpp | 21 + moftmp/private/GraphicsDeviceImpl.hpp | 26 + moftmp/private/Interpreter.hpp | 26 + moftmp/private/Interpreter.hpp~ | 26 + moftmp/private/Mesh.hpp | 40 ++ moftmp/private/MeshDisposer.hpp | 18 + moftmp/private/PixelMapTextureBuilder.hpp | 23 + moftmp/private/TextureBuilder.hpp | 17 + moftmp/private/TextureImpl.hpp | 20 + moftmp/private/VertexFVF.hpp | 37 ++ moftmp/private/commands.hpp~ | 14 + moftmp/private/message.cpp~ | 40 ++ moftmp/private/regist.cpp | 48 ++ moftmp/private/regist.cpp~ | 48 ++ moftmp/private/regist.hpp | 13 + moftmp/private/regist.hpp~ | 12 + moftmp/real.hpp | 16 + moftmp/stream/Animation.hpp~ | 24 + moftmp/stream/AnimationPlayer.hpp | 20 + moftmp/stream/AnimationPlayer.hpp~ | 20 + moftmp/stream/AnimationScheduler.cpp | 41 ++ moftmp/stream/BoundsAnimation.hpp | 38 ++ moftmp/stream/BoundsAnimation.hpp~ | 38 ++ moftmp/stream/Cache.cpp | 19 + moftmp/stream/Cache.cpp~ | 14 + moftmp/stream/Cache.hpp | 69 +++ moftmp/stream/Cache.hpp~ | 69 +++ moftmp/stream/Cascade.hpp | 173 ++++++ moftmp/stream/Cascade.hpp~ | 179 ++++++ moftmp/stream/CascadeAnimation.cpp | 161 ++++++ moftmp/stream/CascadingAnimation.hpp~ | 143 +++++ moftmp/stream/Constant.hpp | 45 ++ moftmp/stream/Constant.hpp~ | 45 ++ moftmp/stream/DataBasedAnimation.cpp | 193 +++++++ moftmp/stream/DataBasedAnimation.h | 37 ++ moftmp/stream/DefaultAnimationPlayer.cpp | 21 + moftmp/stream/DefaultAnimationPlayer.hpp | 22 + moftmp/stream/DefaultAnimationPlayer.hpp~ | 22 + moftmp/stream/Filter.hpp | 51 ++ moftmp/stream/Filter.hpp~ | 51 ++ moftmp/stream/Joint.hpp | 99 ++++ moftmp/stream/Joint.hpp~ | 99 ++++ moftmp/stream/JointAnimation.hpp~ | 39 ++ moftmp/stream/KeyFrameAnimation.hpp | 164 ++++++ moftmp/stream/KeyFrameAnimation.hpp~ | 146 +++++ moftmp/stream/Loop.hpp | 98 ++++ moftmp/stream/Loop.hpp~ | 98 ++++ moftmp/stream/LoopAnimation.hpp~ | 60 ++ moftmp/stream/Manipulator.hpp | 19 + moftmp/stream/Manipulator.hpp~ | 18 + moftmp/stream/Offset.hpp | 55 ++ moftmp/stream/Offset.hpp~ | 55 ++ moftmp/stream/OffsetAnimation.hpp~ | 48 ++ moftmp/stream/ParametricAnimation.hpp | 30 + moftmp/stream/ParametricAnimation.hpp~ | 30 + moftmp/stream/Reference.hpp | 52 ++ moftmp/stream/Reference.hpp~ | 52 ++ moftmp/stream/ReferenceWrapper.hpp | 56 ++ moftmp/stream/ReferenceWrapper.hpp~ | 56 ++ moftmp/stream/Rotation2D.hpp | 76 +++ moftmp/stream/Rotation2D.hpp~ | 76 +++ moftmp/stream/RotationAnimation2D.hpp~ | 45 ++ moftmp/stream/RotationAnimation3D.hpp | 53 ++ moftmp/stream/RotationAnimation3D.hpp~ | 53 ++ moftmp/stream/Scaling2D.hpp | 78 +++ moftmp/stream/Scaling2D.hpp~ | 78 +++ moftmp/stream/ScalingAnimation2D.hpp~ | 55 ++ moftmp/stream/ScalingAnimation3D.hpp | 39 ++ moftmp/stream/ScalingAnimation3D.hpp~ | 39 ++ moftmp/stream/Stream.hpp~ | 76 +++ moftmp/stream/Translation2D.hpp | 80 +++ moftmp/stream/Translation2D.hpp~ | 80 +++ moftmp/stream/TranslationAnimation2D.hpp~ | 96 ++++ moftmp/stream/TranslationAnimation3D.hpp | 53 ++ moftmp/stream/TranslationAnimation3D.hpp~ | 53 ++ moftmp/stream/TypeStream.hpp | 94 +++ moftmp/stream/TypeStream.hpp~ | 94 +++ moftmp/stream/UniformAnimation.hpp | 48 ++ moftmp/stream/UniformAnimation.hpp~ | 48 ++ moftmp/stream/mofAnimations.hpp~ | 18 + moftmp/stream/utilities.cpp | 54 ++ moftmp/stream/utilities.cpp~ | 54 ++ moftmp/stream/utilities.hpp | 26 + moftmp/stream/utilities.hpp~ | 26 + moftmp/streams.hpp | 27 + moftmp/tests/Alltests.cpp | 32 ++ moftmp/tests/SceneGraphTest.cpp | 39 ++ moftmp/tests/TimerTest.cpp | 32 ++ moftmp/tstring.hpp | 13 + moftmp/utilities.hpp | 53 ++ moftmp/widget/ButtonWidgetView.hpp~ | 18 + moftmp/widget/Container.cpp | 174 ++++++ moftmp/widget/Container.cpp~ | 175 ++++++ moftmp/widget/Container.hpp | 55 ++ moftmp/widget/Container.hpp~ | 55 ++ moftmp/widget/ContainerWidgetView.cpp~ | 160 ++++++ moftmp/widget/ContainerWidgetView.hpp~ | 46 ++ moftmp/widget/Effect.cpp | 109 ++++ moftmp/widget/Effect.cpp~ | 108 ++++ moftmp/widget/Effect.hpp | 27 + moftmp/widget/Effect.hpp~ | 27 + moftmp/widget/Frame.cpp | 126 ++++ moftmp/widget/Frame.cpp~ | 126 ++++ moftmp/widget/Frame.hpp | 43 ++ moftmp/widget/Frame.hpp~ | 43 ++ moftmp/widget/FrameBuilder.hpp | 33 ++ moftmp/widget/FrameBuilder.hpp~ | 33 ++ moftmp/widget/GridLayout.cpp | 144 +++++ moftmp/widget/GridLayout.cpp~ | 144 +++++ moftmp/widget/GridLayout.hpp | 38 ++ moftmp/widget/GridLayout.hpp~ | 38 ++ moftmp/widget/ImageView.cpp | 117 ++++ moftmp/widget/ImageView.cpp~ | 118 ++++ moftmp/widget/ImageView.hpp | 38 ++ moftmp/widget/ImageView.hpp~ | 38 ++ moftmp/widget/ImageWidgetView.cpp~ | 115 ++++ moftmp/widget/ImageWidgetView.hpp~ | 33 ++ moftmp/widget/Layout.hpp | 35 ++ moftmp/widget/Layout.hpp~ | 35 ++ moftmp/widget/LayoutManager.cpp~ | 73 +++ moftmp/widget/LayoutManager.hpp~ | 24 + moftmp/widget/Menu.cpp | 158 +++++ moftmp/widget/Menu.cpp~ | 157 +++++ moftmp/widget/Menu.hpp | 68 +++ moftmp/widget/Menu.hpp~ | 68 +++ moftmp/widget/MenuWidget.cpp~ | 150 +++++ moftmp/widget/MenuWidget.hpp~ | 64 +++ moftmp/widget/Message.hpp | 29 + moftmp/widget/Message.hpp~ | 29 + moftmp/widget/MessageWidget.cpp | 238 ++++++++ moftmp/widget/MessageWidget.cpp20090811 | 250 ++++++++ moftmp/widget/MessageWidget.cpp~ | 238 ++++++++ moftmp/widget/MessageWidget.hpp | 48 ++ moftmp/widget/MessageWidget.hpp~ | 48 ++ moftmp/widget/OverlapLayout.cpp | 103 ++++ moftmp/widget/OverlapLayout.cpp~ | 103 ++++ moftmp/widget/OverlapLayout.hpp | 33 ++ moftmp/widget/OverlapLayout.hpp~ | 33 ++ moftmp/widget/Page.hpp~ | 86 +++ moftmp/widget/Pager.cpp | 254 +++++++++ moftmp/widget/Pager.cpp~ | 254 +++++++++ moftmp/widget/Pager.hpp | 44 ++ moftmp/widget/Pager.hpp~ | 44 ++ moftmp/widget/Widget.hpp | 24 + moftmp/widget/Widget.hpp~ | 24 + moftmp/widget/WidgetView.hpp | 36 ++ moftmp/widget/WidgetView.hpp~ | 36 ++ moftmp/widget/[ | 39 ++ moftmp/widget/utilities.cpp | 20 + moftmp/widget/utilities.cpp~ | 20 + moftmp/widget/utilities.hpp | 19 + moftmp/widget/utilities.hpp~ | 21 + moftmp/widgets.hpp | 18 + 279 files changed, 18480 insertions(+) create mode 100755 moftmp/AbstractScene.cpp create mode 100755 moftmp/AmbientLight.cpp create mode 100755 moftmp/AmbientLight.hpp create mode 100755 moftmp/Application.cpp create mode 100755 moftmp/Application.hpp create mode 100755 moftmp/Board.cpp create mode 100755 moftmp/Board.hpp create mode 100755 moftmp/CSVFile.cpp create mode 100755 moftmp/CSVFile.h create mode 100755 moftmp/Camera.cpp create mode 100755 moftmp/Camera.hpp create mode 100755 moftmp/Captor.cpp create mode 100755 moftmp/Captor.hpp create mode 100755 moftmp/Color.cpp create mode 100755 moftmp/Color.hpp create mode 100755 moftmp/ColorComponent.hpp create mode 100755 moftmp/Component2D.cpp create mode 100755 moftmp/Component2D.h create mode 100755 moftmp/Component2D.hpp create mode 100755 moftmp/Component3D.cpp create mode 100755 moftmp/Component3D.hpp create mode 100755 moftmp/ConsoleIO.cpp create mode 100755 moftmp/ConsoleIO.hpp create mode 100755 moftmp/Container2D.cpp create mode 100755 moftmp/Container2D.h create mode 100755 moftmp/Container3D.cpp create mode 100755 moftmp/Container3D.h create mode 100755 moftmp/DataRow.cpp create mode 100755 moftmp/DataRow.h create mode 100755 moftmp/DataTable.cpp create mode 100755 moftmp/DataTable.h create mode 100755 moftmp/Deleter.hpp create mode 100755 moftmp/DeviceInputReceiver.cpp create mode 100755 moftmp/DirectionalLight.cpp create mode 100755 moftmp/DirectionalLight.h create mode 100755 moftmp/Drawable.hpp create mode 100755 moftmp/EventCondition.hpp create mode 100755 moftmp/EventScheduler.cpp create mode 100755 moftmp/EventScheduler.hpp create mode 100755 moftmp/FactoryMethod.hpp create mode 100755 moftmp/FilePath.cpp create mode 100755 moftmp/FilePath.hpp create mode 100755 moftmp/FileTextureBuilder.cpp create mode 100755 moftmp/Finalizer.hpp create mode 100755 moftmp/Font.cpp create mode 100755 moftmp/Font.hpp create mode 100755 moftmp/Graphics3D.hpp create mode 100755 moftmp/GraphicsDevice.cpp create mode 100755 moftmp/GraphicsDevice.hpp create mode 100755 moftmp/GraphicsObject.cpp create mode 100755 moftmp/GraphicsSchedule.cpp create mode 100755 moftmp/GraphicsSchedule.h create mode 100755 moftmp/GraphicsUnit.hpp create mode 100755 moftmp/InputDevice.cpp create mode 100755 moftmp/InputDevice.hpp create mode 100755 moftmp/InputEventCondition.cpp create mode 100755 moftmp/InputEventCondition.hpp create mode 100755 moftmp/InputReceiver.hpp create mode 100755 moftmp/InstructionSet.hpp create mode 100755 moftmp/Interpolation.hpp create mode 100755 moftmp/Interpreter.cpp create mode 100755 moftmp/Interpreter.hpp create mode 100755 moftmp/KeyPressedEventCondition.cpp create mode 100755 moftmp/KeyPressedEventCondition.hpp create mode 100755 moftmp/Light.cpp create mode 100755 moftmp/Light.hpp create mode 100755 moftmp/Line3D.cpp create mode 100755 moftmp/Line3D.h create mode 100755 moftmp/LoggedInputReceiver.cpp create mode 100755 moftmp/LoggedInputReceiver.hpp create mode 100755 moftmp/LoggingInputReceiver.cpp create mode 100755 moftmp/LoggingInputReceiver.hpp create mode 100755 moftmp/LuaScript.cpp create mode 100755 moftmp/LuaScript.hpp create mode 100755 moftmp/Material.hpp create mode 100755 moftmp/MaterialBuilder.cpp create mode 100755 moftmp/MaterialBuilder.hpp create mode 100755 moftmp/Matrix2D.cpp create mode 100755 moftmp/Matrix2D.hpp create mode 100755 moftmp/Matrix3D.cpp create mode 100755 moftmp/Matrix3D.hpp create mode 100755 moftmp/Mesh.cpp create mode 100755 moftmp/MeshBuilder.cpp create mode 100755 moftmp/MeshBuilder.hpp create mode 100755 moftmp/MeshResource.h create mode 100755 moftmp/OnceEventCondition.cpp create mode 100755 moftmp/OnceEventCondition.hpp create mode 100755 moftmp/PixelMap.hpp create mode 100755 moftmp/PixelMapTextureBuilder.cpp create mode 100755 moftmp/PlainWidgetView.cpp create mode 100755 moftmp/PlainWidgetView.hpp create mode 100755 moftmp/Rectangle.hpp create mode 100755 moftmp/ResourceManager.hpp create mode 100755 moftmp/SceneGraph.hpp create mode 100755 moftmp/SelectionModel.cpp create mode 100755 moftmp/SelectionModel.h create mode 100755 moftmp/Sprite.cpp create mode 100755 moftmp/Sprite.hpp create mode 100755 moftmp/TextCompiler.cpp create mode 100755 moftmp/TextCompiler.hpp create mode 100755 moftmp/TextView.cpp create mode 100755 moftmp/TextView.hpp create mode 100755 moftmp/Texture.cpp create mode 100755 moftmp/Texture.hpp create mode 100755 moftmp/TextureComponent.hpp create mode 100755 moftmp/TextureResource.h create mode 100755 moftmp/Timer.cpp create mode 100755 moftmp/Timer.hpp create mode 100755 moftmp/Vector2D.cpp create mode 100755 moftmp/Vector2D.hpp create mode 100755 moftmp/Vector3D.cpp create mode 100755 moftmp/Vector3D.hpp create mode 100755 moftmp/VertexBuffer.cpp create mode 100755 moftmp/VertexBuffer.hpp create mode 100755 moftmp/VertexTypes.hpp create mode 100755 moftmp/Window.cpp create mode 100755 moftmp/Window.hpp create mode 100755 moftmp/graphics/utilities.hpp create mode 100755 moftmp/graphics/utilities.hpp~ create mode 100755 moftmp/mofGraphics.hpp create mode 100755 moftmp/mofInput.hpp create mode 100755 moftmp/moflib.vcproj create mode 100755 moftmp/moflib.vcproj.TOMOHIRO.TomohiroYasuda.user create mode 100755 moftmp/private/DeviceInputReceiver.hpp create mode 100755 moftmp/private/DirectInput.hpp create mode 100755 moftmp/private/FileTextureBuilder.cpp create mode 100755 moftmp/private/FileTextureBuilder.hpp create mode 100755 moftmp/private/GraphicsDeviceImpl.hpp create mode 100755 moftmp/private/Interpreter.hpp create mode 100755 moftmp/private/Interpreter.hpp~ create mode 100755 moftmp/private/Mesh.hpp create mode 100755 moftmp/private/MeshDisposer.hpp create mode 100755 moftmp/private/PixelMapTextureBuilder.hpp create mode 100755 moftmp/private/TextureBuilder.hpp create mode 100755 moftmp/private/TextureImpl.hpp create mode 100755 moftmp/private/VertexFVF.hpp create mode 100755 moftmp/private/commands.hpp~ create mode 100755 moftmp/private/message.cpp~ create mode 100755 moftmp/private/regist.cpp create mode 100755 moftmp/private/regist.cpp~ create mode 100755 moftmp/private/regist.hpp create mode 100755 moftmp/private/regist.hpp~ create mode 100755 moftmp/real.hpp create mode 100755 moftmp/stream/Animation.hpp~ create mode 100755 moftmp/stream/AnimationPlayer.hpp create mode 100755 moftmp/stream/AnimationPlayer.hpp~ create mode 100755 moftmp/stream/AnimationScheduler.cpp create mode 100755 moftmp/stream/BoundsAnimation.hpp create mode 100755 moftmp/stream/BoundsAnimation.hpp~ create mode 100755 moftmp/stream/Cache.cpp create mode 100755 moftmp/stream/Cache.cpp~ create mode 100755 moftmp/stream/Cache.hpp create mode 100755 moftmp/stream/Cache.hpp~ create mode 100755 moftmp/stream/Cascade.hpp create mode 100755 moftmp/stream/Cascade.hpp~ create mode 100755 moftmp/stream/CascadeAnimation.cpp create mode 100755 moftmp/stream/CascadingAnimation.hpp~ create mode 100755 moftmp/stream/Constant.hpp create mode 100755 moftmp/stream/Constant.hpp~ create mode 100755 moftmp/stream/DataBasedAnimation.cpp create mode 100755 moftmp/stream/DataBasedAnimation.h create mode 100755 moftmp/stream/DefaultAnimationPlayer.cpp create mode 100755 moftmp/stream/DefaultAnimationPlayer.hpp create mode 100755 moftmp/stream/DefaultAnimationPlayer.hpp~ create mode 100755 moftmp/stream/Filter.hpp create mode 100755 moftmp/stream/Filter.hpp~ create mode 100755 moftmp/stream/Joint.hpp create mode 100755 moftmp/stream/Joint.hpp~ create mode 100755 moftmp/stream/JointAnimation.hpp~ create mode 100755 moftmp/stream/KeyFrameAnimation.hpp create mode 100755 moftmp/stream/KeyFrameAnimation.hpp~ create mode 100755 moftmp/stream/Loop.hpp create mode 100755 moftmp/stream/Loop.hpp~ create mode 100755 moftmp/stream/LoopAnimation.hpp~ create mode 100755 moftmp/stream/Manipulator.hpp create mode 100755 moftmp/stream/Manipulator.hpp~ create mode 100755 moftmp/stream/Offset.hpp create mode 100755 moftmp/stream/Offset.hpp~ create mode 100755 moftmp/stream/OffsetAnimation.hpp~ create mode 100755 moftmp/stream/ParametricAnimation.hpp create mode 100755 moftmp/stream/ParametricAnimation.hpp~ create mode 100755 moftmp/stream/Reference.hpp create mode 100755 moftmp/stream/Reference.hpp~ create mode 100755 moftmp/stream/ReferenceWrapper.hpp create mode 100755 moftmp/stream/ReferenceWrapper.hpp~ create mode 100755 moftmp/stream/Rotation2D.hpp create mode 100755 moftmp/stream/Rotation2D.hpp~ create mode 100755 moftmp/stream/RotationAnimation2D.hpp~ create mode 100755 moftmp/stream/RotationAnimation3D.hpp create mode 100755 moftmp/stream/RotationAnimation3D.hpp~ create mode 100755 moftmp/stream/Scaling2D.hpp create mode 100755 moftmp/stream/Scaling2D.hpp~ create mode 100755 moftmp/stream/ScalingAnimation2D.hpp~ create mode 100755 moftmp/stream/ScalingAnimation3D.hpp create mode 100755 moftmp/stream/ScalingAnimation3D.hpp~ create mode 100755 moftmp/stream/Stream.hpp~ create mode 100755 moftmp/stream/Translation2D.hpp create mode 100755 moftmp/stream/Translation2D.hpp~ create mode 100755 moftmp/stream/TranslationAnimation2D.hpp~ create mode 100755 moftmp/stream/TranslationAnimation3D.hpp create mode 100755 moftmp/stream/TranslationAnimation3D.hpp~ create mode 100755 moftmp/stream/TypeStream.hpp create mode 100755 moftmp/stream/TypeStream.hpp~ create mode 100755 moftmp/stream/UniformAnimation.hpp create mode 100755 moftmp/stream/UniformAnimation.hpp~ create mode 100755 moftmp/stream/mofAnimations.hpp~ create mode 100755 moftmp/stream/utilities.cpp create mode 100755 moftmp/stream/utilities.cpp~ create mode 100755 moftmp/stream/utilities.hpp create mode 100755 moftmp/stream/utilities.hpp~ create mode 100755 moftmp/streams.hpp create mode 100755 moftmp/tests/Alltests.cpp create mode 100755 moftmp/tests/SceneGraphTest.cpp create mode 100755 moftmp/tests/TimerTest.cpp create mode 100755 moftmp/tstring.hpp create mode 100755 moftmp/utilities.hpp create mode 100755 moftmp/widget/ButtonWidgetView.hpp~ create mode 100755 moftmp/widget/Container.cpp create mode 100755 moftmp/widget/Container.cpp~ create mode 100755 moftmp/widget/Container.hpp create mode 100755 moftmp/widget/Container.hpp~ create mode 100755 moftmp/widget/ContainerWidgetView.cpp~ create mode 100755 moftmp/widget/ContainerWidgetView.hpp~ create mode 100755 moftmp/widget/Effect.cpp create mode 100755 moftmp/widget/Effect.cpp~ create mode 100755 moftmp/widget/Effect.hpp create mode 100755 moftmp/widget/Effect.hpp~ create mode 100755 moftmp/widget/Frame.cpp create mode 100755 moftmp/widget/Frame.cpp~ create mode 100755 moftmp/widget/Frame.hpp create mode 100755 moftmp/widget/Frame.hpp~ create mode 100755 moftmp/widget/FrameBuilder.hpp create mode 100755 moftmp/widget/FrameBuilder.hpp~ create mode 100755 moftmp/widget/GridLayout.cpp create mode 100755 moftmp/widget/GridLayout.cpp~ create mode 100755 moftmp/widget/GridLayout.hpp create mode 100755 moftmp/widget/GridLayout.hpp~ create mode 100755 moftmp/widget/ImageView.cpp create mode 100755 moftmp/widget/ImageView.cpp~ create mode 100755 moftmp/widget/ImageView.hpp create mode 100755 moftmp/widget/ImageView.hpp~ create mode 100755 moftmp/widget/ImageWidgetView.cpp~ create mode 100755 moftmp/widget/ImageWidgetView.hpp~ create mode 100755 moftmp/widget/Layout.hpp create mode 100755 moftmp/widget/Layout.hpp~ create mode 100755 moftmp/widget/LayoutManager.cpp~ create mode 100755 moftmp/widget/LayoutManager.hpp~ create mode 100755 moftmp/widget/Menu.cpp create mode 100755 moftmp/widget/Menu.cpp~ create mode 100755 moftmp/widget/Menu.hpp create mode 100755 moftmp/widget/Menu.hpp~ create mode 100755 moftmp/widget/MenuWidget.cpp~ create mode 100755 moftmp/widget/MenuWidget.hpp~ create mode 100755 moftmp/widget/Message.hpp create mode 100755 moftmp/widget/Message.hpp~ create mode 100755 moftmp/widget/MessageWidget.cpp create mode 100755 moftmp/widget/MessageWidget.cpp20090811 create mode 100755 moftmp/widget/MessageWidget.cpp~ create mode 100755 moftmp/widget/MessageWidget.hpp create mode 100755 moftmp/widget/MessageWidget.hpp~ create mode 100755 moftmp/widget/OverlapLayout.cpp create mode 100755 moftmp/widget/OverlapLayout.cpp~ create mode 100755 moftmp/widget/OverlapLayout.hpp create mode 100755 moftmp/widget/OverlapLayout.hpp~ create mode 100755 moftmp/widget/Page.hpp~ create mode 100755 moftmp/widget/Pager.cpp create mode 100755 moftmp/widget/Pager.cpp~ create mode 100755 moftmp/widget/Pager.hpp create mode 100755 moftmp/widget/Pager.hpp~ create mode 100755 moftmp/widget/Widget.hpp create mode 100755 moftmp/widget/Widget.hpp~ create mode 100755 moftmp/widget/WidgetView.hpp create mode 100755 moftmp/widget/WidgetView.hpp~ create mode 100755 moftmp/widget/[ create mode 100755 moftmp/widget/utilities.cpp create mode 100755 moftmp/widget/utilities.cpp~ create mode 100755 moftmp/widget/utilities.hpp create mode 100755 moftmp/widget/utilities.hpp~ create mode 100755 moftmp/widgets.hpp diff --git a/moftmp/AbstractScene.cpp b/moftmp/AbstractScene.cpp new file mode 100755 index 0000000..f036553 --- /dev/null +++ b/moftmp/AbstractScene.cpp @@ -0,0 +1,112 @@ +#include "mof/AbstractScene.h" +#include "mof/ConsoleIO.h" + + + + +mof::AbstractScene::AbstractScene() { + //m_state = mof::AbstractScene::UNINITIALIZED; + //m_beginEffect = NULL; + //m_endEffect = NULL; + m_active = true; + //m_initialized = false; +} + + +mof::AbstractScene::~AbstractScene(){ + //delete m_beginEffect; + //delete m_endEffect; + +} +/* +bool mof::AbstractScene::isInitialized(){ + return (m_state != mof::AbstractScene::UNINITIALIZED); +}*/ + + +bool mof::AbstractScene::isActive(){ + return m_active;//(m_state == mof::AbstractScene::ACTIVE || m_state == mof::AbstractScene::OPENING || m_state == mof::AbstractScene::CLOSING); +} + +/* +bool mof::AbstractScene::isClosing(){ + return m_state == mof::AbstractScene::CLOSING; +} + + +bool mof::AbstractScene::isOpening(){ + return m_state == mof::AbstractScene::OPENING; +}*/ +/* +void mof::AbstractScene::setBeginEffect(Effect* effect){ + delete m_beginEffect; + m_beginEffect = effect; + if(effect != NULL)effect->addEffectListener(this); +} + +mof::Effect* mof::AbstractScene::getBeginEffect(){ + return m_beginEffect; +} + + +void mof::AbstractScene::setEndEffect(Effect* effect){ + delete m_endEffect; + m_endEffect = effect; + if(effect != NULL)effect->addEffectListener(this); +} + +mof::Effect* mof::AbstractScene::getEndEffect(){ + return m_endEffect; +}*/ + +/* +bool mof::AbstractScene::initialize(){ + m_state = mof::AbstractScene::INITIALIZED; + //Activate(true); + return true; +}*/ + +void mof::AbstractScene::activate(bool activate){ + m_active = activate; + /*if(activate){ + m_state = mof::AbstractScene::ACTIVE; + //playBeginEffect(); + //InputCore::getInstance()->addListener(this); + } + else { + m_state = mof::AbstractScene::UNACTIVE; + //playEndEffect(); + ////InputCore::getInstance()->removeListener(this); + + }*/ +} + +/* +void mof::AbstractScene::notifyEffectEvent(EffectEvent& effectEvent){ + if(effectEvent.object == m_beginEffect && effectEvent.type == EffectEvent::FINISHED){ + m_state = mof::AbstractScene::ACTIVE; + } + if(effectEvent.object == m_endEffect && effectEvent.type == EffectEvent::FINISHED){ + m_state = mof::AbstractScene::UNACTIVE; + } +} + + +void mof::AbstractScene::playBeginEffect(){ + if(m_beginEffect == NULL){ + m_state = mof::AbstractScene::ACTIVE; + return; + } + m_state = mof::AbstractScene::OPENING; + m_beginEffect->play(); +} + + +void mof::AbstractScene::playEndEffect(){ + if(m_endEffect == NULL){ + m_state = mof::AbstractScene::UNACTIVE; + return; + } + m_state = mof::AbstractScene::CLOSING; + m_endEffect->play(); +}*/ diff --git a/moftmp/AmbientLight.cpp b/moftmp/AmbientLight.cpp new file mode 100755 index 0000000..ec78af5 --- /dev/null +++ b/moftmp/AmbientLight.cpp @@ -0,0 +1,74 @@ +#include "mof/AmbientLight.hpp" +#include "mof/ConsoleIO.hpp" +#include "mof/private/GraphicsDeviceImpl.hpp" + +struct mof::AmbientLight::Impl{ + mof::Color lastAmbient; + bool enable; + + Impl(); + ~Impl(); + void reflect( mof::Color color , bool force = false); +}; + +mof::AmbientLight::Impl::Impl() +: enable(true) +{ +} + +mof::AmbientLight::Impl::~Impl(){ + +} + +mof::AmbientLight::AmbientLight( mof::Color4f color ) +: m_pImpl( new Impl() ) , mof::Light() +{ + setDiffuseColor(color); + m_pImpl->reflect( m_diffuseColor->getValue(m_frame).toColorCode() , true); +} + + +mof::AmbientLight::~AmbientLight(){ + try{ + setEnable(false);//—áŠO‚ð“Š‚°‚é‚©‚à + }catch(std::exception& ){ + } +} + +void mof::AmbientLight::setFrameNumber(mof::FrameNumber frame){ + m_frame = frame; + m_pImpl->reflect( m_diffuseColor->getValue(m_frame).toColorCode() ); + +} + +void mof::AmbientLight::nextFrame(){ + setFrameNumber(m_frame + 1); +} + +void mof::AmbientLight::prevFrame(){ + if(m_frame > 0)setFrameNumber(m_frame - 1); +} + + +void mof::AmbientLight::setEnable(bool enable){ + if(!m_pImpl->enable && enable){ + m_pImpl->enable = enable; + m_pImpl->reflect( m_diffuseColor->getValue(m_frame).toColorCode() ); + } + else if(m_pImpl->enable && !enable){ + m_pImpl->enable = enable; + m_pImpl->reflect( m_diffuseColor->getValue(m_frame).toColorCode() ); + } +} + + +void mof::AmbientLight::Impl::reflect(mof::Color color , bool force){ + //•¡”‚̃Aƒ“ƒrƒGƒ“ƒg‚ðƒTƒ|[ƒg‚·‚é‚ׂ« + mof::Color ambient = color; + if(!enable)ambient = mof::createColor(0 , 0 , 0); + + if(ambient != lastAmbient || force){ + mof::GraphicsDevice::getRawDevice()->SetRenderState(D3DRS_AMBIENT , ambient); + lastAmbient = ambient; + } +} diff --git a/moftmp/AmbientLight.hpp b/moftmp/AmbientLight.hpp new file mode 100755 index 0000000..901b738 --- /dev/null +++ b/moftmp/AmbientLight.hpp @@ -0,0 +1,32 @@ +#ifndef MOF_AMBIENT_LIGHT +#define MOF_AMBIENT_LIGHT + +#include "mof/Light.hpp" +#include "mof/Color.hpp" +#include + + +namespace mof{ + + + +class AmbientLight : public Light{ + struct Impl; + boost::scoped_ptr m_pImpl; + +public: + AmbientLight( mof::Color4f color = mof::Color4f(1 , 1 , 1)); + virtual ~AmbientLight(); + + virtual void setEnable(bool enable); + + virtual void setFrameNumber(mof::FrameNumber frame); + virtual void nextFrame(); + virtual void prevFrame(); + +}; + +} + + +#endif diff --git a/moftmp/Application.cpp b/moftmp/Application.cpp new file mode 100755 index 0000000..206cdc5 --- /dev/null +++ b/moftmp/Application.cpp @@ -0,0 +1,111 @@ +#include "mof/Application.hpp" +#include "mof/GraphicsDevice.hpp" +#include "mof/Window.hpp" +#include "mof/SceneGraph.hpp" +#include "mof/ConsoleIO.hpp" +#include "mof/Timer.hpp" +#include +#include "mof/Captor.hpp" +#include "mof/InputDevice.hpp" +#include "mof/private/GraphicsDeviceImpl.hpp" +#include "mof/utilities.hpp" +#include "mof/Finalizer.hpp" + +namespace +{ + int m_frameInterval; + int m_nUpdatingPerFrame; + mof::Window* m_pWindow = NULL; +} + +namespace mof +{ + void Application::initialize + ( + const mof::tstring& appname , + int width , + int height , + bool fullscreen , + int frameInterval , + int nUpdatingPerFrame + ) + { + m_frameInterval = frameInterval; + m_nUpdatingPerFrame = nUpdatingPerFrame; + m_pWindow = new mof::Window( appname , width , height , fullscreen ); + mof::GraphicsDevice::initialize( *m_pWindow , width , height , fullscreen ); + mof::InputDevice::initialize( ); + + } + + void Application::finalize( ) + { + mof::GraphicsDevice::finalize(); + mof::InputDevice::finalize(); + delete m_pWindow; + } + + + void Application::run( Scene& scene ) + { + scene.initialize(); + mof::Finalizer finalizer( scene.finalize ); //run‚𔲂¯‚é‚Æ‚«‚ɉð•úˆ—‚ðs‚¤ + MSG msg; + ZeroMemory( &msg, sizeof(msg) ); + mof::Timer timer; + mof::Timer fpsTimer; + int frameCount = 0; + + mof::Captor Captor( _T("output")); + int sleepingTime = 0; + for( ; ; ) + { + while( PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE ) ) + { + if( msg.message == WM_QUIT )return; + GetMessage( &msg , NULL , 0 , 0 ); + TranslateMessage( &msg ); + DispatchMessage( &msg ); + } + + for( int i = 0 ; i < m_nUpdatingPerFrame ; i++ )scene.update();//ƒV[ƒ“‚̏ˆ— + + + mof::GraphicsDevice::beginScene(); + scene.draw();//ƒV[ƒ“‚Ì•`‰æ + //Captor.capture(); + mof::GraphicsDevice::endScene(); + + + + //FPS‚ÌŒv‘ª + int frameTime = timer.getTime(); + if(m_frameInterval > frameTime) + { + Sleep(m_frameInterval - frameTime); + sleepingTime += m_frameInterval - frameTime; + } + + timer.reset(); + + if(++frameCount % 500 == 0) + { + float fps = 500.0f / static_cast(fpsTimer.getTime() - sleepingTime) * 1000; + fpsTimer.reset(); + sleepingTime = 0; + DEBUG_PRINT( "FPS --- " << fps ); + } + } // for + + + } // function run + + void Application::quit( ) + { + PostQuitMessage(0); + } + + +} + + diff --git a/moftmp/Application.hpp b/moftmp/Application.hpp new file mode 100755 index 0000000..c6dbe02 --- /dev/null +++ b/moftmp/Application.hpp @@ -0,0 +1,34 @@ +#pragma once +#include "mof/tstring.hpp" + +namespace mof{ + + struct Scene + { + void ( *initialize ) (); + void ( *finalize ) (); + void ( *update ) (); + void ( *draw ) (); + }; + + namespace Application + { + //private + + //public + void initialize + ( + const mof::tstring& appname , + int width , + int height , + bool fullscreen , + int frameInterval , + int nUpdatingPerFrame + ); + void finalize(); + void run( Scene& scene ); + void quit(); + } + + +} diff --git a/moftmp/Board.cpp b/moftmp/Board.cpp new file mode 100755 index 0000000..e1e6ca3 --- /dev/null +++ b/moftmp/Board.cpp @@ -0,0 +1,110 @@ +#include "mof/Board.hpp" +#include "mof/Camera.hpp" +#include "mof/private/GraphicsDeviceImpl.hpp" +#include "mof/ConsoleIO.hpp" +#include "mof/Constant.hpp" + +struct mof::Board::Impl{ + boost::shared_ptr pTexture; + mof::Animation::Handler worldMatrix; + mof::Animation::Handler color; + mof::Animation>::Handler textureCoordinates; + + Impl( ) + : + worldMatrix(mof::makeConstantHandler(mof::Matrix3D::createIdentity())) , + textureCoordinates(mof::makeConstantHandler(mof::Rectangle(0 , 0 , 1 , 1))) , + color(mof::makeConstantHandler(mof::Color4f(1 , 1 , 1))) + { + } + + ~Impl(){} +}; + + + +mof::Board::Board() : m_pImpl(new Impl()){ +} + +mof::Board::~Board(){ +} + + + + +void mof::Board::setWorldMatrix(const mof::Animation::Handler& handler){ + m_pImpl->worldMatrix = handler; + +} + + + +void mof::Board::setColor(const mof::Animation::Handler& handler){ + m_pImpl->color = handler; +} + + + + +void mof::Board::setTextureCoordinates(const mof::Animation>::Handler& handler){ + m_pImpl->textureCoordinates = handler; +} + +void mof::Board::setTextureCoordinates(const mof::Rectangle& coordinates){ + setTextureCoordinates(mof::makeConstantHandler(coordinates)); +} + +void mof::Board::setTexture( const boost::shared_ptr& pTexture ){ + m_pImpl->pTexture = pTexture; +} + + +bool mof::Board::isVisible() const{ + return true; +} + +void mof::Board::update(){ + nextFrame(); +} + +void mof::Board::draw() const{ + mof::FrameNumber frame = m_frame; + mof::Rectangle textureCoordinates = m_pImpl->textureCoordinates->getValue(frame); + mof::Color color = m_pImpl->color->getValue(frame).toColorCode(); + static mof::VertexXYZCUV vertices[4]; + vertices[0].x = -0.5f; + vertices[0].y = 0.5f; + vertices[0].z = 0; + vertices[0].color = color; + vertices[0].tu = textureCoordinates.beginX; + vertices[0].tv = textureCoordinates.beginY; + + vertices[1].x = 0.5f; + vertices[1].y = 0.5f; + vertices[1].z = 0; + vertices[1].color = color; + vertices[1].tu = textureCoordinates.endX; + vertices[1].tv = textureCoordinates.beginY; + + vertices[2].x = -0.5f; + vertices[2].y = -0.5f; + vertices[2].z = 0; + vertices[2].color = color; + vertices[2].tu = textureCoordinates.beginX; + vertices[2].tv = textureCoordinates.endY; + + vertices[3].x = 0.5f; + vertices[3].y = -0.5f; + vertices[3].z = 0; + vertices[3].color = color; + vertices[3].tu = textureCoordinates.endX; + vertices[3].tv = textureCoordinates.endY; + + mof::GraphicsDevice::setTexture(m_pImpl->pTexture.get()); + mof::GraphicsDevice::setWorldTransform(m_pImpl->worldMatrix->getValue(frame)); + mof::GraphicsDevice::drawVertexArray(vertices[0] , vertices[3] , PRIMITIVE_TYPE_TRIANGLESTRIP); + + +} + + diff --git a/moftmp/Board.hpp b/moftmp/Board.hpp new file mode 100755 index 0000000..1ff23d7 --- /dev/null +++ b/moftmp/Board.hpp @@ -0,0 +1,41 @@ +#ifndef BILLBOARD_HPP +#define BILLBOARD_HPP + +#include "mof/Component3D.hpp" +#include "mof/SceneGraph.hpp" +#include "mof/Rectangle.hpp" +#include +#include +#include "mof/Texture.hpp" +#include "mof/DefaultAnimationPlayer.hpp" + +namespace mof{ + + +class Camera; + +class Board : public Component3D , public SceneGraph , public DefaultAnimationPlayer{ + struct Impl; + boost::scoped_ptr m_pImpl; + +public : + + Board( ); + virtual ~Board(); + + + virtual void setWorldMatrix(const mof::Animation::Handler& handler); + virtual void setTextureCoordinates(const mof::Animation>::Handler& handler); + virtual void setTextureCoordinates(const mof::Rectangle& coordinates); + virtual void setTexture( const boost::shared_ptr& pTexture ); + + void setColor(const mof::Animation::Handler& handler); + + virtual bool isVisible() const; + virtual void update(); + virtual void draw() const; +}; + +} + +#endif diff --git a/moftmp/CSVFile.cpp b/moftmp/CSVFile.cpp new file mode 100755 index 0000000..6dcd62e --- /dev/null +++ b/moftmp/CSVFile.cpp @@ -0,0 +1,177 @@ +#include "mof/CSVFile.h" +#include +#include +#include "mof/ConsoleIO.h" + +mof::CSVFile::CSVFile(mof::tstring& filename) +: m_ifs(filename.c_str() , std::ios::in) , m_bufferSize(1024){ + if(!m_ifs)throw std::invalid_argument("can't open file"); + m_buffer = new TCHAR[m_bufferSize+1];//’ljÁƒkƒ‹•¶Žš‚Ì‚½‚ß‚É‚P‚—]•ª‚ÉŠm•Û + m_buffer[m_bufferSize] = '\0'; + m_topOfBuffer = m_bufferSize-1; + m_hasBufferedValue = false; + m_ignoreNL = true; + m_pBufferedValue = NULL; + nextLine(); +} + + + +mof::CSVFile::CSVFile(const TCHAR* filename) +: m_ifs(filename , std::ios::in) , m_bufferSize(1024){ + if(!m_ifs)throw std::invalid_argument("can't open file"); + m_buffer = new TCHAR[m_bufferSize+1];//’ljÁƒkƒ‹•¶Žš‚Ì‚½‚ß‚É‚P‚—]•ª‚ÉŠm•Û + m_buffer[m_bufferSize] = '\0'; + m_topOfBuffer = m_bufferSize-1; + m_hasBufferedValue = false; + m_ignoreNL = true; + m_pBufferedValue = NULL; + + + nextLine(); +} + + +mof::CSVFile::~CSVFile(){ + delete[] m_buffer; + +} + +bool mof::CSVFile::hasNextValue(){ + if(m_hasBufferedValue)return true;//Value‚̃oƒbƒtƒ@‚ª‚ ‚é + + //if(m_topOfBuffer == m_bufferSize && !nextLine())return false;//‚±‚ꂪ‚È‚¢‚ƃoƒO‚邪A‰º‚̃‹[ƒ`ƒ“‚ƈê–{‰»‚Å‚«‚È‚¢‚© + + while(!updateNextValue() && m_ignoreNL){ + if( m_topOfBuffer >= m_bufferSize || m_buffer[m_topOfBuffer] == '\0'){ + //ƒoƒbƒtƒ@‚ð“ǂݍž‚Þ + m_topOfBuffer = m_ifs.getline(m_buffer , m_bufferSize) ? 0 : m_bufferSize; + if(m_topOfBuffer >= m_bufferSize)return false; + } + } + return m_pBufferedValue != NULL; + + //if(m_topOfBuffer == m_bufferSize) +} + + + +const TCHAR* mof::CSVFile::getNextValue(){ + if(m_hasBufferedValue && hasNextValue()){//Value‚̃oƒbƒtƒ@‚ª‚ ‚ê‚΂»‚ê‚ðŽg‚¤ + m_hasBufferedValue = false; + return m_pBufferedValue; + } + + //ŽŸ‚Ì’l‚ª‚È‚¢ê‡ + return NULL; + +} + + + + +bool mof::CSVFile::nextLine(){ + m_hasBufferedValue = false; + m_topOfBuffer = m_ifs.getline(m_buffer , m_bufferSize) ? 0 : m_bufferSize; + return m_topOfBuffer == 0; +} + + +void mof::CSVFile::setIgnoreNL(bool ignore){ + m_ignoreNL = ignore; +} + + + +bool mof::CSVFile::updateNextValue(){ + + if(m_topOfBuffer == m_bufferSize){ + //’l‚È‚µ + m_pBufferedValue = NULL; + m_hasBufferedValue = false; + return false; + } + + enum{ + ISPACE , ICOMMA , IQUOTE , IWORD , IEOF + }; + enum{ + S , NQV , QV , NQE , QE , QVQ , + //‰Šúó‘ԁA”ñƒNƒH[ƒg’lAƒNƒH[ƒg’lA”ñƒNƒH[ƒgƒGƒXƒP[ƒvAƒNƒH[ƒgƒGƒXƒP[ƒvAƒNƒH[ƒg‚ň͂܂ꂽ’l + _NULL , _EMP , _V , _ERR , _QVQ + //’l‚È‚µA‹ó•¶Žš—ñA’lAƒGƒ‰[AƒNƒH[ƒg‚ň͂܂ꂽ’l + }; + static const int stateChangeTable[][5] = { + { S , _EMP , QV , NQV , _NULL } , + { NQV , _V , NQE , NQV , _V} , + { QV , QV , QE , QV , _ERR} , + { _ERR , _ERR , NQV , _ERR , _ERR} , + { QVQ , _QVQ , QV , _ERR , _QVQ} , + { QVQ , _QVQ , _ERR , _ERR , _QVQ} + + }; + + + int state = S; + int lastInput = IEOF; + int begin = m_topOfBuffer; + while( state < _NULL ){//I—¹ó‘Ô‚É‚È‚Á‚½‚甲‚¯‚é + lastInput = IWORD; + if( m_buffer[m_topOfBuffer] == '\0'){ + lastInput = IEOF; + } + else if( m_buffer[m_topOfBuffer] == ' ')lastInput = ISPACE; + else if(m_buffer[m_topOfBuffer] == '"')lastInput = IQUOTE; + else if(m_buffer[m_topOfBuffer] == ',')lastInput = ICOMMA; + state = stateChangeTable[state][lastInput]; + m_topOfBuffer++; + } + m_hasBufferedValue = true; + + if(state == _NULL){ + //’l‚È‚µ + m_pBufferedValue = NULL; + m_topOfBuffer = m_bufferSize; + m_hasBufferedValue = false; + return false; + } + else if(state == _EMP){ + m_pBufferedValue = ""; + return true; + } + else if(state == _V || state == _QVQ){ + int end = m_topOfBuffer-2; + //‘OŒã‚©‚çƒgƒŠƒ~ƒ“ƒO + while(m_buffer[begin] == ' ')begin++; + while(m_buffer[end] == ' ' )end--; + + if(state == _QVQ){ + //—¼’[‚́h‚ðœ‹Ž + begin++; + end--; + } + + //"‚̃GƒXƒP[ƒvˆ— + //Œã‚ë‚©‚猩‚Ä‚¢‚Á‚Ä"‚ª‚ ‚ê‚΃Rƒs[‚·‚é + m_buffer[end+1] = '\0'; + for(int tmp = end ; begin < tmp ; tmp--){ + if(m_buffer[tmp] == '"'){ + memmove(m_buffer + tmp-1 , m_buffer+ tmp , sizeof(TCHAR)*(end-tmp+2)); + tmp--; + } + + } + m_pBufferedValue = m_buffer + begin; + return true; + } + else { + //ƒGƒ‰[(ŽŸ‚Ì,‚܂œǂݐi‚ß‚é) m_buffer‚Ì––”ö‚̓kƒ‹•¶Žš‚È‚Ì‚Å•K‚¸’âŽ~‚·‚é + while(lastInput != ',' && lastInput != '\0'){ + lastInput = m_buffer[++m_topOfBuffer]; + } + m_topOfBuffer++; + m_pBufferedValue = "ERROR"; + return true; + } + +} diff --git a/moftmp/CSVFile.h b/moftmp/CSVFile.h new file mode 100755 index 0000000..f3b3cc5 --- /dev/null +++ b/moftmp/CSVFile.h @@ -0,0 +1,28 @@ +#pragma once +#include "mof/tstring.h" +#include + +namespace mof{ + + class CSVFile{ + //bool m_trimming; + std::basic_ifstream m_ifs; + TCHAR* m_buffer; + const int m_bufferSize; + int m_topOfBuffer; + bool m_hasBufferedValue; + TCHAR* m_pBufferedValue; + bool m_ignoreNL; + bool updateNextValue(); + public: + CSVFile(mof::tstring& filename); + CSVFile(const TCHAR* filename); + ~CSVFile(); + + bool hasNextValue(); + const TCHAR* getNextValue(); + bool nextLine(); + void setIgnoreNL(bool ignore); + }; + +}; \ No newline at end of file diff --git a/moftmp/Camera.cpp b/moftmp/Camera.cpp new file mode 100755 index 0000000..9355ba7 --- /dev/null +++ b/moftmp/Camera.cpp @@ -0,0 +1,108 @@ +#include "mof/Camera.hpp" +#include "mof/Constant.hpp" +#include + +struct mof::Camera::Impl{ + mof::Animation::Handler eye; + mof::Animation::Handler center; + mof::Animation::Handler up; + mof::FrameNumber frame; + + Impl( + const mof::Animation::Handler& eye_ , + const mof::Animation::Handler& center_ , + const mof::Animation::Handler& up_ + ) : eye(eye_) , center(center_) , up(up_) , frame(0){} + + ~Impl(){} +}; + + +mof::Camera::Camera( + const mof::Animation::Handler& eye , + const mof::Animation::Handler& center , + const mof::Animation::Handler& up + ) : m_pImpl(new Impl(eye , center , up)){ +} + +mof::Camera::Camera( + const mof::Vector3D& eye , + const mof::Vector3D& center , + const mof::Vector3D& up + ) : m_pImpl(new Impl( + mof::makeConstantHandler(eye) , + mof::makeConstantHandler(center) , + mof::makeConstantHandler(up) + )){ +} + +mof::Camera::~Camera(){ +} + +mof::Matrix3D mof::Camera::getViewMatrix() const{ + return mof::Matrix3D::createLookAtLH( + m_pImpl->eye->getValue(m_pImpl->frame) , + m_pImpl->center->getValue(m_pImpl->frame) , + m_pImpl->up->getValue(m_pImpl->frame) + ); +} + +void mof::Camera::setEye(const mof::Animation::Handler& eye){ + m_pImpl->eye = eye; +} + + +void mof::Camera::setEye(const mof::Vector3D& eye){ + m_pImpl->eye = mof::makeConstantHandler(eye); +} + +void mof::Camera::setCenter(const mof::Animation::Handler& center){ + m_pImpl->center = center; +} + + +void mof::Camera::setCenter(const mof::Vector3D& center){ + m_pImpl->center = mof::makeConstantHandler(center); +} + + +void mof::Camera::setUp(const mof::Animation::Handler& up){ + m_pImpl->up = up; +} + + +void mof::Camera::setUp(const mof::Vector3D& up){ + m_pImpl->up = mof::makeConstantHandler(up); +} + + +mof::Vector3D mof::Camera::getEye() const{ + return m_pImpl->eye->getValue(m_pImpl->frame); +} + + +mof::Vector3D mof::Camera::getCenter() const{ + return m_pImpl->center->getValue(m_pImpl->frame); +} + + +mof::Vector3D mof::Camera::getUp() const{ + return m_pImpl->up->getValue(m_pImpl->frame); +} + + + + +void mof::Camera::setFrameNumber(mof::FrameNumber frame){ + m_pImpl->frame = frame; +} + + +void mof::Camera::nextFrame(){ + m_pImpl->frame++; +} + +void mof::Camera::prevFrame(){ + if(m_pImpl->frame > 0)m_pImpl->frame--; +} + diff --git a/moftmp/Camera.hpp b/moftmp/Camera.hpp new file mode 100755 index 0000000..9c6d196 --- /dev/null +++ b/moftmp/Camera.hpp @@ -0,0 +1,44 @@ +#ifndef MOF_CAMERA_HPP +#define mOF_CAMERA_HPP +#include "mof/Vector3D.hpp" +#include "mof/AnimationPlayer.hpp" +#include +#include "mof/Matrix3D.hpp" + +namespace mof{ + + + class Camera : public mof::AnimationPlayer{ + struct Impl; + boost::scoped_ptr m_pImpl; + + public: + Camera( + const mof::Animation::Handler& eye , + const mof::Animation::Handler& center , + const mof::Animation::Handler& up ); + Camera(const mof::Vector3D& eye , const mof::Vector3D& center , const mof::Vector3D& up); + virtual ~Camera(); + + mof::Matrix3D getViewMatrix() const; + + void setEye(const mof::Animation::Handler& eye); + void setEye(const mof::Vector3D& eye); + void setCenter(const mof::Animation::Handler& center); + void setCenter(const mof::Vector3D& center); + void setUp(const mof::Animation::Handler& up); + void setUp(const mof::Vector3D& up); + + mof::Vector3D getEye() const; + mof::Vector3D getCenter() const; + mof::Vector3D getUp() const; + + virtual void setFrameNumber(mof::FrameNumber frame); + virtual void nextFrame(); + virtual void prevFrame(); + + }; + +} + +#endif diff --git a/moftmp/Captor.cpp b/moftmp/Captor.cpp new file mode 100755 index 0000000..7421825 --- /dev/null +++ b/moftmp/Captor.cpp @@ -0,0 +1,48 @@ +#include "mof/Captor.hpp" +#include "mof/private/GraphicsDeviceImpl.hpp" +#include "mof/FilePath.hpp" +#include "mof/ConsoleIO.hpp" +#include + + +mof::Captor::Captor(const mof::tstring& output) +: m_output(output) +{ + m_num = 0; +} + +mof::Captor::~Captor(){ + +} + +bool mof::Captor::capture(){ + mof::otstringstream os; + os << m_output.c_str() << _T("/") << m_num << _T(".bmp"); + return capture(os.str().c_str()); +} + + + +bool mof::Captor::capture(const mof::tstring& filename){ + + LPDIRECT3DDEVICE9 pDevice = mof::GraphicsDevice::getRawDevice(); + + LPDIRECT3DSURFACE9 pBackBuffer; + HRESULT hr = pDevice->GetBackBuffer(0 , 0 , D3DBACKBUFFER_TYPE_MONO , &pBackBuffer); + if(FAILED(hr))throw std::runtime_error("Failed --- GetBackBuffer"); + D3DSURFACE_DESC desc; + pBackBuffer->GetDesc(&desc); + + hr = D3DXSaveSurfaceToFile( + filename.c_str() , D3DXIFF_BMP , pBackBuffer , + NULL , NULL); + pBackBuffer->Release(); + if(FAILED(hr)){ + + throw std::runtime_error("Failed -- D3DXSaveSurfaceToFile"); + } + m_num++; + return true; + + +} diff --git a/moftmp/Captor.hpp b/moftmp/Captor.hpp new file mode 100755 index 0000000..9e5de20 --- /dev/null +++ b/moftmp/Captor.hpp @@ -0,0 +1,19 @@ +#pragma once +#include "mof/tstring.hpp" + +namespace mof{ + + class Captor + { + mof::tstring m_output; + int m_num; + + public : + Captor( const mof::tstring& output); + ~Captor(); + bool capture(); + bool capture(const mof::tstring& filename); + + }; + +} diff --git a/moftmp/Color.cpp b/moftmp/Color.cpp new file mode 100755 index 0000000..461aa27 --- /dev/null +++ b/moftmp/Color.cpp @@ -0,0 +1,155 @@ +#include "mof/Color.hpp" +#include +#include "mof/ConsoleIO.hpp" +#include "mof/tstring.hpp" + + +mof::Color4f::Color4f() : + alpha(0) , red(1) , green(1) , blue(1) +{ +} + +mof::Color4f::Color4f(float alpha_ , float red_ , float green_ , float blue_) : + alpha(alpha_) , red(red_) , green(green_) , blue(blue_) +{ +} + +mof::Color4f::Color4f( float red_ , float green_ , float blue_) : + alpha(1) , red(red_) , green(green_) , blue(blue_) +{ +} + +mof::Color4f::Color4f(mof::Color color) : + alpha(static_cast(getAlpha(color)) / 255) , + red(static_cast(getRed(color)) / 255) , + green(static_cast(getGreen(color)) / 255) , + blue(static_cast(getBlue(color)) / 255 ) +{ +} + +mof::Color mof::Color4f::toColorCode() const{ + return createColor( + static_cast(alpha * 255) , + static_cast(red * 255) , + static_cast(green * 255) , + static_cast(blue * 255) + ); +} + +mof::Color4f mof::Color4f::operator +(const mof::Color4f& rhs) const{ + return mof::Color4f( + alpha + rhs.alpha , + red + rhs.red , + green + rhs.green , + blue + rhs.blue ); +} + +mof::Color4f mof::Color4f::operator -(const mof::Color4f& rhs) const{ + return mof::Color4f( + alpha - rhs.alpha , + red - rhs.red , + green - rhs.green , + blue - rhs.blue ); +} + +mof::Color4f mof::Color4f::operator *(const Color4f& color ) const +{ + return mof::Color4f(color.alpha * alpha , color.red * red , color.green * green , color.blue * blue ); +} + +mof::Color4f mof::operator *(const Color4f& color , float f){ + return mof::Color4f(color.alpha * f , color.red * f , color.green * f , color.blue * f); +} + +mof::Color4f mof::operator *(float f , const mof::Color4f & color){ + return mof::Color4f(color.alpha * f , color.red * f , color.green * f , color.blue * f); +} + + + +unsigned char hex2Decimal(const TCHAR* code){ + unsigned char a = *code; + if(a < '0')return 0;//error + else if( a <= '9')return a - '0'; + else if( a < 'A')return 0;//error + else if( a <= 'Z')return a - 'A'+10; + else if( a < 'a')return 0;//error + else if( a <= 'z')return a - 'a'+10; + else return 0;//error +} + +char decimal2hex(unsigned char n){ + if( n >= 16)return '-';//error + return "0123456789abcdef"[n]; +} + +mof::Color mof::createColor(unsigned char r , unsigned char g , unsigned char b){ + return D3DCOLOR_XRGB(r , g , b); +} + +mof::Color mof::createColor(unsigned char a , unsigned char r , unsigned char g , unsigned char b){ + return D3DCOLOR_ARGB(a , r , g , b); +} + + +mof::Color mof::createColor(const mof::tstring& code){ + const TCHAR* pBuffer = code.c_str(); + unsigned char a , r , g , b; + if(code.size() == 8)a = ( hex2Decimal(pBuffer++) << 4 ) + hex2Decimal(pBuffer++); + else if(code.size() != 6)return 0;//error + else a = 0xff; + r = (hex2Decimal(pBuffer++) << 4) + hex2Decimal(pBuffer++); + g = (hex2Decimal(pBuffer++) << 4) + hex2Decimal(pBuffer++); + b = (hex2Decimal(pBuffer++) << 4) + hex2Decimal(pBuffer++); + return createColor(a , r , g , b); +} + +unsigned char mof::getAlpha(const mof::Color& color){ + return (unsigned char)((color >> 24) & 0xff); +} + + +unsigned char mof::getRed(const mof::Color& color){ + return (unsigned char)((color >> 16) & 0xff); +} + +unsigned char mof::getGreen(const mof::Color& color){ + return (unsigned char)((color >> 8) & 0xff); +} + + +unsigned char mof::getBlue(const mof::Color& color){ + return (unsigned char)(color & 0xff); +} + + +mof::Color mof::blendColor( mof::Color a , mof::Color b , float rate ){ + return createColor( + static_cast(getAlpha(a) * rate + getAlpha(b) * (1 - rate)) , //alpha + static_cast(getRed(a) * rate + getRed(b) * (1 - rate)) , //red + static_cast(getGreen(a) * rate + getGreen(b) * (1 - rate)) , //green + static_cast(getBlue(a) * rate + getBlue(b) * (1 - rate)) ); //blue +} + +mof::Color mof::inverseColor(mof::Color src){ + return createColor( + 255 - getAlpha(src) , //alpha + 255 - getRed(src) , //red + 255 - getGreen(src) , //green + 255 - getBlue(src) ); //blue +} + + +mof::tstring mof::toColorCode(mof::Color color){ + mof::otstringstream os; + unsigned char a = getAlpha(color); + unsigned char r = getRed(color); + unsigned char g = getGreen(color); + unsigned char b = getBlue(color); + os << decimal2hex(a >> 4) << decimal2hex(a & 0x0f) + << decimal2hex(r >> 4) << decimal2hex(r & 0x0f) + << decimal2hex(g >> 4) << decimal2hex(g & 0x0f) + << decimal2hex(b >> 4) << decimal2hex(b & 0x0f) ; + return os.str(); + +} diff --git a/moftmp/Color.hpp b/moftmp/Color.hpp new file mode 100755 index 0000000..8cfb697 --- /dev/null +++ b/moftmp/Color.hpp @@ -0,0 +1,43 @@ +#pragma once +#include "mof/tstring.hpp" +#include "mof/real.hpp" + +namespace mof{ + typedef unsigned int Color; + typedef unsigned char ColorChannel; + Color createColor(ColorChannel r , ColorChannel g , ColorChannel b); + Color createColor(ColorChannel a , ColorChannel r , ColorChannel g , ColorChannel b); + Color createColor(const mof::tstring& code); + ColorChannel getRed(const Color& color); + ColorChannel getGreen(const Color& color); + ColorChannel getBlue(const Color& color); + ColorChannel getAlpha(const Color& color); + Color blendColor( Color a , Color b , real rate ); + Color inverseColor( Color color ); + mof::tstring toColorCode( Color color ); + + struct Color4f{ + real red; + real green; + real blue; + real alpha; + + Color4f(); + Color4f(real alpha_ , real red_ , real green_ , real blue_); + Color4f( real red_ , real green_ , real blue_); + explicit Color4f(mof::Color color); + mof::Color toColorCode() const; + + mof::Color4f operator +( const mof::Color4f& rhs ) const ; + mof::Color4f operator -( const mof::Color4f& rhs ) const ; + mof::Color4f operator *( const Color4f& rhs ) const; + + friend mof::Color4f operator *(const Color4f& color , real f); + friend mof::Color4f operator *(real f , const mof::Color4f & color); + + }; + + + + +}; diff --git a/moftmp/ColorComponent.hpp b/moftmp/ColorComponent.hpp new file mode 100755 index 0000000..467fd0b --- /dev/null +++ b/moftmp/ColorComponent.hpp @@ -0,0 +1,50 @@ +#pragma once +#include "mof/stream/utilities.hpp" + +namespace mof +{ + + class ColorComponent + { + public: + virtual ~ColorComponent( ){} + + virtual void setColorStream( const ColorStream& stream ) + { + m_colorStream = stream; + } + + virtual const ColorStream& getColorStream( ) const + { + return m_colorStream; + } + + virtual ColorStream& getColorStream( ) + { + return m_colorStream; + } + + + protected: + ColorStream m_colorStream; + + ColorComponent( ) + : + m_colorStream( makeConstantHandler( Color4f( 1 , 1 , 1 ) ) ) + { + } + + ColorComponent( const Color4f& color ) + : + m_colorStream( makeConstantHandler( color ) ) + { + } + + ColorComponent( const ColorStream& stream ) + : + m_colorStream( stream ) + { + } + + }; +} // namespace mof diff --git a/moftmp/Component2D.cpp b/moftmp/Component2D.cpp new file mode 100755 index 0000000..e69de29 diff --git a/moftmp/Component2D.h b/moftmp/Component2D.h new file mode 100755 index 0000000..5493633 --- /dev/null +++ b/moftmp/Component2D.h @@ -0,0 +1,24 @@ +#pragma once +#include "mof/RectangleModel.h" +#include "mof/Vector2D.h" +#include "mof/GraphicsObject.h" + +namespace mof{ + + class Component2D : public GraphicsObject + { + + public: + Component2D(void); + virtual ~Component2D(void); + + virtual void setPosition(Vector2D& position) = 0; + virtual int getWidth() = 0; + virtual int getHeight() = 0; + virtual mof::Vector2D getPosition() = 0; + + virtual void setVisible(bool visible) = 0; + virtual RectangleModel getBounds() = 0; + }; + +}; \ No newline at end of file diff --git a/moftmp/Component2D.hpp b/moftmp/Component2D.hpp new file mode 100755 index 0000000..f5546d4 --- /dev/null +++ b/moftmp/Component2D.hpp @@ -0,0 +1,104 @@ +#pragma once +#include "mof/stream/utilities.hpp" + +namespace mof +{ + + class Component2D + { + public: + virtual ~Component2D( ){} + + /** コンポーネントの左上の位置を指定する + * @note このメソッドで指定するハンドラとgetPosition()で + * 得られるハンドラは同一であると扱える + * @retval このウィジェットの左上の位置を得るためのハンドラ + */ + /*virtual void setPositionStream( const Vector2DStream& stream ) + { + m_positionStream = stream; + }*/ + + /** コンポーネントの左上の位置を得る + * @note このメソッドで得られるハンドラとsetPosition()で + * 指定したハンドラは同一であると扱える + * @retval このウィジェットの左上の位置を得るためのハンドラ + */ + virtual const Vector2DStream& getPositionStream( ) const + { + return m_positionStream; + } + + /** コンポーネントの左上の位置を得る + * @note このメソッドで得られるハンドラとsetPosition()で + * 指定したハンドラは同一であると扱える + * @retval このウィジェットの左上の位置を得るためのハンドラ + */ + virtual Vector2DStream& getPositionStream( ) + { + return m_positionStream; + } + + + /** コンポーネントの左上の位置を指定する + * @note このメソッドで指定するハンドラとgetPosition()で + * 得られるハンドラは同一であると扱える + * @retval このウィジェットの左上の位置を得るためのハンドラ + */ + /*virtual void setSizeStream( const Vector2DStream& stream ) + { + m_sizeStream = stream; + }*/ + + /** コンポーネントの大きさを得る + * @note このメソッドで得られるハンドラとsetSize()で + * 指定したハンドラは同一であると扱える + * @retval このウィジェットの大きさを得るためのハンドラ + */ + virtual const Vector2DStream& getSizeStream( ) const + { + return m_sizeStream; + } + + /** コンポーネントの大きさを得る + * @note このメソッドで得られるハンドラとsetSize()で + * 指定したハンドラは同一であると扱える + * @retval このウィジェットの大きさを得るためのハンドラ + */ + virtual Vector2DStream& getSizeStream( ) + { + return m_sizeStream; + } + + + protected: + Vector2DStream m_positionStream; + Vector2DStream m_sizeStream; + + Component2D( ) + : + m_positionStream( makeConstantHandler( Vector2D( 0 , 0 ) ) ) , + m_sizeStream( makeConstantHandler( Vector2D( 0 , 0 ) ) ) + { + } + + Component2D( const Rectangle< int >& region ) + : + m_positionStream + ( + makeConstantHandler + ( + Vector2D(region.beginX , region.beginY) + ) + ) , + m_sizeStream + ( + makeConstantHandler + ( + Vector2D(region.getWidth() , region.getHeight()) + ) + ) + {} + + }; +} // namespace mof diff --git a/moftmp/Component3D.cpp b/moftmp/Component3D.cpp new file mode 100755 index 0000000..1c747a1 --- /dev/null +++ b/moftmp/Component3D.cpp @@ -0,0 +1,7 @@ +#include "mof/Component3D.hpp" +#include "mof/Constant.hpp" +#include "mof/Matrix3D.hpp" + +void mof::Component3D::setWorldMatrix(const mof::Matrix3D& matrix){ + setWorldMatrix(mof::makeConstantHandler(matrix)); +} diff --git a/moftmp/Component3D.hpp b/moftmp/Component3D.hpp new file mode 100755 index 0000000..ce0a282 --- /dev/null +++ b/moftmp/Component3D.hpp @@ -0,0 +1,22 @@ + +//#include "mof/Matrix3D.hpp" + +#include "mof/Vector3D.hpp" +#include "mof/stream/Manipulator.hpp" + +namespace mof{ +class Matrix3D; + +class Component3D { + +public: + ~Component3D(){} + + virtual void setWorldMatrix(const mof::Animation::Handler& handler) = 0; + virtual void setWorldMatrix(const mof::Matrix3D& matrix); + //TODO ƒRƒŠƒWƒ‡ƒ“ +}; + +} + +#endif diff --git a/moftmp/ConsoleIO.cpp b/moftmp/ConsoleIO.cpp new file mode 100755 index 0000000..3a3b085 --- /dev/null +++ b/moftmp/ConsoleIO.cpp @@ -0,0 +1,3 @@ +#include "mof/ConsoleIO.hpp" + +ConsoleOut* ConsoleOut::obj = NULL; \ No newline at end of file diff --git a/moftmp/ConsoleIO.hpp b/moftmp/ConsoleIO.hpp new file mode 100755 index 0000000..60fb739 --- /dev/null +++ b/moftmp/ConsoleIO.hpp @@ -0,0 +1,80 @@ + +#ifndef CONSOLE_H +#define CONSOLE_H + +#include +#include +#include + +//-------------------------------------------- +// class ConsoleIO +// +// ƒRƒ“ƒ\[ƒ‹‚ðŒÄ‚яo‚µA“üo—Í‚ðs‚¤B +// C++‚Ì“üo—̓XƒgƒŠ[ƒ€ƒNƒ‰ƒXAstd::basic_stream +// ‚ðŒp³‚·‚éB +//-------------------------------------------- +template > +class ConsoleIO : public std::basic_streambuf{ + +protected: + std::streampos seekoff( + std::streamoff off, + std::ios::seek_dir dir, + int nMode = std::ios::in | std::ios::out ){ + return EOF; + } + + std::streampos seekpos( std::streampos , int ){ + return EOF; + } + + int_type overflow( int_type nCh = EOF ){ + DWORD size; + WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),(WCHAR*)&nCh,1,&size,NULL); + return 0; + } + + int_type underflow(void){ + return EOF; + } + + +public: + ConsoleIO(){ + setbuf(0,0); + AllocConsole(); + } + + ~ConsoleIO(){ + FreeConsole(); + } + +}; + + + +//-------------------------------------------- +// class ConsoleOut +// +// ƒRƒ“ƒ\[ƒ‹o—͂ɂ́A‚±‚̃Nƒ‰ƒX‚̃IƒuƒWƒFƒNƒg‚ðì‚é +//-------------------------------------------- +class ConsoleOut : public std::basic_iostream { + static ConsoleOut* obj; + + ConsoleOut(void) + : std::basic_iostream(new ConsoleIO() ){ + } + +public: + static ConsoleOut* getInstance(){ + if(obj == NULL)obj = new ConsoleOut(); + return obj; + } + + +}; + +#define DEBUG_PRINT(x) (*ConsoleOut::getInstance() << x << std::endl) +//#define DEBUG_PRINT(x) + +#endif diff --git a/moftmp/Container2D.cpp b/moftmp/Container2D.cpp new file mode 100755 index 0000000..142ab97 --- /dev/null +++ b/moftmp/Container2D.cpp @@ -0,0 +1,162 @@ +#include "mof/Container2D.h" +#include "mof/ConsoleIO.h" + + + +mof::Container2D::Container2D(int nColumns) +: mof::Component2D() , m_margin(0) , m_paddingX(0) , m_paddingY(0) +{ + m_nColumns = nColumns; +} + + +mof::Container2D::~Container2D(){ + + for(int i = 0 ; i < m_children.size() ; i ++){ + delete m_children.at(i); + } +} + +bool mof::Container2D::update(){ + + for(int i = 0 ; i < m_children.size() ; i ++){ + m_children.at(i)->update(); + } + + + //setPosition(getAnimationSet()->getPosition(getPosition())); + setPosition(getAnimationSet()->getPosition()); + getAnimationSet()->update(); + return true; +} + + +bool mof::Container2D::draw(){ + + for(int i = 0 ; i < m_children.size() ; i ++){ + m_children.at(i)->draw(); + } + return true; +} + + +/* +bool mof::Container2D::draw(mof::Matrix3D& transform){ + transform = m_worldTransform * transform; + for(int i = 0 ; i < m_children.size() ; i ++){ + m_children.at(i)->draw(transform); + } + return true; +}*/ + + +void mof::Container2D::add(mof::Component2D* component){ + m_children.push_back(component); +} + +bool mof::Container2D::remove(mof::Component2D* component){ + for(std::vector::iterator itr = m_children.begin() ; itr !=m_children.end() ; ++itr){ + if((*itr) == component){ + delete component; + return true; + } + } + return false; +} + +int mof::Container2D::indexOf(mof::Component2D* component){ + for(int i = 0 ; i < m_children.size() ; ++i){ + if(m_children.at(i) == component)return i; + } + return -1; +} + +void mof::Container2D::set(int index , mof::Component2D* component){ + delete m_children.at(index); + m_children.at(index) = component; +} + +mof::Component2D* mof::Container2D::get(int index){ + return m_children.at(index); +} + +mof::Vector2D mof::Container2D::getPositionOf(int index){ + return get(index)->getPosition();/* * m_worldTransform;*/ + //return get(index)->getPosition(); +} + +void mof::Container2D::setPosition(Vector2D& _position){ + mof::Vector2D position = _position; + m_position = position; + position.x += m_margin; + position.y += m_margin; + + int* maxWidthArray = new int[m_nColumns]; + + //—ñ–ˆ‚ɍő啝‚ð‹‚ß‚é + for(int i = 0 ; i < m_nColumns ; i++){ + maxWidthArray[i] = 0 ; + for(int j = i ; j < m_children.size() ; j += m_nColumns){ + int width = get(j)->getWidth(); + if(maxWidthArray[i] < width)maxWidthArray[i] = width; + } + } + + for(int i = 0 ; i < m_children.size() ; i++){ + get(i)->setPosition(position); + if(i % m_nColumns == m_nColumns -1){ + position.y += get(i)->getHeight() + m_paddingY; + position.x = m_position.x + m_margin; + } + else position.x += maxWidthArray[i % m_nColumns] + m_paddingX; + } + + delete[] maxWidthArray; +} + +mof::Vector2D mof::Container2D::getPosition(){ + return m_position; +} + +void mof::Container2D::setVisible(bool visible){ + + +} + +int mof::Container2D::getWidth(){ + int* maxWidthArray = new int[m_nColumns]; + //—ñ–ˆ‚ɍő啝‚ð‹‚ß‚é + for(int i = 0 ; i < m_nColumns ; i++){ + maxWidthArray[i] = 0 ; + for(int j = i ; j < m_children.size() ; j += m_nColumns){ + int width = get(j)->getWidth(); + if(maxWidthArray[i] < width)maxWidthArray[i] = width; + } + } + int sumWidth = 0; + for(int i = 0 ; i < m_nColumns ; i++)sumWidth += maxWidthArray[i]; + delete[] maxWidthArray; + return sumWidth + (m_nColumns-1)* m_paddingX + getMargin()*2; +} + +int mof::Container2D::getHeight(){ + int sumHeight = 0; + for(int i = 0 ; i < m_children.size() ; i++){ + if(i % m_nColumns == 0)sumHeight += m_children.at(i)->getHeight() + m_paddingY; + } + return sumHeight + getMargin() *2; +} + + +mof::RectangleModel mof::Container2D::getBounds(){ + return mof::RectangleModel(getPosition().x , getPosition().y , getWidth() , getHeight()); +} + +void mof::Container2D::setLayout(){ + mof::Vector2D position = getPosition(); + position.x += m_margin; + position.y += m_margin; + //DEBUG_PRINT(position.x << _T(",") << position.y); + setPosition(getPosition()); +} + \ No newline at end of file diff --git a/moftmp/Container2D.h b/moftmp/Container2D.h new file mode 100755 index 0000000..a4ccedb --- /dev/null +++ b/moftmp/Container2D.h @@ -0,0 +1,45 @@ +#pragma once +#include "mof/Component2D.h" +#include + +namespace mof{ + + class Container2D : public Component2D{ + std::vector m_children; + mof::Vector2D m_position; + int m_margin; + int m_paddingX; + int m_paddingY; + int m_nColumns; + public: + Container2D(int nColumns = 1); + ~Container2D(); + + virtual bool update(); + virtual bool draw(); + + void add(mof::Component2D* component); + bool remove(mof::Component2D* component); + mof::Component2D* get(int index); + void set(int index , mof::Component2D* component); + int indexOf(mof::Component2D* component); + int size(){return m_children.size();} + + mof::Vector2D getPositionOf(int index); + + virtual void setPosition(Vector2D& position); + void setMargin(int margin){m_margin = margin;} + void setColumn(int nColumns){m_nColumns = nColumns;} + void setPaddingX(int paddingX){m_paddingX = paddingX;} + void setPaddingY(int paddingY){m_paddingY = paddingY;} + int getMargin(){return m_margin;} + virtual mof::Vector2D getPosition(); + virtual int getWidth(); + virtual int getHeight(); + + virtual void setVisible(bool visible); + virtual RectangleModel getBounds(); + virtual void setLayout(); + + }; +}; \ No newline at end of file diff --git a/moftmp/Container3D.cpp b/moftmp/Container3D.cpp new file mode 100755 index 0000000..2034f77 --- /dev/null +++ b/moftmp/Container3D.cpp @@ -0,0 +1,62 @@ +#include "mof/Container3D.h" + + + +mof::Container3D::Container3D() +: mof::Component3D() +{ +} + + +mof::Container3D::~Container3D(){ + + for(int i = 0 ; i < m_children.size() ; i ++){ + delete m_children.at(i); + } +} + +bool mof::Container3D::draw(){ + for(int i = 0 ; i < m_children.size() ; i ++){ + if(m_children.at(i) == NULL)continue; + m_children.at(i)->draw(m_worldTransform); + } + return true; +} + + +bool mof::Container3D::draw(mof::Matrix3D& transform){ + transform = m_worldTransform * transform; + for(int i = 0 ; i < m_children.size() ; i ++){ + if(m_children.at(i) == NULL)continue; + m_children.at(i)->draw(transform); + } + return true; +} + +bool mof::Container3D::update(){ + for(int i = 0 ; i < m_children.size() ; i ++){ + if(m_children.at(i) == NULL)continue; + m_children.at(i)->update(); + } + return mof::Component3D::update(); +} + + +void mof::Container3D::add(mof::Component3D* component){ + for(int i = 0 ; i < m_children.size() ; i ++){ + if(m_children.at(i) == NULL){ + m_children.at(i) = component; + return; + } + } + m_children.push_back(component); +} + +mof::Component3D* mof::Container3D::get(int index){ + return m_children.at(index); +} + +mof::Vector3D mof::Container3D::getPositionOf(int index){ + return get(index)->getPosition() * m_worldTransform; + //return get(index)->getPosition(); +} \ No newline at end of file diff --git a/moftmp/Container3D.h b/moftmp/Container3D.h new file mode 100755 index 0000000..9b8682b --- /dev/null +++ b/moftmp/Container3D.h @@ -0,0 +1,27 @@ +#pragma once +#include "mof/Component3D.h" +#include + +namespace mof{ + + class Container3D : public Component3D{ + protected: + std::vector m_children; + public: + Container3D(); + ~Container3D(); + + + virtual bool draw(); + virtual bool draw(mof::Matrix3D& transform); + virtual bool update(); + + void add(mof::Component3D* component); + mof::Component3D* get(int index); + + mof::Vector3D getPositionOf(int index); + + //void deleteAll(); + + }; +}; \ No newline at end of file diff --git a/moftmp/DataRow.cpp b/moftmp/DataRow.cpp new file mode 100755 index 0000000..4fcd9b0 --- /dev/null +++ b/moftmp/DataRow.cpp @@ -0,0 +1,12 @@ +#include "DataRow.h" + +mof::DataRow::DataRow( const DataResource& data , const TCHAR* const pRowName) +: m_data(data){ + m_rowIndex = m_data->getRowIndex(pRowName); +} + +mof::DataRow::DataRow( const DataResource& data , int index) +: m_data(data) , m_rowIndex(index){ + +} + diff --git a/moftmp/DataRow.h b/moftmp/DataRow.h new file mode 100755 index 0000000..1fc1d7a --- /dev/null +++ b/moftmp/DataRow.h @@ -0,0 +1,47 @@ +#pragma once +#include "mof/DataTable.h" + +namespace mof{ + class DataRow + { + int m_rowIndex; + DataResource m_data; + public: + DataRow(){;} + DataRow( const DataResource& data , const TCHAR * const pRowName); + DataRow( const DataResource& data , int index); + + inline mof::tstring& getData( const TCHAR * const pColumnName); + inline mof::tstring& getData( int columnIndex); + + inline int getIntegerData( const TCHAR * const pColumnName); + inline int getIntegerData( int columnIndex); + }; + + +} + + +mof::tstring& mof::DataRow::getData( const TCHAR * const pColumnName){ + return m_data->getData(m_rowIndex , pColumnName); +} + + + +mof::tstring& mof::DataRow::getData( int columnIndex){ + return m_data->getData(m_rowIndex , columnIndex); +} + + + +int mof::DataRow::getIntegerData( const TCHAR * const pColumnName){ + return m_data->getIntegerData(m_rowIndex , pColumnName); +} + + + +int mof::DataRow::getIntegerData( int columnIndex){ + return m_data->getIntegerData(m_rowIndex , columnIndex); +} + + diff --git a/moftmp/DataTable.cpp b/moftmp/DataTable.cpp new file mode 100755 index 0000000..5270eba --- /dev/null +++ b/moftmp/DataTable.cpp @@ -0,0 +1,104 @@ +#include "mof/ConsoleIO.h" +#include "mof/DataTable.h" +#include "mof/CSVFile.h" +#include +#include +#include + +mof::DataTable::DataTable(tstring& name ) + : mof::Resource(name){ +} + +mof::DataTable::DataTable(const TCHAR * const name) + : mof::Resource(mof::tstring(name)){ +} + + +void mof::DataTable::load(){ + if(isAvailable())return; + //CVSƒtƒ@ƒCƒ‹‚©‚çƒf[ƒ^‚ðƒ[ƒh + mof::CSVFile csvFile(getName().c_str()); + csvFile.setIgnoreNL(false); + + //columnî•ñ‚̃[ƒh + for(int i = 0 ; csvFile.hasNextValue() ; i++){ + m_columnMap.insert(std::pair( mof::tstring(csvFile.getNextValue()) , i)); + } + + while(csvFile.nextLine()){ + m_dataList.push_back(std::vector()); + while(csvFile.hasNextValue()){ + m_dataList.back().push_back(mof::tstring(csvFile.getNextValue())); + } + + } + setAvailable(true); + +} + +void mof::DataTable::unload(){ + if(!isAvailable())return; + m_dataList.clear(); + m_columnMap.clear(); + setAvailable(false); + } + + +int mof::DataTable::getRowIndex(const TCHAR * const pRowName){ + if(!isAvailable())load(); + for(int i = 0 ; i < m_dataList.size() ; ++i){ + if(!m_dataList.at(i).empty() && m_dataList.at(i).at(0) == pRowName)return i; + } + return -1; +} + + +int mof::DataTable::getColumnIndex(const TCHAR * const pColumnName){ + if(!isAvailable())load(); + mof::tstring tmp(pColumnName); + std::map::iterator itr = m_columnMap.find(tmp); + return itr != m_columnMap.end() ? itr->second : -1; +} + + +mof::tstring& mof::DataTable::getData(const TCHAR * const pRowName , const TCHAR * const pColumnName){ + if(!isAvailable())load(); + int columnIndex = getColumnIndex(pColumnName); + int rowIndex = getRowIndex(pRowName); + return m_dataList.at(rowIndex).at(columnIndex); + +} + + +mof::tstring& mof::DataTable::getData(int rowIndex , const TCHAR *const pColumnName){ + if(!isAvailable())load(); + int columnIndex = getColumnIndex(pColumnName); + return m_dataList.at(rowIndex).at(columnIndex); +} + + +mof::tstring& mof::DataTable::getData(int rowIndex , int columnIndex){ + if(!isAvailable())load(); + return m_dataList.at(rowIndex).at(columnIndex); +} + +int mof::DataTable::getIntegerData(const TCHAR *const pRowName ,const TCHAR * const pColumnName){ + if(!isAvailable())load(); + return boost::lexical_cast(getData(pRowName , pColumnName)); +} + +int mof::DataTable::getIntegerData(int rowIndex , const TCHAR *const pColumnName){ + if(!isAvailable())load(); + return boost::lexical_cast(getData(rowIndex , pColumnName)); +} + +int mof::DataTable::getIntegerData(int rowIndex , int columnIndex){ + if(!isAvailable())load(); + return boost::lexical_cast(getData(rowIndex , columnIndex)); +} + + +int mof::DataTable::getNumberOfRows(){ + if(!isAvailable())load(); + return m_dataList.size(); +} \ No newline at end of file diff --git a/moftmp/DataTable.h b/moftmp/DataTable.h new file mode 100755 index 0000000..da42f97 --- /dev/null +++ b/moftmp/DataTable.h @@ -0,0 +1,41 @@ +#pragma once +#include "mof/Resource.h" +#include "mof/tstring.h" +#include +#include +#include "mof/ResourceManager.h" + + +namespace mof{ + + + class DataTable : public Resource + { + std::map m_columnMap; + std::vector> m_dataList; + + public: + DataTable(tstring& name ); + DataTable(const TCHAR * const name); + + virtual void load(); + virtual void unload(); + + int getRowIndex(const TCHAR * const pRowName); + int getColumnIndex(const TCHAR * const pRowName); + mof::tstring& getData(const TCHAR * const pRowName , const TCHAR * const pColumnName); + mof::tstring& getData(int rowIndex , const TCHAR * const pColumnName); + mof::tstring& getData(int rowIndex , int columnIndex); + + int getIntegerData(const TCHAR * const pRowName , const TCHAR * const pColumnName); + int getIntegerData(int rowIndex , const TCHAR * const pColumnName); + int getIntegerData(int rowIndex , int columnIndex); + + int getNumberOfRows(); + }; + + + + typedef mof::ResourceManager DataResourceManager; + typedef boost::shared_ptr DataResource; +}; diff --git a/moftmp/Deleter.hpp b/moftmp/Deleter.hpp new file mode 100755 index 0000000..2ca215a --- /dev/null +++ b/moftmp/Deleter.hpp @@ -0,0 +1,23 @@ +#include +#include +#include "mof/EventScheduler.hpp" + +namespace mof{ + + template + class Deleter{ + boost::shared_ptr m_p; + public: + Deleter(T* p) : m_p(p) {} + Deleter( typename boost::shared_ptr& p) : m_p(p) {} + + void operator ()(){ + m_p = boost::shared_ptr(); + } + + boost::weak_ptr getWeak(){ + return m_p; + } + }; + +}; diff --git a/moftmp/DeviceInputReceiver.cpp b/moftmp/DeviceInputReceiver.cpp new file mode 100755 index 0000000..462298d --- /dev/null +++ b/moftmp/DeviceInputReceiver.cpp @@ -0,0 +1,133 @@ +#include "mof/private/DirectInput.hpp" +#include "mof/private/DeviceInputReceiver.hpp" +#include "mof/InputDevice.hpp" +#include "mof/ConsoleIO.hpp" +#include "mof/InputEventCondition.hpp" + + +mof::DeviceInputReceiver::DeviceInputReceiver() +: mof::InputReceiver(){ + m_pKeyStates = new bool[mof::DeviceInputReceiver::END]; + for(int i = 0 ; i < mof::DeviceInputReceiver::END ; i++)m_pKeyStates[i] = false; +} + +mof::DeviceInputReceiver::~DeviceInputReceiver(){ + delete[] m_pKeyStates; + +} + +bool mof::DeviceInputReceiver::testKeyState(mof::InputReceiver::Key key){ + + return m_pKeyStates[key]; + +} + +void mof::DeviceInputReceiver::update(){ + mof::InputDevice::update(); +} + + +void mof::DeviceInputReceiver::notifyInputEvent(mof::InputEvent& inputEvent){ + mof::DeviceInputReceiver::Key key; + + + switch(inputEvent.dwOfs){ + case DIK_UP : + key = mof::DeviceInputReceiver::UP; + break; + case DIK_DOWN : + key = mof::DeviceInputReceiver::DOWN; + break; + case DIK_LEFT : + key = mof::DeviceInputReceiver::LEFT; + break; + case DIK_RIGHT : + key = mof::DeviceInputReceiver::RIGHT; + break; + case DIK_A : + key = mof::DeviceInputReceiver::A; + break; + case DIK_B : + key = mof::DeviceInputReceiver::B; + break; + case DIK_C : + key = mof::DeviceInputReceiver::C; + break; + case DIK_D : + key = mof::DeviceInputReceiver::D; + break; + case DIK_E : + key = mof::DeviceInputReceiver::E; + break; + case DIK_F : + key = mof::DeviceInputReceiver::F; + break; + case DIK_G : + key = mof::DeviceInputReceiver::G; + break; + case DIK_H : + key = mof::DeviceInputReceiver::H; + break; + case DIK_I : + key = mof::DeviceInputReceiver::I; + break; + case DIK_J : + key = mof::DeviceInputReceiver::J; + break; + case DIK_K : + key = mof::DeviceInputReceiver::K; + break; + case DIK_L : + key = mof::DeviceInputReceiver::L; + break; + case DIK_M : + key = mof::DeviceInputReceiver::M; + break; + case DIK_N : + key = mof::DeviceInputReceiver::N; + break; + case DIK_O : + key = mof::DeviceInputReceiver::O; + break; + case DIK_P : + key = mof::DeviceInputReceiver::P; + break; + case DIK_Q : + key = mof::DeviceInputReceiver::Q; + break; + case DIK_R : + key = mof::DeviceInputReceiver::R; + break; + case DIK_S : + key = mof::DeviceInputReceiver::S; + break; + case DIK_T : + key = mof::DeviceInputReceiver::T; + break; + case DIK_U : + key = mof::DeviceInputReceiver::U; + break; + case DIK_V : + key = mof::DeviceInputReceiver::V; + break; + case DIK_W : + key = mof::DeviceInputReceiver::W; + break; + case DIK_X : + key = mof::DeviceInputReceiver::X; + break; + case DIK_Y : + key = mof::DeviceInputReceiver::Y; + break; + case DIK_Z : + key = mof::DeviceInputReceiver::Z; + break; + case DIK_ESCAPE : + key = mof::DeviceInputReceiver::ESCAPE; + break; + default : + return; + } + m_pKeyStates[key] = (inputEvent.dwData & 0x80) != 0; + +} diff --git a/moftmp/DirectionalLight.cpp b/moftmp/DirectionalLight.cpp new file mode 100755 index 0000000..670bc5a --- /dev/null +++ b/moftmp/DirectionalLight.cpp @@ -0,0 +1,44 @@ +#include "mof/DirectionalLight.h" +#include +#include "GraphicsDevice.h" + + +mof::DirectionalLight::DirectionalLight(mof::Color diffuse , mof::Color ambient , mof::Vector3D& direction) +: mof::Light() +{ + setDiffuseColor(diffuse); + setAmbientColor(ambient); + setDirection(direction); + +} + + +void mof::DirectionalLight::update(){ + //mof::Animation* pAnimation = getAnimation(); + //if(pAnimation == NULL)return; + //pAnimation->update(); + //mof::Color color = pAnimation->get(); + //set(pAnimation->getColor()); +} + +void mof::DirectionalLight::reflect(){ + GRAPHICS_DEVICE pDevice = mof::GraphicsDevice::getInstance()->getGraphicsDevice(); + D3DLIGHT9 light; + ZeroMemory(&light , sizeof(light)); + light.Type = D3DLIGHT_DIRECTIONAL; + light.Diffuse.a = (float)mof::getAlpha(m_diffuse) / 255.0f; + light.Diffuse.r = (float)mof::getRed(m_diffuse) / 255.0f; + light.Diffuse.g = (float)mof::getGreen(m_diffuse) / 255.0f; + light.Diffuse.b = (float)mof::getBlue(m_diffuse) / 255.0f; + + light.Ambient.a = (float)mof::getAlpha(m_ambient) / 255.0f; + light.Ambient.r = (float)mof::getRed(m_ambient) / 255.0f; + light.Ambient.g = (float)mof::getGreen(m_ambient) / 255.0f; + light.Ambient.b = (float)mof::getBlue(m_ambient) / 255.0f; + + light.Direction = D3DXVECTOR3(m_direction.x , m_direction.y , m_direction.z); + + + pDevice->SetLight(0 , &light); + pDevice->LightEnable(0 , TRUE); +} diff --git a/moftmp/DirectionalLight.h b/moftmp/DirectionalLight.h new file mode 100755 index 0000000..5a5c0a6 --- /dev/null +++ b/moftmp/DirectionalLight.h @@ -0,0 +1,22 @@ +#pragma once +#include "mof/Light.h" +#include "mof/Color.h" + +namespace mof{ + + class DirectionalLight : public Light{ + mof::Color m_diffuse; + mof::Color m_ambient; + mof::Vector3D m_direction; + public: + DirectionalLight(mof::Color diffuse , mof::Color ambient , mof::Vector3D& direction); + void setDiffuseColor(mof::Color diffuse){m_diffuse = diffuse;} + void setAmbientColor(mof::Color ambient){m_ambient = ambient;} + void setDirection(mof::Vector3D& direction){m_direction = direction;} + + virtual void update(); + virtual void reflect(); + + }; + +}; \ No newline at end of file diff --git a/moftmp/Drawable.hpp b/moftmp/Drawable.hpp new file mode 100755 index 0000000..d20ba2d --- /dev/null +++ b/moftmp/Drawable.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace mof +{ + class Drawable + { + public: + virtual ~Drawable(){} + virtual void draw() const = 0; + }; +} diff --git a/moftmp/EventCondition.hpp b/moftmp/EventCondition.hpp new file mode 100755 index 0000000..881d877 --- /dev/null +++ b/moftmp/EventCondition.hpp @@ -0,0 +1,14 @@ +#pragma once + +namespace mof{ + + class EventCondition{ + public: + virtual ~EventCondition(){} + virtual bool test() = 0; + virtual void update() = 0; + virtual bool isDisposable() = 0; + }; + +} + diff --git a/moftmp/EventScheduler.cpp b/moftmp/EventScheduler.cpp new file mode 100755 index 0000000..5cd2277 --- /dev/null +++ b/moftmp/EventScheduler.cpp @@ -0,0 +1,83 @@ +#include "mof/EventScheduler.hpp" +#include "mof/EventCondition.hpp" +#include +#include +#include "mof/utilities.hpp" + + +class TimeEventCondition : public mof::EventCondition{ + mof::FrameNumber limit; + mof::FrameNumber count; + +public: + TimeEventCondition(mof::FrameNumber limit) + : limit(limit) , count(0) + { + } + + virtual ~TimeEventCondition(){} + + virtual bool test(){ + return count == limit; + } + + virtual bool isDisposable(){ + return count > limit; + } + + virtual void update(){ + if(limit >= count)count++; + } +}; + +struct mof::EventScheduler::Impl{ + typedef std::pair> Schedule; + typedef std::list>> EventList; + EventList eventList; + + Impl(){ + } + + ~Impl(){ + foreach( Impl::Schedule &value , eventList ){ + delete value.first; + } + } + +}; + +mof::EventScheduler::EventScheduler() +: m_pImpl(new Impl()) +{ +} + +mof::EventScheduler::~EventScheduler(){ + +} + +void mof::EventScheduler::addEvent( mof::EventCondition* pCondition , const boost::function0 &action){ + m_pImpl->eventList.push_back(std::pair>(pCondition , action)); +} + +void mof::EventScheduler::addEvent(mof::FrameNumber frame, const boost::function0 &action){ + addEvent(new TimeEventCondition(frame) , action); +} + +void mof::EventScheduler::update(){ + for( Impl::EventList::iterator itr = m_pImpl->eventList.begin() ; + itr != m_pImpl->eventList.end() ; + ){ + itr->first->update(); + if(itr->first->test()){ + itr->second(); + } + if(itr->first->isDisposable()){ + delete itr->first; + itr = m_pImpl->eventList.erase(itr); + } + else ++itr; + } +} + + + diff --git a/moftmp/EventScheduler.hpp b/moftmp/EventScheduler.hpp new file mode 100755 index 0000000..bc7cd13 --- /dev/null +++ b/moftmp/EventScheduler.hpp @@ -0,0 +1,30 @@ +#ifndef MOF_EVENT_SCHEDULER_HPP +#define MOF_EVENT_SCHEDULER_HPP +#include +#include +#include "mof/stream/Manipulator.hpp" + +namespace mof{ + +class EventCondition; + +class EventScheduler{ + struct Impl; + boost::scoped_ptr m_pImpl; + +public: + typedef boost::function0 Action; + EventScheduler(); + ~EventScheduler(); + + void addEvent(mof::EventCondition* pCondition , const Action& action); + void addEvent(mof::FrameNumber interval , const Action& action); + void update(); +}; + +} + + + + +#endif diff --git a/moftmp/FactoryMethod.hpp b/moftmp/FactoryMethod.hpp new file mode 100755 index 0000000..f52554d --- /dev/null +++ b/moftmp/FactoryMethod.hpp @@ -0,0 +1,137 @@ +#pragma once +#include + +namespace mof +{ + //TODO タイプリストとかで、そのままのインタフェースでより汎用的にする + //非const参照を渡したい場合は?(constructorにそれはありえない) + + +//{{{ FactoryMethod + template < class T > + class FactoryMethod + { + public: + FactoryMethod( const boost::function& factory) + : m_factory(factory){} + + T* operator() () const{ return m_factory(); } + + template + operator FactoryMethod( ) const + { + return FactoryMethod(m_factory); + } + + + + private: + boost::function m_factory; + }; + + +//}}} +//{{{ Constructor0 + template < class T > + class Constructor0 + { + public: + T* operator() ( ) const {return new T();} + }; +//}}} +//{{{ Constructor1 + template + class Constructor1 : protected Constructor0 + { + protected: + P1 p1; + public: + Constructor1(const P1& p1_) + : p1(p1_) + {} + + T* operator() ( ) const {return new T(p1);} + }; +//}}} +//{{{ Constructor2 + template + class Constructor2 : protected Constructor1 + { + protected: + P2 p2; + public: + Constructor2(const P1& p1_ , const P2& p2_) + : Constructor1(p1_) , p2(p2_) + {} + + T* operator() ( ) const {return new T(p1 , p2);} + }; +//}}} +//{{{ Constructor3 + template + class Constructor3 : protected Constructor2 + { + protected: + P3 p3; + public: + Constructor3(const P1& p1_ , const P2& p2_ , const P3& p3_) + : Constructor2(p1_ , p2_) , p3(p3_) + {} + + T* operator() ( ) const {return new T(p1 , p2 , p3);} + }; +//}}} +//{{{ Constructor4 + template + class Constructor4 : protected Constructor3 + { + protected: + P4 p4; + public: + Constructor4(const P1& p1_ , const P2& p2_ , const P3& p3_ , const P4& p4_) + : Constructor2(p1_ , p2_ , p3_) , p4(p4_) + {} + + T* operator() ( ) const {return new T(p1 , p2 , p3 , p4);} + }; +//}}} + +//{{{ makeFactoryMethod + template + FactoryMethod + makeFactoryMethod() + { + return FactoryMethod( Constructor0() ); + } + + template + FactoryMethod + makeFactoryMethod(const P1& p1) + { + return FactoryMethod( Constructor1(p1) ); + } + + template + FactoryMethod + makeFactoryMethod(const P1& p1 , const P2& p2) + { + return FactoryMethod( Constructor2(p1 , p2) ); + } + + template + FactoryMethod + makeFactoryMethod(const P1& p1 , const P2& p2 , const P3& p3) + { + return FactoryMethod( Constructor3(p1 , p2 , p3) ); + } + + template + FactoryMethod + makeFactoryMethod(const P1& p1 , const P2& p2 , const P3& p3 , const P4& p4) + { + return FactoryMethod( Constructor4(p1 , p2 , p3 , p4) ); + } +//}}} + + +} diff --git a/moftmp/FilePath.cpp b/moftmp/FilePath.cpp new file mode 100755 index 0000000..68a5ed7 --- /dev/null +++ b/moftmp/FilePath.cpp @@ -0,0 +1,68 @@ +#include "mof/FilePath.hpp" +#include +#include "mof/ConsoleIO.hpp" + + +mof::FilePath::FilePath(const mof::tstring& path){ + m_path = path; +} + + +mof::tstring mof::FilePath::getFormat(){ + try { + boost::regex regex("(.*)\\.(.*)");//name . format + boost::smatch match; + //Š¿Žš‚ɂ͑Ήž‚µ‚Ä‚¢‚È‚¢ + if(!boost::regex_search(m_path , match , regex)){ + DEBUG_PRINT(_T("FormatError --- ") << m_path); + return mof::tstring(); + } + return match.str(2); + } + catch (std::exception &e) { + throw e; + } + return mof::tstring(); +} + + +mof::tstring& mof::FilePath::getPath(){ + return m_path; +} + +mof::tstring mof::FilePath::dir(){ + try { + boost::regex regex("(.*)/[^/]*\\.(.*)");//name . format + boost::smatch match; + //Š¿Žš‚ɂ͑Ήž‚µ‚Ä‚¢‚È‚¢ + if(!boost::regex_search(m_path , match , regex)){ + DEBUG_PRINT(_T("FormatError --- ") << m_path); + return mof::tstring(); + } + return match.str(1); + } + catch (std::exception &e) { + throw e; + } + return mof::tstring(); + +} + +mof::tstring mof::FilePath::basename(){ + try { + boost::regex regex("(.*)/([^/]*)");//name . format + boost::smatch match; + //Š¿Žš‚ɂ͑Ήž‚µ‚Ä‚¢‚È‚¢ + if(!boost::regex_search(m_path , match , regex)){ + DEBUG_PRINT(_T("FormatError --- ") << m_path); + return mof::tstring(); + } + return match.str(2); + } + catch (std::exception &e) { + throw e; + } + return mof::tstring(); + +} + diff --git a/moftmp/FilePath.hpp b/moftmp/FilePath.hpp new file mode 100755 index 0000000..2522ee0 --- /dev/null +++ b/moftmp/FilePath.hpp @@ -0,0 +1,22 @@ +#ifndef MOF_FILE_PATH_HPP +#define MOF_FILE_PATH_HPP + +#include "mof/tstring.hpp" + +namespace mof{ + +class FilePath{ + mof::tstring m_path; + +public: + FilePath(const mof::tstring& path); + + mof::tstring getFormat(); + mof::tstring& getPath(); + mof::tstring dir(); + mof::tstring basename(); +}; + +} + +#endif diff --git a/moftmp/FileTextureBuilder.cpp b/moftmp/FileTextureBuilder.cpp new file mode 100755 index 0000000..e3b83d9 --- /dev/null +++ b/moftmp/FileTextureBuilder.cpp @@ -0,0 +1,37 @@ + +#include "mof/FileTextureBuilder.h" +#include +#include +#include "GraphicsDevice.h" +#include "mof/ConsoleIO.h" + +mof::FileTextureBuilder::FileTextureBuilder(mof::tstring& path) +{ + m_path = path; +} + +mof::FileTextureBuilder::~FileTextureBuilder(void) +{ +} + + +mof::TextureRecord mof::FileTextureBuilder::create(){ + LPDIRECT3DTEXTURE9 texture; + mof::GRAPHICS_DEVICE pDevice = mof::GraphicsDevice::getInstance()->getGraphicsDevice(); + HRESULT hr = D3DXCreateTextureFromFileEx(pDevice , m_path.c_str() , + 0 , 0 , 1 , 0/*RENDER*/ , D3DFMT_UNKNOWN , D3DPOOL_MANAGED , + D3DX_DEFAULT , D3DX_DEFAULT , mof::createColor(0 , 0 , 0) , NULL , NULL , &texture); + + if(FAILED(hr)){ + *ConsoleOut::getInstance() << "CreateTexture --- " << DXGetErrorDescription9(hr) << std::endl; + TextureRecord record; + record.pTexture = NULL; + return record; + } + + TextureRecord record; + record.pTexture = texture; + record.validRect = mof::RectangleModel(0 , 0 , 0 , 0);//‘S”ÍˆÍ + return record; + +} \ No newline at end of file diff --git a/moftmp/Finalizer.hpp b/moftmp/Finalizer.hpp new file mode 100755 index 0000000..bb5eb8f --- /dev/null +++ b/moftmp/Finalizer.hpp @@ -0,0 +1,53 @@ +#pragma once + + +namespace mof +{ + + + //TODO ƒRƒ“ƒeƒi‚É‘ã“ü‚Å‚«‚È‚¢‚悤‚É‚·‚é + class Finalizer + { + mutable void (*m_finalize)( ); + + public: + Finalizer( ) + : m_finalize(NULL) + { + // do nothing + } + + Finalizer( void (*finalize_)() ) + : m_finalize(finalize_) + { + // do nothing + } + + Finalizer( const Finalizer& obj){ + if( this == &obj)return; + m_finalize = obj.m_finalize; + obj.m_finalize = NULL; + } + + ~Finalizer( ) + { + if( m_finalize )m_finalize(); + } + + void cancel( ) + { + m_finalize = NULL; + } + + Finalizer& operator = ( const Finalizer& obj ) + { + if( this == &obj)return *this; + if( m_finalize )m_finalize(); + m_finalize = obj.m_finalize; + obj.m_finalize = NULL; + return *this; + } + + + }; +} \ No newline at end of file diff --git a/moftmp/Font.cpp b/moftmp/Font.cpp new file mode 100755 index 0000000..a53527d --- /dev/null +++ b/moftmp/Font.cpp @@ -0,0 +1,183 @@ +#include "mof/Font.hpp" +#include +#include +#include "mof/ConsoleIO.hpp" +#include +#include "mof/utilities.hpp" + +const TCHAR* mof::Font::MS_GOTHIC = _T("‚l‚r ƒSƒVƒbƒN"); +const TCHAR* mof::Font::MS_P_GOTHIC = _T("‚l‚r ‚oƒSƒVƒbƒN"); + + +namespace +{ + struct FontManager + { + std::vector additionalFontResources; + + ~FontManager() + { + foreach( mof::tstring& filename , additionalFontResources ) + { + RemoveFontResource( filename.c_str() ); + } + } + } g_fontManager; +} + +struct GlyphData{ + int iOfs_x , iOfs_y , iBmp_w , iBmp_h , level , width; + BYTE* pBmpBuffer; + bool valid; + + GlyphData(GLYPHMETRICS& GM , TEXTMETRIC& TM , int _level , int bufSize){ + iOfs_x = GM.gmptGlyphOrigin.x; + iOfs_y = TM.tmAscent - GM.gmptGlyphOrigin.y; + iBmp_w = GM.gmBlackBoxX + (4-(GM.gmBlackBoxX%4))%4; + iBmp_h = GM.gmBlackBoxY; + level = _level; + width = GM.gmCellIncX; + pBmpBuffer = new BYTE[bufSize]; + valid = true; + } + + ~GlyphData(){ + delete[] pBmpBuffer; + } +}; + +struct mof::Font::Impl{ + HFONT hFont; + size_t fontSize; + + Impl(size_t fontSize_) + : hFont(NULL) ,fontSize(fontSize_) + { + } + + ~Impl(){ + DeleteObject(hFont); + } + +}; + +mof::Font::Font(const TCHAR* fontName , size_t size) +: m_pImpl(new Impl(size)) +{ + LOGFONT lf = {m_pImpl->fontSize , 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, OUT_TT_ONLY_PRECIS, + CLIP_DEFAULT_PRECIS , PROOF_QUALITY, FIXED_PITCH | FF_MODERN , "" }; + strcpy_s(lf.lfFaceName , fontName ); + + if(!(m_pImpl->hFont = CreateFontIndirect(&lf))){ + throw std::runtime_error("Failed --- CreateFontIndirect"); + } + + + +} + +mof::Font::~Font(){ + +} + + + +mof::PixelMap* mof::Font::createText(const mof::tstring& text) const{ + + // ƒfƒoƒCƒXƒRƒ“ƒeƒLƒXƒgŽæ“¾ + // ƒfƒoƒCƒX‚ɃtƒHƒ“ƒg‚ðŽ‚½‚¹‚È‚¢‚ÆGetGlyphOutlineŠÖ”‚̓Gƒ‰[‚Æ‚È‚é + HDC hdc = GetDC(NULL); + HFONT oldFont = static_cast(SelectObject(hdc , m_pImpl->hFont)); + TEXTMETRIC TM; + GetTextMetrics( hdc, &TM ); + + int sumWidth = 0; + int maxHeight = 0; + typedef std::list::iterator GDITR; + std::list glyphDataList; + for(int i = 0 ; text.c_str()[i] ; ){ + + + // •¶ŽšƒR[ƒhŽæ“¾ + UINT code = 0; + #if _UNICODE + // unicode‚̏ꍇA•¶ŽšƒR[ƒh‚Í’Pƒ‚ɃƒCƒh•¶Žš‚ÌUINT•ÏŠ·‚Å‚· + code = (UINT)str[i++]; + #else + // ƒ}ƒ‹ƒ`ƒoƒCƒg•¶Žš‚̏ꍇA + // 1ƒoƒCƒg•¶Žš‚̃R[ƒh‚Í1ƒoƒCƒg–Ú‚ÌUINT•ÏŠ·A + // 2ƒoƒCƒg•¶Žš‚̃R[ƒh‚Í[æ“±ƒR[ƒh]*256 + [•¶ŽšƒR[ƒh]‚Å‚· + if(IsDBCSLeadByte(text[i])){ + code = (text[i] << 8) | (text[i+1] & 0xff); // •¶Žš + code &= 0x0000ffff; + i += 2; + } + else{ + code = text[i++]; + } + #endif + + unsigned int spaceCode = (_T(" ")[0]); + unsigned int wSpaceCode = (_T("@")[0] << 8) | (_T("@")[1] & 0xff); + wSpaceCode &= 0x0000ffff; + + + // ƒtƒHƒ“ƒgƒrƒbƒgƒ}ƒbƒvŽæ“¾ + GLYPHMETRICS GM; + CONST MAT2 Mat = {{0,1},{0,0},{0,0},{0,1}}; + DWORD size = GetGlyphOutline(hdc, code , GGO_GRAY8_BITMAP, &GM, 0, NULL, &Mat); + GlyphData* pGD = new GlyphData(GM , TM , 65 , size); + GetGlyphOutline(hdc, code, GGO_GRAY8_BITMAP, &GM, size, pGD->pBmpBuffer , &Mat); + + if(code == spaceCode || code == wSpaceCode){ + //‹ó”’‚͉½ŒÌ‚©‚¤‚Ü‚­‘‚«ž‚ß‚È‚¢‚±‚Ƃւ̑Ώˆ + pGD->valid = false; + } + glyphDataList.push_back(pGD); + sumWidth += pGD->width;//‘S‘Ì‚Ì• + maxHeight = max(maxHeight , TM.tmHeight); + } + + // ƒfƒoƒCƒXƒRƒ“ƒeƒLƒXƒg‚ƃtƒHƒ“ƒgƒnƒ“ƒhƒ‹‚ÌŠJ•ú + SelectObject(hdc, oldFont); + ReleaseDC(NULL, hdc); + + typedef mof::PixelMap::size_type size_type; + boost::array sizes = {{ sumWidth , maxHeight }}; + mof::PixelMap* pPixelMap = new mof::PixelMap(sizes); + + // ƒtƒHƒ“ƒgî•ñ‚̏‘‚«ž‚Ý + // iOfs_x, iOfs_y : ‘‚«o‚µˆÊ’u(¶ã) + // iBmp_w, iBmp_h : ƒtƒHƒ“ƒgƒrƒbƒgƒ}ƒbƒv‚Ì•‚ + // Level : ƒ¿’l‚Ì’iŠK (GGO_GRAY4_BITMAP‚È‚Ì‚Å17’iŠK) + + DWORD Alpha, Color; + int hoseiX = 0; + for(int y = 0 ; y < maxHeight ; y++){ + for(int x = 0 ; x < sumWidth ; x++){ + (*pPixelMap)[x][y] = 0; + } + } + for(GDITR itr = glyphDataList.begin() ; itr != glyphDataList.end() ; ++itr){ + for(int y = (*itr)->iOfs_y ; y < (*itr)->iOfs_y + (*itr)->iBmp_h ; y++){ + if(!(*itr)->valid)break;//‹ó”’•¶Žš‚Ȃ珑‚«ž‚݂𖳎‹‚·‚é + for(int x = (*itr)->iOfs_x + hoseiX ; x < (*itr)->iOfs_x + (*itr)->iBmp_w + hoseiX && x < sumWidth ; x++){ + Alpha = (255 * (*itr)->pBmpBuffer[x - ((*itr)->iOfs_x + hoseiX) + (*itr)->iBmp_w * ( y - (*itr)->iOfs_y ) ] ) / ((*itr)->level-1); + Color = 0x00ffffff | (Alpha<<24); + + (*pPixelMap)[x][y] = Color; + + } + } + hoseiX += (*itr)->width; + delete *itr; + } + + return pPixelMap; +} + + +bool mof::Font::addFontResource(const mof::tstring& filename ){ + g_fontManager.additionalFontResources.push_back(filename); + return AddFontResource( filename.c_str() ) ? true : false ; +} diff --git a/moftmp/Font.hpp b/moftmp/Font.hpp new file mode 100755 index 0000000..518431a --- /dev/null +++ b/moftmp/Font.hpp @@ -0,0 +1,29 @@ +#ifndef MOF_FONT_HPP +#define MOF_FONT_HPP +#include +#include "mof/tstring.hpp" +#include "mof/PixelMap.hpp" + +namespace mof{ + +class Font{ + struct Impl; + boost::shared_ptr m_pImpl; + +public: + Font(const TCHAR* fontName , size_t size); + ~Font(); + + mof::PixelMap* createText(const mof::tstring& text) const; + + static const TCHAR* MS_GOTHIC; + static const TCHAR* MS_P_GOTHIC; + + static bool addFontResource(const mof::tstring& filename ); +}; + +} + + + +#endif diff --git a/moftmp/Graphics3D.hpp b/moftmp/Graphics3D.hpp new file mode 100755 index 0000000..87c2ef1 --- /dev/null +++ b/moftmp/Graphics3D.hpp @@ -0,0 +1,21 @@ +#ifndef MOF_GRAPHICS3D_HPP +#define MOF_GRAPHICS3D_HPP +#include "mof/Component3D.hpp" +#include "mof/SceneGraph.hpp" +#include "mof/Texture.hpp" + +namespace mof{ + + +class Graphics3D : public Component3D , public SceneGraph { +public : + virtual ~Graphics3D(){} + //virtual const mof::GraphicsUnit& getUnit() = 0; + virtual void setTexture( + unsigned int num , const boost::shared_ptr& pTexture) = 0; + +}; + +} + +#endif diff --git a/moftmp/GraphicsDevice.cpp b/moftmp/GraphicsDevice.cpp new file mode 100755 index 0000000..1ea5be7 --- /dev/null +++ b/moftmp/GraphicsDevice.cpp @@ -0,0 +1,506 @@ + + +#include "mof/private/GraphicsDeviceImpl.hpp" +#include "mof/ConsoleIO.hpp" +#include +#include +#include "mof/private/VertexFVF.hpp" +#include "mof/Material.hpp" +#include "mof/private/TextureImpl.hpp" +#include "mof/Window.hpp" + +namespace +{ + + HWND m_hWnd = NULL; + int m_width; + int m_height; + LPDIRECT3DDEVICE9 m_pDevice = NULL; + LPDIRECT3D9 m_pD3D = NULL; + D3DPRESENT_PARAMETERS* m_pParam = NULL; + IDirect3DStateBlock9* m_pNormalBlendingBlock = NULL; + IDirect3DStateBlock9* m_pAddBlendingBlock = NULL; + IDirect3DStateBlock9* m_pAlphaBlendingBlock = NULL; + int m_currentStateBlock; + mof::Matrix3D m_worldTransform; + mof::Matrix3D m_viewTransform; + mof::Matrix3D m_projectionTransform; + bool m_flagActive; + bool m_flagDeviceLost; +} + + +inline bool isOK(HRESULT hr){ + return hr == S_OK; +} + + +namespace mof +{ + template void GraphicsDevice::drawVertexArray( const VertexXYZRHWCUV& , const VertexXYZRHWCUV& , PRIMITIVE_TYPE ); + template void GraphicsDevice::drawVertexArray( const VertexXYZRHWC& , const VertexXYZRHWC& , PRIMITIVE_TYPE); + template void GraphicsDevice::drawVertexArray( const VertexXYZCUV& , const VertexXYZCUV& , PRIMITIVE_TYPE); + template void GraphicsDevice::drawVertexArray( const VertexXYZNUV& , const VertexXYZNUV& , PRIMITIVE_TYPE); + template void GraphicsDevice::drawVertexArray( const VertexXYZC& , const VertexXYZC& , PRIMITIVE_TYPE); + + + + //TODO ŠÖ”•ªŠ„ + void GraphicsDevice::initialize( const mof::Window& window , int width , int height , bool fullscreen ) + { + + HRESULT hr; + m_hWnd = window.getHandler(); + m_width = width; + m_height = height; + + if( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) + { + throw std::runtime_error( "Failed --- Direct3DCreate9" ); + } + + m_pParam = new D3DPRESENT_PARAMETERS; + ZeroMemory( m_pParam, sizeof(D3DPRESENT_PARAMETERS) ); + m_pParam->Windowed = (fullscreen)? FALSE : TRUE; //TRUE=Window,FALSE=FULLSCREEN + m_pParam->BackBufferCount = 1; + m_pParam->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + + if( fullscreen ) + { + //ƒtƒ‹ƒXƒNƒŠ[ƒ“Žž‚̓oƒbƒNƒoƒbƒtƒ@‚Ì•A‚‚³‚ðÄŽw’è + m_pParam->BackBufferWidth = width; //• + m_pParam->BackBufferHeight = height; //‚‚³ + m_pParam->BackBufferFormat = D3DFMT_X8R8G8B8; //16bit + //m_pParam->BackBufferFormat = D3DFMT_R5G6B5; //16bit + m_pParam->FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; + } + else + { + m_pParam->BackBufferFormat = D3DFMT_UNKNOWN; //Œ»Ý‚̉æ–ʃ‚[ƒh‚ð—˜—p + } + m_pParam->SwapEffect = D3DSWAPEFFECT_DISCARD; + // Z ƒoƒbƒtƒ@‚ÌŽ©“®ì¬ + m_pParam->EnableAutoDepthStencil = 1; + m_pParam->AutoDepthStencilFormat = D3DFMT_D16; + + + + + //HAL(pure vp) + if + ( + FAILED + ( + hr = + m_pD3D->CreateDevice + ( + 0 , D3DDEVTYPE_HAL , m_hWnd , + D3DCREATE_HARDWARE_VERTEXPROCESSING , m_pParam , &m_pDevice + ) + ) + ) + { + //HAL(soft vp) + if + ( + FAILED + ( + hr = + m_pD3D->CreateDevice + ( + 0 , D3DDEVTYPE_HAL , m_hWnd , + D3DCREATE_SOFTWARE_VERTEXPROCESSING , m_pParam , &(m_pDevice) + ) + ) + ) + { + //REF + if + ( + FAILED( + hr = + m_pD3D->CreateDevice + ( + 0 , D3DDEVTYPE_REF , m_hWnd , + D3DCREATE_HARDWARE_VERTEXPROCESSING , m_pParam , &m_pDevice + ) + ) + ) + { + delete m_pParam; + m_pD3D->Release(); + throw std::runtime_error(std::string("Failed --- CreateDevice")); + } + } // if + } // if + + setViewport( mof::Rectangle(0 , 0 , width , height) ); + + // + m_pDevice->SetSamplerState(0 , D3DSAMP_MAGFILTER , D3DTEXF_LINEAR ); //D3DTEXF_POINT + m_pDevice->SetSamplerState(0 , D3DSAMP_MINFILTER , D3DTEXF_LINEAR ); //D3DTEXF_POINT + + + m_pDevice->BeginStateBlock( ); + m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE , TRUE ); + m_pDevice->SetRenderState( D3DRS_SRCBLEND,D3DBLEND_SRCALPHA ); + m_pDevice->SetRenderState( D3DRS_DESTBLEND,D3DBLEND_ONE ); + m_pDevice->SetTextureStageState( 0 , D3DTSS_ALPHAOP,D3DTOP_MODULATE ); //ARG1‚ÆARG2‚̃¿’l‚ðæŽZ‚µ‚ă¿’l‚ðŽæ“¾‚µ‚Ü‚·B + m_pDevice->SetTextureStageState( 0 , D3DTSS_ALPHAARG1,D3DTA_DIFFUSE ); //ƒeƒNƒXƒ`ƒƒ‚̃¿’l + m_pDevice->SetTextureStageState( 0 , D3DTSS_ALPHAARG2,D3DTA_TEXTURE ); //’¸“_‚̃¿ + m_pDevice->SetTextureStageState( 0 , D3DTSS_COLOROP,D3DTOP_MODULATE ); //ARG1‚ÆARG2‚̃Jƒ‰[‚Ì’l‚ðæŽZ‚µ‚Ü‚·B + m_pDevice->SetTextureStageState( 0 , D3DTSS_COLORARG1,D3DTA_TEXTURE ); //ƒeƒNƒXƒ`ƒƒ‚̃Jƒ‰[ + m_pDevice->SetTextureStageState( 0 , D3DTSS_COLORARG2,D3DTA_DIFFUSE ); //’¸“_‚̃Jƒ‰[*/ + m_pDevice->EndStateBlock( &m_pAddBlendingBlock ); + + m_pDevice->BeginStateBlock( ); + m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE , TRUE ); + m_pDevice->SetRenderState( D3DRS_SRCBLEND , D3DBLEND_SRCALPHA ); + m_pDevice->SetRenderState( D3DRS_DESTBLEND , D3DBLEND_INVSRCALPHA ); + m_pDevice->SetTextureStageState( 0 ,D3DTSS_ALPHAOP , D3DTOP_SELECTARG2 ); //ARG1‚ÆARG2‚̃¿’l‚ðæŽZ‚µ‚ă¿’l‚ðŽæ“¾‚µ‚Ü‚·B + m_pDevice->SetTextureStageState( 0 ,D3DTSS_ALPHAARG1 , D3DTA_DIFFUSE ); //ƒeƒNƒXƒ`ƒƒ‚̃¿’l + m_pDevice->SetTextureStageState( 0 ,D3DTSS_ALPHAARG2 , D3DTA_TEXTURE ); //’¸“_‚̃¿’l + m_pDevice->SetTextureStageState( 0 ,D3DTSS_COLOROP , D3DTOP_MODULATE ); //ARG1‚ÆARG2‚̃Jƒ‰[‚Ì’l‚ðæŽZ‚µ‚Ü‚·B + m_pDevice->SetTextureStageState( 0 ,D3DTSS_COLORARG1 , D3DTA_DIFFUSE ); //ƒeƒNƒXƒ`ƒƒ‚̃Jƒ‰[ + m_pDevice->SetTextureStageState( 0 ,D3DTSS_COLORARG2 , D3DTA_TEXTURE ); //’¸“_‚̃Jƒ‰[*/ + m_pDevice->EndStateBlock( &m_pNormalBlendingBlock ); + + m_pDevice->BeginStateBlock( ); + m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE , TRUE ); + m_pDevice->SetRenderState( D3DRS_SRCBLEND , D3DBLEND_SRCALPHA ); + m_pDevice->SetRenderState( D3DRS_DESTBLEND , D3DBLEND_INVSRCALPHA ); + m_pDevice->SetTextureStageState( 0,D3DTSS_ALPHAOP , D3DTOP_MODULATE ); //ARG1‚ÆARG2‚̃¿’l‚ðæŽZ‚µ‚ă¿’l‚ðŽæ“¾‚µ‚Ü‚·B + m_pDevice->SetTextureStageState( 0,D3DTSS_ALPHAARG1 , D3DTA_DIFFUSE ); //ƒeƒNƒXƒ`ƒƒ‚̃¿’l + m_pDevice->SetTextureStageState( 0,D3DTSS_ALPHAARG2 , D3DTA_TEXTURE ); //’¸“_‚̃¿’l + m_pDevice->SetTextureStageState( 0,D3DTSS_COLOROP , D3DTOP_MODULATE ); //ARG1‚ÆARG2‚̃Jƒ‰[‚Ì’l‚ðæŽZ‚µ‚Ü‚·B + m_pDevice->SetTextureStageState( 0,D3DTSS_COLORARG1 , D3DTA_DIFFUSE ); //ƒeƒNƒXƒ`ƒƒ‚̃Jƒ‰[ + m_pDevice->SetTextureStageState( 0,D3DTSS_COLORARG2 , D3DTA_TEXTURE ); //’¸“_‚̃Jƒ‰[*/ + m_pDevice->EndStateBlock( &m_pAlphaBlendingBlock ); + + setProjectionTransform(0.1f , 100); + } // function initialize + + + + void GraphicsDevice::finalize( ) + { + m_pAddBlendingBlock->Release(); + m_pNormalBlendingBlock->Release(); + m_pAlphaBlendingBlock->Release(); + if(m_pDevice != NULL)m_pDevice->Release(); + if(m_pD3D != NULL)m_pD3D->Release(); + delete m_pParam; + } + + + + + void GraphicsDevice::beginScene( ) + { + + + if(true == m_flagDeviceLost) + { + Sleep(100); // 0.1•b‘Ò‚Â + if(/*m_flagActive == true &&*/ m_pDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET ) + { + //---ƒfƒoƒCƒX•œ‹A‚ðŽŽ‚Ý‚é + + if( FAILED( m_pDevice->Reset( m_pParam) ) )return; + + //ƒfƒoƒCƒX‚Ì•œ‹A‚ɐ¬Œ÷ + m_flagDeviceLost = false; + //---ƒXƒe[ƒg‚𕜋A + DEBUG_PRINT( "DeviceRecovered!" ); + } + else return; + } + + + + if( !isOK( m_pDevice->BeginScene( ) ) ) + { + throw std::runtime_error("Failed --- BeginScene"); + } + + + } // function beginScene + + + + + void GraphicsDevice::endScene( ) + { + + if( !isOK( m_pDevice->EndScene() ) ) + { + throw std::runtime_error("Failed --- EndScene"); + } + + //ƒoƒbƒNƒoƒbƒtƒ@‚©‚çƒvƒ‰ƒCƒ}ƒŠƒoƒbƒtƒ@‚Ö“]‘— + HRESULT hr = m_pDevice->Present( NULL, NULL, NULL, NULL ); + + if( hr == D3DERR_DEVICELOST && false == m_flagDeviceLost ) + { + DEBUG_PRINT( "DeviceLost!" ); + m_flagDeviceLost = true; + //ƒŠƒ\[ƒX‚̉ð•úˆ— + + } + + + if( !isOK( hr ) )throw std::runtime_error("Present"); + + + } // function endScene + + + + + void GraphicsDevice::setWorldTransform( const mof::Matrix3D& matrix ) + { + m_worldTransform = matrix; + D3DXMATRIX mat; + for(int i = 0 ; i < 4 ; ++i ){ + for(int j = 0 ; j < 4 ; ++j){ + mat(i , j) = matrix.at(i , j); + } + } + m_pDevice->SetTransform( D3DTS_WORLD, &mat ); + } + + + + void GraphicsDevice::setProjectionTransform( real min , real max ) + { + D3DXMATRIX matProj; + D3DXMatrixPerspectiveFovLH + ( + &matProj, D3DX_PI / 4.0f, + static_cast(getViewportWidth()) / static_cast(getViewportHeight()) , min, max + ); + + mof::Matrix3D::Array arry; + for(int i = 0 ; i < 4 ; ++i ){ + for(int j = 0 ; j < 4 ; ++j){ + arry.elements[i][j] = matProj( i , j ); + } + } + m_projectionTransform = mof::Matrix3D( arry ); + m_pDevice->SetTransform( D3DTS_PROJECTION , &matProj ); + + } + + + + void GraphicsDevice::setViewTransform( const mof::Matrix3D& matrix ) + { + m_viewTransform = matrix; + D3DXMATRIX mat; + for(int i = 0 ; i < 4 ; ++i ){ + for(int j = 0 ; j < 4 ; ++j){ + mat(i , j) = matrix.at(i , j); + } + } + m_pDevice->SetTransform( D3DTS_VIEW , &mat ); + } + + + + + const mof::Matrix3D& GraphicsDevice::getWorldTransform( ) + { + return m_worldTransform; + } + + + + const mof::Matrix3D& GraphicsDevice::getProjectionTransform() + { + return m_projectionTransform; + } + + + + const mof::Matrix3D& GraphicsDevice::getViewTransform() + { + return m_viewTransform; + } + + + + void GraphicsDevice::setZBuffer( bool available ) + { + if( available )m_pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE ); + else m_pDevice->SetRenderState( D3DRS_ZENABLE , D3DZB_FALSE ); + } + + + + void GraphicsDevice::lightEnable( bool available ) + { + m_pDevice->SetRenderState( D3DRS_LIGHTING , available ); + } + + + + void GraphicsDevice::clearZBuffer() + { + m_pDevice->Clear( 0 , NULL , D3DCLEAR_ZBUFFER , 0 , 1.0f, 0 ); + } + + + + void GraphicsDevice::clearRenderTarget( mof::Color color ) + { + m_pDevice->Clear( 0 , 0 , D3DCLEAR_TARGET , color , 0 , 0 ); + } + + + + void GraphicsDevice::setAlphaBlendingMode( const int flag ) + { + if(flag == m_currentStateBlock )return; + + if( flag == mof::GraphicsDevice::BLENDING_MODE_ADD ){ + m_pAddBlendingBlock->Apply(); + } + else if(flag == mof::GraphicsDevice::BLENDING_MODE_BASIC) + { + m_pNormalBlendingBlock->Apply(); + } + else if( flag == mof::GraphicsDevice::BLENDING_MODE_ALPHA ) + { + m_pAlphaBlendingBlock->Apply(); + } + + m_currentStateBlock = flag; + } + + + + Vector2D GraphicsDevice::to2DPosition( const mof::Vector3D& position ) + { + mof::Matrix3D matrix = m_worldTransform; + matrix = m_viewTransform * m_projectionTransform; + int hWidth = getViewportWidth() / 2; + int hHeight = getViewportHeight() / 2; + mof::Vector3D tmpPosition = position * matrix; + + return mof::Vector2D + ( + static_cast(tmpPosition.x * hWidth + hWidth ) , + static_cast(-tmpPosition.y * hHeight + hHeight) + ); + } + + + void GraphicsDevice::setViewport( const mof::Rectangle& area ) + { + D3DVIEWPORT9 vp; + vp.X = area.beginX; + vp.Y = area.beginY; + vp.Width = area.getWidth( ); + vp.Height = area.getHeight( ); + vp.MinZ = 0.0f; + vp.MaxZ = 1.0f; + if( FAILED( m_pDevice->SetViewport( &vp ) ) ) + { + throw std::runtime_error( "Failed --- SetViewport" ); + } + } + + int GraphicsDevice::getViewportWidth( ) + { + D3DVIEWPORT9 vp; + if( FAILED(m_pDevice->GetViewport( &vp ) ) ) + { + throw std::runtime_error("Failed --- getViewportWidth"); + } + return vp.Width; + } + + + int GraphicsDevice::getViewportHeight() { + D3DVIEWPORT9 vp; + if( FAILED( m_pDevice->GetViewport( &vp ) ) ) + { + throw std::runtime_error("Failed --- getViewportHeight"); + } + return vp.Height; + } + + + + + template + void GraphicsDevice::drawVertexArray( const T& front , const T& last , mof::PRIMITIVE_TYPE type ) + { + HRESULT hr = E_FAIL; + if(&last < &front)return; + int length = &last - &front + 1; //’¸“_” + + m_pDevice->SetFVF( mof::getFVF() ); + + if(type == mof::PRIMITIVE_TYPE_TRIANGLESTRIP) + { + hr = m_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP , length > 3 ? length - 2 : 1 , (const void*)&front , sizeof(T) ); + } + else if( type == PRIMITIVE_TYPE_TRIANGLELIST ) + { + hr = m_pDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST , length / 3 , (const void*)&front , sizeof(T) ); + } + else if( type == mof::PRIMITIVE_TYPE_LINELIST ) + { + hr = m_pDevice->DrawPrimitiveUP(D3DPT_LINELIST , length / 2 , (const void*)&front , sizeof(T) ); + } + + if( FAILED( hr ) ) + { + throw std::runtime_error("Failed -- DrawPrimitiveUP"); + } + + } // function drawVertexArray + + + + void GraphicsDevice::setMaterial(const mof::Material& material){ + D3DMATERIAL9 mat; + + memcpy(static_cast(&mat) , static_cast(&material) , sizeof(D3DMATERIAL9)); + + if( FAILED( m_pDevice->SetMaterial( &mat ) ) ) + { + throw std::runtime_error("Faild --- SetMaterial"); + } + } + + + void GraphicsDevice::setTexture( const mof::Texture* pTexture ) + { + if( pTexture == NULL )m_pDevice->SetTexture( 0 , NULL ); + else m_pDevice->SetTexture( 0 , pTexture->m_pImpl->pTexture ); + } + + + mof::Rectangle GraphicsDevice::getClientRegion() + { + + + RECT rect; + GetWindowRect(m_hWnd , &rect); + POINT point; + point.x = rect.left; + point.y = rect.top; + ScreenToClient(m_hWnd , &point); + int beginX = rect.left - point.x; + int beginY = rect.top - point.y; + return mof::Rectangle(beginX , beginY , beginX + m_width , beginY + m_height); + } + + LPDIRECT3DDEVICE9 GraphicsDevice::getRawDevice( ) + { + return m_pDevice; + } + +} // namespace GraphicsDevice diff --git a/moftmp/GraphicsDevice.hpp b/moftmp/GraphicsDevice.hpp new file mode 100755 index 0000000..711e671 --- /dev/null +++ b/moftmp/GraphicsDevice.hpp @@ -0,0 +1,56 @@ +#pragma once +#include "mof/real.hpp" +#include "mof/Color.hpp" +#include "mof/Matrix3D.hpp" +#include "mof/VertexTypes.hpp" +#include +#include +#include "mof/Rectangle.hpp" + + + +namespace mof{ + struct Material; + class Texture; + + namespace GraphicsDevice + { + + // public + + enum BlendingMode + { + BLENDING_MODE_ADD , + BLENDING_MODE_BASIC , + BLENDING_MODE_ALPHA + }; + + void setWorldTransform( const mof::Matrix3D& matrix ); + void setProjectionTransform( real min , real max ); + void setViewTransform( const mof::Matrix3D& matrix ); + const mof::Matrix3D& getWorldTransform( ); + const mof::Matrix3D& getProjectionTransform( ); + const mof::Matrix3D& getViewTransform( ); + void setZBuffer( bool flag ); + void lightEnable( bool enable ); + void clearZBuffer( ); + void clearRenderTarget( mof::Color color ); + void setAlphaBlendingMode( const int flag ); + mof::Vector2D to2DPosition( const mof::Vector3D& position ); + void setViewport( const mof::Rectangle& area ); + int getViewportWidth( ); + int getViewportHeight( ); + + template void drawVertexArray + ( + const T& front , const T& last , + mof::PRIMITIVE_TYPE type = PRIMITIVE_TYPE_TRIANGLELIST + ); + void setMaterial( const mof::Material& material ); + void setTexture( const mof::Texture* pTexture ); + mof::Rectangle getClientRegion( ); + + } // namespace GraphicsDevice + + +} // namespace mof diff --git a/moftmp/GraphicsObject.cpp b/moftmp/GraphicsObject.cpp new file mode 100755 index 0000000..ce24629 --- /dev/null +++ b/moftmp/GraphicsObject.cpp @@ -0,0 +1,15 @@ + +#include "mof/GraphicsObject.h" +#include + +mof::GraphicsObject::GraphicsObject(void) +: m_pAnimations( new mof::CascadeAnimation()) +{ + +} + +mof::GraphicsObject::~GraphicsObject(void) +{ + +} + diff --git a/moftmp/GraphicsSchedule.cpp b/moftmp/GraphicsSchedule.cpp new file mode 100755 index 0000000..9205b47 --- /dev/null +++ b/moftmp/GraphicsSchedule.cpp @@ -0,0 +1,66 @@ +#include "mof/GraphicsSchedule.h" +#include "mof/ConsoleIO.h" + + + + + +mof::GraphicsSchedule::GraphicsSchedule(){ + m_key = 0; + +} + +mof::GraphicsSchedule::~GraphicsSchedule(){ + +} + +void mof::GraphicsSchedule::update(){ + + std::pair range = m_map.equal_range(m_key); + for(MapItr itr = range.first ; itr != range.second ; ++itr){ + if((*itr).second.pAnimation.get() != NULL){ + (*itr).second.pObject->setAnimation(0 , (*itr).second.pAnimation); + (*itr).second.pAnimation->start(); + } + } + + m_key++; +} + +void mof::GraphicsSchedule::add(int index , mof::GraphicsModelPtr& pObject , mof::AnimationResource& pAnimation){ + if(pObject.get() == NULL)return; + if(pAnimation.get() != NULL)pAnimation->stop(); + mof::GraphicsSchedule::Element element = {pObject , pAnimation }; + m_modelList.push_back(pObject); + m_map.insert(std::multimap::value_type(index , element)); +} + +std::list& mof::GraphicsSchedule::appendModelList( std::list& modelList){ + modelList.insert(modelList.end() , m_modelList.begin() , m_modelList.end()); + return modelList; +} + + + + +bool mof::GraphicsSchedule::isFinalized(){ + if(m_map.size() == 0)return true; + for(MapItr itr = m_map.begin() ; itr != m_map.end() ; ++itr){ + if(!itr->second.pAnimation->isFinalized() )return false; + } + return true; +} + + +bool mof::GraphicsSchedule::isPlaying(){ + for(MapItr itr = m_map.begin() ; itr != m_map.end() ; ++itr){ + if(itr->second.pAnimation->isPlaying() || itr->second.pAnimation->isFinalized())return true; + } + return false; +} + + +void mof::GraphicsSchedule::clear(){ + m_key = 0; + m_map.clear(); +} \ No newline at end of file diff --git a/moftmp/GraphicsSchedule.h b/moftmp/GraphicsSchedule.h new file mode 100755 index 0000000..c3b8416 --- /dev/null +++ b/moftmp/GraphicsSchedule.h @@ -0,0 +1,37 @@ +#pragma once +#include "mof/GraphicsObject.h" +#include +#include +#include + +namespace mof{ + + typedef boost::shared_ptr GraphicsModelPtr; + + class GraphicsSchedule{ + + struct Element{ + mof::GraphicsModelPtr pObject; + mof::AnimationResource pAnimation; + }; + typedef std::multimap::iterator MapItr; + + std::multimap m_map; + std::list m_modelList; + int m_key; + public: + GraphicsSchedule(); + ~GraphicsSchedule(); + + void update(); + void add(int index , mof::GraphicsModelPtr& pObject , mof::AnimationResource& pAnimation); + bool isFinalized(); + bool isPlaying(); + void clear(); + bool isEmpty(){return m_map.empty();} + + std::list& appendModelList( std::list& modelList); + + }; + +}; \ No newline at end of file diff --git a/moftmp/GraphicsUnit.hpp b/moftmp/GraphicsUnit.hpp new file mode 100755 index 0000000..5fdfa65 --- /dev/null +++ b/moftmp/GraphicsUnit.hpp @@ -0,0 +1,17 @@ +#pragma once +#include +#include "mof/Material.hpp" +#include "mof/Texture.hpp" +#include "mof/VertexBuffer.hpp" +#include "mof/VertexTypes.hpp" + +namespace mof{ + + struct GraphicsUnit + { + boost::shared_ptr pMaterial; + boost::shared_ptr pTexture; + boost::shared_ptr > pModel; + }; + +} diff --git a/moftmp/InputDevice.cpp b/moftmp/InputDevice.cpp new file mode 100755 index 0000000..4cab3a9 --- /dev/null +++ b/moftmp/InputDevice.cpp @@ -0,0 +1,310 @@ +#include "mof/private/DirectInput.hpp" +#include +#include "mof/InputReceiver.hpp" +#include "mof/InputDevice.hpp" +#include "mof/ConsoleIO.hpp" +#include "mof/private/DeviceInputReceiver.hpp" +#include "boost/shared_ptr.hpp" + +namespace { + LPDIRECTINPUT8 pInput; + LPDIRECTINPUTDEVICE8A pDevice; + boost::shared_ptr pInputReceiver;//ŠO•”‚É“n‚·‚½‚ß + mof::DeviceInputReceiver* pDeviceInputReceiver;//ã‹L‚Æ“¯‚¶ƒCƒ“ƒXƒ^ƒ“ƒX +} + +//--- ƒvƒƒgƒ^ƒCƒvéŒ¾ +BOOL CALLBACK enumJoyCallback(const DIDEVICEINSTANCE* pInstance , VOID* pContext); + +/** + * mof::InputDevice::initialize + * + */ +void mof::InputDevice::initialize( ){ + HINSTANCE hInst = GetModuleHandle(NULL); + HRESULT hr; + hr = DirectInput8Create(hInst , DIRECTINPUT_VERSION ,IID_IDirectInput8 , (void**)&pInput , NULL); + if(FAILED(hr)){ + switch(hr){ + case DIERR_BETADIRECTINPUTVERSION : + DEBUG_PRINT("DIERR_BETADIRECTINPUTVERSION"); + break; + case DIERR_INVALIDPARAM : + DEBUG_PRINT("DIERR_INVALIDPARAM"); + break; + case DIERR_OLDDIRECTINPUTVERSION : + DEBUG_PRINT("DIERR_OLDDIRECTINPUTVERSION"); + break; + case DIERR_OUTOFMEMORY : + DEBUG_PRINT("DIERR_OUTOFMEMORY"); + break; + } + throw std::runtime_error("Failed --- create direct input"); + } + + LPCDIDATAFORMAT dataFmt = &c_dfDIJoystick;//ƒWƒ‡ƒCƒXƒeƒBƒbƒN‚ªŽæ“¾‚Å‚«‚½‚Ɖ¼’è + //---ƒfƒoƒCƒX‚̐ݒè + //ƒQ[ƒ€ƒpƒbƒhƒfƒoƒCƒX‚ð’T‚· + hr = pInput->EnumDevices(DI8DEVCLASS_GAMECTRL , enumJoyCallback , NULL , DIEDFL_ATTACHEDONLY); + if(FAILED(hr) || pDevice == NULL){ + //ƒQ[ƒ€ƒpƒbƒh‚ª‚È‚¯‚ê‚΃L[ƒ{[ƒh + hr = pInput->CreateDevice(GUID_SysKeyboard , &pDevice , NULL); + if(FAILED(hr)){ + pInput->Release(); + pInput = NULL; + throw std::runtime_error("Failed --- create device"); + } + dataFmt = &c_dfDIKeyboard;//ƒL[ƒ{[ƒh‚ðƒfƒoƒCƒX‚Æ‚µ‚Ď擾 + DEBUG_PRINT("Select --- keyboard as input device"); + } + else DEBUG_PRINT("Select --- joystick as input device"); + + hr = pDevice->SetDataFormat(dataFmt); + if(FAILED(hr)){ + pDevice->Release(); + pDevice = NULL; + pInput->Release(); + pInput = NULL; + throw std::runtime_error("Failed --- set data format"); + } + + + DIPROPDWORD diprop; + diprop.diph.dwSize = sizeof(diprop); + diprop.diph.dwHeaderSize = sizeof(diprop.diph); + diprop.diph.dwObj = 0; + diprop.diph.dwHow = DIPH_DEVICE; + diprop.dwData = 1000; + pDevice->SetProperty(DIPROP_BUFFERSIZE , &diprop.diph); + setActivation(true); + + pDeviceInputReceiver = new mof::DeviceInputReceiver(); + pInputReceiver = boost::shared_ptr(pDeviceInputReceiver); +} + + + +/** + * mof::InputDevice::finalize + * + */ +void mof::InputDevice::finalize(void) +{ + mof::InputDevice::setActivation(false); + if(pDevice != NULL)pDevice->Release(); + if(pInput != NULL)pInput->Release(); +} + + +void mof::InputDevice::setActivation(bool active){ + if(pDevice == NULL)return; + + if(active == false)pDevice->Unacquire(); + else pDevice->Acquire(); +} + + + +BOOL CALLBACK enumJoyCallback(const DIDEVICEINSTANCE* pInstance , VOID* /*pContext*/ ){ + HRESULT hr; + + hr = pInput->CreateDevice(pInstance->guidInstance , &(pDevice) , NULL); + if(FAILED(hr))return DIENUM_CONTINUE; + + DIDEVICEINSTANCE deviceInstance; + deviceInstance.dwSize = sizeof(DIDEVCAPS); + hr = pDevice->GetCapabilities((LPDIDEVCAPS)&deviceInstance); + if(FAILED(hr)){ + pDevice->Release(); + pDevice = NULL; + return DIENUM_CONTINUE; + } + + *ConsoleOut::getInstance() << "Found InputDevice --- " << deviceInstance.tszInstanceName + << ":" << deviceInstance.tszProductName << std::endl; + return DIENUM_STOP;//‰½‚Å‚à‚¢‚¢‚©‚çÌ—p +} + + +void mof::InputDevice::update(){ + + HRESULT hr; + while(true){ + DIDEVICEOBJECTDATA od; + DWORD dwItems = 1; + hr = pDevice->GetDeviceData(sizeof(DIDEVICEOBJECTDATA) , &od , &dwItems , 0); + if(hr == DIERR_INPUTLOST)pDevice->Acquire(); + else if(FAILED(hr) || dwItems == 0)return; + + InputEvent iEvent(od.dwOfs , od.dwData); + //inputSignal(iEvent); + pDeviceInputReceiver->notifyInputEvent(iEvent); + + /*for(int i = 0 ; i < listenerList.size() ; ++i){ + int tmpSize = listenerList.size(); + listenerList.at(i)->notifyInputEvent(iEvent); + if(tmpSize != listenerList.size())i--;//NotifyInputEvent‚ÅRemove‚³‚ꂽ‚©‚ðƒ`ƒFƒbƒN + }*/ + + } + + +} + + + +boost::shared_ptr mof::InputDevice::getInputReceiver(){ + return pInputReceiver; +} + + +/* +namespace mof{ + + class DeviceInputReceiver; + + class InputDevice + { + + + std::vector listenerList; + + void addReceiver(DeviceInputReceiver* pReceiver); + public: + InputDevice(void); + ~InputDevice(void); + + + bool initialize( HINSTANCE hInst); + static BOOL CALLBACK enumJoyCallback(const DIDEVICEINSTANCE* pInstance , VOID* pContext); + + void activate(bool); + void updateInputData(); + InputReceiver* getInputReceiver(); + void removeReceiver(DeviceInputReceiver* pReceiver); + //void clearListenerList(); + + + }; + +}; + +typedef std::vector::iterator LISTENERITR; + +mof::InputDevice::InputDevice(void) +{ + m_pInput = NULL; + m_pDevice = NULL; +} + +mof::InputDevice::~InputDevice(void) +{ + activate(false); + if(m_pDevice != NULL)m_pDevice->Release(); + if(m_pInput != NULL)m_pInput->Release(); +} + + +bool mof::InputDevice::initialize( HINSTANCE hInst){ + HRESULT hr; + hr = DirectInput8Create(hInst , DIRECTINPUT_VERSION ,IID_IDirectInput8 , (void**)&m_pInput , NULL); + if(FAILED(hr))return false; + + LPCDIDATAFORMAT dataFmt = &c_dfDIJoystick;//ƒWƒ‡ƒCƒXƒeƒBƒbƒN‚ªŽæ“¾‚Å‚«‚½‚Ɖ¼’è + //---ƒfƒoƒCƒX‚̐ݒè + //ƒQ[ƒ€ƒpƒbƒhƒfƒoƒCƒX‚ð’T‚· + hr = m_pInput->EnumDevices(DI8DEVCLASS_GAMECTRL , enumJoyCallback , NULL , DIEDFL_ATTACHEDONLY); + if(FAILED(hr) || m_pDevice == NULL){ + //ƒQ[ƒ€ƒpƒbƒh‚ª‚È‚¯‚ê‚΃L[ƒ{[ƒh + hr = m_pInput->CreateDevice(GUID_SysKeyboard , &m_pDevice , NULL); + if(FAILED(hr)){ + m_pInput->Release(); + m_pInput = NULL; + return false; + } + else dataFmt = &c_dfDIKeyboard;//ƒL[ƒ{[ƒh‚ðƒfƒoƒCƒX‚Æ‚µ‚Ď擾 + } + + + hr = m_pDevice->SetDataFormat(dataFmt); + if(FAILED(hr)){ + *ConsoleOut::getInstance() << "SetDataFormat --- ERROR" << std::endl; + m_pDevice->Release(); + m_pDevice = NULL; + m_pInput->Release(); + m_pInput = NULL; + return false; + } + + //m_pDevice->SetCooperativeLevel( hWnd , DISCL_FOREGROUND); + + DIPROPDWORD diprop; + diprop.diph.dwSize = sizeof(diprop); + diprop.diph.dwHeaderSize = sizeof(diprop.diph); + diprop.diph.dwObj = 0; + diprop.diph.dwHow = DIPH_DEVICE; + diprop.dwData = 1000; + m_pDevice->SetProperty(DIPROP_BUFFERSIZE , &diprop.diph); + activate(true); + return true; +} + + +void mof::InputDevice::activate(bool active){ + if(m_pDevice == NULL)return; + + if(active == false)m_pDevice->Unacquire(); + else m_pDevice->Acquire(); +} + +void mof::InputDevice::updateInputData(){ + + HRESULT hr; + while(true){ + DIDEVICEOBJECTDATA od; + DWORD dwItems = 1; + hr = m_pDevice->GetDeviceData(sizeof(DIDEVICEOBJECTDATA) , &od , &dwItems , 0); + if(hr == DIERR_INPUTLOST)m_pDevice->Acquire(); + else if(FAILED(hr) || dwItems == 0)return; + + InputEvent iEvent(od.dwOfs , od.dwData); + //inputSignal(iEvent); + + for(int i = 0 ; i < listenerList.size() ; ++i){ + int tmpSize = listenerList.size(); + listenerList.at(i)->notifyInputEvent(iEvent); + if(tmpSize != listenerList.size())i--;//NotifyInputEvent‚ÅRemove‚³‚ꂽ‚©‚ðƒ`ƒFƒbƒN + } + + } + + +} + + + +mof::InputReceiver* mof::InputDevice::getInputReceiver(){ + mof::DeviceInputReceiver* pReceiver = new mof::DeviceInputReceiver(); + addReceiver(pReceiver); + return pReceiver; + +} + + +void mof::InputDevice::addReceiver(mof::DeviceInputReceiver* pReceiver){ + for(LISTENERITR itr = listenerList.begin() ; itr != listenerList.end() ; ++itr){ + if((*itr) == pReceiver)return;//Šù‚É“o˜^Ï‚Ý + } + listenerList.push_back(pReceiver); +} + +void mof::InputDevice::removeReceiver(mof::DeviceInputReceiver* pReceiver){ + for(LISTENERITR itr = listenerList.begin() ; itr != listenerList.end() ; ++itr){ + if((*itr) == pReceiver){ + listenerList.erase(itr); + return; + } + } + +} +*/ diff --git a/moftmp/InputDevice.hpp b/moftmp/InputDevice.hpp new file mode 100755 index 0000000..d861cf0 --- /dev/null +++ b/moftmp/InputDevice.hpp @@ -0,0 +1,23 @@ +#pragma once +#include +#include + +//TODO private‚͕ʃtƒ@ƒCƒ‹‚É +namespace mof { + class InputReceiver; + + namespace InputDevice{ + + // --- private + void initialize(); + void finalize(); + void setActivation(bool active); + void update(); + + // -- public + boost::shared_ptr getInputReceiver(); + + + + } +} \ No newline at end of file diff --git a/moftmp/InputEventCondition.cpp b/moftmp/InputEventCondition.cpp new file mode 100755 index 0000000..d20a428 --- /dev/null +++ b/moftmp/InputEventCondition.cpp @@ -0,0 +1,24 @@ +#include "mof/InputEventCondition.hpp" + +mof::InputEventCondition::InputEventCondition( + mof::InputReceiver::Key key, + const boost::shared_ptr &pInputReceiver) + : m_key(key) , m_pInputReceiver(pInputReceiver) +{ + update(); +} + +mof::InputEventCondition::~InputEventCondition(){ +} + +bool mof::InputEventCondition::test(){ + return m_state; +} + +void mof::InputEventCondition::update(){ + m_state = m_pInputReceiver->testKeyState(m_key); +} + +bool mof::InputEventCondition::isDisposable(){ + return false; +} diff --git a/moftmp/InputEventCondition.hpp b/moftmp/InputEventCondition.hpp new file mode 100755 index 0000000..709740e --- /dev/null +++ b/moftmp/InputEventCondition.hpp @@ -0,0 +1,27 @@ +#pragma once +#include "mof/EventCondition.hpp" +#include "mof/InputReceiver.hpp" +#include "boost/shared_ptr.hpp" + +namespace mof{ + + + class InputEventCondition : public EventCondition{ + mof::InputReceiver::Key m_key; + boost::shared_ptr m_pInputReceiver; + bool m_state; + public: + InputEventCondition( + mof::InputReceiver::Key key , + const boost::shared_ptr& pInputReceiver + ); + + virtual ~InputEventCondition(); + virtual bool test(); + virtual void update(); + virtual bool isDisposable(); + }; + + +} + diff --git a/moftmp/InputReceiver.hpp b/moftmp/InputReceiver.hpp new file mode 100755 index 0000000..7765ace --- /dev/null +++ b/moftmp/InputReceiver.hpp @@ -0,0 +1,28 @@ +#pragma once + + +namespace mof{ + + class InputReceiver{ + public: + typedef enum{ + UP = 0 , DOWN , LEFT , RIGHT , + A , B , C , D , E , F , G , H , I , + J , K , L , M , N , O , P , Q , R , + S , T , U , V , W , X , Y , Z , + ESCAPE , + END //ÅŒã‚Í•K‚¸‚±‚ê‚ŏI‚í‚é‚悤‚É + } Key; + + + virtual ~InputReceiver(){} + virtual bool testKeyState(Key key) = 0; + + /** + * •s“Á’葽”‚̃IƒuƒWƒFƒNƒg‚ª‚±‚̃ƒ\ƒbƒh‚ðŒÄ‚яo‚·‚ƁA + * ˆÓ}‚µ‚½“ü—͏ˆ—‚ª‚Å‚«‚È‚¢‰Â”\«‚ª‚ ‚è‚Ü‚·B + */ + virtual void update() = 0; + + }; +}; diff --git a/moftmp/InstructionSet.hpp b/moftmp/InstructionSet.hpp new file mode 100755 index 0000000..bb1480c --- /dev/null +++ b/moftmp/InstructionSet.hpp @@ -0,0 +1,47 @@ +#pragma once +#include +//#include "mof/MessageWidget.hpp" +#include "mof/tstring.hpp" + +namespace mof +{ + class MessageWidget; + + class InstructionSet + { + public: + /** + * @brief ƒƒbƒZ[ƒWƒEƒBƒ“ƒhƒE‚𐶐¬‚·‚邽‚߂̃R[ƒ‹ƒoƒbƒN + * @return ¶¬‚µ‚½ƒƒbƒZ[ƒWƒEƒBƒ“ƒhƒE + */ + virtual boost::shared_ptr< MessageWidget > createMessageWidget( ) = 0; + + /** + * @brief ƒƒbƒZ[ƒWƒEƒBƒ“ƒhƒE‚Ƀy[ƒW‚ð’ljÁ‚·‚邽‚߂̃R[ƒ‹ƒoƒbƒN + * @param[in] ƒƒbƒZ[ƒW‚̃^ƒCƒgƒ‹ + * @param[in] ƒƒbƒZ[ƒW“à—e + * @return ¶¬‚µ‚½ƒƒbƒZ[ƒWƒEƒBƒ“ƒhƒE + */ + virtual int addMessageWidgetPage + ( + boost::shared_ptr& message , + const tstring& title , + const tstring& text + ) = 0; + + + + /** + * @brief ƒNƒ‰ƒCƒAƒ“ƒg‘¤‚ňø‚«‘±‚«ƒŠƒ\[ƒX‚ð—˜—p‚·‚邽‚߂̃R[ƒ‹ƒoƒbƒN + * @note ˆø”‚Å“n‚³‚ꂽƒŠƒ\[ƒX‚ª‚±‚̃Nƒ‰ƒX‚̃IƒuƒWƒFƒNƒg‚É‚æ‚荡ŒãŽQÆ‚³‚ê‚邱‚Æ‚Í‚È‚¢ + * @param[in] •s—v‚Æ‚È‚Á‚½ƒŠƒ\[ƒX + */ + virtual void inactive( boost::shared_ptr& message ) = 0; + + virtual ~InstructionSet(){} + + }; + +} + + diff --git a/moftmp/Interpolation.hpp b/moftmp/Interpolation.hpp new file mode 100755 index 0000000..ae9390c --- /dev/null +++ b/moftmp/Interpolation.hpp @@ -0,0 +1,79 @@ + #pragma once + #include "mof/Vector2D.hpp" + #include "mof/stream/Manipulator.hpp" + #include + #include + + namespace mof{ + + template + T stepInterpolate(const std::map& map , mof::FrameNumber current ){ + if(map.empty())throw std::invalid_argument("the map is empty"); + for( + typename std::map::const_reverse_iterator itr = map.rbegin() ; + itr != map.rend() ; + ++itr + ){ + if(itr->first <= current)return itr->second; + } + return map.begin()->second;//default + } + + template inline + T calcLinerInterpolationValue( float blending , const T& prevObj , const T& nextObj){ + return (1 - blending) * prevObj + blending * nextObj; + } + + //Œë·’ጸ‚Ì‚½‚ß‚Ì“ÁŽê‰» + /*template<> inline + Vector2D calcLinerInterpolationValue( float blending , const Vector2D& prev , const Vector2D& next ) + { + return mof::Vector2D + ( + prev.x != next.x ? (1 - blending) * prev.x + blending * next.x : prev.x , + prev.y != next.y ? (1 - blending) * prev.y + blending * next.y : prev.y + ); + }*/ + + template + T linerInterpolate(const std::map& map , mof::FrameNumber current ){ + if(map.empty())throw std::invalid_argument("the map is empty"); + typename std::map::const_iterator n = map.find(current); + if(n != map.end())return n->second;// just key frame + + //’¼‘OA’¼Œã‚̃L[‚ðŒŸõ + mof::FrameNumber prevKeyFrame = current; + bool foundPrev = false; + T prevObj; + mof::FrameNumber nextKeyFrame = current; + bool foundNext = false; + T nextObj; + + for( + typename std::map::const_iterator itr = map.begin() ; + itr != map.end() ; + ++itr + ){ + if(itr->first < current && (!foundPrev || itr->first > prevKeyFrame)){ + foundPrev = true; + prevKeyFrame = itr->first; + prevObj = itr->second; + } + else if(itr->first > current && (!foundNext || itr->first < nextKeyFrame)){ + foundNext = true; + nextKeyFrame = itr->first; + nextObj = itr->second; + } + + } + + assert(foundPrev || foundNext); + if(!foundPrev && foundNext)return nextObj;//’¼‘O‚̃L[‚ÍŒ©‚‚©‚ç‚È‚©‚Á‚½ + else if(foundPrev && !foundNext)return prevObj;//’¼Œã‚̃L[‚ÍŒ©‚‚©‚ç‚È‚©‚Á‚½ + float blending = static_cast(current - prevKeyFrame) / static_cast(nextKeyFrame - prevKeyFrame); + return calcLinerInterpolationValue(blending , prevObj , nextObj); + } + + } //namespace mof + + diff --git a/moftmp/Interpreter.cpp b/moftmp/Interpreter.cpp new file mode 100755 index 0000000..c66a117 --- /dev/null +++ b/moftmp/Interpreter.cpp @@ -0,0 +1,167 @@ +#include "mof/Interpreter.hpp" +#include "mof/private/Interpreter.hpp" +#include "mof/private/regist.hpp" +#include "mof/EventScheduler.hpp" +#include "mof/OnceEventCondition.hpp" +#include "mof/InputReceiver.hpp" +#include "mof/MessageWidget.hpp" +#include "mof/LuaScript.hpp" +#include "mof/KeyPressedEventCondition.hpp" +#include "mof/ConsoleIO.hpp" +#include "mof/utilities.hpp" +#include + +typedef boost::shared_ptr< mof::MessageWidget > MessageWidgetHandler; + +//{{{ ƒ‚ƒWƒ…[ƒ‹•Ï” +namespace +{ + + std::vector m_messages; + mof::EventScheduler m_scheduler; + mof::LuaScript* m_pLua; + boost::shared_ptr m_pInput; + mof::InstructionSet* m_pInstructionSet; + mof::Interpreter::State m_state; +} // namepsace +//}}} +namespace mof +{ +//{{{ _setState + void _setState( Interpreter::State state ) + { + m_state = state; + /*switch( m_state ) + { + case mof::Interpreter::WAITING : + throw std::runtime_error("waiting on taskFinished");//‚±‚±‚É—ˆ‚邱‚Æ‚Í‚ ‚肦‚È‚¢ + break; + case mof::Interpreter::RUNNING : + m_state = mof::Interpreter::WAITING; + break; + case mof::Interpreter::BUSY : + m_state = mof::Interpreter::RUNNING; + mof::Interpreter::doNextCommand(); + break; + case mof::Interpreter::FREE : + throw std::runtime_error("waiting on taskFinished");//‚±‚±‚É—ˆ‚邱‚Æ‚Í‚ ‚肦‚È‚¢ + break; + }*/ + } +//}}} +//{{{ _createMessageWidget + int Interpreter::_createMessageWidget() + { + m_messages.push_back( m_pInstructionSet->createMessageWidget( ) ); + return m_messages.size() -1; + } +//}}} +//{{{ _addMessageWidgetPage + int Interpreter::_addMessageWidgetPage + ( + int id , + const mof::tstring& title , + const mof::tstring& text + ) + { + int frame = m_pInstructionSet->addMessageWidgetPage( m_messages.at(id) , title , text ) ; + m_messages.at(id)->nextPage(); + return frame; + } +//}}} +//{{{ _hideMessageWidget + int Interpreter::_hideMessageWidget( int id ){ + m_messages.at( id )->close(); + return 10; + } +//}}} +//{{{ _waitKey + void Interpreter::_waitKey( const mof::tstring& keystring ){ + mof::InputReceiver::Key key; + if( keystring == "z" || keystring == "Z")key = mof::InputReceiver::Z; + else return; + + m_scheduler.addEvent + ( + new mof::OnceEventCondition( new mof::KeyPressedEventCondition( key , m_pInput ) ) , + boost::bind( &mof::_setState , mof::Interpreter::WAITING ) + ); + _setState( mof::Interpreter::RUNNING ); + } +//}}} +//{{{ _waitFrame + void Interpreter::_waitFrame( int frame ){ + m_scheduler.addEvent + ( + frame , + boost::bind( &mof::_setState , mof::Interpreter::WAITING ) + ); + _setState( mof::Interpreter::RUNNING ); + } +//}}} +//{{{ initialize + void Interpreter::initialize + ( + const boost::shared_ptr& pInput , + InstructionSet& implementation + ) + { + m_pLua = NULL; + m_pInput = pInput; + m_pInstructionSet = &implementation; + m_state = WAITING; + + } +//}}} +//{{{ finalize + void Interpreter::finalize() + { + mof::safe_delete( m_pLua ); + } +//}}} +//{{{ getState + Interpreter::State Interpreter::getState( ) + { + return m_state; + } +//}}} +//{{{ doNextCommand + void Interpreter::doNextCommand( ) + { + switch( m_state ) + { + case WAITING : + m_pLua->nextCommand(); + break; + case RUNNING : + m_state = BUSY; + break; + case BUSY : + break; + case FREE : + break; + } + } +//}}} +//{{{ open + void Interpreter::open( const tstring& filename ) + { + if( !m_pLua )m_pLua = new LuaScript(filename); + //---ŠÖ”‚ÌŠ„‚è“–‚Ä + mof::regist::registMessage( m_pLua->getLuaState() ); + mof::regist::registWait( m_pLua->getLuaState() ); + } +//}}} +//{{{ update + void Interpreter::update() + { + + m_scheduler.update(); + + foreach( MessageWidgetHandler& handler , m_messages ) + { + if( handler.get() )handler->update(); + } + } +//}}} +} //namespace mof diff --git a/moftmp/Interpreter.hpp b/moftmp/Interpreter.hpp new file mode 100755 index 0000000..d2dc48f --- /dev/null +++ b/moftmp/Interpreter.hpp @@ -0,0 +1,63 @@ +#pragma once +#include "mof/InstructionSet.hpp" + +namespace mof +{ + class InputReceiver; + + namespace Interpreter + { + enum State + { + WAITING , /** doNextCommand‚ÅŽŸ‚̃Rƒ}ƒ“ƒh‚ð‰ðÍ‚·‚é */ + BUSY , /** ƒRƒ}ƒ“ƒh‚ðˆ—’†(doNextCommand‚͌Ă΂ê‚Ä‚¢‚é) */ + RUNNING , /** ƒRƒ}ƒ“ƒh‚ðˆ—’†(doNextCommand‚͌Ă΂ê‚Ä‚¢‚È‚¢) */ + FREE /** ƒXƒNƒŠƒvƒg‚ðÅŒã‚܂ŏˆ—‚µ‚½ */ + }; + + /** + * @note ˆø”‚Å“n‚µ‚½“ü—̓ŒƒV[ƒo‚É‚æ‚Á‚āAƒRƒ}ƒ“ƒh‚̏ˆ—‚ªs‚í‚ê‚é + * @param[in] ƒRƒ}ƒ“ƒhˆ——pƒCƒ“ƒvƒbƒgƒŒƒV[ƒo + * @param[in] –½—ß‚ÌŽÀ‘• + */ + void initialize + ( + const boost::shared_ptr & pInput , + InstructionSet& implementation + ); + + void finalize( ); + + + /** + * @brief ‚±‚̃Nƒ‰ƒX‚̃IƒuƒWƒFƒNƒg‚É‚æ‚è‰ðÍ‚³‚ê‚éƒXƒNƒŠƒvƒg‚ð’ljÁ‚·‚é + * @param[in] ƒXƒNƒŠƒvƒgƒtƒ@ƒCƒ‹–¼ + */ + void open( const tstring& filename ); + + /** + * @brief Œ»Ý‚̃Cƒ“ƒ^ƒvƒŠƒ^‚̏ó‘Ԃ𓾂é + * @return Œ»Ý‚̏ó‘Ô + */ + State getState(); + + /** + * @brief ƒRƒ}ƒ“ƒh‚̏ˆ—‚ðs‚¤ + * @note createŒnƒƒ\ƒbƒh‚Ő¶¬‚³‚ꂽƒŠƒ\[ƒX‚̍XVƒƒ\ƒbƒh‚ªŒÄ‚΂ê‚éB + * @note ‚½‚¾‚µAinactiveŒnƒƒ\ƒbƒh‚Å“n‚³‚ꂽƒŠƒ\[ƒX‚ɂ‚¢‚Ä‚Í‚±‚ÌŒÀ‚è‚Å‚È‚¢B + */ + void update(); + + /** + * @brief ƒCƒ“ƒ^ƒvƒŠƒ^‚ÉŽŸ‚̃Rƒ}ƒ“ƒh‚ÌŽÀs‚𑣂· + * @note ƒCƒ“ƒ^ƒvƒŠƒ^‚ªWAITINGó‘Ԃ̏ꍇA’¼‚¿‚ÉŽŸ‚̃Rƒ}ƒ“ƒh‚ª‰ðÍ‚³‚ê‚éBRUNNINGABUSYó‘Ô + * @note ‚̏ꍇ‚ÍupdateŒÄ‚яo‚µ‚É‚æ‚èƒCƒ“ƒ^ƒvƒŠƒ^‚ªŒ»Ý‚̃Rƒ}ƒ“ƒh‚̏ˆ—‚ðŠ®—¹‚µ‚½Œã‚ÅŽŸ‚Ì + * @note ‰ðÍ‚ªŠJŽn‚³‚ê‚éB + */ + void doNextCommand(); + + + }; + +} + diff --git a/moftmp/KeyPressedEventCondition.cpp b/moftmp/KeyPressedEventCondition.cpp new file mode 100755 index 0000000..01e4322 --- /dev/null +++ b/moftmp/KeyPressedEventCondition.cpp @@ -0,0 +1,29 @@ +#include "mof/KeyPressedEventCondition.hpp" + +mof::KeyPressedEventCondition::KeyPressedEventCondition +( + mof::InputReceiver::Key key, + const boost::shared_ptr &pInputReceiver +) +: m_key(key) , m_pInputReceiver(pInputReceiver) , m_currentState(false) +{ + update(); +} + +mof::KeyPressedEventCondition::~KeyPressedEventCondition(){ +} + +bool mof::KeyPressedEventCondition::test(){ + return m_oldState == false && m_currentState == true ; +} + +void mof::KeyPressedEventCondition::update(){ + m_oldState = m_currentState; + m_currentState = m_pInputReceiver->testKeyState(m_key); +} + +bool mof::KeyPressedEventCondition::isDisposable(){ + return false; +} + + diff --git a/moftmp/KeyPressedEventCondition.hpp b/moftmp/KeyPressedEventCondition.hpp new file mode 100755 index 0000000..4f365e2 --- /dev/null +++ b/moftmp/KeyPressedEventCondition.hpp @@ -0,0 +1,29 @@ +#pragma once +#include "mof/EventCondition.hpp" +#include "mof/InputReceiver.hpp" +#include "boost/shared_ptr.hpp" + +namespace mof{ + + + class KeyPressedEventCondition : public EventCondition{ + mof::InputReceiver::Key m_key; + boost::shared_ptr m_pInputReceiver; + bool m_oldState; + bool m_currentState; + public: + KeyPressedEventCondition + ( + mof::InputReceiver::Key key , + const boost::shared_ptr& pInputReceiver + ); + + virtual ~KeyPressedEventCondition(); + virtual bool test(); + virtual void update(); + virtual bool isDisposable(); + }; + + +} + diff --git a/moftmp/Light.cpp b/moftmp/Light.cpp new file mode 100755 index 0000000..86a1128 --- /dev/null +++ b/moftmp/Light.cpp @@ -0,0 +1,22 @@ +#include "mof/Light.hpp" +#include "mof/Constant.hpp" + +mof::Light::Light() +: m_diffuseColor(mof::makeConstantHandler(mof::Color4f(1 , 1 , 1))) , m_frame(0){ + +} + + +mof::Light::~Light(){ +} + +void mof::Light::setDiffuseColor(mof::Color4f color){ + mof::Animation::Handler f = mof::makeConstantHandler(color); + setDiffuseColor(f); +} + +void mof::Light::setDiffuseColor(const mof::Animation::Handler& f){ + m_diffuseColor = f; + m_frame = 0; +} + diff --git a/moftmp/Light.hpp b/moftmp/Light.hpp new file mode 100755 index 0000000..e70ce69 --- /dev/null +++ b/moftmp/Light.hpp @@ -0,0 +1,25 @@ +#ifndef MOF_ANIMATION +#define MOF_ANIMATION +#include +#include "mof/Color.hpp" + +namespace mof{ + +class Light : public boost::noncopyable{ + +protected: + mof::Manipulator::Handler m_diffuseColor; + FrameNumber m_frame; +public: + Light(); + virtual ~Light(); + void setDiffuseColor(mof::Color4f color); + void setDiffuseColor(const Manipulator::Handler& f); + + virtual void setEnable(bool enable) = 0; + +}; + +}; + +#endif diff --git a/moftmp/Line3D.cpp b/moftmp/Line3D.cpp new file mode 100755 index 0000000..f681279 --- /dev/null +++ b/moftmp/Line3D.cpp @@ -0,0 +1,20 @@ +#include "Line3D.h" + +mof::Line3D::Line3D(float beginX , float beginY , float beginZ , float endX , float endY , float endZ) +{ + m_begin = mof::Vector3D(beginX , beginY , beginZ); + m_end = mof::Vector3D(endX , endY , endZ); +} + + +mof::Line3D::Line3D(mof::Vector3D& begin , mof::Vector3D& end){ + m_begin = begin; + m_end = end; +} + +mof::Line3D::~Line3D(void) +{ +} + + + diff --git a/moftmp/Line3D.h b/moftmp/Line3D.h new file mode 100755 index 0000000..aaac8ee --- /dev/null +++ b/moftmp/Line3D.h @@ -0,0 +1,22 @@ +#pragma once +#include "mof/Vector3D.h" + +namespace mof{ + class Line3D + { + + mof::Vector3D m_begin; + mof::Vector3D m_end; + public: + Line3D(float beginX , float beginY , float beginZ , float endX , float endY , float endZ); + Line3D(mof::Vector3D& begin , mof::Vector3D& end); + ~Line3D(void); + + mof::Vector3D& getBegin(){return m_begin;} + mof::Vector3D& getEnd(){return m_end;} + + + }; + + +}; \ No newline at end of file diff --git a/moftmp/LoggedInputReceiver.cpp b/moftmp/LoggedInputReceiver.cpp new file mode 100755 index 0000000..f68c713 --- /dev/null +++ b/moftmp/LoggedInputReceiver.cpp @@ -0,0 +1,21 @@ +#include "mof/LoggedInputReceiver.hpp" +#include "mof/InputDevice.hpp" + +mof::LoggedInputReceiver::LoggedInputReceiver(TCHAR* filename ) +: mof::InputReceiver() , m_log(filename){ +} + +mof::LoggedInputReceiver::~LoggedInputReceiver(){ + +} + +bool mof::LoggedInputReceiver::testKeyState(mof::InputReceiver::Key){ + bool result = false; + m_log >> result; + return result; + +} + +void mof::LoggedInputReceiver::update(){ +} + diff --git a/moftmp/LoggedInputReceiver.hpp b/moftmp/LoggedInputReceiver.hpp new file mode 100755 index 0000000..3d596e1 --- /dev/null +++ b/moftmp/LoggedInputReceiver.hpp @@ -0,0 +1,24 @@ +#pragma once +#include "mof/InputReceiver.hpp" +#include "mof/tstring.hpp" +#include + + + +namespace mof{ + + + class LoggedInputReceiver : public InputReceiver + { + std::ifstream m_log; + + public: + + LoggedInputReceiver(TCHAR* filename ); + virtual ~LoggedInputReceiver(); + virtual bool testKeyState(mof::InputReceiver::Key key); + virtual void update(); + + }; + +}; diff --git a/moftmp/LoggingInputReceiver.cpp b/moftmp/LoggingInputReceiver.cpp new file mode 100755 index 0000000..77589f7 --- /dev/null +++ b/moftmp/LoggingInputReceiver.cpp @@ -0,0 +1,33 @@ +#include "mof/LoggingInputReceiver.hpp" +#include "mof/InputDevice.hpp" +#include + + +mof::LoggingInputReceiver::LoggingInputReceiver(TCHAR* filename ) +: m_filename(filename){ +} + +mof::LoggingInputReceiver::~LoggingInputReceiver(){ + output(); +} + +bool mof::LoggingInputReceiver::testKeyState(mof::InputReceiver::Key key){ + bool result = mof::InputDevice::getInputReceiver()->testKeyState(key); + m_log.push_back(result); + return result; + +} + +void mof::LoggingInputReceiver::update(){ + mof::InputDevice::getInputReceiver()->update(); +} + + + +void mof::LoggingInputReceiver::output(){ + std::ofstream ofs( m_filename.c_str() ); + for(std::list::iterator itr = m_log.begin() ; itr != m_log.end() ; ++itr){ + ofs << *itr << std::endl; + } + +} \ No newline at end of file diff --git a/moftmp/LoggingInputReceiver.hpp b/moftmp/LoggingInputReceiver.hpp new file mode 100755 index 0000000..e1fba33 --- /dev/null +++ b/moftmp/LoggingInputReceiver.hpp @@ -0,0 +1,22 @@ +#pragma once +#include "mof/InputReceiver.hpp" +#include "mof/tstring.hpp" +#include + +namespace mof{ + + + class LoggingInputReceiver : public InputReceiver + { + std::list m_log; + mof::tstring m_filename; + public: + + LoggingInputReceiver(TCHAR* filename ); + virtual ~LoggingInputReceiver(); + virtual bool testKeyState(Key key); + virtual void update(); + void output(); + }; + +}; diff --git a/moftmp/LuaScript.cpp b/moftmp/LuaScript.cpp new file mode 100755 index 0000000..6bc9beb --- /dev/null +++ b/moftmp/LuaScript.cpp @@ -0,0 +1,67 @@ +#include "mof/LuaScript.hpp" +#include "mof/ConsoleIO.hpp" +#include +#include "luabind/luabind.hpp" +#include "mof/utilities.hpp" + + +struct mof::LuaScript::Impl{ + lua_State *l; + lua_State *co; + + + + Impl() + : l(NULL) + { + } + + ~Impl(){ + if(l)lua_close(l); + } + + + +}; + + + +mof::LuaScript::LuaScript(const mof::tstring& filename ) +: m_pImpl(new Impl()){ + m_pImpl->l = lua_open(); + luaL_openlibs(m_pImpl->l); + luabind::open(m_pImpl->l); + + + + + + int error = luaL_dofile(m_pImpl->l , filename.c_str()); + //error = luaL_dofile(m_pImpl->l , "script/test2.lua"); + if(error){ + DEBUG_PRINT(_T("ERROR-") << lua_tostring(m_pImpl->l , -1)); + throw std::runtime_error("Failed --- start lua script"); + } + m_pImpl->co = lua_newthread(m_pImpl->l); + if(!m_pImpl->co){ + DEBUG_PRINT(_T("ERROR-Failed lua_newthread") ); + throw std::runtime_error("Failed --- start lua script"); + } + lua_getglobal(m_pImpl->co , "main"); + +} + +mof::LuaScript::~LuaScript(){ + +} + + +void mof::LuaScript::nextCommand(){ + lua_resume(m_pImpl->co , 0); + + +} + +lua_State* mof::LuaScript::getLuaState() const{ + return m_pImpl->l; +} diff --git a/moftmp/LuaScript.hpp b/moftmp/LuaScript.hpp new file mode 100755 index 0000000..2121373 --- /dev/null +++ b/moftmp/LuaScript.hpp @@ -0,0 +1,25 @@ +#ifndef _LUASCRIPT_HPP +#define _LUASCRIPT_HPP +#include +#include "mof/tstring.hpp" +#include + +namespace mof{ + class MessageWidget; + + + class LuaScript{ + struct Impl; + boost::scoped_ptr m_pImpl; + public : + LuaScript(const mof::tstring& filename ); + ~LuaScript(); + + void nextCommand(); + lua_State * getLuaState() const; + }; + +} + + +#endif diff --git a/moftmp/Material.hpp b/moftmp/Material.hpp new file mode 100755 index 0000000..baa8458 --- /dev/null +++ b/moftmp/Material.hpp @@ -0,0 +1,45 @@ +#ifndef MOF_MATERIAL_HPP +#define MOF_MATERIAL_HPP +#include "Color.hpp" + +namespace mof{ + +struct Material{ + mof::Color4f diffuseColor; + mof::Color4f ambientColor; + mof::Color4f specularColor; + float power; + mof::Color4f emissiveColor; + + Material() + : ambientColor(0 , 0 , 0) , + diffuseColor(0 , 0 , 0) , + specularColor(0 , 0 , 0), + power(0), + emissiveColor(0 , 0 , 0) + { + + } + + Material( + mof::Color4f ambient_ , + mof::Color4f diffuse_ , + mof::Color4f specular_ , + real power_ , + mof::Color4f emissive_ + ) + : ambientColor(ambient_) , + diffuseColor(diffuse_) , + specularColor(specular_), + power(power_), + emissiveColor(emissive_) + { + + } + + +}; + +} + +#endif diff --git a/moftmp/MaterialBuilder.cpp b/moftmp/MaterialBuilder.cpp new file mode 100755 index 0000000..8780e08 --- /dev/null +++ b/moftmp/MaterialBuilder.cpp @@ -0,0 +1,134 @@ +#include "mof/MaterialBuilder.hpp" +#include "mof/Material.hpp" +#include "mof/private/GraphicsDeviceImpl.hpp" +#include "mof/Constant.hpp" + +struct mof::MaterialBuilder::Impl{ + + Impl( + const mof::Animation::Handler& ambient_ , + const mof::Animation::Handler& diffuse_ , + const mof::Animation::Handler& specular_ , + const mof::Animation::Handler& specularPower_ , + const mof::Animation::Handler& emissive_) + : diffuse(diffuse_) , ambient(ambient_) , specular(specular_) , + specularPower(specularPower_) , emissive(emissive_) , pMaterial(NULL) , frame(0) { + } + + ~Impl(){ + delete pMaterial; + } + + mof::Material* pMaterial; + FrameNumber frame; + mof::Animation::Handler diffuse; + mof::Animation::Handler ambient; + mof::Animation::Handler specular; + mof::Animation::Handler specularPower; + mof::Animation::Handler emissive; + + +}; + + + + +mof::MaterialBuilder::MaterialBuilder( ) +: m_pImpl(new Impl( + mof::makeConstantHandler(mof::Color4f(0 , 0 , 0)) , + mof::makeConstantHandler(mof::Color4f(0 , 0 , 0)) , + mof::makeConstantHandler(mof::Color4f(0 , 0 , 0)) , + mof::makeConstantHandler(0.0f) , + mof::makeConstantHandler(mof::Color4f(0 , 0 , 0)) + ) ) +{ + m_pImpl->pMaterial = new Material; +} + + +mof::MaterialBuilder::MaterialBuilder( mof::Color4f ambient ) +: m_pImpl(new Impl( + mof::makeConstantHandler(ambient) , + mof::makeConstantHandler(mof::Color4f(0 , 0 , 0)) , + mof::makeConstantHandler(mof::Color4f(0 , 0 , 0)) , + mof::makeConstantHandler(0.0f) , + mof::makeConstantHandler(mof::Color4f(0 , 0 , 0)) )) +{ + m_pImpl->pMaterial = new Material; + construct(); +} + + +mof::MaterialBuilder::MaterialBuilder( mof::Color4f ambient , mof::Color4f diffuse , + mof::Color4f specular , float power , mof::Color4f emissive ) +: m_pImpl(new Impl( + mof::makeConstantHandler(ambient) , + mof::makeConstantHandler(diffuse) , + mof::makeConstantHandler(specular) , + mof::makeConstantHandler(power) , + mof::makeConstantHandler(emissive) )) +{ + m_pImpl->pMaterial = new Material; + construct(); +} + +mof::MaterialBuilder::MaterialBuilder( + const mof::Animation::Handler& ambient_ , + const mof::Animation::Handler& diffuse_ , + const mof::Animation::Handler& specular_ , + const mof::Animation::Handler& power_ , + const mof::Animation::Handler& emissive_ ) +: m_pImpl(new Impl( ambient_ , diffuse_ , specular_ , power_ , emissive_ )) +{ + m_pImpl->pMaterial = new Material; + construct(); +} + +mof::MaterialBuilder::~MaterialBuilder(){ +} + +void mof::MaterialBuilder::setFrameNumber(mof::FrameNumber frame){ + m_pImpl->frame = frame; +} + +void mof::MaterialBuilder::nextFrame(){ + setFrameNumber(m_pImpl->frame + 1 ); +} + +void mof::MaterialBuilder::prevFrame(){ + if(m_pImpl->frame > 0)setFrameNumber(m_pImpl->frame - 1); +} + + + +mof::Color4f mof::MaterialBuilder::getDiffuseColor() const{ + return m_pImpl->diffuse->getValue(m_pImpl->frame); +} + +mof::Color4f mof::MaterialBuilder::getAmbientColor() const{ + return m_pImpl->ambient->getValue(m_pImpl->frame); +} + +mof::Color4f mof::MaterialBuilder::getSpecularColor() const{ + return m_pImpl->specular->getValue(m_pImpl->frame); +} + +mof::Color4f mof::MaterialBuilder::getEmissiveColor() const{ + return m_pImpl->emissive->getValue(m_pImpl->frame); +} + +float mof::MaterialBuilder::getSpecularPower() const{ + return m_pImpl->specularPower->getValue(m_pImpl->frame); +} + + +const mof::Material& mof::MaterialBuilder::construct() const{ + + m_pImpl->pMaterial->diffuseColor = m_pImpl->diffuse->getValue(m_pImpl->frame); + m_pImpl->pMaterial->ambientColor = m_pImpl->ambient->getValue(m_pImpl->frame); + m_pImpl->pMaterial->specularColor = m_pImpl->specular->getValue(m_pImpl->frame); + m_pImpl->pMaterial->power = m_pImpl->specularPower->getValue(m_pImpl->frame); + m_pImpl->pMaterial->emissiveColor = m_pImpl->emissive->getValue(m_pImpl->frame); + + return *(m_pImpl->pMaterial); +} diff --git a/moftmp/MaterialBuilder.hpp b/moftmp/MaterialBuilder.hpp new file mode 100755 index 0000000..67b2c5a --- /dev/null +++ b/moftmp/MaterialBuilder.hpp @@ -0,0 +1,50 @@ +#ifndef MOF_MATERIAL_BUILDER_HPP +#define MOF_MATERIAL_BUILDER_HPP + +#include "mof/Color.hpp" +#include +#include +#include "mof/stream/Manipulator.hpp" + +//struct _D3DMATERIAL9; +//typedef _D3DMATERIAL9 D3DMATERIAL9; +namespace mof{ + + +struct Material; + +class MaterialBuilder : boost::noncopyable{ + + struct Impl; + boost::scoped_ptr m_pImpl; + +public: + MaterialBuilder(); + MaterialBuilder( mof::Color4f ambient ); + MaterialBuilder( mof::Color4f ambient , mof::Color4f diffuse , mof::Color4f specular , float power , mof::Color4f emissive ); + MaterialBuilder + ( + const mof::Animation::Handler& ambient , + const mof::Animation::Handler& diffuse , + const mof::Animation::Handler& specular , + const mof::Animation::Handler& power , + const mof::Animation::Handler& emissive + ); + ~MaterialBuilder(); + + void setFrameNumber(mof::FrameNumber frame); + void nextFrame(); + void prevFrame(); + + mof::Color4f getDiffuseColor() const; + mof::Color4f getAmbientColor() const; + mof::Color4f getSpecularColor() const; + float getSpecularPower() const; + mof::Color4f getEmissiveColor() const; + + const mof::Material& construct() const; +}; + +} + +#endif diff --git a/moftmp/Matrix2D.cpp b/moftmp/Matrix2D.cpp new file mode 100755 index 0000000..3bb0bc4 --- /dev/null +++ b/moftmp/Matrix2D.cpp @@ -0,0 +1,175 @@ +#include +#include +#include "mof/Matrix2D.hpp" +#include "mof/ConsoleIO.hpp" + +const int DIMENSION = 2; + + +mof::Matrix2D::Matrix2D() +: m_pImpl(new Array) +{ + for(int i = 0 ; i <= DIMENSION ; ++i){ + for(int j = 0 ; j <= DIMENSION ; ++j){ + if(i == j)m_pImpl->elements[i][j] = 1; + else m_pImpl->elements[i][j] = 0; + } + } +} + +mof::Matrix2D::Matrix2D(const Matrix2D& obj ) +: m_pImpl(new Array) +{ + *m_pImpl = *obj.m_pImpl; +} + +mof::Matrix2D::Matrix2D(const mof::Matrix2D::Array & arr) +: m_pImpl(new Array) +{ + *m_pImpl = arr; +} + + +mof::Matrix2D::~Matrix2D(){ +} + + +mof::real mof::Matrix2D::at(int row , int column) const{ + return m_pImpl->elements[row][column]; +} + +mof::Matrix2D::Array mof::Matrix2D::getArray() const{ + return *m_pImpl; +} + + +mof::Matrix2D mof::Matrix2D::createIdentity(){ + return mof::Matrix2D(); +} + + +mof::Matrix2D mof::Matrix2D::createTransposed(mof::Matrix2D& matrix){ + Matrix2D transposed; + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + transposed.m_pImpl->elements[j][i] = matrix.m_pImpl->elements[i][j]; + } + } + return transposed; +} + + + +mof::Matrix2D mof::Matrix2D::createRotation(const mof::Vector2D& position){ + Matrix2D matrix; + matrix.m_pImpl->elements[DIMENSION][0] = position.x; + matrix.m_pImpl->elements[DIMENSION][1] = position.y; + return matrix; +} + + +mof::Matrix2D mof::Matrix2D::createTranslation(const mof::Vector2D& position){ + Matrix2D matrix; + matrix.m_pImpl->elements[DIMENSION][0] = position.x; + matrix.m_pImpl->elements[DIMENSION][1] = position.y; + return matrix; +} + +mof::Matrix2D mof::Matrix2D::createScaling(const mof::Vector2D& scaling){ + Matrix2D matrix; + matrix.m_pImpl->elements[0][0] = scaling.x; + matrix.m_pImpl->elements[1][1] = scaling.y; + return matrix; +} + + +mof::Vector2D mof::Matrix2D::getTranslation(const mof::Matrix2D& matrix){ + return mof::Vector2D( + matrix.m_pImpl->elements[DIMENSION][0] , + matrix.m_pImpl->elements[DIMENSION][1] + ); +} + +mof::Vector2D mof::Matrix2D::getDiagonal() const{ + return mof::Vector2D( + m_pImpl->elements[0][0] , + m_pImpl->elements[1][1] + ); +} + + +mof::Matrix2D mof::Matrix2D::operator *(const mof::Matrix2D& matrix) const{ + mof::Matrix2D multiplied; + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + mof::real sum = 0; + for(int k = 0 ; k <= DIMENSION ; k++){ + sum += m_pImpl->elements[i][k] * matrix.m_pImpl->elements[k][j]; + } + multiplied.m_pImpl->elements[i][j] = sum; + } + } + return multiplied; +} + + +mof::Matrix2D mof::Matrix2D::operator +(const mof::Matrix2D& matrix) const{ + mof::Matrix2D result; + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + result.m_pImpl->elements[i][j] = + m_pImpl->elements[i][j] + matrix.m_pImpl->elements[i][j]; + } + } + return result; +} + + +mof::Matrix2D mof::Matrix2D::operator -(const mof::Matrix2D& matrix) const{ + mof::Matrix2D result; + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + result.m_pImpl->elements[i][j] = + m_pImpl->elements[i][j] - matrix.m_pImpl->elements[i][j]; + } + } + return result; +} + + +mof::Matrix2D mof::operator *(const mof::Matrix2D& matrix , mof::real f){ + mof::Matrix2D result; + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + result.m_pImpl->elements[i][j] = + matrix.m_pImpl->elements[i][j] * f; + } + } + return result; +} + +mof::Matrix2D mof::operator *(mof::real f , mof::Matrix2D const& matrix){ + return matrix * f; +} + + +mof::Vector2D mof::operator *(const mof::Vector2D& vec , const mof::Matrix2D& matrix) { + mof::real input[3] = {vec.x , vec.y , 1}; + mof::real output[3]; + for(int i = 0 ; i < DIMENSION ; i++){ + mof::real sum = 0; + for(int k = 0 ; k <= DIMENSION ; k++){ + sum += input[k] * matrix.at(k , i); + } + output[i] = sum; + + } + return mof::Vector2D(output[0] , output[1]); +} + + +mof::Rectangle mof::Matrix2D::toBoundingBox(){ + mof::Vector2D begin = mof::Vector2D(0 , 0) * (*this); + mof::Vector2D end = mof::Vector2D(1 , 1) * (*this); + return mof::Rectangle( (int)begin.x , (int)begin.y , (int)end.x , (int)end.y ); +} diff --git a/moftmp/Matrix2D.hpp b/moftmp/Matrix2D.hpp new file mode 100755 index 0000000..54639d1 --- /dev/null +++ b/moftmp/Matrix2D.hpp @@ -0,0 +1,50 @@ +#ifndef MATRIX2D_HPP +#define MATRIX2D_HPP +#include +#include "mof/Vector2D.hpp" +#include "mof/Rectangle.hpp" +#include + + +namespace mof{ + class Matrix2D{ + public: + struct Array{ + real elements[3][3]; + }; + private: + boost::shared_ptr m_pImpl; + public: + + Matrix2D(); + Matrix2D(const Matrix2D& ); + explicit Matrix2D(const mof::Matrix2D::Array &); + ~Matrix2D(); + real at(int row , int column) const; + Array getArray() const; + + static Matrix2D createIdentity(); + static Matrix2D createTransposed(Matrix2D& matrix); + static Matrix2D createRotation(const mof::Vector2D& angle); + static Matrix2D createTranslation(const mof::Vector2D& position); + static Matrix2D createScaling(const mof::Vector2D& scale); + static Vector2D getTranslation(const mof::Matrix2D& matrix); + Vector2D getDiagonal() const; + + + Matrix2D operator *(const mof::Matrix2D& matrix ) const; + Matrix2D operator +(const mof::Matrix2D& matrix ) const; + Matrix2D operator -(const mof::Matrix2D& matrix ) const; + + friend Vector2D operator *(const mof::Vector2D& vec , const mof::Matrix2D& matrix); + friend Matrix2D operator *(const mof::Matrix2D& matrix , real f); + friend Matrix2D operator *(real f , const mof::Matrix2D & matrix); + + mof::Rectangle toBoundingBox(); + + + }; +} // namespace mof + + +#endif diff --git a/moftmp/Matrix3D.cpp b/moftmp/Matrix3D.cpp new file mode 100755 index 0000000..30a76c5 --- /dev/null +++ b/moftmp/Matrix3D.cpp @@ -0,0 +1,227 @@ +#include +#include +#include "mof/Matrix3D.hpp" +#include "mof/utilities.hpp" +#include + +const int DIMENSION = 3; + + +mof::Matrix3D::Matrix3D() +: m_pImpl(new Array) +{ + for(int i = 0 ; i <= DIMENSION ; ++i){ + for(int j = 0 ; j <= DIMENSION ; ++j){ + if(i == j)m_pImpl->elements[i][j] = 1; + else m_pImpl->elements[i][j] = 0; + } + } +} + +mof::Matrix3D::Matrix3D(const mof::Matrix3D::Array & arr) +: m_pImpl(new Array) +{ + *m_pImpl = arr; +} + + +mof::Matrix3D::~Matrix3D(){ +} + + +mof::real mof::Matrix3D::at(int row , int column) const{ + return m_pImpl->elements[row][column]; +} + +mof::Matrix3D::Array mof::Matrix3D::getArray() const{ + return *m_pImpl; +} + + +mof::Matrix3D mof::Matrix3D::createIdentity(){ + return mof::Matrix3D(); +} + + +mof::Matrix3D mof::Matrix3D::createTransposed(const mof::Matrix3D& matrix){ + Matrix3D transposed; + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + transposed.m_pImpl->elements[j][i] = matrix.m_pImpl->elements[i][j]; + } + } + return transposed; +} + + +mof::Matrix3D mof::Matrix3D::createRotation(const mof::Vector3D& radians){ + mof::real cosx = cosf(radians.x); + mof::real sinx = sinf(radians.x); + mof::real cosy = cosf(radians.y); + mof::real siny = sinf(radians.y); + mof::real cosz = cosf(radians.z); + mof::real sinz = sinf(radians.z); + mof::Matrix3D::Array x = + {{ + { 1.f , 0.f , 0.f , 0.f } , + { 0.f , cosx , sinx , 0.f } , + { 0.f , -sinx , cosx , 0.f } , + { 0.f , 0.f , 0.f , 1.f } + }}; + mof::Matrix3D::Array y = + {{ + { cosy , 0.f , -siny , 0.f } , + { 0.f , 1.f , 0.f , 0.f } , + { siny , 0.f , cosy , 0.f } , + { 0.f , 0.f , 0.f , 1.f } + }}; + mof::Matrix3D::Array z = + {{ + { cosz , sinz , 0.f , 0.f } , + { -sinz , cosz , 0.f , 0.f } , + { 0.f , 0.f , 1.f , 0.f } , + { 0.f , 0.f , 0.f , 1.f } + }}; + return mof::Matrix3D(x) * mof::Matrix3D(y) * mof::Matrix3D(z); //TODO Ï‚ðƒn[ƒhƒR[ƒfƒBƒ“ƒO +} + + +mof::Matrix3D mof::Matrix3D::createTranslation(const mof::Vector3D& position){ + Matrix3D matrix; + matrix.m_pImpl->elements[DIMENSION][0] = position.x; + matrix.m_pImpl->elements[DIMENSION][1] = position.y; + matrix.m_pImpl->elements[DIMENSION][2] = position.z; + return matrix; +} + +mof::Matrix3D mof::Matrix3D::createScaling(const mof::Vector3D& scaling){ + Matrix3D matrix; + matrix.m_pImpl->elements[0][0] = scaling.x; + matrix.m_pImpl->elements[1][1] = scaling.y; + matrix.m_pImpl->elements[2][2] = scaling.z; + return matrix; +} + + + +mof::Matrix3D mof::Matrix3D::createLookAtLH +( + const mof::Vector3D& eye , + const mof::Vector3D& lookAt , + const mof::Vector3D& up +) +{ + D3DXVECTOR3 vEye(eye.x , eye.y , eye.z); + D3DXVECTOR3 vLookAt(lookAt.x , lookAt.y , lookAt.z); + D3DXVECTOR3 vUp(up.x , up.y , up.z); + D3DXMATRIX m; + mof::Matrix3D::Array array; + D3DXMatrixLookAtLH( &m , &vEye , &vLookAt , &vUp ); + for( int i = 0 ; i < DIMENSION ; i++ ) + { + for( int j = 0 ; j < DIMENSION ; j++ ) + { + array.elements[i][j] = m.m[i][j]; + } + } + return mof::Matrix3D( array ); +} + +mof::Vector3D mof::Matrix3D::getTranslation(const mof::Matrix3D& matrix){ + return mof::Vector3D( + matrix.m_pImpl->elements[DIMENSION][0] , + matrix.m_pImpl->elements[DIMENSION][1] , + matrix.m_pImpl->elements[DIMENSION][2] + ); +} + +mof::Vector3D mof::Matrix3D::getDiagonal() const{ + return mof::Vector3D( + m_pImpl->elements[0][0] , + m_pImpl->elements[1][1] , + m_pImpl->elements[2][2] + ); +} + + + +mof::Matrix3D mof::Matrix3D::operator *(const mof::Matrix3D& matrix) const{ + mof::Matrix3D multiplied; + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + mof::real sum = 0; + for(int k = 0 ; k <= DIMENSION ; k++){ + sum += m_pImpl->elements[i][k] * matrix.m_pImpl->elements[k][j]; + } + multiplied.m_pImpl->elements[i][j] = sum; + } + } + return multiplied; +} + + +mof::Matrix3D mof::Matrix3D::operator +(const mof::Matrix3D& matrix) const{ + mof::Matrix3D result; + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + result.m_pImpl->elements[i][j] = + m_pImpl->elements[i][j] + matrix.m_pImpl->elements[i][j]; + } + } + return result; +} + + +mof::Matrix3D mof::Matrix3D::operator -(const mof::Matrix3D& matrix) const{ + mof::Matrix3D result; + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + result.m_pImpl->elements[i][j] = + m_pImpl->elements[i][j] - matrix.m_pImpl->elements[i][j]; + } + } + return result; +} + + +mof::Matrix3D mof::operator *(const mof::Matrix3D& matrix , mof::real f){ + mof::Matrix3D result; + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + result.m_pImpl->elements[i][j] = + matrix.m_pImpl->elements[i][j] * f; + } + } + return result; +} + +mof::Matrix3D mof::operator *(mof::real f , mof::Matrix3D const& matrix){ + return matrix * f; +} + + +mof::Vector3D mof::operator *(const mof::Vector3D& vec , const mof::Matrix3D& matrix) { + mof::real input[4] = {vec.x , vec.y , vec.z , 1}; + mof::real output[4]; + for(int i = 0 ; i < DIMENSION ; i++){ + mof::real sum = 0; + for(int k = 0 ; k <= DIMENSION ; k++){ + sum += input[k] * matrix.at(k , i); + } + output[i] = sum; + + } + return mof::Vector3D(output[0] , output[1] , output[2]); +} + + +std::ostream& mof::operator <<(std::ostream& os , const mof::Matrix3D& mat){ + for(int i = 0 ; i <= DIMENSION ; i++){ + for(int j = 0 ; j <= DIMENSION ; j++){ + if(j != 0)os << " , "; + os << mat.m_pImpl->elements[i][j]; + } + os << '\n'; + } + return os; +} diff --git a/moftmp/Matrix3D.hpp b/moftmp/Matrix3D.hpp new file mode 100755 index 0000000..24d614b --- /dev/null +++ b/moftmp/Matrix3D.hpp @@ -0,0 +1,49 @@ +#pragma once +#include "mof/Vector3D.hpp" +#include +#include + + +namespace mof{ + + class Matrix3D + { + public: + struct Array + { + real elements[4][4]; + }; + private: + boost::shared_ptr m_pImpl; + public: + + Matrix3D(); + explicit Matrix3D(const Array &); + ~Matrix3D(); + real at(int row , int column) const; + Array getArray() const; + + static Matrix3D createIdentity(); + static Matrix3D createTransposed(const Matrix3D& matrix); + static Matrix3D createRotation(const mof::Vector3D& angle); + static Matrix3D createTranslation(const mof::Vector3D& position); + static Matrix3D createScaling(const mof::Vector3D& scale); + static Matrix3D createLookAtLH( const Vector3D& eye , const Vector3D& lookAt , const Vector3D& up ); + static Vector3D getTranslation(const mof::Matrix3D& matrix); + Vector3D getDiagonal() const; + + + Matrix3D operator *(const mof::Matrix3D& matrix ) const; + Matrix3D operator +(const mof::Matrix3D& matrix ) const; + Matrix3D operator -(const mof::Matrix3D& matrix ) const; + + friend Vector3D operator *(const mof::Vector3D& vec , const mof::Matrix3D& matrix); + friend Matrix3D operator *(const mof::Matrix3D& matrix , real f); + friend Matrix3D operator *(real f , const mof::Matrix3D & matrix); + friend std::ostream& operator <<(std::ostream& os , const mof::Matrix3D& mat); + }; // class Matrix3D + + std::ostream& operator <<(std::ostream& os , const mof::Matrix3D& mat); + +} // namespace mof + diff --git a/moftmp/Mesh.cpp b/moftmp/Mesh.cpp new file mode 100755 index 0000000..c0ea8f0 --- /dev/null +++ b/moftmp/Mesh.cpp @@ -0,0 +1,91 @@ +#include "mof/private/Mesh.hpp" +#include "mof/GraphicsDevice.hpp" +#include "mof/private/MeshDisposer.hpp" +#include "mof/Constant.hpp" +#include "mof/ConsoleIO.hpp" + +struct mof::Mesh::Impl{ + + boost::shared_ptr pMeshDisposer; + unsigned long nMaterials; + boost::shared_ptr* materials; + boost::shared_ptr* textures; + mof::Animation::Handler worldMatrix; + + + Impl( + boost::shared_ptr pMeshDisposer_ , + unsigned long nMaterials_ + ) : + pMeshDisposer(pMeshDisposer_) , + nMaterials(nMaterials_) , materials(NULL) , textures(NULL) , + worldMatrix(mof::makeConstantHandler(mof::Matrix3D::createIdentity())) + {} + + ~Impl(){ + delete[] materials; + delete[] textures; + } +}; + +mof::Mesh::Mesh( + boost::shared_ptr pMeshDisposer , + unsigned long nMaterials , + const boost::shared_ptr* materials , + const boost::shared_ptr* textures + ) : m_pImpl(new Impl(pMeshDisposer , nMaterials )){ + + m_pImpl->materials = new boost::shared_ptr[nMaterials]; + m_pImpl->textures = new boost::shared_ptr[nMaterials]; + + for(unsigned long i = 0 ; i < nMaterials ; i++ ){ + m_pImpl->materials[i] = materials[i]; + m_pImpl->textures[i] = textures[i]; + } +} + +mof::Mesh::~Mesh(){ +} + + + +void mof::Mesh::setWorldMatrix(const mof::Animation::Handler& handler){ + m_pImpl->worldMatrix = handler; +} + + + + + +void mof::Mesh::setTexture( + unsigned int num , + const boost::shared_ptr& pTexture){ + + if(num < m_pImpl->nMaterials)m_pImpl->textures[num] = pTexture; + +} + + +bool mof::Mesh::isVisible() const{ + return true; +} + + +void mof::Mesh::update(){ + nextFrame(); +} + +void mof::Mesh::draw() const{ + + + for( DWORD i = 0; i < m_pImpl->nMaterials ; i++ ) + { + mof::GraphicsDevice::setMaterial(*m_pImpl->materials[i].get()); + mof::GraphicsDevice::setTexture(m_pImpl->textures[i].get()); + mof::GraphicsDevice::setWorldTransform(m_pImpl->worldMatrix->getValue(m_frame)); + + HRESULT hr = m_pImpl->pMeshDisposer->pMesh->DrawSubset( i ); + if(FAILED(hr))throw std::runtime_error("Failed --- DrawSubset"); + } +} + diff --git a/moftmp/MeshBuilder.cpp b/moftmp/MeshBuilder.cpp new file mode 100755 index 0000000..b91df59 --- /dev/null +++ b/moftmp/MeshBuilder.cpp @@ -0,0 +1,115 @@ +#include "MeshBuilder.hpp" +#include "mof/private/GraphicsDeviceImpl.hpp" +#include "mof/ConsoleIO.hpp" +#include +#include "mof/private/MeshDisposer.hpp" +#include +#include +#include "mof/FilePath.hpp" +#include "mof/private/VertexFVF.hpp" +#include "mof/Material.hpp" +#include "mof/Texture.hpp" +#include "mof/private/Mesh.hpp" + +struct mof::MeshBuilder::Impl{ + boost::shared_ptr pMeshDisposer; + unsigned long nMaterials; + boost::shared_ptr* materials; + boost::shared_ptr* textures; + + + Impl() + : pMeshDisposer() , nMaterials(0) , + materials(NULL) , textures(NULL){ + } + + ~Impl(){ + delete[] materials; + delete[] textures; + } + +}; + +mof::MeshBuilder::MeshBuilder(const mof::tstring& path ) +: m_pImpl(new Impl()) +{ + + LPDIRECT3DDEVICE9 pDevice = mof::GraphicsDevice::getRawDevice(); + HRESULT hr; + LPD3DXBUFFER pD3DXMtrlBuffer; //ƒ}ƒeƒŠƒAƒ‹—pƒoƒbƒtƒ@ + m_pImpl->pMeshDisposer = boost::shared_ptr( new mof::MeshDisposer() ); + + //ƒtƒ@ƒCƒ‹ƒ[ƒh + hr = D3DXLoadMeshFromX(path.c_str() , D3DXMESH_MANAGED, pDevice, + &(m_pImpl->pMeshDisposer->pAdjacency) , + &pD3DXMtrlBuffer , NULL, + &(m_pImpl->nMaterials) , + &(m_pImpl->pMeshDisposer->pMesh) ); + if(hr != D3D_OK)throw std::invalid_argument("Failed --- D3DXLoadMeshFromX"); + + //ŠeŽíƒCƒ“ƒXƒ^ƒ“ƒXŽæ“¾ + D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer(); + try{ + m_pImpl->materials = new boost::shared_ptr[m_pImpl->nMaterials]; + m_pImpl->textures = new boost::shared_ptr[m_pImpl->nMaterials]; + + + for( DWORD i = 0; i< m_pImpl->nMaterials; i++ ) + { + //ƒ}ƒeƒŠƒAƒ‹‚̃Rƒs[ + D3DMATERIAL9 mat = d3dxMaterials[i].MatD3D; + mat.Ambient = mat.Diffuse; + mof::Material tmp; + memcpy( + static_cast(&tmp) , + static_cast(&mat) , + sizeof(D3DMATERIAL9) + ); + + boost::shared_ptr p(new mof::Material(tmp)); + m_pImpl->materials[i] = p; + + //ƒeƒNƒXƒ`ƒƒƒtƒ@ƒCƒ‹‚̓ǂݍž‚Ý + if( d3dxMaterials[i].pTextureFilename != NULL && + lstrlen(d3dxMaterials[i].pTextureFilename) > 0 ) + { + mof::otstringstream os; + mof::FilePath path(path); + os << path.dir().c_str() << _T("/") << d3dxMaterials[i].pTextureFilename; + m_pImpl->textures[i] = boost::shared_ptr(new mof::Texture( os.str())); + } + } + + } + catch( std::exception& e){ + pD3DXMtrlBuffer->Release(); //ƒoƒbƒtƒ@‰ð•ú + throw e; + } + pD3DXMtrlBuffer->Release(); //ƒoƒbƒtƒ@‰ð•ú + + LPD3DXMESH pMesh = NULL; + if(m_pImpl->pMeshDisposer->pMesh->GetFVF() != mof::getFVF()) + { + //ƒƒbƒVƒ…‚É–@ü‚ª‚È‚¢ê‡‘‚«ž‚Þ + m_pImpl->pMeshDisposer->pMesh->CloneMeshFVF( + m_pImpl->pMeshDisposer->pMesh->GetOptions() , + mof::getFVF() , + pDevice , &pMesh ); + + LPD3DXMESH tmp = m_pImpl->pMeshDisposer->pMesh; + m_pImpl->pMeshDisposer->pMesh = pMesh; + tmp->Release(); + } + +} + +mof::MeshBuilder::~MeshBuilder(){} + +mof::Graphics3D* mof::MeshBuilder::construct() const{ + return new mof::Mesh( + m_pImpl->pMeshDisposer , + m_pImpl->nMaterials , + m_pImpl->materials , + m_pImpl->textures + ); +} diff --git a/moftmp/MeshBuilder.hpp b/moftmp/MeshBuilder.hpp new file mode 100755 index 0000000..5af1c8a --- /dev/null +++ b/moftmp/MeshBuilder.hpp @@ -0,0 +1,24 @@ +#ifndef MOF_MESH_BUILDER_HPP +#define MOF_MESH_BUILDER_HPP +#include +#include +#include "mof/tstring.hpp" + + +namespace mof{ + class Graphics3D; + + class MeshBuilder : boost::noncopyable + { + struct Impl; + boost::scoped_ptr m_pImpl; + public: + + MeshBuilder( const mof::tstring& path ); + ~MeshBuilder(); + + mof::Graphics3D* construct() const; + }; +} + +#endif diff --git a/moftmp/MeshResource.h b/moftmp/MeshResource.h new file mode 100755 index 0000000..44b595c --- /dev/null +++ b/moftmp/MeshResource.h @@ -0,0 +1,12 @@ +#pragma once + +#include "mof/ResourceManager.h" +#include "mof/Mesh.h" +#include + +namespace mof{ + + typedef boost::shared_ptr MeshResource; + typedef mof::ResourceManager MeshManager; + +}; \ No newline at end of file diff --git a/moftmp/OnceEventCondition.cpp b/moftmp/OnceEventCondition.cpp new file mode 100755 index 0000000..7da37fb --- /dev/null +++ b/moftmp/OnceEventCondition.cpp @@ -0,0 +1,36 @@ +#include "mof/OnceEventCondition.hpp" +#include "mof/utilities.hpp" + +namespace mof +{ + OnceEventCondition::OnceEventCondition( EventCondition* pBody ) + : m_disposable( false ) , m_pBody( pBody ) + { + } + + OnceEventCondition::~OnceEventCondition( ) + { + mof::safe_delete( m_pBody ); + } + + bool OnceEventCondition::test( ) + { + bool result = m_pBody->test(); + if( !m_disposable && result )m_disposable = true; + return result; + } + + void OnceEventCondition::update( ) + { + m_pBody->update(); + } + + bool OnceEventCondition::isDisposable( ) + { + return m_disposable; + } + + + +} + diff --git a/moftmp/OnceEventCondition.hpp b/moftmp/OnceEventCondition.hpp new file mode 100755 index 0000000..0db35c3 --- /dev/null +++ b/moftmp/OnceEventCondition.hpp @@ -0,0 +1,20 @@ +#pragma once +#include "mof/EventCondition.hpp" + +namespace mof +{ + + class OnceEventCondition : public EventCondition + { + bool m_disposable; + EventCondition* m_pBody; + public: + OnceEventCondition( EventCondition* pBody ); + virtual ~OnceEventCondition(); + virtual bool test(); + virtual void update(); + virtual bool isDisposable(); + }; + +} + diff --git a/moftmp/PixelMap.hpp b/moftmp/PixelMap.hpp new file mode 100755 index 0000000..9ebeae0 --- /dev/null +++ b/moftmp/PixelMap.hpp @@ -0,0 +1,11 @@ +#ifndef MOF_PIXEL_MAP_HPP +#define MOF_PIXEL_MAP_HPP + +#include "mof/Color.hpp" +#include + +namespace mof{ + typedef boost::multi_array PixelMap; +} + +#endif diff --git a/moftmp/PixelMapTextureBuilder.cpp b/moftmp/PixelMapTextureBuilder.cpp new file mode 100755 index 0000000..4886292 --- /dev/null +++ b/moftmp/PixelMapTextureBuilder.cpp @@ -0,0 +1,70 @@ +#include "mof/private/PixelMapTextureBuilder.hpp" +#include "mof/private/GraphicsDeviceImpl.hpp" +#include +#include "mof/ConsoleIO.hpp" +#include "mof/Font.hpp" + + +mof::PixelMapTextureBuilder::PixelMapTextureBuilder( const boost::shared_ptr& pixelMap) +: m_pPixelMap(pixelMap) +{ +} + +mof::PixelMapTextureBuilder::~PixelMapTextureBuilder(void) +{ + +} + + +LPDIRECT3DTEXTURE9 mof::PixelMapTextureBuilder::create(){ + HRESULT hr; + LPDIRECT3DDEVICE9 pDevice = mof::GraphicsDevice::getRawDevice(); + + unsigned int tWidth = 2; + while(tWidth < m_pPixelMap->shape()[0])tWidth *= 2; + unsigned int tHeight = 2; + while(tHeight < m_pPixelMap->shape()[1])tHeight *= 2; + + + // ƒeƒNƒXƒ`ƒƒì¬ + LPDIRECT3DTEXTURE9 texture; + if + ( + FAILED + ( + hr = D3DXCreateTexture + ( + pDevice , tWidth , tHeight , + 1 , D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, + D3DPOOL_DEFAULT, &texture + ) + ) + ) + { + throw std::runtime_error("Failed --- D3DXCreateTexture"); + } + + + + // ƒeƒNƒXƒ`ƒƒ‚ɃtƒHƒ“ƒgƒrƒbƒgƒ}ƒbƒv‘‚«ž‚Ý + D3DLOCKED_RECT LockedRect; + if(FAILED(hr = texture->LockRect(0, &LockedRect, NULL, D3DLOCK_DISCARD))){ + throw std::runtime_error("Failed --- LockRect"); + } + + // ƒtƒHƒ“ƒgî•ñ‚̏‘‚«ž‚Ý + + FillMemory(LockedRect.pBits , LockedRect.Pitch * tHeight , 0); + for(unsigned int y = 0 ; y < m_pPixelMap->shape()[1] ; y++){ + for(unsigned int x = 0 ; x < m_pPixelMap->shape()[0] ; x++){ + memcpy((BYTE*)LockedRect.pBits + LockedRect.Pitch * y + 4 * x , &((*m_pPixelMap)[x][y]) , sizeof(DWORD)); + } + } + + + texture->UnlockRect(0); + return texture; + + +} + diff --git a/moftmp/PlainWidgetView.cpp b/moftmp/PlainWidgetView.cpp new file mode 100755 index 0000000..74959f9 --- /dev/null +++ b/moftmp/PlainWidgetView.cpp @@ -0,0 +1,128 @@ +#include "mof/PlainWidgetView.hpp" +#include "mof/GraphicsDevice.hpp" +#include "mof/Sprite.hpp" +#include "mof/mofAnimations.hpp" +#include "mof/Font.hpp" + + +struct mof::PlainWidgetView::Impl{ + mof::Animation::Handler transform; + mof::Animation::Handler visible; + mof::FrameNumber frame; + mof::Rectangle bounds; + mof::Sprite* pCaption; + + + Impl() + : frame(0) , + bounds(mof::Rectangle(0 , 0 , 0 , 0)) , pCaption(NULL) + { + } + + ~Impl(){ + delete pCaption; + } +}; + + +mof::PlainWidgetView::PlainWidgetView +( + mof::Color begin , mof::Color end +) +: m_pImpl( new Impl( ) ) +{ + + + //m_pImpl->pFrame = new mof::Frame(m_pImpl->pGraphicsDevice , pTexture); + m_pImpl->transform = mof::makeConstantHandler(mof::Matrix2D::createIdentity()); + { + //visible‚̐ݒè + m_pImpl->visible = mof::makeConstantHandler(false); + } + + //m_pImpl->pCaption = mof::Sprite::createTextSprite(pGraphicsDevice , mof::Font(mof::Font::MS_P_GOTHIC , 25) , title ); +} + +mof::PlainWidgetView::~PlainWidgetView(){ + +} + + + +void mof::PlainWidgetView::setBounds(const mof::Rectangle& bounds){ + m_pImpl->bounds = bounds; +} + +mof::Rectangle mof::PlainWidgetView::getBounds() const{ + return m_pImpl->transform->getValue(m_pImpl->frame).toBoundingBox(); +} + + + +void mof::PlainWidgetView::focus(){ + +} + +void mof::PlainWidgetView::blur(){ + +} + + +void mof::PlainWidgetView::show(){ + const int width = m_pImpl->bounds.endX - m_pImpl->bounds.beginX; + const int height = m_pImpl->bounds.endY - m_pImpl->bounds.beginY; + + mof::Animation::Handler list[] = { + mof::Animation::Handler(mof::makeConstantHandler(mof::Matrix2D::createScaling(mof::Vector2D(width , height)))) , + mof::Animation::Handler(mof::makeConstantHandler( + mof::Matrix2D::createTranslation(mof::Vector2D(m_pImpl->bounds.beginX , m_pImpl->bounds.beginY)) + )) + }; + m_pImpl->transform = mof::Animation::Handler(new mof::CascadingAnimation(list[0] , list[1])); + + { + //visible‚̐ݒè + m_pImpl->visible = mof::makeConstantHandler(true); + } + m_pImpl->frame = 0; + +} + +void mof::PlainWidgetView::close(){ + const int width = m_pImpl->bounds.endX - m_pImpl->bounds.beginX; + const int height = m_pImpl->bounds.endY - m_pImpl->bounds.beginY; + + mof::Animation::Handler list[] = { + mof::Animation::Handler(mof::makeConstantHandler(mof::Matrix2D::createScaling(mof::Vector2D(width , height)))) , + mof::Animation::Handler(mof::makeConstantHandler( + mof::Matrix2D::createTranslation(mof::Vector2D(m_pImpl->bounds.beginX , m_pImpl->bounds.beginY)) + )) + }; + m_pImpl->transform = mof::Animation::Handler(new mof::CascadingAnimation(list[0] , list[1])); + + { + //visible‚̐ݒè + mof::KeyFrameAnimation::KeyFrame keyFrames[] = { + mof::makeKeyFrame(0 , true) , + mof::makeKeyFrame(20 , false) + }; + m_pImpl->visible = mof::Animation::Handler( + new mof::KeyFrameAnimation(keyFrames[0] , keyFrames[1] , &mof::stepInterpolate ) + ); + } + m_pImpl->frame = 0; +} + + + +void mof::PlainWidgetView::update(){ + m_pImpl->frame++; + //m_pImpl->pCaption->update(); + +} + +void mof::PlainWidgetView::draw(){ + if(m_pImpl->visible->getValue(m_pImpl->frame)){ + //m_pImpl->pCaption->draw(); + } +} diff --git a/moftmp/PlainWidgetView.hpp b/moftmp/PlainWidgetView.hpp new file mode 100755 index 0000000..ddd8609 --- /dev/null +++ b/moftmp/PlainWidgetView.hpp @@ -0,0 +1,29 @@ +#pragma once +#include +#include "mof/WidgetView.hpp" +#include "mof/tstring.hpp" +#include "mof/Color.hpp" + +namespace mof{ + + + class PlainWidgetView : public WidgetView{ + struct Impl; + boost::scoped_ptr m_pImpl; + public: + PlainWidgetView( mof::Color begin , mof::Color end); + ~PlainWidgetView(); + + virtual void setBounds(const mof::Rectangle& bounds); + virtual mof::Rectangle getBounds() const; + + virtual void show(); + virtual void close(); + virtual void focus(); + virtual void blur(); + + virtual void update(); + virtual void draw(); + }; + +} diff --git a/moftmp/Rectangle.hpp b/moftmp/Rectangle.hpp new file mode 100755 index 0000000..8c642da --- /dev/null +++ b/moftmp/Rectangle.hpp @@ -0,0 +1,72 @@ +#pragma once +#include + +namespace mof +{ + template + struct Rectangle + { + E beginX; + E beginY; + E endX; + E endY; + + Rectangle(){} + + template< typename T > + Rectangle(const Rectangle& obj) + { + beginX = obj.beginX; + beginY = obj.beginY; + endX = obj.endX; + endY = obj.endY; + } + + Rectangle(const E& beginX_ , const E& beginY_ , const E& endX_ , const E& endY_) + : beginX(beginX_) , beginY(beginY_) , endX(endX_) , endY(endY_) + { + } + + template< typename T > + Rectangle& operator = ( const Rectangle& obj ) + { + beginX = obj.beginX; + beginY = obj.beginY; + endX = obj.endX; + endY = obj.endY; + return *this; + } + + E getWidth( ) const + { + E width = endX - beginX; + return width < 0 ? -width : width; + } + + E getHeight( ) const + { + E height = endY - beginY; + return height < 0 ? -height : height; + } + + + bool operator ==(const mof::Rectangle& rect){ + if( + beginX == rect.beginX && + beginY == rect.beginY && + endX == rect.endX && + endY == rect.endY )return true; + else return false; + } + + + }; + + template + std::ostream& operator <<(std::ostream& os , const mof::Rectangle& rect){ + os << '(' << rect.beginX << ',' << rect.beginY << ',' + << rect.endX << ',' << rect.endY << ')'; + return os; + } + +} diff --git a/moftmp/ResourceManager.hpp b/moftmp/ResourceManager.hpp new file mode 100755 index 0000000..34b810b --- /dev/null +++ b/moftmp/ResourceManager.hpp @@ -0,0 +1,134 @@ +#pragma once +#include "mof/tstring.hpp" +#include +#include +#include +#include "mof/ConsoleIO.hpp" + +namespace mof{ + + + + /** ƒŠƒ\[ƒX‚̃v[ƒ‹A’x‰„ƒ[ƒh‹@”\‚ð’ñ‹Ÿ‚·‚éƒeƒ“ƒvƒŒ[ƒg + * + * + */ + template + class ResourceManager + { + typedef std::list > > MANAGER_LIST; + typedef std::map> RESOURCE_MAP; + + + ResourceManager* m_pParent; + RESOURCE_MAP m_resources; + MANAGER_LIST m_children; + + static boost::shared_ptr nullPtr; + //void addResouce(Resouce* pResource); + public: + ResourceManager(); + virtual ~ResourceManager(void); + + boost::shared_ptr& getResource(tstring& name ); + boost::shared_ptr& getResource(const TCHAR * const name ); + void addResource(const TCHAR * const name , boost::shared_ptr& resource); + boost::shared_ptr< ResourceManager > createChild(); + }; + + + + template + boost::shared_ptr ResourceManager::nullPtr = boost::shared_ptr(); + + + + /** e‚È‚µ‚Æ‚µ‚ăIƒuƒWƒFƒNƒg¶¬ + * + */ + template + ResourceManager::ResourceManager( ){ + m_pParent = NULL; + } + + /** Ž©g‚̃Šƒ\[ƒX‚ÆŽq‚ð‰ð•ú‚µAe‚ÌŽqƒŠƒXƒg‚©‚玩g‚ðíœ + */ + template + ResourceManager::~ResourceManager(){ + //Ž©g‚ÌŠÇ—‚·‚郊ƒ\[ƒX‚ðƒAƒ“ƒ[ƒh + m_resources.clear(); + + //ŽqƒIƒuƒWƒFƒNƒg‚ðíœ + m_children.clear(); + + //e‚©‚玩g‚ðíœ + if(m_pParent != NULL){ + for(MANAGER_LIST::iterator itr = m_pParent->m_children.begin() ; itr != m_pParent->m_children.end() ; ++itr){ + if(this == itr->get() ){ + m_pParent->m_children.erase(itr); + return; + } + } + } + } + + + + /** V‚½‚ÈŽq‚ð’ljÁ‚µA•Ô‚· + * @return ¶¬‚µ‚½Žq + */ + template + boost::shared_ptr< ResourceManager > ResourceManager::createChild(){ + boost::shared_ptr< ResourceManager > manager(new ResourceManager( )); + manager->m_pParent = this; + m_children.push_back(manager); + return manager; + } + + + /** –؍\‘¢‘S‘Ì‚©‚çŽw’肳‚ꂽ–¼‘O‚̃Šƒ\[ƒX‚ðŒŸõEŽæ“¾
+ * Œ©‚‚©‚ç‚È‚¯‚ê‚΁Aˆø”‚ðŒ³‚ÉV‚½‚ɐ¶¬‚·‚éB + * @param name ƒŠƒ\[ƒX–¼ + * @param parameter ƒŠƒ\[ƒXì¬Žž‚̈ø”iŽw’肵‚È‚­‚Ä‚à‚æ‚¢j + * @return —v‹‚³‚ꂽƒŠƒ\[ƒX + */ + template + boost::shared_ptr& ResourceManager::getResource(mof::tstring& name){ + //Ž©•ª‚̃ŠƒXƒg‚©‚ç’T‚· + RESOURCE_MAP::const_iterator n = m_resources.find(name); + if (n != m_resources.end()){ + return (boost::shared_ptr&)n->second; + } + + //Žq‚̃ŠƒXƒg‚©‚ç’T‚· + + //e‚̃ŠƒXƒg‚©‚ç’T‚· + + //‚È‚¯‚ê‚΍쐬‚·‚é + boost::shared_ptr resource( new T( name ) ); + //DEBUG_PRINT(resource->getName() << _T("‚ª¶¬‚³‚ê‚Ü‚µ‚½") ); + m_resources.insert(RESOURCE_MAP::value_type(name , resource)); + n = m_resources.find(name); + return (boost::shared_ptr&)n->second; + } + + + + template + boost::shared_ptr& ResourceManager::getResource(const TCHAR* const name){ + return getResource(mof::tstring(name)); + } + + template + void ResourceManager::addResource(const TCHAR* const name , boost::shared_ptr& resource){ + m_resources.insert(RESOURCE_MAP::value_type(mof::tstring(name) , resource)); + } + + + /*template + boost::shared_ptr& ResourceManager::findResource(mof::tstring& name , K parameter){ + + }*/ + + +}; diff --git a/moftmp/SceneGraph.hpp b/moftmp/SceneGraph.hpp new file mode 100755 index 0000000..8cc3161 --- /dev/null +++ b/moftmp/SceneGraph.hpp @@ -0,0 +1,23 @@ +#ifndef SCENE_GRAPH_HPP +#define SCENE_GRAPH_HPP + + + +namespace mof{ + + + +class SceneGraph +{ +public: + virtual ~SceneGraph(){} + virtual bool isVisible() const = 0; + virtual void update() = 0; + virtual void draw() const = 0; + //virtual bool isDisposable() const = 0; + +}; + +} + +#endif diff --git a/moftmp/SelectionModel.cpp b/moftmp/SelectionModel.cpp new file mode 100755 index 0000000..6941b78 --- /dev/null +++ b/moftmp/SelectionModel.cpp @@ -0,0 +1,73 @@ +#include "mof/SelectionModel.h" +#include "mof/ConsoleIO.h" + +mof::SelectionModel::SelectionModel( std::vector& selectables , mof::AnimationResource& pMenuAnimation , int nColumns) +{ + m_nColumns = nColumns; + m_pMenuAnimation = pMenuAnimation; + m_selectables = selectables; + m_selectingIndex = 0; + m_selectables.at(m_selectingIndex)->setFocused(true); + +} + +mof::SelectionModel::~SelectionModel(){ + +} + +void mof::SelectionModel::next(){ + if(m_pMenuAnimation.get() != NULL && !m_pMenuAnimation->isFinalized())return; + m_selectables.at(m_selectingIndex)->setFocused(false); + m_selectingIndex = (m_selectingIndex+1)%m_selectables.size(); + m_selectables.at(m_selectingIndex)->setFocused(true); +} + +void mof::SelectionModel::previous(){ + if(m_pMenuAnimation.get() != NULL && !m_pMenuAnimation->isFinalized())return; + m_selectables.at(m_selectingIndex)->setFocused(false); + m_selectingIndex = (m_selectingIndex == 0)? m_selectables.size()-1 : m_selectingIndex-1; + m_selectables.at(m_selectingIndex)->setFocused(true); + +} + +void mof::SelectionModel::up(){ + if(m_pMenuAnimation.get() != NULL && !m_pMenuAnimation->isFinalized())return; + m_selectables.at(m_selectingIndex)->setFocused(false); + m_selectingIndex = (m_selectingIndex - m_nColumns); + if(m_selectingIndex < 0)m_selectingIndex += m_selectables.size(); + m_selectables.at(m_selectingIndex)->setFocused(true); +} + +void mof::SelectionModel::down(){ + if(m_pMenuAnimation.get() != NULL && !m_pMenuAnimation->isFinalized())return; + m_selectables.at(m_selectingIndex)->setFocused(false); + m_selectingIndex = (m_selectingIndex + m_nColumns)% m_selectables.size(); + m_selectables.at(m_selectingIndex)->setFocused(true); +} + +void mof::SelectionModel::left(){ + if(m_pMenuAnimation.get() != NULL && !m_pMenuAnimation->isFinalized())return; + m_selectables.at(m_selectingIndex)->setFocused(false); + m_selectingIndex += (m_selectingIndex % m_nColumns == 0)? m_nColumns-1 : -1; + m_selectables.at(m_selectingIndex)->setFocused(true); +} + +void mof::SelectionModel::right(){ + if(m_pMenuAnimation.get() != NULL && !m_pMenuAnimation->isFinalized())return; + m_selectables.at(m_selectingIndex)->setFocused(false); + m_selectingIndex += (m_selectingIndex % m_nColumns == m_nColumns-1)? -(m_selectingIndex % m_nColumns) : 1; + m_selectables.at(m_selectingIndex)->setFocused(true); +} + + +int mof::SelectionModel::getSelectingIndex(){ + return m_selectingIndex; +} + +mof::Window* mof::SelectionModel::getSelectingItem(){ + return m_selectables.at(m_selectingIndex); +} + +void mof::SelectionModel::setMenuAnimation(mof::AnimationResource& pMenuAnimation){ + m_pMenuAnimation = pMenuAnimation; +} diff --git a/moftmp/SelectionModel.h b/moftmp/SelectionModel.h new file mode 100755 index 0000000..1f48f30 --- /dev/null +++ b/moftmp/SelectionModel.h @@ -0,0 +1,34 @@ +#pragma once +#include "mof/Window.h" +#include + +namespace mof{ + + class SelectionModel { + + mof::AnimationResource m_pMenuAnimation; + std::vector m_selectables; + int m_selectingIndex; + int m_nColumns; + public: + SelectionModel( std::vector& selectables , mof::AnimationResource& pOpenedAnimation , int nColumn = 1); + ~SelectionModel(); + + + void next(); + void previous(); + + void up(); + void down(); + void left(); + void right(); + + int getSelectingIndex(); + Window* getSelectingItem(); + void setMenuAnimation(mof::AnimationResource& pMenuAnimation); + + + + }; + +}; \ No newline at end of file diff --git a/moftmp/Sprite.cpp b/moftmp/Sprite.cpp new file mode 100755 index 0000000..1489475 --- /dev/null +++ b/moftmp/Sprite.cpp @@ -0,0 +1,192 @@ +#include "mof/Sprite.hpp" +#include "mof/private/GraphicsDeviceImpl.hpp" +#include "mof/stream/Constant.hpp" +#include "mof/ConsoleIO.hpp" +#include "mof/Font.hpp" + +namespace mof +{ + struct Sprite::Impl{ + boost::shared_ptr pTexture; + + Impl() + { + } + + ~Impl(){ + } + }; + + Sprite::Sprite + ( + const Rectangle& rect , + const boost::shared_ptr& pTexture , + const Rectangle& tRect + ) + : + m_pImpl( new Impl( ) ) , + Component2D( rect ) , + TextureComponent( tRect ) + { + m_pImpl->pTexture = pTexture; + } + + + Sprite::Sprite + ( + const boost::shared_ptr& pTexture , + const Rectangle& tRect + ) + : + m_pImpl(new Impl()) , + Component2D( Rectangle( 0 , 0 , pTexture->getWidth() , pTexture->getHeight() ) ) , + TextureComponent( tRect ) + { + m_pImpl->pTexture = pTexture; + } + + + Sprite::~Sprite() + { + } + + void Sprite::update() + { + m_textureStream.update(); + m_colorStream.update(); + m_sizeStream.update(); + m_positionStream.update(); + } + + void Sprite::draw() const + { + static VertexXYZRHWCUV vertices[4]; + + Rectangle textureCoordinates = m_textureStream.value( ); + Color color = m_colorStream.value( ).toColorCode( ); + + //textureCoordinates = mof::Rectangle( 0 , 0 , 0.625 , 0.546875 ); + Vector2D position = m_positionStream.value( ); + Vector2D size = m_sizeStream.value( ); + Vector2D begin = Vector2D( position.x , position.y ); + Vector2D end = begin + Vector2D( size.x , size.y ); + + vertices[0].x = static_cast(begin.x); + vertices[0].y = static_cast(begin.y); + vertices[0].z = 0; + vertices[0].rhw = 1; + vertices[0].color = color; + vertices[0].tu = textureCoordinates.beginX; + vertices[0].tv = textureCoordinates.beginY; + + vertices[1].x = static_cast(end.x); + vertices[1].y = static_cast(begin.y); + vertices[1].z = 0; + vertices[1].rhw = 1; + vertices[1].color = color; + vertices[1].tu = textureCoordinates.endX; + vertices[1].tv = textureCoordinates.beginY; + + vertices[2].x = static_cast(begin.x); + vertices[2].y = static_cast(end.y); + vertices[2].z = 0; + vertices[2].rhw = 1; + vertices[2].color = color; + vertices[2].tu = textureCoordinates.beginX; + vertices[2].tv = textureCoordinates.endY; + + vertices[3].x = static_cast(end.x); + vertices[3].y = static_cast(end.y); + vertices[3].z = 0; + vertices[3].rhw = 1; + vertices[3].color = color; + vertices[3].tu = textureCoordinates.endX; + vertices[3].tv = textureCoordinates.endY; + + GraphicsDevice::setTexture(m_pImpl->pTexture.get()); + GraphicsDevice::drawVertexArray(vertices[0] , vertices[3] , PRIMITIVE_TYPE_TRIANGLESTRIP); + + } + + void Sprite::setPositionStream( const Vector2DStream& stream ) + { + m_positionStream = stream; + } + + void Sprite::setSizeStream( const Vector2DStream& stream ) + { + m_sizeStream = stream; + } + + + void Sprite::append + ( + std::vector& list , + const Rectangle& region , + Color color , + const Rectangle& textureCoordinates + ) + { + list.push_back + ( + VertexXYZRHWCUV(Vector2D(region.beginX , region.beginY) , + color , textureCoordinates.beginX , textureCoordinates.beginY) + ); + + list.push_back + ( + VertexXYZRHWCUV(Vector2D(region.endX , region.beginY) , + color , textureCoordinates.endX , textureCoordinates.beginY) + ); + + list.push_back + ( + VertexXYZRHWCUV(Vector2D(region.beginX , region.endY) , + color , textureCoordinates.beginX , textureCoordinates.endY) + ); + + list.push_back + ( + VertexXYZRHWCUV(Vector2D(region.beginX , region.endY) , + color , textureCoordinates.beginX , textureCoordinates.endY) + ); + + list.push_back + ( + VertexXYZRHWCUV(Vector2D(region.endX , region.beginY) , + color , textureCoordinates.endX , textureCoordinates.beginY) + ); + + + list.push_back + ( + VertexXYZRHWCUV(Vector2D(region.endX , region.endY) , + color , textureCoordinates.endX , textureCoordinates.endY) + ); + + } + + Sprite* Sprite::createTextSprite( const Font& font , const tstring& text) + { + boost::shared_ptr pPixelMap( font.createText(text) ); + boost::shared_ptr pTexture(new Texture( pPixelMap)); + + return new Sprite + ( + Rectangle( 0 , 0 , pPixelMap->shape()[0] , pPixelMap->shape()[1]) , + pTexture , + Rectangle + ( + 0 , 0 , + static_cast(pPixelMap->shape()[0]) / pTexture->getWidth() , + static_cast(pPixelMap->shape()[1]) / pTexture->getHeight() + ) + ); + + } + + +} // namespace mof + + + diff --git a/moftmp/Sprite.hpp b/moftmp/Sprite.hpp new file mode 100755 index 0000000..46ec146 --- /dev/null +++ b/moftmp/Sprite.hpp @@ -0,0 +1,69 @@ +#pragma once +#include +#include "mof/Rectangle.hpp" +#include +#include "mof/Texture.hpp" +#include "mof/VertexTypes.hpp" +#include "mof/stream/Manipulator.hpp" +#include "mof/Matrix2D.hpp" +#include "mof/Component2D.hpp" +#include "mof/ColorComponent.hpp" +#include "mof/TextureComponent.hpp" +#include "mof/Drawable.hpp" +#include + + +namespace mof{ + + class Font; + + class Sprite + : + public Component2D , + public ColorComponent , + public TextureComponent , + public Drawable + { + + public : + Sprite + ( + const Rectangle& rect , + const boost::shared_ptr& pTexture , + const Rectangle& tRect + ); + + Sprite + ( + const boost::shared_ptr& pTexture , + const Rectangle& tRect + ); + + virtual ~Sprite(); + virtual void update(); + virtual void draw() const; + virtual void setPositionStream( const Vector2DStream& stream ); + virtual void setSizeStream( const Vector2DStream& stream ); + + + + static void append + ( + std::vector& list , + const Rectangle& region , + Color color , + const Rectangle& textureCoordinates + ); + + static Sprite* createTextSprite + ( + const Font& font , + const tstring& text + ); + private: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + + +} // namespace mof diff --git a/moftmp/TextCompiler.cpp b/moftmp/TextCompiler.cpp new file mode 100755 index 0000000..afbcf6a --- /dev/null +++ b/moftmp/TextCompiler.cpp @@ -0,0 +1,42 @@ +#include "mof/TextCompiler.hpp" +#include +#include "mof/ConsoleIO.hpp" + +namespace { + enum NodeType{ + PLANE , + NEWLINE + } ; + + struct Node{ + mof::tstring subtext; + NodeType type; + }; + +} + +void recursive(const mof::tstring& text , std::vector& result, const mof::Font& font){ + boost::basic_regex regex("(.*)<\\s*nl\\s*/\\s*>(.*)"); + boost::smatch results; + if(boost::regex_search(text , results , regex)){ + if( results.str(1).length() != 0)recursive(results.str(1) , result , font); + if( results.str(2).length() != 0)recursive(results.str(2) , result , font); + } + else { + result.push_back(mof::Sprite::createTextSprite(font , text) ); + } +} + +bool mof::compileText +( + const mof::tstring &text , + const mof::Font &font , + std::vector &result +){ + + recursive(text , result , font); + + + + return true; +} \ No newline at end of file diff --git a/moftmp/TextCompiler.hpp b/moftmp/TextCompiler.hpp new file mode 100755 index 0000000..d4493e9 --- /dev/null +++ b/moftmp/TextCompiler.hpp @@ -0,0 +1,18 @@ +#pragma once +#include +#include +#include "mof/Sprite.hpp" +#include "mof/utilities.hpp" +#include "mof/Font.hpp" +#include "mof/tstring.hpp" + +namespace mof{ + + + bool compileText( + const mof::tstring& text , + const mof::Font& font , + std::vector& result + ); + +} diff --git a/moftmp/TextView.cpp b/moftmp/TextView.cpp new file mode 100755 index 0000000..3da8e46 --- /dev/null +++ b/moftmp/TextView.cpp @@ -0,0 +1,184 @@ +#include "mof/TextView.hpp" +#include "mof/MenuItemInfo.hpp" +#include "mof/Sprite.hpp" +#include "mof/Effect.hpp" +#include "mof/Frame.hpp" +#include "mof/mofAnimations.hpp" +#include "mof/utilities.hpp" + +namespace mof +{ + struct TextView::Impl + { + mof::Font font; + mof::tstring caption; + mof::Effect* pEffect; + mof::Vector2D scaling; + mof::Frame* pFrame; + + Impl(const mof::tstring& _caption , const mof::Font& _font) + : font(_font) , caption(_caption) , pEffect(NULL) , pFrame( NULL ) + { + + } + + + ~Impl(){ + delete pEffect; + } + }; +//{{{ TextView + TextView::TextView(const mof::tstring& caption , const mof::Font& font) + : m_pImpl(new Impl(caption , font)) + { + m_pImpl->pEffect = new mof::Effect(); + } +//}}} +//{{{ ~TextView + TextView::~TextView( ) + { + } +//}}} +//{{{ initialize + mof::Rectangle TextView::initialize( ) + { + + + mof::Sprite* pSprite = mof::Sprite::createTextSprite + ( + m_pImpl->font , m_pImpl->caption + ); + + m_pImpl->pEffect->addSprite(_T("text") , pSprite); + m_pImpl->scaling = pSprite->getWorldTransform().mof::Matrix2D::getDiagonal(); + + { + //color + pSprite->setColor( mof::makeConstantHandler(mof::Color4f(0 , 1 , 1 , 1)) ); + } + mof::Rectangle bounds = pSprite->getWorldTransform().toBoundingBox(); + + boost::shared_ptr pTexture(new mof::Texture( _T("image/frame3.png") )); + m_pImpl->pFrame = new mof::Frame( pTexture ); + m_pImpl->pEffect->addDrawable( _T("bg") , m_pImpl->pFrame ); + m_pImpl->pFrame->setRegion( mof::Rectangle( 100 , 100 , 200 , 132 ) ); + return bounds; + } +//}}} +//{{{ show + void TextView::show( ) + { + mof::Sprite* pText = m_pImpl->pEffect->getSpriteByName(_T("text")); + { + //color + mof::KeyFrameAnimation::KeyFrame keyFrames[] = + { + mof::makeKeyFrame( 0 , mof::Color4f(0 , 1, 1 , 1) ), + mof::makeKeyFrame( 30 , mof::Color4f(1 , 1, 1 , 1) ) + }; + mof::Animation::Handler handler + ( + new mof::KeyFrameAnimation + ( + keyFrames[0] , keyFrames[1] + ) + ); + pText->setColor( handler ); + pText->setFrameNumber( 0 ); + } + + } +//}}} +//{{{ close + void mof::TextView::close(){ + mof::Sprite* pText = m_pImpl->pEffect->getSpriteByName(_T("text")); + { + //color + mof::Sprite* pText = m_pImpl->pEffect->getSpriteByName(_T("text")); + mof::KeyFrameAnimation::KeyFrame keyFrames[] = { + mof::makeKeyFrame( 0 , mof::Color4f(1 , 1, 1 , 1) ), + mof::makeKeyFrame( 10 , mof::Color4f(0 , 1, 1 , 1) ) + }; + mof::Animation::Handler handler(new mof::KeyFrameAnimation( + keyFrames[0] , keyFrames[1] + )); + pText->setColor( handler ); + pText->setFrameNumber(0); + } + } +//}}} +//{{{ focus + void mof::TextView::focus( ) + { + } +//}}} +//{{{ blur + void mof::TextView::blur() + { + } +//}}} +//{{{ setPosition + void mof::TextView::setPosition + ( + const mof::Animation::Handler& handler + ) + { + mof::Sprite* pText = m_pImpl->pEffect->getSpriteByName(_T("text")); + mof::Animation::Handler cascading[] = { + mof::makeConstantHandler(mof::Matrix2D::createScaling(m_pImpl->scaling)) , + handler + }; + mof::Animation::Handler pAnimation( + new mof::CascadingAnimation(cascading[0] , cascading[1]) + ); + pText->setWorldTransform(pAnimation); + /*pText->setWorldTransform( + mof::cascadingHandler2( + mof::Multiply cascaor , + mof::makeConstantHandler(mof::Matrix2D::createScaling(m_pImpl->scaling)) , + handler + ));*/ + } +//}}} +//{{{ setWorldTransform + void mof::TextView::setWorldTransform + ( + const mof::Animation::Handler& handler + ) + { + mof::Sprite* pText = m_pImpl->pEffect->getSpriteByName(_T("text")); + pText->setWorldTransform( handler ); + + } +//}}} +//{{{ setBounds + void mof::TextView::setBounds( const mof::Rectangle& bounds ) + { + mof::Sprite* pText = m_pImpl->pEffect->getSpriteByName(_T("text")); + //m_pImpl->scaling = mof::Vector2D( bounds.endX - bounds.beginX , bounds.endY - bounds.beginY ); + mof::Vector2D translation( bounds.beginX , bounds.beginY ); + mof::Animation::Handler cascading[] = + { + mof::makeConstantHandler( mof::Matrix2D::createScaling( m_pImpl->scaling ) ) , + mof::makeConstantHandler( mof::Matrix2D::createTranslation( translation ) ) , + }; + mof::Animation::Handler pAnimation( + new mof::CascadingAnimation(cascading[0] , mof::lastOf( cascading ) ) + ); + pText->setWorldTransform(pAnimation); + } +//}}} +//{{{ getEffect + const mof::Effect* TextView::getEffect() const + { + return m_pImpl->pEffect; + } +//}}} +//{{{ update + void mof::TextView::update() + { + m_pImpl->pEffect->update(); + + } +//}}} +} diff --git a/moftmp/TextView.hpp b/moftmp/TextView.hpp new file mode 100755 index 0000000..5917f11 --- /dev/null +++ b/moftmp/TextView.hpp @@ -0,0 +1,44 @@ +#pragma once +#include +#include "mof/MenuView.hpp" +#include "mof/tstring.hpp" +#include "mof/Font.hpp" + +namespace mof +{ + + + class TextView : public MenuView + { + public: + TextView( const mof::tstring& caption , const mof::Font& font ); + virtual ~TextView(); + virtual mof::Rectangle initialize(); + virtual void show(); + virtual void close(); + virtual void focus(); + virtual void blur(); + /* diprecated */ + virtual void setPosition + ( + const mof::Animation::Handler& handler + ); + void setBounds( const mof::Rectangle& bounds ); + + /* candidate */ + virtual void setWorldTransform + ( + const mof::Animation::Handler& handler + ); + + virtual const mof::Effect* getEffect() const; + virtual void update(); + private: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; + + +} // namespace mof + diff --git a/moftmp/Texture.cpp b/moftmp/Texture.cpp new file mode 100755 index 0000000..1dda016 --- /dev/null +++ b/moftmp/Texture.cpp @@ -0,0 +1,53 @@ +#include "mof/private/TextureImpl.hpp" +#include "mof/ConsoleIO.hpp" +#include "mof/private/FileTextureBuilder.hpp" +#include "mof/private/PixelMapTextureBuilder.hpp" + +mof::Texture::Texture( const tstring& filename) +: m_pImpl(new Impl()) +{ + m_pImpl->pTexture = mof::FileTextureBuilder( filename).create(); + D3DSURFACE_DESC desc; + m_pImpl->pTexture->GetLevelDesc(0 , &desc); + m_pImpl->width = desc.Width; + m_pImpl->height = desc.Height; +} + +mof::Texture::Texture( const boost::shared_ptr& pPixelMap) +: m_pImpl(new Impl()) +{ + m_pImpl->pTexture = mof::PixelMapTextureBuilder( pPixelMap).create(); + D3DSURFACE_DESC desc; + m_pImpl->pTexture->GetLevelDesc(0 , &desc); + m_pImpl->width = desc.Width; + m_pImpl->height = desc.Height; +} + +mof::Texture::~Texture(){} + +boost::shared_ptr mof::Texture::getPixelMap(){ + typedef mof::PixelMap::size_type size_type; + boost::array sizes = {{getWidth() , getHeight()}}; + + boost::shared_ptr pMap(new mof::PixelMap(sizes)); + D3DLOCKED_RECT rect; + m_pImpl->pTexture->LockRect(0 , &rect , NULL , 0); + for(int y = 0 ; y < getHeight() ; y++){ + for(int x = 0 ; x < getWidth() ; x++){ + BYTE* pPixel = (BYTE*)rect.pBits + x * 4 + y * rect.Pitch; + (*pMap)[x][y] = mof::createColor(*(pPixel + 3) , *(pPixel+2) , *(pPixel+1) , *(pPixel)); + } + } + m_pImpl->pTexture->UnlockRect(0); + return pMap; +} + +int mof::Texture::getWidth(){ + return m_pImpl->width; +} + +int mof::Texture::getHeight(){ + return m_pImpl->height; +} + + diff --git a/moftmp/Texture.hpp b/moftmp/Texture.hpp new file mode 100755 index 0000000..b583910 --- /dev/null +++ b/moftmp/Texture.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include "mof/PixelMap.hpp" +#include +#include +#include +#include "mof/GraphicsDevice.hpp" + +namespace mof{ + + class Texture : boost::noncopyable + { + friend void GraphicsDevice::setTexture( const Texture* ); + struct Impl; + boost::scoped_ptr m_pImpl; + + public: + Texture( const tstring& filename ); + Texture( const boost::shared_ptr& pPixelMap); + ~Texture(); + + boost::shared_ptr getPixelMap(); + + int getWidth(); + int getHeight(); + + }; +} diff --git a/moftmp/TextureComponent.hpp b/moftmp/TextureComponent.hpp new file mode 100755 index 0000000..0923f10 --- /dev/null +++ b/moftmp/TextureComponent.hpp @@ -0,0 +1,45 @@ +#pragma once +#include "mof/stream/utilities.hpp" + +namespace mof +{ + + class TextureComponent + { + public: + virtual ~TextureComponent( ){} + + virtual void setRectangleCoordinatesStream( const RectangleStream& stream ) + { + m_textureStream = stream; + } + + virtual const RectangleStream& getRectangleCoordinatesStream( ) const + { + return m_textureStream; + } + + protected: + RectangleStream m_textureStream; + + TextureComponent( ) + : + m_textureStream( makeConstantHandler( Rectangle< real >( 0 , 0 , 1 , 1 ) ) ) + { + } + + TextureComponent( const Rectangle< real >& rect ) + : + m_textureStream( makeConstantHandler( rect ) ) + { + } + + TextureComponent( const RectangleStream& stream ) + : + m_textureStream( stream ) + { + } + + }; + +} // namespace mof diff --git a/moftmp/TextureResource.h b/moftmp/TextureResource.h new file mode 100755 index 0000000..8a6233f --- /dev/null +++ b/moftmp/TextureResource.h @@ -0,0 +1,18 @@ +#pragma once + +#include "mof/ResourceManager.h" +#include "mof/Texture.h" +#include "mof/Animation.h" +//#include "mof/MultipleAnimation.h" +#include + +namespace mof{ + typedef boost::shared_ptr TextureResource; + typedef mof::ResourceManager TextureManager; + + + + //typedef boost::shared_ptr MultipleAnimation; + + +}; \ No newline at end of file diff --git a/moftmp/Timer.cpp b/moftmp/Timer.cpp new file mode 100755 index 0000000..5c50444 --- /dev/null +++ b/moftmp/Timer.cpp @@ -0,0 +1,76 @@ +#include "mof/Timer.hpp" +#include + +bool mof::Timer::initialized = false; + + + +mof::Timer::Timer() : m_startTime(timeGetTime()){ + if(!initialized){ + TIMECAPS caps; + timeGetDevCaps(&caps, sizeof(TIMECAPS)); + timeBeginPeriod(caps.wPeriodMin);//Å‚«”\‚ÅŒv‘ª + initialized = true; + } +} + +void mof::Timer::reset(){ + m_startTime = timeGetTime(); +} + +int mof::Timer::getTime() const{ + return timeGetTime() - m_startTime; +} + +/* +//----------------------------------------------- +// Clock::Clock +// +//----------------------------------------------- +mof::Clock::Clock() + +{ + + m_begintime = 0; + + +} + +//----------------------------------------------- +// Clock::SetTimer +// +//----------------------------------------------- +void mof::Clock::setTimer(){ + + m_begintime = timeGetTime(); + + +} + + +//----------------------------------------------- +// Clock::GetBetweenTime +// +//----------------------------------------------- +DWORD mof::Clock::getBetweenTime(){ + DWORD temp_time = m_begintime; + m_begintime = timeGetTime(); + return m_begintime - temp_time; + +} + + + +// void StopTimer(); +// DWORD GetAvgTime(); + + +//----------------------------------------------- +// Clock::GetFPS +// ‚ ‚éƒtƒŒ[ƒ€”‚É‚©‚©‚Á‚½ŽžŠÔ‚©‚çAFPS‚ðŽZo‚·‚é +//----------------------------------------------- +float mof::Clock::getFPS(DWORD in_time , UINT in_cnt_frame){ + if(in_time == 0)return 0.0f;//‚O‚ŏœŽZ‚ð‰ñ”ð + return (float)in_cnt_frame / (float)in_time * 1000.0f; + +}*/ diff --git a/moftmp/Timer.hpp b/moftmp/Timer.hpp new file mode 100755 index 0000000..aa63bca --- /dev/null +++ b/moftmp/Timer.hpp @@ -0,0 +1,22 @@ +#ifndef TIMER_HPP +#define TIMER_HPP + +#pragma comment(lib , "winmm.lib") + +namespace mof{ + + +class Timer{ + int m_startTime; + static bool initialized; +public: + Timer(); + + void reset(); + int getTime() const; + +}; + +} + +#endif diff --git a/moftmp/Vector2D.cpp b/moftmp/Vector2D.cpp new file mode 100755 index 0000000..0467c32 --- /dev/null +++ b/moftmp/Vector2D.cpp @@ -0,0 +1,75 @@ + +#include "mof/Vector2D.hpp" + +mof::Vector2D::Vector2D(real x_ , real y_) +: x(x_) , y(y_) +{} + +mof::Vector2D::Vector2D(int x_ , int y_) +: x(mof::int2real(x_)) , y(mof::int2real(y_)) +{} + + +mof::Vector2D::Vector2D(){ + x = y = 0; +} + +mof::Vector2D::~Vector2D(void) +{ +} + + +bool mof::Vector2D::operator == (const mof::Vector2D& obj) const{ + if(x == obj.x && y == obj.y)return true; + else return false; +} + +bool mof::Vector2D::operator != (const mof::Vector2D& obj) const{ + return !(*this == obj); +} + +mof::Vector2D mof::Vector2D::operator - () const{ + return mof::Vector2D( -x , -y); +} + + + +mof::Vector2D mof::Vector2D::operator +( const mof::Vector2D& rhs) const{ + return mof::Vector2D(this->x + rhs.x , this->y + rhs.y); +} + + +mof::Vector2D mof::Vector2D::operator -( const mof::Vector2D& rhs) const{ + return mof::Vector2D(this->x - rhs.x , this->y - rhs.y); +} + +mof::Vector2D mof::Vector2D::operator *(float rhs) const{ + return mof::Vector2D(this->x * rhs , this->y * rhs); +} + + +mof::Vector2D mof::Vector2D::operator /(float rhs) const{ + return mof::Vector2D(this->x / rhs , this->y / rhs); +} + + +mof::Vector2D mof::operator *(const mof::Vector2D& vec , float f){ + mof::Vector2D obj; + obj.x = vec.x * f; + obj.y = vec.y * f; + return obj; +} + +mof::Vector2D mof::operator *(float f , const mof::Vector2D& vec ){ + mof::Vector2D obj; + obj.x = vec.x * f; + obj.y = vec.y * f; + return obj; +} + +std::ostream& mof::operator <<(std::ostream& os , const mof::Vector2D& obj) +{ + os << '(' << obj.x << ',' << obj.y << ')'; + return os; +} + diff --git a/moftmp/Vector2D.hpp b/moftmp/Vector2D.hpp new file mode 100755 index 0000000..f83dd8b --- /dev/null +++ b/moftmp/Vector2D.hpp @@ -0,0 +1,34 @@ +#ifndef VECTOR2D_HPP +#define VECTOR2D_HPP +#include +#include + +namespace mof{ + + struct Vector2D + { + real x , y; + + Vector2D(real x_ , real y_); + Vector2D(int x_ , int y_); + Vector2D(); + ~Vector2D(void); + + mof::Vector2D operator +(const mof::Vector2D& rhs) const; + mof::Vector2D operator -(const mof::Vector2D& rhs) const; + mof::Vector2D operator *(float rhs) const; + mof::Vector2D operator /(float rhs) const; + + bool operator ==(const mof::Vector2D& obj) const; + bool operator !=(const mof::Vector2D& obj) const; + mof::Vector2D operator -( ) const; + + friend mof::Vector2D operator *(const mof::Vector2D& vec , real f); + friend mof::Vector2D operator *(real f , const mof::Vector2D & vec); + friend std::ostream& operator <<(std::ostream& os , const Vector2D& obj ); + + }; + +}; + +#endif diff --git a/moftmp/Vector3D.cpp b/moftmp/Vector3D.cpp new file mode 100755 index 0000000..9a9eaef --- /dev/null +++ b/moftmp/Vector3D.cpp @@ -0,0 +1,72 @@ + #include "mof/Vector3D.hpp" + #include + + mof::Vector3D::Vector3D(real _x , float _y , float _z) + { + x = _x; + y = _y; + z = _z; + } + + mof::Vector3D::Vector3D(){ + x = y = z = 0.0f; + } + + mof::Vector3D::~Vector3D(void) + { + } + + + void mof::Vector3D::normalize(){ + real norm = sqrt(x*x + y*y + z*z); + if(norm < 1E-7 )return ; + x = x / norm; + y = y / norm; + z = z / norm; + } + + + bool mof::Vector3D::operator ==(const mof::Vector3D& rhs) const{ + if(x == rhs.x && y == rhs.y && rhs.z == z)return true; + else return false; + } + + bool mof::Vector3D::operator != (const mof::Vector3D& obj) const{ + return !(*this == obj); + } + + + mof::Vector3D mof::Vector3D::operator +(const mof::Vector3D& rhs) const{ + return mof::Vector3D(this->x + rhs.x , this->y + rhs.y , this->z + rhs.z); + } + + + mof::Vector3D mof::Vector3D::operator -(const mof::Vector3D& rhs) const{ + return mof::Vector3D(this->x - rhs.x , this->y - rhs.y , this->z - rhs.z); + } + + mof::Vector3D mof::Vector3D::operator *(real rhs) const{ + return mof::Vector3D(this->x * rhs , this->y * rhs ,this->z * rhs); + } + + + mof::Vector3D mof::Vector3D::operator /(real rhs) const{ + return mof::Vector3D(this->x / rhs , this->y / rhs , this->z / rhs); + } + + /* + mof::Vector3D mof::operator *(const mof::Vector3D& vec , real f){ + mof::Vector3D obj; + obj.x = vec.x * f; + obj.y = vec.y * f; + obj.z = vec.z * f; + return obj; + }*/ + + mof::Vector3D mof::operator *(real f , const mof::Vector3D& vec ){ + mof::Vector3D obj; + obj.x = vec.x * f; + obj.y = vec.y * f; + obj.z = vec.z * f; + return obj; + } diff --git a/moftmp/Vector3D.hpp b/moftmp/Vector3D.hpp new file mode 100755 index 0000000..1000bd5 --- /dev/null +++ b/moftmp/Vector3D.hpp @@ -0,0 +1,28 @@ + #pragma once +#include + + namespace mof{ + struct Vector3D + { + real x , y , z; + Vector3D(real _x , real _y , real _z); + Vector3D(); + ~Vector3D(void); + void normalize(); + + mof::Vector3D operator +(const mof::Vector3D& rhs) const ; + mof::Vector3D operator -(const mof::Vector3D& rhs) const ; + mof::Vector3D operator *(real rhs) const; + mof::Vector3D operator /(real rhs) const; + + //friend mof::Vector3D operator *(const mof::Vector3D& vec , real f); + friend mof::Vector3D operator *(real f , const mof::Vector3D & vec); + + + bool operator ==(const mof::Vector3D& rhs) const; + bool operator !=(const mof::Vector3D& rhs) const; + }; + + Vector3D operator *(real f , const mof::Vector3D & vec); + } //namespace mof + diff --git a/moftmp/VertexBuffer.cpp b/moftmp/VertexBuffer.cpp new file mode 100755 index 0000000..4ea6c26 --- /dev/null +++ b/moftmp/VertexBuffer.cpp @@ -0,0 +1,102 @@ +#pragma once +#include "mof/VertexBuffer.hpp" +#include "mof/private/GraphicsDeviceImpl.hpp" +#include +#include "mof/VertexTypes.hpp" +#include "mof/private/VertexFVF.hpp" +#include + +template class mof::VertexBuffer; +template class mof::VertexBuffer; +template class mof::VertexBuffer; +template class mof::VertexBuffer; +template class mof::VertexBuffer; + + +template +struct mof::VertexBuffer::Impl{ + IDirect3DVertexBuffer9* pBuffer; + mof::PRIMITIVE_TYPE primitiveType; + + + Impl(mof::PRIMITIVE_TYPE primitiveType_); + ~Impl(); +}; + + +template +mof::VertexBuffer::Impl::Impl(mof::PRIMITIVE_TYPE primitiveType_ ) +: pBuffer(NULL) , primitiveType(primitiveType_) +{ +} + +template +mof::VertexBuffer::Impl::~Impl() +{ + if(pBuffer != NULL)pBuffer->Release(); +} + + +template +mof::VertexBuffer::VertexBuffer(const T& front , const T& back , mof::PRIMITIVE_TYPE primitiveType ) +: m_pImpl(new Impl( primitiveType )) +{ + int length = &back - &front + 1; + if(length <= 0)throw std::invalid_argument("•s³‚È’¸“_”z—ñŽw’è"); + + const LPDIRECT3DDEVICE9 pDevice = mof::GraphicsDevice::getRawDevice(); + HRESULT hr = pDevice->CreateVertexBuffer( sizeof(T) * length , 0 , mof::getFVF() , D3DPOOL_DEFAULT , &m_pImpl->pBuffer , NULL); + if(FAILED(hr))throw std::runtime_error("Failed -- CreateVertexBuffer"); + + T* pBuffer; + hr = m_pImpl->pBuffer->Lock( 0, 0 ,(LPVOID*)&pBuffer , 0); + if(FAILED(hr))throw std::invalid_argument(std::string("’¸“_ƒoƒbƒtƒ@‚̃ƒbƒN‚ÉŽ¸”s‚µ‚Ü‚µ‚½")); + + memcpy( pBuffer , &front , sizeof(T) * length ); + m_pImpl->pBuffer->Unlock(); +} + + + +template +mof::VertexBuffer::~VertexBuffer(){ +} + + +template +int mof::VertexBuffer::getLength() const{ + D3DVERTEXBUFFER_DESC desc; + m_pImpl->pBuffer->GetDesc(&desc); + return desc.Size / sizeof(T); +} + + +template +mof::PRIMITIVE_TYPE mof::VertexBuffer::getPrimitiveType() const{ + return m_pImpl->primitiveType; +} + + +template +void mof::VertexBuffer::draw() const{ + HRESULT hr = E_FAIL; + + const LPDIRECT3DDEVICE9 pDevice = mof::GraphicsDevice::getRawDevice(); + + pDevice->SetFVF(mof::getFVF()); + pDevice->SetStreamSource(0 , m_pImpl->pBuffer , 0 , sizeof(T)); + + + int length = getLength(); + + if(m_pImpl->primitiveType == mof::PRIMITIVE_TYPE_TRIANGLESTRIP){ + hr = pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP , 0 , length -2 ); + } + else if(m_pImpl->primitiveType == mof::PRIMITIVE_TYPE_TRIANGLELIST){ + hr = pDevice->DrawPrimitive( D3DPT_TRIANGLELIST , 0 , length /3 ); + } + + if(FAILED(hr))throw std::runtime_error("Failed -- DrawPrimitive"); + +} + diff --git a/moftmp/VertexBuffer.hpp b/moftmp/VertexBuffer.hpp new file mode 100755 index 0000000..ab0a9dc --- /dev/null +++ b/moftmp/VertexBuffer.hpp @@ -0,0 +1,30 @@ +#pragma once +#include +#include "mof/VertexTypes.hpp" +#include + +namespace mof{ + + + +template +class VertexBuffer : boost::noncopyable{ + + struct Impl; + boost::scoped_ptr m_pImpl; +public: + VertexBuffer + ( + const T& front , const T& back , + mof::PRIMITIVE_TYPE primitiveType = PRIMITIVE_TYPE_TRIANGLELIST + ); + ~VertexBuffer(); + + int getLength() const; + mof::PRIMITIVE_TYPE getPrimitiveType() const; + void draw() const; + +}; + + +} diff --git a/moftmp/VertexTypes.hpp b/moftmp/VertexTypes.hpp new file mode 100755 index 0000000..1cfd2d8 --- /dev/null +++ b/moftmp/VertexTypes.hpp @@ -0,0 +1,104 @@ +#pragma once +#include "mof/Color.hpp" +#include "mof/Vector2D.hpp" +#include "mof/Vector3D.hpp" +namespace mof{ + + +struct VertexXYZRHWCUV{ + float x , y , z , rhw; + mof::Color color; + float tu , tv; + + VertexXYZRHWCUV(){ + } + + VertexXYZRHWCUV(const mof::Vector2D& position , mof::Color color , float tu , float tv){ + x = static_cast(position.x); + y = static_cast(position.y); + z = 0.0f; + rhw = 1.0f; + this->color = color; + this->tu = tu; + this->tv = tv; + } +}; + +struct VertexXYZRHWC{ + float x , y , z , rhw; + mof::Color color; + + VertexXYZRHWC(){ + } + + VertexXYZRHWC(const mof::Vector2D& position , mof::Color color){ + x = static_cast(position.x); + y = static_cast(position.y); + z = 0.0f; + rhw = 1.0f; + this->color = color; + } +}; + + +struct VertexXYZCUV{ + float x , y , z; + mof::Color color; + float tu , tv; + + VertexXYZCUV(){ + } + + VertexXYZCUV(const mof::Vector3D& position , mof::Color color ,float tu , float tv){ + x = position.x; + y = position.y; + z = position.z; + this->color = color; + this->tu = tu; + this->tv = tv; + } +}; + +struct VertexXYZNUV{ + float x , y , z; + float nx , ny , nz; + float tu , tv; + + VertexXYZNUV(){ + } + + VertexXYZNUV(const mof::Vector3D& position , const mof::Vector3D& normal , float tu , float tv){ + x = position.x; + y = position.y; + z = position.z; + nx = normal.x; + ny = normal.y; + nz = normal.z; + this->tu = tu; + this->tv = tv; + } +}; + +struct VertexXYZC{ + float x , y , z; + mof::Color color; + + VertexXYZC(){ + } + + VertexXYZC(const mof::Vector3D& position , const mof::Color _color){ + x = position.x; + y = position.y; + z = position.z; + color = _color; + } +}; + +enum PRIMITIVE_TYPE{ + PRIMITIVE_TYPE_TRIANGLESTRIP, + PRIMITIVE_TYPE_TRIANGLELIST , + PRIMITIVE_TYPE_LINELIST +}; + + +} diff --git a/moftmp/Window.cpp b/moftmp/Window.cpp new file mode 100755 index 0000000..f164673 --- /dev/null +++ b/moftmp/Window.cpp @@ -0,0 +1,128 @@ +#include "mof/Window.hpp" +#include "mof/InputDevice.hpp" +#include "mof/ConsoleIO.hpp" +#include + +LRESULT WINAPI wndProc( HWND hWnd , UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch(msg) + { + case WM_ACTIVATEAPP: + if(LOWORD(wParam) == 0) + { + /* *ConsoleOut::getInstance() << "Window‚ª”ñƒAƒNƒeƒBƒu‚É‚È‚è‚Ü‚µ‚½" << std::endl; + mof::System::getInstance()->activate(false); + mof::InputDevice::getInstance()->activate(false);*/ + mof::InputDevice::setActivation(false); + } + else + { + /* *ConsoleOut::getInstance() << "Window‚ªƒAƒNƒeƒBƒu‚É‚È‚è‚Ü‚µ‚½" << std::endl; + mof::System::getInstance()->activate(true); + mof::InputDevice::getInstance()->activate(true);*/ + mof::InputDevice::setActivation(true); + } + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + case WM_SETCURSOR: + SetCursor(NULL); + break; + } + + return DefWindowProc( hWnd, msg, wParam, lParam ); +} + + + + +namespace mof +{ + + struct Window::Impl + { + mof::tstring appName; + HINSTANCE hInstance; + HWND hWindow; + + Impl(const mof::tstring& appname , HINSTANCE hInstance ); + }; + + Window::Impl::Impl(const mof::tstring &appname, HINSTANCE hInstance ) + : appName( appname ) , hInstance( hInstance ) , hWindow( NULL ) + { + // do nothing + } + + Window::Window( const mof::tstring &appname , int width , int height , bool fullscreen ) + : m_pImpl( new mof::Window::Impl( appname , GetModuleHandle(NULL) ) ) + { + + // ƒEƒBƒ“ƒhƒEƒNƒ‰ƒXÝ’è + WNDCLASSEX wc = + { + sizeof(WNDCLASSEX), CS_CLASSDC, wndProc, 0L, 0L, + m_pImpl->hInstance , NULL, NULL, NULL, NULL, + m_pImpl->appName.c_str() , NULL + }; + RegisterClassEx( &wc ); + + // ƒEƒBƒ“ƒhƒE¶¬ + if( !fullscreen ) + { + // Žw’肳‚ꂽƒNƒ‰ƒCƒAƒ“ƒg—̈æ‚ðŠm•Û‚·‚邽‚ß‚É•K—v‚ȃEƒBƒ“ƒhƒEƒTƒCƒY‚𓾂é + RECT rect_win; + SetRect( &rect_win , 0 , 0 , width , height ); + AdjustWindowRect( &rect_win , WS_OVERLAPPEDWINDOW , false ); + + //Windowƒ‚[ƒh + m_pImpl->hWindow = + CreateWindow + ( + m_pImpl->appName.c_str() , m_pImpl->appName.c_str() , + WS_OVERLAPPEDWINDOW , CW_USEDEFAULT, CW_USEDEFAULT, (rect_win.right - rect_win.left) , + (rect_win.bottom - rect_win.top) , GetDesktopWindow() , NULL , wc.hInstance , NULL + ); + } + else + { + //ƒtƒ‹ƒXƒNƒŠ[ƒ“ + m_pImpl->hWindow = + CreateWindow + ( + m_pImpl->appName.c_str() , m_pImpl->appName.c_str() , + WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , width , height , + HWND_DESKTOP , NULL , wc.hInstance , NULL + ); + } + + + // ƒEƒBƒ“ƒhƒE•`‰æ + ShowWindow( m_pImpl->hWindow , SW_SHOWDEFAULT ); + UpdateWindow( m_pImpl->hWindow ); + + + } // function constructor + + + + Window::~Window( ) + { + try + { + + //—áŠO‚È‚°‚éH + UnregisterClass(m_pImpl->appName.c_str() , m_pImpl->hInstance ); + } + catch(...) + { + } + + } + + HWND Window::getHandler() const { + return m_pImpl->hWindow; + } + +} // namespace mof \ No newline at end of file diff --git a/moftmp/Window.hpp b/moftmp/Window.hpp new file mode 100755 index 0000000..b62b50a --- /dev/null +++ b/moftmp/Window.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "mof/tstring.hpp" +#include +#include +#include + +namespace mof +{ + + + class Window : boost::noncopyable + { + + struct Impl; + boost::scoped_ptr m_pImpl; + + public: + Window( const mof::tstring& appname , int width , int height , bool fullscreen ); + ~Window( ); + HWND getHandler() const; + + + }; + + +} diff --git a/moftmp/graphics/utilities.hpp b/moftmp/graphics/utilities.hpp new file mode 100755 index 0000000..cca335a --- /dev/null +++ b/moftmp/graphics/utilities.hpp @@ -0,0 +1,11 @@ +#pragma once +#include +#include +#include + +namespace mof +{ + typedef boost::shared_ptr< Texture > TextureHandler; + typedef ResourceManager< Texture > TextureManager; + typedef boost::shared_ptr< TextureManager > TextureManagerHandler; +} diff --git a/moftmp/graphics/utilities.hpp~ b/moftmp/graphics/utilities.hpp~ new file mode 100755 index 0000000..643e639 --- /dev/null +++ b/moftmp/graphics/utilities.hpp~ @@ -0,0 +1,11 @@ +#pragma once +#include +#include +#include + +namespace mof +{ + typedef boost::shared_ptr< Texture > TextureHandler; + typedef ResourceManager< Texture > TextureManager; + typedef boost::shared_ptr< TextureManager > TextureManagerHandler; +} diff --git a/moftmp/mofGraphics.hpp b/moftmp/mofGraphics.hpp new file mode 100755 index 0000000..17e8141 --- /dev/null +++ b/moftmp/mofGraphics.hpp @@ -0,0 +1,15 @@ +#pragma once +//#include "mof/AmbientLight.hpp" +#include "mof/GraphicsDevice.hpp" +//#include "mof/Camera.hpp" +#include "mof/Captor.hpp" +#include "mof/Color.hpp" +#include "mof/GraphicsUnit.hpp" +//#include "mof/Light.hpp" +//#include "mof/Material.hpp" +//#include "mof/MaterialBuilder.hpp" +#include "mof/PixelMap.hpp" +#include "mof/Texture.hpp" +#include "mof/VertexBuffer.hpp" +#include "mof/VertexTypes.hpp" +#include "mof/graphics/utilities.hpp" diff --git a/moftmp/mofInput.hpp b/moftmp/mofInput.hpp new file mode 100755 index 0000000..3dfa25d --- /dev/null +++ b/moftmp/mofInput.hpp @@ -0,0 +1,7 @@ +#pragma +#include "mof/InputDevice.hpp" +#include "mof/InputEventCondition.hpp" +#include "mof/KeyPressedEventCondition.hpp" +#include "mof/private/DeviceInputReceiver.hpp" +#include "mof/LoggedInputReceiver.hpp" +#include "mof/LoggingInputReceiver.hpp" diff --git a/moftmp/moflib.vcproj b/moftmp/moflib.vcproj new file mode 100755 index 0000000..4eb8426 --- /dev/null +++ b/moftmp/moflib.vcproj @@ -0,0 +1,665 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/moftmp/moflib.vcproj.TOMOHIRO.TomohiroYasuda.user b/moftmp/moflib.vcproj.TOMOHIRO.TomohiroYasuda.user new file mode 100755 index 0000000..19f9a33 --- /dev/null +++ b/moftmp/moflib.vcproj.TOMOHIRO.TomohiroYasuda.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/moftmp/private/DeviceInputReceiver.hpp b/moftmp/private/DeviceInputReceiver.hpp new file mode 100755 index 0000000..d3fb6a5 --- /dev/null +++ b/moftmp/private/DeviceInputReceiver.hpp @@ -0,0 +1,27 @@ +#pragma once +#include "mof/InputReceiver.hpp" + + +namespace mof{ + struct InputEvent{ + InputEvent(unsigned int _dwOfs , unsigned int _dwData){ + dwOfs = _dwOfs; + dwData = _dwData; + } + unsigned int dwOfs; + unsigned int dwData; + }; + + class DeviceInputReceiver : public InputReceiver + { + bool* m_pKeyStates; + public: + + DeviceInputReceiver(); + virtual ~DeviceInputReceiver(); + virtual bool testKeyState(mof::InputReceiver::Key key); + virtual void update(); + void notifyInputEvent(InputEvent& iEvent); + }; + +}; \ No newline at end of file diff --git a/moftmp/private/DirectInput.hpp b/moftmp/private/DirectInput.hpp new file mode 100755 index 0000000..c240ed2 --- /dev/null +++ b/moftmp/private/DirectInput.hpp @@ -0,0 +1,8 @@ +#pragma + +#pragma comment(lib , "dinput8.lib") +#pragma comment(lib , "dxguid.lib") + +#define DIRECTINPUT_VERSION 0x0800 +#include +#include \ No newline at end of file diff --git a/moftmp/private/FileTextureBuilder.cpp b/moftmp/private/FileTextureBuilder.cpp new file mode 100755 index 0000000..db00c2d --- /dev/null +++ b/moftmp/private/FileTextureBuilder.cpp @@ -0,0 +1,32 @@ + +#include "mof/private/FileTextureBuilder.hpp" +#include +#include +#include "mof/private/GraphicsDeviceImpl.hpp" +#include "mof/ConsoleIO.hpp" + +mof::FileTextureBuilder::FileTextureBuilder( const mof::tstring& path) +{ + m_path = path; + +} + +mof::FileTextureBuilder::~FileTextureBuilder(void) +{ +} + + +LPDIRECT3DTEXTURE9 mof::FileTextureBuilder::create(){ + LPDIRECT3DTEXTURE9 texture; + LPDIRECT3DDEVICE9 pDevice = mof::GraphicsDevice::getRawDevice(); + HRESULT hr = D3DXCreateTextureFromFileEx(pDevice , m_path.c_str() , + 0 , 0 , 1 , 0/*RENDER*/ , D3DFMT_UNKNOWN , D3DPOOL_MANAGED , + D3DX_DEFAULT , D3DX_DEFAULT , mof::createColor(0 , 0 , 0) , NULL , NULL , &texture); + + if(FAILED(hr))throw std::runtime_error("Failed --- CreateTextureFromFileEx"); + + return texture; + + + +} \ No newline at end of file diff --git a/moftmp/private/FileTextureBuilder.hpp b/moftmp/private/FileTextureBuilder.hpp new file mode 100755 index 0000000..0326415 --- /dev/null +++ b/moftmp/private/FileTextureBuilder.hpp @@ -0,0 +1,21 @@ +#ifndef MOF_FILE_TEXTURE_BUILDER_HPP +#define MOF_FILE_TEXTURE_BUILDER_HPP + +#include "mof/private/TextureBuilder.hpp" +#include "mof/tstring.hpp" + +namespace mof{ + + class FileTextureBuilder : public TextureBuilder + { + mof::tstring m_path; + public: + FileTextureBuilder( const mof::tstring& path); + virtual ~FileTextureBuilder(void); + virtual LPDIRECT3DTEXTURE9 create(); + }; + + +}; + +#endif \ No newline at end of file diff --git a/moftmp/private/GraphicsDeviceImpl.hpp b/moftmp/private/GraphicsDeviceImpl.hpp new file mode 100755 index 0000000..a3d0e3c --- /dev/null +++ b/moftmp/private/GraphicsDeviceImpl.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include "mof/GraphicsDevice.hpp" + +#include +#pragma comment(lib, "d3dxof.lib") +#pragma comment(lib , "dxguid.lib") +#pragma comment(lib , "d3dx9dt.lib") +#pragma comment(lib , "d3d9.lib") +#pragma comment(lib , "dxerr9.lib") + +namespace mof +{ + class Window; + + namespace GraphicsDevice + { + // private + void initialize(const Window& window , int width , int height , bool fullscreen); + void finalize(); + void beginScene(); + void endScene(); + LPDIRECT3DDEVICE9 getRawDevice( ); + } +} diff --git a/moftmp/private/Interpreter.hpp b/moftmp/private/Interpreter.hpp new file mode 100755 index 0000000..728a283 --- /dev/null +++ b/moftmp/private/Interpreter.hpp @@ -0,0 +1,26 @@ +#pragma once +#include "../Interpreter.hpp" + +namespace mof +{ + namespace Interpreter + { + + int _createMessageWidget( ); + + int _addMessageWidgetPage + ( + int id , + const tstring& title , + const tstring& text + ); + + int _hideMessageWidget( int id ); + + void _waitKey( const tstring& keystring ); + + void _waitFrame( int frame ); + } +} + + diff --git a/moftmp/private/Interpreter.hpp~ b/moftmp/private/Interpreter.hpp~ new file mode 100755 index 0000000..93943b7 --- /dev/null +++ b/moftmp/private/Interpreter.hpp~ @@ -0,0 +1,26 @@ +#pragma once +#include "../Interpreter.hpp" + +namespace mof +{ + namespace Interpreter + { + + int _createMessageWidget(); + + int _addMessageWidgetPage + ( + int id , + const tstring& title , + const tstring& text + ); + + int _hideMessageWidget( int id ); + + void _waitKey( const tstring& keystring ); + + void _waitFrame( int frame ); + } +} + + diff --git a/moftmp/private/Mesh.hpp b/moftmp/private/Mesh.hpp new file mode 100755 index 0000000..edf30de --- /dev/null +++ b/moftmp/private/Mesh.hpp @@ -0,0 +1,40 @@ +#ifndef MOF_MESH_HPP +#define MOF_MESH_HPP +#include +#include "mof/Graphics3D.hpp" +#include +#include "mof/Material.hpp" +#include "mof/Texture.hpp" +#include "mof/DefaultAnimationPlayer.hpp" + +namespace mof{ + +struct MeshDisposer; + +class Mesh : public Graphics3D , public DefaultAnimationPlayer{ + struct Impl; + boost::scoped_ptr m_pImpl; + +public : + Mesh( + boost::shared_ptr pMeshDisposer , + unsigned long nMaterials , + const boost::shared_ptr* pMaterials , + const boost::shared_ptr* pTextures ); + virtual ~Mesh(); + + virtual void setWorldMatrix(const mof::Animation::Handler& handler); + virtual void setTexture( + unsigned int num , + const boost::shared_ptr& pTexture); + + virtual bool isVisible() const; + virtual void update(); + virtual void draw() const; + //virtual bool isDisposable() const; + +}; + +} + +#endif \ No newline at end of file diff --git a/moftmp/private/MeshDisposer.hpp b/moftmp/private/MeshDisposer.hpp new file mode 100755 index 0000000..73f20df --- /dev/null +++ b/moftmp/private/MeshDisposer.hpp @@ -0,0 +1,18 @@ +#pragma once +#include +#include + +namespace mof{ + +struct MeshDisposer{ + + LPD3DXMESH pMesh; //ƒƒbƒVƒ… + LPD3DXBUFFER pAdjacency; //ƒƒbƒVƒ…‚ÉŠÜ‚Ü‚ê‚éŠe–ʂ̗אږʂðŠi”[‚·‚éƒ|ƒCƒ“ƒ^ + + ~MeshDisposer(){ + if(pAdjacency != NULL)pAdjacency->Release(); + if(pMesh != NULL)pMesh->Release(); + } +}; + +} diff --git a/moftmp/private/PixelMapTextureBuilder.hpp b/moftmp/private/PixelMapTextureBuilder.hpp new file mode 100755 index 0000000..89c2435 --- /dev/null +++ b/moftmp/private/PixelMapTextureBuilder.hpp @@ -0,0 +1,23 @@ +#ifndef MOF_PIXEL_TEXTURE_BUILDER_HPP +#define MOF_PIXEL_TEXTURE_BUILDER_HPP + +#include "mof/private/TextureBuilder.hpp" +#include "mof/tstring.hpp" +#include +#include "mof/PixelMap.hpp" + +namespace mof{ + + class PixelMapTextureBuilder : public TextureBuilder + { + boost::shared_ptr m_pPixelMap; + public: + PixelMapTextureBuilder( const boost::shared_ptr& pPixelMap); + virtual ~PixelMapTextureBuilder(); + virtual LPDIRECT3DTEXTURE9 create(); + }; + + +}; + +#endif \ No newline at end of file diff --git a/moftmp/private/TextureBuilder.hpp b/moftmp/private/TextureBuilder.hpp new file mode 100755 index 0000000..2c13437 --- /dev/null +++ b/moftmp/private/TextureBuilder.hpp @@ -0,0 +1,17 @@ +#ifndef MOF_TEXTURE_BUILDER_HPP +#define MOF_TEXTURE_BUILDER_HPP +#include + +namespace mof{ + + class TextureBuilder + { + public: + virtual ~TextureBuilder(){} + virtual LPDIRECT3DTEXTURE9 create() = 0; + }; + + +} + +#endif \ No newline at end of file diff --git a/moftmp/private/TextureImpl.hpp b/moftmp/private/TextureImpl.hpp new file mode 100755 index 0000000..9e3d41e --- /dev/null +++ b/moftmp/private/TextureImpl.hpp @@ -0,0 +1,20 @@ +#ifndef MOF_TEXTURE_IMPL_HPP +#define MOF_TEXTURE_IMPL_HPP +#include "Texture.hpp" + + +#include "mof/GraphicsDevice.hpp" +#include + + +struct mof::Texture::Impl{ + LPDIRECT3DTEXTURE9 pTexture; + int width , height; + + Impl() : pTexture(NULL) , width(0) , height(0){} + ~Impl(){ + if(pTexture != NULL)pTexture->Release(); + } +}; + +#endif \ No newline at end of file diff --git a/moftmp/private/VertexFVF.hpp b/moftmp/private/VertexFVF.hpp new file mode 100755 index 0000000..b33329c --- /dev/null +++ b/moftmp/private/VertexFVF.hpp @@ -0,0 +1,37 @@ +#pragma once +#include "VertexTypes.hpp" +#include + + +namespace mof{ + +template +DWORD getFVF(); + +template<> +inline DWORD getFVF(){ + return D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1; +} + +template<> +inline DWORD getFVF(){ + return D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX0; +} + +template<> +inline DWORD getFVF(){ + return D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; +} + +template<> +inline DWORD getFVF(){ + return D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1; +} + +template<> +inline DWORD getFVF(){ + return D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX0; +} + + +}; \ No newline at end of file diff --git a/moftmp/private/commands.hpp~ b/moftmp/private/commands.hpp~ new file mode 100755 index 0000000..01bad12 --- /dev/null +++ b/moftmp/private/commands.hpp~ @@ -0,0 +1,14 @@ +#pragma once +#include "mof/tstring.hpp" +#include "luabind/luabind.hpp" +#include + +struct lua_State; + +namespace mof +{ + namespace command + { + void registMessage( lua_State* l ); + } +} diff --git a/moftmp/private/message.cpp~ b/moftmp/private/message.cpp~ new file mode 100755 index 0000000..b3dda90 --- /dev/null +++ b/moftmp/private/message.cpp~ @@ -0,0 +1,40 @@ +#include "mof/Interpreter.hpp" +#include "mof/private/Interpreter.hpp" +#include "mof/private/commands.hpp" +#include "luabind/luabind.hpp" + +namespace mof +{ +//{{{ _messageNewImplGlue old +/* int _messageNewImplGlue( lua_State* l ){ + int n = lua_gettop(l); + if(!lua_isstring(l , 1))throw std::runtime_error("invalid call"); + if(!lua_istable(l , 2))throw std::runtime_error("invalid call"); + mof::tstring title = lua_tostring(l , 1); + + std::vector texts; + for(int i = 1 ; ; i++){ + lua_pushnumber(l , i); + lua_gettable(l , -2); + if(lua_isnil(l , -1))break; + if(!lua_isstring(l , -1))throw std::runtime_error("invalid call"); + texts.push_back(lua_tostring(l , -1)); + lua_pop(l , 1); + } + lua_pop(l , n); + + m_pMenu = m_pInstructionSet->createMessageWidget(title , texts.at(0)) ; + //m_pMenu.push_back( m_pInstructionSet->createMessageWidget(title , texts.at(0)) ); + return 0; + } */ +//}}} +//{{{ registMessage + void command::registMessage( lua_State* l ) + { + luabind::module( l )[ luabind::def( "messageNewImpl" , mof::Interpreter::_createMessageWidget ) ]; + luabind::module( l )[ luabind::def( "messagePageImpl" , mof::Inerpreter::_addMessageWidgetPage ) ]; + luabind::module( l )[ luabind::def( "messageHideImpl" , mof::Interpreter::_hideMessageWidget ) ]; + + } +//}}} +} diff --git a/moftmp/private/regist.cpp b/moftmp/private/regist.cpp new file mode 100755 index 0000000..a113f21 --- /dev/null +++ b/moftmp/private/regist.cpp @@ -0,0 +1,48 @@ +#include "mof/Interpreter.hpp" +#include "mof/private/Interpreter.hpp" +#include "mof/private/regist.hpp" +#include "luabind/luabind.hpp" + +namespace mof +{ +//{{{ _messageNewImplGlue old +/* int _messageNewImplGlue( lua_State* l ){ + int n = lua_gettop(l); + if(!lua_isstring(l , 1))throw std::runtime_error("invalid call"); + if(!lua_istable(l , 2))throw std::runtime_error("invalid call"); + mof::tstring title = lua_tostring(l , 1); + + std::vector texts; + for(int i = 1 ; ; i++){ + lua_pushnumber(l , i); + lua_gettable(l , -2); + if(lua_isnil(l , -1))break; + if(!lua_isstring(l , -1))throw std::runtime_error("invalid call"); + texts.push_back(lua_tostring(l , -1)); + lua_pop(l , 1); + } + lua_pop(l , n); + + m_pMenu = m_pInstructionSet->createMessageWidget(title , texts.at(0)) ; + //m_pMenu.push_back( m_pInstructionSet->createMessageWidget(title , texts.at(0)) ); + return 0; + } */ +//}}} +//{{{ registMessage + void regist::registMessage( lua_State* l ) + { + luabind::module( l )[ luabind::def( "messageNewImpl" , mof::Interpreter::_createMessageWidget ) ]; + luabind::module( l )[ luabind::def( "messagePageImpl" , mof::Interpreter::_addMessageWidgetPage ) ]; + luabind::module( l )[ luabind::def( "messageHideImpl" , mof::Interpreter::_hideMessageWidget ) ]; + + } +//}}} +//{{{ registWait + void regist::registWait( lua_State* l ) + { + luabind::module( l )[ luabind::def( "waitFrameImpl" , mof::Interpreter::_waitFrame ) ]; + luabind::module( l )[ luabind::def( "waitKeyImpl" , mof::Interpreter::_waitKey ) ]; + + } +//}}} +} diff --git a/moftmp/private/regist.cpp~ b/moftmp/private/regist.cpp~ new file mode 100755 index 0000000..a113f21 --- /dev/null +++ b/moftmp/private/regist.cpp~ @@ -0,0 +1,48 @@ +#include "mof/Interpreter.hpp" +#include "mof/private/Interpreter.hpp" +#include "mof/private/regist.hpp" +#include "luabind/luabind.hpp" + +namespace mof +{ +//{{{ _messageNewImplGlue old +/* int _messageNewImplGlue( lua_State* l ){ + int n = lua_gettop(l); + if(!lua_isstring(l , 1))throw std::runtime_error("invalid call"); + if(!lua_istable(l , 2))throw std::runtime_error("invalid call"); + mof::tstring title = lua_tostring(l , 1); + + std::vector texts; + for(int i = 1 ; ; i++){ + lua_pushnumber(l , i); + lua_gettable(l , -2); + if(lua_isnil(l , -1))break; + if(!lua_isstring(l , -1))throw std::runtime_error("invalid call"); + texts.push_back(lua_tostring(l , -1)); + lua_pop(l , 1); + } + lua_pop(l , n); + + m_pMenu = m_pInstructionSet->createMessageWidget(title , texts.at(0)) ; + //m_pMenu.push_back( m_pInstructionSet->createMessageWidget(title , texts.at(0)) ); + return 0; + } */ +//}}} +//{{{ registMessage + void regist::registMessage( lua_State* l ) + { + luabind::module( l )[ luabind::def( "messageNewImpl" , mof::Interpreter::_createMessageWidget ) ]; + luabind::module( l )[ luabind::def( "messagePageImpl" , mof::Interpreter::_addMessageWidgetPage ) ]; + luabind::module( l )[ luabind::def( "messageHideImpl" , mof::Interpreter::_hideMessageWidget ) ]; + + } +//}}} +//{{{ registWait + void regist::registWait( lua_State* l ) + { + luabind::module( l )[ luabind::def( "waitFrameImpl" , mof::Interpreter::_waitFrame ) ]; + luabind::module( l )[ luabind::def( "waitKeyImpl" , mof::Interpreter::_waitKey ) ]; + + } +//}}} +} diff --git a/moftmp/private/regist.hpp b/moftmp/private/regist.hpp new file mode 100755 index 0000000..d1dfc9d --- /dev/null +++ b/moftmp/private/regist.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "mof/tstring.hpp" + +struct lua_State; + +namespace mof +{ + namespace regist + { + void registMessage( lua_State* l ); + void registWait( lua_State* l ); + } +} diff --git a/moftmp/private/regist.hpp~ b/moftmp/private/regist.hpp~ new file mode 100755 index 0000000..115b285 --- /dev/null +++ b/moftmp/private/regist.hpp~ @@ -0,0 +1,12 @@ +#pragma once +#include "mof/tstring.hpp" + +struct lua_State; + +namespace mof +{ + namespace command + { + void registMessage( lua_State* l ); + } +} diff --git a/moftmp/real.hpp b/moftmp/real.hpp new file mode 100755 index 0000000..d42256b --- /dev/null +++ b/moftmp/real.hpp @@ -0,0 +1,16 @@ +#pragma once + +namespace mof +{ + typedef float real; + + inline real int2real(int v) + { + return static_cast(v); + } + + inline int real2int(real v) + { + return static_cast(v); + } +} diff --git a/moftmp/stream/Animation.hpp~ b/moftmp/stream/Animation.hpp~ new file mode 100755 index 0000000..2dc9666 --- /dev/null +++ b/moftmp/stream/Animation.hpp~ @@ -0,0 +1,24 @@ + #pragma once + #include + #include + + namespace mof{ + + typedef unsigned int FrameNumber; + + /** + * ƒAƒjƒ[ƒVƒ‡ƒ“ƒNƒ‰ƒX‚Í•¡”ƒCƒ“ƒXƒ^ƒ“ƒXŠÔ‚Å‹¤—L‚Å‚«‚é‚悤‚É‚·‚邽‚߂ɁA + * update()‚ðŒÄ‚яo‚µ‚Ä“à—e‚ð‘‚«Š·‚¦‚é‹@\‚É‚Í‚·‚ׂ«‚Å‚Í‚È‚¢ + * + */ + template + class Animation : boost::noncopyable{ + public: + typedef boost::shared_ptr > Handler; + + virtual T getValue(mof::FrameNumber) const = 0; + + }; + + + } // namespace mof diff --git a/moftmp/stream/AnimationPlayer.hpp b/moftmp/stream/AnimationPlayer.hpp new file mode 100755 index 0000000..6da6e9c --- /dev/null +++ b/moftmp/stream/AnimationPlayer.hpp @@ -0,0 +1,20 @@ +#ifndef MOF_ANIMATION_PLAYER_HPP +#define MOF_ANIMATION_PLAYER_HPP +#include "mof/Animation.hpp" + +namespace mof{ + + +class AnimationPlayer{ + +public: + virtual void setFrameNumber(mof::FrameNumber frame) = 0; + virtual void nextFrame() = 0; + virtual void prevFrame() = 0; + //virtual void reset(){setFrameNumber(0);} +}; + +} + + +#endif diff --git a/moftmp/stream/AnimationPlayer.hpp~ b/moftmp/stream/AnimationPlayer.hpp~ new file mode 100755 index 0000000..6da6e9c --- /dev/null +++ b/moftmp/stream/AnimationPlayer.hpp~ @@ -0,0 +1,20 @@ +#ifndef MOF_ANIMATION_PLAYER_HPP +#define MOF_ANIMATION_PLAYER_HPP +#include "mof/Animation.hpp" + +namespace mof{ + + +class AnimationPlayer{ + +public: + virtual void setFrameNumber(mof::FrameNumber frame) = 0; + virtual void nextFrame() = 0; + virtual void prevFrame() = 0; + //virtual void reset(){setFrameNumber(0);} +}; + +} + + +#endif diff --git a/moftmp/stream/AnimationScheduler.cpp b/moftmp/stream/AnimationScheduler.cpp new file mode 100755 index 0000000..65e7787 --- /dev/null +++ b/moftmp/stream/AnimationScheduler.cpp @@ -0,0 +1,41 @@ +#include "mof/AnimationScheduler.h" +#include "mof/ConsoleIO.h" + +typedef std::multimap::iterator MapItr; + +mof::AnimationScheduler::AnimationScheduler(){ + m_key = 0; + +} + +mof::AnimationScheduler::~AnimationScheduler(){ + +} + +void mof::AnimationScheduler::update(){ + + std::pair range(m_map.begin() , m_map.upper_bound(m_key)); + for(MapItr itr = range.first ; itr != range.second ; ++itr){ + if(itr->second.get() != NULL && !itr->second->isPlaying())itr->second->start(); + } + + m_key++; +} + +void mof::AnimationScheduler::add(int index , mof::AnimationResource pAnimation){ + if(pAnimation.get() != NULL)pAnimation->stop(); + m_map.insert(std::multimap::value_type(index , pAnimation)); + +} + +bool mof::AnimationScheduler::isFinalized(){ + for(MapItr itr = m_map.begin() ; itr != m_map.end() ; ++itr){ + if(!itr->second->isFinalized())return false; + } + return true; +} + +void mof::AnimationScheduler::clear(){ + m_key = 0; + m_map.clear(); +} \ No newline at end of file diff --git a/moftmp/stream/BoundsAnimation.hpp b/moftmp/stream/BoundsAnimation.hpp new file mode 100755 index 0000000..cdca1ea --- /dev/null +++ b/moftmp/stream/BoundsAnimation.hpp @@ -0,0 +1,38 @@ +#pragma once +#include "mof/KeyFrameAnimation.hpp" +#include "mof/Rectangle.hpp" +#include "mof/Vector2D.hpp" + +namespace mof +{ + class BoundsAnimation : public mof::Animation< mof::Rectangle > + { + public: + + BoundsAnimation + ( + const mof::Animation::Handler& position , + const mof::Animation::Handler& scale + ) + : m_position( position) , m_scale( scale ) + { + } + + mof::Rectangle getValue( mof::FrameNumber frame ) const + { + mof::Vector2D position = m_position->getValue( frame ); + mof::Vector2D scale = m_scale->getValue( frame ); + return mof::Rectangle + ( + position.x , position.y , + position.x + scale.x , + position.y + scale.y + ); + } + + private: + + mof::Animation::Handler m_position; + mof::Animation::Handler m_scale; + }; +} diff --git a/moftmp/stream/BoundsAnimation.hpp~ b/moftmp/stream/BoundsAnimation.hpp~ new file mode 100755 index 0000000..cdca1ea --- /dev/null +++ b/moftmp/stream/BoundsAnimation.hpp~ @@ -0,0 +1,38 @@ +#pragma once +#include "mof/KeyFrameAnimation.hpp" +#include "mof/Rectangle.hpp" +#include "mof/Vector2D.hpp" + +namespace mof +{ + class BoundsAnimation : public mof::Animation< mof::Rectangle > + { + public: + + BoundsAnimation + ( + const mof::Animation::Handler& position , + const mof::Animation::Handler& scale + ) + : m_position( position) , m_scale( scale ) + { + } + + mof::Rectangle getValue( mof::FrameNumber frame ) const + { + mof::Vector2D position = m_position->getValue( frame ); + mof::Vector2D scale = m_scale->getValue( frame ); + return mof::Rectangle + ( + position.x , position.y , + position.x + scale.x , + position.y + scale.y + ); + } + + private: + + mof::Animation::Handler m_position; + mof::Animation::Handler m_scale; + }; +} diff --git a/moftmp/stream/Cache.cpp b/moftmp/stream/Cache.cpp new file mode 100755 index 0000000..764f1e1 --- /dev/null +++ b/moftmp/stream/Cache.cpp @@ -0,0 +1,19 @@ +#include + +namespace +{ + bool caching = true; +} + +namespace mof +{ + void setCaching(bool b) + { + caching = b; + } + + bool getCaching() + { + return caching; + } +} diff --git a/moftmp/stream/Cache.cpp~ b/moftmp/stream/Cache.cpp~ new file mode 100755 index 0000000..5be4e3d --- /dev/null +++ b/moftmp/stream/Cache.cpp~ @@ -0,0 +1,14 @@ +#include + +namespace +{ + bool g_caching = true; +} + +namespace mof +{ + void setCaching(bool b) + { + g_caching = b; + } +} diff --git a/moftmp/stream/Cache.hpp b/moftmp/stream/Cache.hpp new file mode 100755 index 0000000..b848aa8 --- /dev/null +++ b/moftmp/stream/Cache.hpp @@ -0,0 +1,69 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" + +namespace mof{ + + void setCaching(bool b); + bool getCaching(); + + + template< typename T > + class Cache : public Manipulator< T > + { + + public: + typedef typename boost::shared_ptr Handler; + + virtual ~Cache( ){} + + virtual T value( FrameNumber frame ) const + { + if(getCaching()) + { + if(m_lastFrame == (int)frame)return m_cached; + m_lastFrame = (int)frame; + m_cached = m_pBody->value(frame); + return m_cached; + } + else + { + return m_pBody->value(frame); + } + } + + + private: + typename Manipulator::Handler m_pBody; + mutable int m_lastFrame; + mutable T m_cached; + + + Cache(const typename Manipulator::Handler& pBody) + : m_pBody(pBody) , m_lastFrame(-1) + { + } + + template friend + typename boost::shared_ptr< Cache > makeCacheHandler + ( + const typename Manipulator::Handler& pBody + ); + + }; + + + + template< typename T > + boost::shared_ptr< Cache< T > > makeCacheHandler + ( + const typename Manipulator< T >::Handler& pBody + ) + { + return typename Cache< T >::Handler( + new Cache< T >( pBody ) + ); + } + + +} //namespace mof + diff --git a/moftmp/stream/Cache.hpp~ b/moftmp/stream/Cache.hpp~ new file mode 100755 index 0000000..53ad444 --- /dev/null +++ b/moftmp/stream/Cache.hpp~ @@ -0,0 +1,69 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" + +namespace mof{ + + void setCaching(bool b); + bool getCaching(); + + + template< typename T > + class Cache : public Manipulator< T > + { + + public: + typedef typename boost::shared_ptr Handler; + + virtual ~Cache( ){} + + virtual T value( FrameNumber frame ) const + { + if(getCaching()) + { + //if(m_lastFrame == (int)frame)return m_cached; + m_lastFrame = (int)frame; + m_cached = m_pBody->value(0); + return m_cached; + } + else + { + return m_pBody->value(0); + } + } + + + private: + typename Manipulator::Handler m_pBody; + mutable int m_lastFrame; + mutable T m_cached; + + + Cache(const typename Manipulator::Handler& pBody) + : m_pBody(pBody) , m_lastFrame(-1) + { + } + + template friend + typename boost::shared_ptr< Cache > makeCacheHandler + ( + const typename Manipulator::Handler& pBody + ); + + }; + + + + template< typename T > + boost::shared_ptr< Cache< T > > makeCacheHandler + ( + const typename Manipulator< T >::Handler& pBody + ) + { + return typename Cache< T >::Handler( + new Cache< T >( pBody ) + ); + } + + +} //namespace mof + diff --git a/moftmp/stream/Cascade.hpp b/moftmp/stream/Cascade.hpp new file mode 100755 index 0000000..300c723 --- /dev/null +++ b/moftmp/stream/Cascade.hpp @@ -0,0 +1,173 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" +#include + +namespace mof +{ + #define DEFAULT_CASCADOR Multiply +//{{{ struct Add + template + struct Add + { + inline static T apply(const T& a , const T& b) + { + return a + b; + } + }; +//}}} +//{{{ struct Multiply + template + struct Multiply + { + inline static T apply(const T& a , const T& b) + { + return a * b; + } + }; +//}}} +//{{{ struct Overwrite + template + struct Overwrite + { + inline static T apply(const T& , const T& b) + { + return b; + } + }; +//}}} +//{{{ class Cascade + template< typename T , class Cascador = DEFAULT_CASCADOR< T > > + class Cascade : public Manipulator< T >{ + public: + typedef typename boost::shared_ptr< Cascade > Handler; + + virtual ~Cascade() + { + } + + virtual T value( FrameNumber frame) const + { + T obj = m_list[0]->value(frame); + for(unsigned int i = 1 ; i < m_list.size() ; i++) + { + obj = Cascador::apply(obj , m_list[i]->value(frame)); + } + return obj; + } + + void clear() + { + m_list.clear(); + } + + void add( const typename Manipulator::Handler& handler ) + { + m_list.push_back( handler ); + } + + private: + typedef std::vector< typename Manipulator< T >::Handler > List; + List m_list; + + Cascade + ( + const typename Manipulator< T >::Handler& front , + const typename Manipulator< T >::Handler& back + ) + { + int length = &back - &front + 1; + if(length <= 0)throw std::invalid_argument("list size is 0"); + + for( int i = 0 ; i < length ; i++) + { + m_list.push_back( (&front)[i] ); + } + } + + + Cascade(){} + + template< typename T , class Cascador > + friend typename boost::shared_ptr< Cascade< T , Cascador > > + makeCascadeHandler + ( + const typename Manipulator< T >::Handler& front , + const typename Manipulator< T >::Handler& back + ); + + template< typename T , class Cascador > + friend typename boost::shared_ptr< Cascade< T , Cascador > > makeCascadeHandler(); + + + }; +//}}} +//{{{ ヘルパ関数 + template< typename T , class Cascador > + boost::shared_ptr< Cascade< T , Cascador > > + makeCascadeHandler + ( + const typename Manipulator< T >::Handler& front , + const typename Manipulator< T >::Handler& back + ) + { + return typename Cascade< T , Cascador >::Handler + ( + new Cascade< T , Cascador >( front , back ) + ); + } + + template< typename T , class Cascador > + typename boost::shared_ptr< Cascade< T , Cascador > > + makeCascadeHandler( ) + { + return typename Cascade< T , Cascador >::Handler + ( + new Cascade< T , Cascador > + ); + } + + template + typename boost::shared_ptr< Cascade< T , DEFAULT_CASCADOR< T > > > + makeCascadeHandler + ( + const typename Manipulator< T >::Handler& front , + const typename Manipulator< T >::Handler& back + ) + { + return makeCascadeHandler< T , DEFAULT_CASCADOR< T > >( front , back ); + } + + template + typename boost::shared_ptr< Cascade< T , DEFAULT_CASCADOR< T > > > + makeCascadeHandler( ) + { + return makeCascadeHandler< T , DEFAULT_CASCADOR< T > >(); + } +//}}} +//{{{ ストリーム演算子 + template< typename T , class Cascador > + boost::shared_ptr< Cascade< T , Cascador > >& + operator << + ( + boost::shared_ptr< Cascade< T , Cascador > >& a , + const typename Manipulator< T >::Handler& b + ) + { + a->add( b ); + return a; + } + + template< typename T , class Cascador > + typename boost::shared_ptr< Cascade< T , Cascador > >& + operator << + ( + boost::shared_ptr< Cascade< T , Cascador > >& a , + const T& b + ) + { + a->add( mof::makeConstantHandler( b ) ); + return a; + } +//}}} +} //namespace mof + diff --git a/moftmp/stream/Cascade.hpp~ b/moftmp/stream/Cascade.hpp~ new file mode 100755 index 0000000..f7cfaf3 --- /dev/null +++ b/moftmp/stream/Cascade.hpp~ @@ -0,0 +1,179 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" +#include + +namespace mof +{ + #define DEFAULT_CASCADOR Multiply +//{{{ struct Add + template + struct Add + { + inline static T apply(const T& a , const T& b) + { + return a + b; + } + }; +//}}} +//{{{ struct Multiply + template + struct Multiply + { + inline static T apply(const T& a , const T& b) + { + return a * b; + } + }; +//}}} +//{{{ struct Overwrite + template + struct Overwrite + { + inline static T apply(const T& , const T& b) + { + return b; + } + }; +//}}} +//{{{ class Cascade + template< typename T , class Cascador = DEFAULT_CASCADOR< T > > + class Cascade : public Manipulator< T >{ + public: + typedef typename boost::shared_ptr< Cascade > Handler; + + virtual ~Cascade() + { + } + + virtual T value( FrameNumber frame) const + { + T obj = m_list[0]->value(frame); + for(unsigned int i = 1 ; i < m_list.size() ; i++) + { + obj = Cascador::apply(obj , m_list[i]->value(frame)); + } + return obj; + } + + void clear() + { + m_list.clear(); + } + + void add( const typename Manipulator::Handler& handler ) + { + m_list.push_back( handler ); + } + + const typename Manipulator::Handler get( int i ) + { + return m_cascadeList.at(i); + } + + + private: + typedef std::vector< typename Manipulator< T >::Handler > List; + List m_list; + + Cascade + ( + const typename Manipulator< T >::Handler& front , + const typename Manipulator< T >::Handler& back + ) + { + int length = &back - &front + 1; + if(length <= 0)throw std::invalid_argument("list size is 0"); + + for( int i = 0 ; i < length ; i++) + { + m_list.push_back( (&front)[i] ); + } + } + + + Cascade(){} + + template< typename T , class Cascador > + friend typename boost::shared_ptr< Cascade< T , Cascador > > + makeCascadeHandler + ( + const typename Manipulator< T >::Handler& front , + const typename Manipulator< T >::Handler& back + ); + + template< typename T , class Cascador > + friend typename boost::shared_ptr< Cascade< T , Cascador > > makeCascadeHandler(); + + + }; +//}}} +//{{{ ヘルパ関数 + template< typename T , class Cascador > + boost::shared_ptr< Cascade< T , Cascador > > + makeCascadeHandler + ( + const typename Manipulator< T >::Handler& front , + const typename Manipulator< T >::Handler& back + ) + { + return typename Cascade< T , Cascador >::Handler + ( + new Cascade< T , Cascador >( front , back ) + ); + } + + template< typename T , class Cascador > + typename boost::shared_ptr< Cascade< T , Cascador > > + makeCascadeHandler( ) + { + return typename Cascade< T , Cascador >::Handler + ( + new Cascade< T , Cascador > + ); + } + + template + typename boost::shared_ptr< Cascade< T , DEFAULT_CASCADOR< T > > > + makeCascadeHandler + ( + const typename Manipulator< T >::Handler& front , + const typename Manipulator< T >::Handler& back + ) + { + return makeCascadeHandler< T , DEFAULT_CASCADOR< T > >( front , back ); + } + + template + typename boost::shared_ptr< Cascade< T , DEFAULT_CASCADOR< T > > > + makeCascadeHandler( ) + { + return makeCascadeHandler< T , DEFAULT_CASCADOR< T > >(); + } +//}}} +//{{{ ストリーム演算子 + template< typename T , class Cascador > + boost::shared_ptr< Cascade< T , Cascador > >& + operator << + ( + boost::shared_ptr< Cascade< T , Cascador > >& a , + const typename Manipulator< T >::Handler& b + ) + { + a->add( b ); + return a; + } + + template< typename T , class Cascador > + typename boost::shared_ptr< Cascade< T , Cascador > >& + operator << + ( + boost::shared_ptr< Cascade< T , Cascador > >& a , + const T& b + ) + { + a->add( mof::makeConstantHandler( b ) ); + return a; + } +//}}} +} //namespace mof + diff --git a/moftmp/stream/CascadeAnimation.cpp b/moftmp/stream/CascadeAnimation.cpp new file mode 100755 index 0000000..b2ab0a4 --- /dev/null +++ b/moftmp/stream/CascadeAnimation.cpp @@ -0,0 +1,161 @@ + +#include "mof/CascadeAnimation.h" + + + +mof::CascadeAnimation::CascadeAnimation() +: mof::Animation(false) +{ + m_key = 0; + m_maxKey = m_finalKey = 0; +} + +mof::CascadeAnimation::~CascadeAnimation(){ + +} + +void mof::CascadeAnimation::setElement(int index , mof::AnimationResource& pAnimation){ + if(m_pAnimations.size() <= index)m_pAnimations.resize(index+1); + m_pAnimations.at(index) = pAnimation; + +} + +mof::AnimationResource mof::CascadeAnimation::getElement(int index){ + if(m_pAnimations.size() <= index)return mof::AnimationResource(); + else return m_pAnimations.at(index); +} + + + +bool mof::CascadeAnimation::update(){ + if(!isPlaying())return false; + m_key++; + for(int i = 0 ; i < m_pAnimations.size() ; i++){ + if(m_pAnimations.at(i).get() != NULL)m_pAnimations.at(i)->update(); + } + return true; +} + +bool mof::CascadeAnimation::isFinalized(){ + + for(int i = 0 ; i < m_pAnimations.size() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + if(!m_pAnimations.at(i)->isFinalized())return false; + } + return true; +} + +void mof::CascadeAnimation::setFinalKey(mof::AnimationKey key){ + if(key > m_maxKey)m_finalKey = m_maxKey; + else m_finalKey = key; +} + +/* +mof::Vector2D mof::CascadeAnimation::getPosition(mof::Vector2D& position){ + for(int i = 0 ; i < m_pAnimations.size() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + position = m_pAnimations.at(i)->getPosition(position); + } + return position; + +}*/ + +mof::Vector2D mof::CascadeAnimation::getPosition(){ + mof::Vector2D position; + for(int i = 0 ; i < m_pAnimations.size() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + position = position + m_pAnimations.at(i)->getPosition(); + } + return position; + +} + +float mof::CascadeAnimation::getWidth(){ + float result = 1.0f; + for(int i = 0 ; i < m_pAnimations.size() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + result *= m_pAnimations.at(i)->getWidth(); + } + return result; +} + +float mof::CascadeAnimation::getHeight(){ + float result = 1.0f; + for(int i = 0 ; i < m_pAnimations.size() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + result *= m_pAnimations.at(i)->getHeight(); + } + return result; +} + + +float mof::CascadeAnimation::getDepth(){ + float result = 1.0f; + for(int i = 0 ; i < m_pAnimations.size() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + result *= m_pAnimations.at(i)->getDepth(); + } + return result; +} + + + +mof::Color mof::CascadeAnimation::getColor(){ + float a = 1.0f , r = 1.0f, g = 1.0f, b = 1.0f; + for(int i = 0 ; i < m_pAnimations.size() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + mof::Color tmp = m_pAnimations.at(i)->getColor(); + a = a * ((float)mof::getAlpha(tmp) / 255); + r = r * ((float)mof::getRed(tmp) / 255); + g = g * ((float)mof::getGreen(tmp) / 255); + b = b * ((float)mof::getBlue(tmp) / 255); + } + return mof::createColor(a * 255 , r * 255 , g * 255 , b * 255); +} + + +mof::Matrix3D mof::CascadeAnimation::getWorldTransform(mof::Matrix3D& matrix){ + for(int i = 0 ; i < m_pAnimations.size() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + matrix = m_pAnimations.at(i)->getWorldTransform(matrix); + } + return matrix; +} + + +mof::Line2D mof::CascadeAnimation::getTextureRectangle(){ + mof::Line2D result; + for(int i = 0 ; i < m_pAnimations.size() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + mof::Line2D tmp = m_pAnimations.at(i)->getTextureRectangle(); + if(tmp != mof::Line2D())result = tmp; + } + return result; +} + + +void mof::CascadeAnimation::start(){ + for(int i = 0 ; i < getLength() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + if(!m_pAnimations.at(i)->isPlaying())m_pAnimations.at(i)->start(); + } +} + +void mof::CascadeAnimation::stop(){ + for(int i = 0 ; i < getLength() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + if(m_pAnimations.at(i)->isPlaying())m_pAnimations.at(i)->stop(); + } +} + +bool mof::CascadeAnimation::isPlaying(){ + if(getLength() == 0)return true; + bool hasAnimation = false; + + for(int i = 0 ; i < getLength() ; i++){ + if(m_pAnimations.at(i).get() == NULL)continue; + if(m_pAnimations.at(i)->isPlaying())return true; + else hasAnimation = true; + } + return !hasAnimation;//‘S—v‘f‚ªNULL‚È‚çtrue +} \ No newline at end of file diff --git a/moftmp/stream/CascadingAnimation.hpp~ b/moftmp/stream/CascadingAnimation.hpp~ new file mode 100755 index 0000000..013d6db --- /dev/null +++ b/moftmp/stream/CascadingAnimation.hpp~ @@ -0,0 +1,143 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" +#include +#include + +namespace mof +{ +namespace stream +{ + + template + struct Add + { + inline static T apply(const T& a , const T& b){ + return a + b; + } + }; + + template + struct Multiply + { + inline static T apply(const T& a , const T& b){ + return a * b; + } + }; + + template > + class Cascade : public Manipulator{ + typedef std::vector< typename Manipulator< T >::Handler > List; + List m_list; + public: + + virtual ~Cascade() + { + } + + virtual T value( mof::FrameNumber frame) const + { + T obj = m_list[0]->getValue(frame); + for(unsigned int i = 1 ; i < m_cascadeList.size() ; i++){ + obj = Cascador::apply(obj , m_list[i]->value(frame)); + } + return obj; + } + + void clear() + { + m_list.clear(); + } + + void add( const typename Manipulator::Handler& handler ) + { + + m_list.push_back( handler ); + } + + + + void set(int i , const typename Manipulator::Handler& handler ) + { + + m_list.at(i) = handler; + } + + + const typename Manipulator::Handler get(int i ){ + return m_cascadeList.at(i); + } + + private: + Cascade + ( + const typename Manipulator< T >::Handler& front , + const typename Manipulator< T >::Handler& back + ) + { + int length = &back - &front + 1; + if(length <= 0)throw std::invalid_argument("list size is 0"); + + for( int i = 0 ; i < length ; i++){ + m_list.push_back( (&front)[i] ); + } + } + + Cascade( ){} + + friend template< class T , class Cascador > + mof::stream::Cascade< T , Cascador >::Handler + operator << + ( + mof::stream::Cascade< T , Cascador >::Handler a , + const mof::stream::Manipulator< T >::Handler& b + ); + + }; + + template > + Cascade< T , Cascador > makeCascadeHandler + ( + const typename Manipulator< T >::Handler& front , + const typename Manipulator< T >::Handler& back + ) + { + return typename Cascade< T , Cascador >::Handler + ( + new Cascade< T , Cascador >( front , back ); + ); + } + + template > + Cascade< T , Cascador > makeCascadeHandler( ) + { + return typename Cascade< T , Cascador >::Handler + ( + new Cascade< T , Cascador >( ); + ); + } + + +} //namespace stream +} //namespace mof + +template< class T , class Cascador > +mof::stream::Cascade< T , Cascador >::Handler +operator << +( + mof::stream::Cascade< T , Cascador >::Handler a , + const mof::stream::Manipulator< T >::Handler& b +) +{ + return a->add( b ); +} + +template< class T , class Cascador > +mof::stream::Cascade< T , Cascador >::Handler +operator << +( + mof::stream::Cascade< T , Cascador >::Handler a , + const T& b +) +{ + return a->add( mof::stream::makeConstantHandler( b ) ); +} diff --git a/moftmp/stream/Constant.hpp b/moftmp/stream/Constant.hpp new file mode 100755 index 0000000..e390b5f --- /dev/null +++ b/moftmp/stream/Constant.hpp @@ -0,0 +1,45 @@ +#pragma once +#include + +namespace mof +{ + template< typename T > class Constant; + + template< typename T > + boost::shared_ptr< Constant > makeConstantHandler(const T&); + + + template< typename T > + class Constant : public Manipulator< T >{ + public: + typedef typename boost::shared_ptr< Constant< T > > Handler; + + virtual ~Constant( ){} + + virtual T value( FrameNumber ) const + { + return m_value; + } + + private: + T m_value; + + Constant(const T& value) : m_value(value) + { + } + + template< typename T > + friend boost::shared_ptr< Constant > makeConstantHandler(const T&); + }; + +//{{{ ヘルパ関数 + template + boost::shared_ptr< Constant > makeConstantHandler( const T& value) + { + return typename Constant::Handler(new Constant(value)); + } +//}}} + +} // namespace mof + + diff --git a/moftmp/stream/Constant.hpp~ b/moftmp/stream/Constant.hpp~ new file mode 100755 index 0000000..ceda069 --- /dev/null +++ b/moftmp/stream/Constant.hpp~ @@ -0,0 +1,45 @@ +#pragma once +#include + +namespace mof +{ + template< typename T > class Constant; + + template< typename T > + boost::shared_ptr< Constant > makeConstantHandler(const T&); + + + template< typename T > + class Constant : public Manipulator< T >{ + public: + typedef typename boost::shared_ptr< Constant< T > > Handler; + + virtual ~Constant( ){} + + virtual T value( FrameNumber ) const + { + return m_value; + } + + private: + T m_value; + + Constant(const T& value) : m_value(value) + { + } + + template< typename T > + friend boost::shared_ptr< Constant > makeConstantHandler(const T&); + }; + +//{{{ ヘルパ関数 + template + boost::shared_ptr< Constant > makeConstantHandler( const T& value) + { + return typename Constant::Handler( new Constant( value ) ); + } +//}}} + +} // namespace mof + + diff --git a/moftmp/stream/DataBasedAnimation.cpp b/moftmp/stream/DataBasedAnimation.cpp new file mode 100755 index 0000000..caed86b --- /dev/null +++ b/moftmp/stream/DataBasedAnimation.cpp @@ -0,0 +1,193 @@ +#include "mof/DataBasedAnimation.h" +#include "mof/KeyFrameAnimation.h" +#include "mof/CSVFile.h" +#include + + +mof::DataBasedAnimation::DataBasedAnimation(const TCHAR * const pPath , mof::Vector3D& denormalizeScale , bool isLooping ) +: mof::Animation(isLooping) , m_denormalizeScale(denormalizeScale){ + m_pBody = new KeyFrameAnimation(isLooping); + m_pFile = new CSVFile(pPath); + m_pFile->setIgnoreNL(false); + m_pFile->nextLine();//1s–Ú‚Í—ñ’è‹`‚È‚Ì‚ÅŽÌ‚Ä‚é + loadNextKeyFrame(); + +} + +mof::DataBasedAnimation::DataBasedAnimation(const TCHAR * const pPath , bool isLooping ) +: mof::Animation(isLooping) , m_denormalizeScale(1 , 1 , 1){ + m_pBody = new KeyFrameAnimation(isLooping); + m_pFile = new CSVFile(pPath); + m_pFile->setIgnoreNL(false); + m_pFile->nextLine();//1s–Ú‚Í—ñ’è‹`‚È‚Ì‚ÅŽÌ‚Ä‚é + loadNextKeyFrame(); + +} + +void mof::DataBasedAnimation::loadNextKeyFrame(){ + if(!m_pFile->hasNextValue())return; + + //KeyFrame + int keyFrame = boost::lexical_cast(m_pFile->getNextValue()); + + //Position + { + if(!m_pFile->hasNextValue())goto END; + mof::tstring buf1 = m_pFile->getNextValue(); + if(!m_pFile->hasNextValue())goto END; + mof::tstring buf2 = m_pFile->getNextValue(); + if(buf1 != _T("") && buf2 != _T("")){ + mof::tstring buf3; + if(m_pFile->hasNextValue())buf3 = m_pFile->getNextValue(); + if(buf3 != _T("")){ + //zÀ•W‚à—LŒø‚ȏꍇ‚Í‚RŽŸŒ³À•W‚Æ‚µ‚Ĉµ‚¤ + mof::Vector3D pos( + boost::lexical_cast(buf1) , boost::lexical_cast(buf2) , boost::lexical_cast(buf3)); + pos.x = pos.x * m_denormalizeScale.x; + pos.y = pos.y * m_denormalizeScale.y; + pos.z = pos.z * m_denormalizeScale.z; + m_pBody->setPosition(keyFrame , pos); + } + else m_pBody->setPosition(keyFrame , mof::Vector2D(boost::lexical_cast(buf1) , boost::lexical_cast(buf2))); + } + else if(m_pFile->hasNextValue())m_pFile->getNextValue();//PositionZ‚ðŽÌ‚Ä‚é + } + + //Color + { + if(!m_pFile->hasNextValue())goto END; + mof::tstring buf1 = m_pFile->getNextValue(); + if(buf1 != _T("")){ + m_pBody->setColor(keyFrame , mof::createColor(buf1)); + } + } + + //Texture + { + if(!m_pFile->hasNextValue())goto END; + mof::tstring tux = m_pFile->getNextValue(); + if(!m_pFile->hasNextValue())goto END; + mof::tstring tuy = m_pFile->getNextValue(); + if(!m_pFile->hasNextValue())goto END; + mof::tstring tvx = m_pFile->getNextValue(); + if(!m_pFile->hasNextValue())goto END; + mof::tstring tvy = m_pFile->getNextValue(); + if(tux != _T("") && tuy != _T("") && tvx != _T("") && tvy != _T("")){ + m_pBody->setTextureRectangle(keyFrame , mof::Line2D( + boost::lexical_cast(tux) , boost::lexical_cast(tuy) , + boost::lexical_cast(tvx) , boost::lexical_cast(tvy))); + } + } + + //Scale + { + if(!m_pFile->hasNextValue())goto END; + mof::tstring buf1 = m_pFile->getNextValue(); + if(!m_pFile->hasNextValue())goto END; + mof::tstring buf2 = m_pFile->getNextValue(); + if(buf1 != _T("") && buf2 != _T("")){ + mof::tstring buf3; + if(m_pFile->hasNextValue())buf3 = m_pFile->getNextValue(); + if(buf3 != _T("")){ + //‰œs‚«‚à—LŒø‚ȏꍇ‚Í‚RŽŸŒ³À•W‚Æ‚µ‚Ĉµ‚¤ + m_pBody->setScale(keyFrame , mof::Vector3D( + boost::lexical_cast(buf1) , boost::lexical_cast(buf2) , boost::lexical_cast(buf3))); + } + else { + //ToDo ‚QŽŸŒ³‚̃XƒP[ƒ‹ + //m_pBody->set(keyFrame , mof::Vector2D(boost::lexical_cast(buf1) , boost::lexical_cast(buf2))); + } + } + else if(m_pFile->hasNextValue())m_pFile->getNextValue();//Depth‚ðŽÌ‚Ä‚é + } + + //Rotate + { + if(!m_pFile->hasNextValue())goto END; + mof::tstring buf1 = m_pFile->getNextValue(); + if(!m_pFile->hasNextValue())goto END; + mof::tstring buf2 = m_pFile->getNextValue(); + if(buf1 != _T("") && buf2 != _T("")){ + mof::tstring buf3; + if(m_pFile->hasNextValue())buf3 = m_pFile->getNextValue(); + if(buf3 != _T("")){ + //ZŽ²’†S‚à—LŒø‚ȏꍇ‚Í‚RŽŸŒ³À•W‚Æ‚µ‚Ĉµ‚¤ + m_pBody->setRotation(keyFrame , mof::Vector3D( + boost::lexical_cast(buf1) , boost::lexical_cast(buf2) , boost::lexical_cast(buf3))); + } + else { + //ToDo ‚QŽŸŒ³‚̉ñ“] + //m_pBody->set(keyFrame , mof::Vector2D(boost::lexical_cast(buf1) , boost::lexical_cast(buf2))); + } + } + else if(m_pFile->hasNextValue())m_pFile->getNextValue();//RotZ‚ðŽÌ‚Ä‚é + } + + + //finalizeƒVƒOƒiƒ‹ + { + if(!m_pFile->hasNextValue())goto END; + mof::tstring buf1 = m_pFile->getNextValue(); + if(buf1 != _T("")){ + m_pBody->setFinalKey(boost::lexical_cast(buf1)); + } + } + + +END: + m_pFile->nextLine(); +} + + +mof::DataBasedAnimation::~DataBasedAnimation(void){ + delete m_pBody; + delete m_pFile; +} + + +bool mof::DataBasedAnimation::update(){ + if(!isPlaying())return false; + m_pBody->update(); + + loadNextKeyFrame(); + return false; +} + + +bool mof::DataBasedAnimation::isFinalized(){ + return m_pBody->isFinalized(); +} + + +mof::Vector2D mof::DataBasedAnimation::getPosition(){ + return m_pBody->getPosition(); +} + + +float mof::DataBasedAnimation::getWidth(){ + return m_pBody->getWidth(); +} + + +float mof::DataBasedAnimation::getHeight(){ + return m_pBody->getHeight(); +} + + +float mof::DataBasedAnimation::getDepth(){ + return m_pBody->getDepth(); +} + +mof::Color mof::DataBasedAnimation::getColor(){ + return m_pBody->getColor(); +} + + +mof::Matrix3D mof::DataBasedAnimation::getWorldTransform(mof::Matrix3D& matrix){ + return m_pBody->getWorldTransform(matrix); +} + + +mof::Line2D mof::DataBasedAnimation::getTextureRectangle(){ + return m_pBody->getTextureRectangle(); +} diff --git a/moftmp/stream/DataBasedAnimation.h b/moftmp/stream/DataBasedAnimation.h new file mode 100755 index 0000000..271bff5 --- /dev/null +++ b/moftmp/stream/DataBasedAnimation.h @@ -0,0 +1,37 @@ + +#pragma once +#include "mof/Animation.h" +#include "mof/tstring.h" + +namespace mof{ + + class KeyFrameAnimation; + class CSVFile; + + class DataBasedAnimation : public Animation + { + KeyFrameAnimation* m_pBody; + CSVFile* m_pFile; + mof::Vector3D m_denormalizeScale; + + void loadNextKeyFrame(); + public: + DataBasedAnimation(const TCHAR * const pPath , bool isLooping = false); + DataBasedAnimation(const TCHAR * const pPath , mof::Vector3D& denormalizePositionScale , bool isLooping = false); + virtual ~DataBasedAnimation(void); + + virtual bool update(); + virtual bool isFinalized(); + + virtual mof::Vector2D getPosition(); + virtual float getWidth(); + virtual float getHeight(); + virtual float getDepth(); + virtual mof::Color getColor(); + virtual mof::Matrix3D getWorldTransform(mof::Matrix3D& matrix); + virtual mof::Line2D getTextureRectangle(); + + + }; + +}; \ No newline at end of file diff --git a/moftmp/stream/DefaultAnimationPlayer.cpp b/moftmp/stream/DefaultAnimationPlayer.cpp new file mode 100755 index 0000000..e5ce380 --- /dev/null +++ b/moftmp/stream/DefaultAnimationPlayer.cpp @@ -0,0 +1,21 @@ +#include "DefaultAnimationPlayer.hpp" + + + + +mof::DefaultAnimationPlayer::DefaultAnimationPlayer() +: m_frame(0) +{ +} + +void mof::DefaultAnimationPlayer::setFrameNumber(mof::FrameNumber frame){ + m_frame = frame; +} + +void mof::DefaultAnimationPlayer::nextFrame(){ + m_frame++; +} + +void mof::DefaultAnimationPlayer::prevFrame(){ + if(m_frame > 0)m_frame--; +} \ No newline at end of file diff --git a/moftmp/stream/DefaultAnimationPlayer.hpp b/moftmp/stream/DefaultAnimationPlayer.hpp new file mode 100755 index 0000000..92e9026 --- /dev/null +++ b/moftmp/stream/DefaultAnimationPlayer.hpp @@ -0,0 +1,22 @@ +#ifndef MOF_DEFAULT_ANIMATION_PLAYER_HPP +#define MOF_DEFAULT_ANIMATION_PLAYER_HPP +#include "mof/AnimationPlayer.hpp" + +namespace mof{ + + +class DefaultAnimationPlayer : AnimationPlayer{ +protected: + mof::FrameNumber m_frame; +public: + DefaultAnimationPlayer(); + virtual void setFrameNumber(mof::FrameNumber frame); + virtual void nextFrame(); + virtual void prevFrame(); + +}; + +} + + +#endif diff --git a/moftmp/stream/DefaultAnimationPlayer.hpp~ b/moftmp/stream/DefaultAnimationPlayer.hpp~ new file mode 100755 index 0000000..e1101da --- /dev/null +++ b/moftmp/stream/DefaultAnimationPlayer.hpp~ @@ -0,0 +1,22 @@ +#ifndef MOF_DEFAULT_ANIMATION_PLAYER_HPP +#define MOF_DEFAULT_ANIMATION_PLAYER_HPP +#include "mof/AnimationPlayer.hpp" + +namespace mof{ + + +class DefaultAnimationPlayer : AnimationPlayer{ +protected: + mof::FrameNumber m_frame; +public: + DefaultAnimationPlayer(); + virtual void setFrameNumber(mof::FrameNumber frame); + virtual void nextFrame(); + virtual void prevFrame(); + +}; + +} + + +#endif \ No newline at end of file diff --git a/moftmp/stream/Filter.hpp b/moftmp/stream/Filter.hpp new file mode 100755 index 0000000..6c9afac --- /dev/null +++ b/moftmp/stream/Filter.hpp @@ -0,0 +1,51 @@ +#pragma once +#include "mof/Vector2D.hpp" +#include "mof/stream/Manipulator.hpp" + + +namespace mof{ + + class Filter : public Manipulator< Vector2D > + { + public: + typedef boost::shared_ptr Handler; + + Filter + ( + const Manipulator::Handler& body , + const mof::Vector2D& filter + ) + : m_body( body ) , m_filter( filter) + { + } + + virtual Vector2D value( FrameNumber frame ) const + { + mof::Vector2D value = m_body->value(frame); + return mof::Vector2D( value.x * m_filter.x , value.y * m_filter.y); + } + + + private: + Manipulator< Vector2D >::Handler m_body; + Vector2D m_filter; + + + }; + +//{{{ ヘルパ関数 + inline Filter::Handler makeFilterHandler + ( + const Manipulator< Vector2D >::Handler& body , + const Vector2D& filter + ) + { + return Filter::Handler + ( + new Filter( body , filter ) + ); + } +//}}} + +} // namespace mof + diff --git a/moftmp/stream/Filter.hpp~ b/moftmp/stream/Filter.hpp~ new file mode 100755 index 0000000..e442d31 --- /dev/null +++ b/moftmp/stream/Filter.hpp~ @@ -0,0 +1,51 @@ +#pragma once +#include "mof/Vector2D.hpp" +#include "mof/stream/Manipulator.hpp" + + +namespace mof{ + + class Filter : public Manipulator< Vector2D > + { + public: + typedef boost::shared_ptr< Translation2D > Handler; + + Filter + ( + const Manipulator::Handler& body , + const mof::Vector2D& filter + ) + : m_body( body ) , m_filter( filter) + { + } + + virtual Vector2D value( FrameNumber frame ) const + { + mof::Vector2D value = m_body->value(frame); + return mof::Vector2D( value.x * m_filter.x , value.y * m_filter.y); + } + + + private: + Manipulator< Vector2D >::Handler m_body; + Vector2D m_filter; + + + }; + +//{{{ ヘルパ関数 + inline Filter::Handler makeFilterHandler + ( + const Manipulator< Vector2D >::Handler& body , + const Vector2D& filter + ) + { + return Filter::Handler + ( + new Filter( body , filter ) + ); + } +//}}} + +} // namespace mof + diff --git a/moftmp/stream/Joint.hpp b/moftmp/stream/Joint.hpp new file mode 100755 index 0000000..b343cd2 --- /dev/null +++ b/moftmp/stream/Joint.hpp @@ -0,0 +1,99 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" + +namespace mof +{ + template< typename T , typename K > + class Joint : public Manipulator< T > + { + public: + typedef typename boost::shared_ptr< mof::Joint< T , K > > Handler; + + + virtual ~Joint( ) + { + } + + virtual T value( FrameNumber frame ) const + { + return m_converter( m_body->value( frame ) ); + } + + typename Manipulator< K >::Handler get( ) const { return m_body; } + + void set( const typename Manipulator< K >::Handler& handler ){ m_body = handler; } + + private: + typename Manipulator::Handler m_body; + T (*m_converter)( const K& ); + + Joint( const typename Manipulator< K >::Handler& handler , T (*converter)( const K& ) ) + : m_body( handler) , m_converter( converter ) + { + } + + template< typename T , typename K > friend + typename Joint< T , K >::Handler makeJointHandler + ( + const typename Manipulator< K >::Handler& handler , + T (*converter)( const K& ) + ); + + }; // class Joint + + /** Œ^•ÏŠ·‚ðs‚í‚È‚¢Joint */ + template< typename T > + class Joint< T , T > : public Manipulator< T > + { + public: + typedef typename boost::shared_ptr< mof::Joint< T , T > > Handler; + + + virtual T getValue( mof::FrameNumber frame ) const + { + return m_body->getValue( frame ); + } + + typename mof::Manipulator< T >::Handler get( ) const { return m_body; } + void set( const typename mof::Manipulator< T >::Handler& handler ){ m_body = handler; } + + private: + typename mof::Manipulator< T >::Handler m_body; + + Joint( const typename Manipulator< T >::Handler& handler ) + : m_body( handler) + { + } + + template< typename T > friend + typename Joint< T , T >::Handler makeJointHandler + ( + const typename Manipulator< T >::Handler& handler + ); + + }; // class Joint + + + template< typename T , typename K > + typename Joint< T , K >::Handler makeJointHandler + ( + const typename Manipulator< K >::Handler& handler , + T (*converter)( const K& ) + ) + { + return typename Joint< T , K >::Handler( new Joint< T , K >( handler , converter ) ); + } + + /** Œ^•ÏŠ·‚ðs‚í‚È‚¢Joint‚̐¶¬ */ + // TODO Œ^„˜_‚ªŒø‚©‚È‚¢ + template< typename T > + typename Joint< T , T >::Handler makeJointHandler + ( + const typename Manipulator< T >::Handler& handler + ) + { + return typename Joint< T , T >::Handler( new Joint< T , T >( handler ) ); + } + + +} // namespace mof diff --git a/moftmp/stream/Joint.hpp~ b/moftmp/stream/Joint.hpp~ new file mode 100755 index 0000000..f1e28cb --- /dev/null +++ b/moftmp/stream/Joint.hpp~ @@ -0,0 +1,99 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" + +namespace mof +{ + template< typename T , typename K > + class Joint : public Manipulator< T > + { + public: + typedef typename boost::shared_ptr< mof::Joint< T , K > > Handler; + + + virtual ~Joint( ) + { + } + + virtual T value( FrameNumber frame ) const + { + return m_converter( m_body->value( frame ) ); + } + + typename Manipulator< K >::Handler get( ) const { return m_body; } + + void set( const typename Manipulator< K >::Handler& handler ){ m_body = handler; } + + private: + typename Manipulator::Handler m_body; + T (*m_converter)( const K& ); + + Joint( const typename Manipulator< K >::Handler& handler , T (*converter)( const K& ) ) + : m_body( handler) , m_converter( converter ) + { + } + + template< typename T , typename K > friend + typename Joint< T , K >::Handler makeJointHandler + ( + const typename Manipulator< K >::Handler& handler , + T (*converter)( const K& ) + ); + + }; // class Joint + + /** Œ^•ÏŠ·‚ðs‚í‚È‚¢Joint */ + template< typename T > + class Joint< T , T > : public Manipulator< T > + { + public: + typedef typename boost::shared_ptr< mof::Joint< T , T > > Handler; + + + virtual T getValue( mof::FrameNumber frame ) const + { + return m_body->getValue( frame ); + } + + typename mof::Manipulator< T >::Handler get( ) const { return m_body; } + void set( const typename mof::Manipulator< T >::Handler& handler ){ m_body = handler; } + + private: + typename mof::Manipulator< T >::Handler m_body; + + Joint( const typename Manipulator< T >::Handler& handler ) + : m_body( handler) + { + } + + template< typename T > friend + typename Joint< T , T >::Handler makeJointHandler + ( + const Manipulator< T >::Handler& handler + ); + + }; // class Joint + + + template< typename T , typename K > + typename Joint< T , K >::Handler makeJointHandler + ( + const typename Manipulator< K >::Handler& handler , + T (*converter)( const K& ) + ) + { + return typename Joint< T , K >::Handler( new Joint< T , K >( handler , converter ) ); + } + + /** Œ^•ÏŠ·‚ðs‚í‚È‚¢Joint‚̐¶¬ */ + // TODO Œ^„˜_‚ªŒø‚©‚È‚¢ + template< typename T > + typename Joint< T , T >::Handler makeJointHandler + ( + const typename Manipulator< T >::Handler& handler + ) + { + return typename Joint< T , T >::Handler( new Joint< T , T >( handler ) ); + } + + +} // namespace mof diff --git a/moftmp/stream/JointAnimation.hpp~ b/moftmp/stream/JointAnimation.hpp~ new file mode 100755 index 0000000..f22ff2a --- /dev/null +++ b/moftmp/stream/JointAnimation.hpp~ @@ -0,0 +1,39 @@ +#pragma once +#include "mof/Animation.hpp" +#include + +namespace mof{ + + + template< typename T , typename K > + class Joint : boost::noncopyable{ + public: + typedef boost::shared_ptr< mof::Joint > Handler; + typedef boost::function1< const T& , const K& > Converter; + + Joint( const mof::Animation::Handler& handler , const Converter& converter ) + : m_body( handler) , m_converter( converter ) + { + } + + virtual T getValue( mof::FrameNumber frame ) const + { + return m_converter( m_body->getValue( frame ) ); + } + + private: + mof::Animation::Handler m_body; + Converter m_converter; + }; + + template< typename T , typename K > + Joint< T , K >::Handler makeJointHandler + ( + const Animation::Handler& handler , + const Joint< T , K >::Converter& converter + ) + { + return Joint::Handler( new Joint( handler , converter) ); + } + +} // namespace mof diff --git a/moftmp/stream/KeyFrameAnimation.hpp b/moftmp/stream/KeyFrameAnimation.hpp new file mode 100755 index 0000000..839c50c --- /dev/null +++ b/moftmp/stream/KeyFrameAnimation.hpp @@ -0,0 +1,164 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" +#include +#include +#include +#include "mof/Interpolation.hpp" + +namespace mof{ + + template + class KeyFrameAnimation : public Manipulator< T > + { + public: + typedef std::pair< FrameNumber , T > KeyFrame; + typedef typename std::map< FrameNumber , T> KeyMap; + + virtual ~KeyFrameAnimation(){} + + virtual T value( mof::FrameNumber frame) const + { + return m_interpolator(m_map , frame); + } + + mof::FrameNumber getFinalKeyFrameNumber() + { + return m_maxKeyFrameNumber; + } + + private: + KeyMap m_map; + FrameNumber m_maxKeyFrameNumber; + boost::function2 m_interpolator; + + KeyFrameAnimation + ( + const KeyFrame& front , + const KeyFrame& back , + const boost::function2< T , const KeyMap& , FrameNumber > & interpolator + ) + : m_interpolator(interpolator) + { + int length = &back - &front + 1; + if(length < 1)throw std::invalid_argument("length < 1"); + m_maxKeyFrameNumber = 0; + for(int i = 0 ; i < length ; i++) + { + if((&front)[i].first > m_maxKeyFrameNumber)m_maxKeyFrameNumber = (&front)[i].first; + m_map.insert( std::make_pair((&front)[i].first , (&front)[i].second ) ); + } + } + + KeyFrameAnimation + ( + const KeyFrame& front , const KeyFrame& back + ) + : m_interpolator(&mof::linerInterpolate) + { + int length = &back - &front + 1; + if(length < 1)throw std::invalid_argument("length < 1"); + m_maxKeyFrameNumber = 0; + for(int i = 0 ; i < length ; i++) + { + if((&front)[i].first > m_maxKeyFrameNumber)m_maxKeyFrameNumber = (&front)[i].first; + m_map.insert( std::make_pair((&front)[i].first , (&front)[i].second ) ); + } + } + + template< typename T > friend + typename KeyFrameAnimation< T >::KeyFrame + makeKeyFrame( mof::FrameNumber frame , const T & obj ); + + template< typename T > friend + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + const std::pair< FrameNumber , T >& front , + const std::pair< FrameNumber , T >& back , + const boost::function2< T , const std::map< FrameNumber , T >& , FrameNumber> & interpolator + ); + + template< typename T > friend + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + const std::pair< FrameNumber , T >& front , + const std::pair< FrameNumber , T >& back + ); + + }; +//{{{ ヘルパ関数 + template< typename T > + typename KeyFrameAnimation< T >::KeyFrame + makeKeyFrame( mof::FrameNumber frame , const T & obj ) + { + return std::make_pair< FrameNumber , T>(frame , obj); + } + + template< typename T > + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + const std::pair< FrameNumber , T >& front , + const std::pair< FrameNumber , T >& back , + const boost::function2< T , const std::map< FrameNumber , T >& , FrameNumber> & interpolator + ) + { + return KeyFrameAnimation< T >::Handler + ( + new KeyFrameAnimation< T >( front , back , interpolator ) + ); + } + + template< typename T > + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + const std::pair< FrameNumber , T >& front , + const std::pair< FrameNumber , T >& back + ) + { + return KeyFrameAnimation< T >::Handler + ( + new KeyFrameAnimation< T >( front , back ) + ); + } + + template< typename T > + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + FrameNumber fn1 , const T& v1 , + FrameNumber fn2 , const T& v2 + ) + { + KeyFrameAnimation::KeyFrame keyFrames[] = + { + makeKeyFrame(fn1 , v1) , + makeKeyFrame(fn2 , v2) + }; + return makeKeyFrameAnimationHandler(keyFrames[0] , lastOf(keyFrames)); + } + + template< typename T > + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + FrameNumber fn1 , const T& v1 , + FrameNumber fn2 , const T& v2 , + const boost::function2< T , const std::map< FrameNumber , T >& , FrameNumber> & interpolator + ) + { + KeyFrameAnimation::KeyFrame keyFrames[] = + { + makeKeyFrame(fn1 , v1) , + makeKeyFrame(fn2 , v2) + }; + return makeKeyFrameAnimationHandler(keyFrames[0] , lastOf(keyFrames) , interpolator); + } + + + +//}}} +} //namespace mof + diff --git a/moftmp/stream/KeyFrameAnimation.hpp~ b/moftmp/stream/KeyFrameAnimation.hpp~ new file mode 100755 index 0000000..9bc6ee1 --- /dev/null +++ b/moftmp/stream/KeyFrameAnimation.hpp~ @@ -0,0 +1,146 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" +#include +#include +#include +#include "mof/Interpolation.hpp" + +namespace mof{ + + template + class KeyFrameAnimation : public Manipulator< T > + { + public: + typedef std::pair< FrameNumber , T > KeyFrame; + typedef typename std::map< FrameNumber , T> KeyMap; + + virtual ~KeyFrameAnimation(){} + + virtual T value( mof::FrameNumber frame) const + { + return m_interpolator(m_map , frame); + } + + mof::FrameNumber getFinalKeyFrameNumber() + { + return m_maxKeyFrameNumber; + } + + private: + KeyMap m_map; + FrameNumber m_maxKeyFrameNumber; + boost::function2 m_interpolator; + + KeyFrameAnimation + ( + const KeyFrame& front , + const KeyFrame& back , + const boost::function2< T , const KeyMap& , FrameNumber > & interpolator + ) + : m_interpolator(interpolator) + { + int length = &back - &front + 1; + if(length < 1)throw std::invalid_argument("length < 1"); + m_maxKeyFrameNumber = 0; + for(int i = 0 ; i < length ; i++) + { + if((&front)[i].first > m_maxKeyFrameNumber)m_maxKeyFrameNumber = (&front)[i].first; + m_map.insert( std::make_pair((&front)[i].first , (&front)[i].second ) ); + } + } + + KeyFrameAnimation + ( + const KeyFrame& front , const KeyFrame& back + ) + : m_interpolator(&mof::linerInterpolate) + { + int length = &back - &front + 1; + if(length < 1)throw std::invalid_argument("length < 1"); + m_maxKeyFrameNumber = 0; + for(int i = 0 ; i < length ; i++) + { + if((&front)[i].first > m_maxKeyFrameNumber)m_maxKeyFrameNumber = (&front)[i].first; + m_map.insert( std::make_pair((&front)[i].first , (&front)[i].second ) ); + } + } + + template< typename T > friend + typename KeyFrameAnimation< T >::KeyFrame + makeKeyFrame( mof::FrameNumber frame , const T & obj ); + + template< typename T > friend + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + const std::pair< FrameNumber , T >& front , + const std::pair< FrameNumber , T >& back , + const boost::function2< T , const std::map< FrameNumber , T >& , FrameNumber> & interpolator + ); + + template< typename T > friend + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + const std::pair< FrameNumber , T >& front , + const std::pair< FrameNumber , T >& back + ); + + }; +//{{{ ヘルパ関数 + template< typename T > + typename KeyFrameAnimation< T >::KeyFrame + makeKeyFrame( mof::FrameNumber frame , const T & obj ) + { + return std::make_pair< FrameNumber , T>(frame , obj); + } + + template< typename T > + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + const std::pair< FrameNumber , T >& front , + const std::pair< FrameNumber , T >& back , + const boost::function2< T , const std::map< FrameNumber , T >& , FrameNumber> & interpolator + ) + { + return KeyFrameAnimation< T >::Handler + ( + new KeyFrameAnimation< T >( front , back , interpolator ) + ); + } + + template< typename T > + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + const std::pair< FrameNumber , T >& front , + const std::pair< FrameNumber , T >& back + ) + { + return KeyFrameAnimation< T >::Handler + ( + new KeyFrameAnimation< T >( front , back ) + ); + } + + template< typename T > + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + FrameNumber fn1 , const T& v1 , + FrameNumber fn2 , const T& v2 + ) + { + KeyFrameAnimation::KeyFrame keyFrames[] = + { + makeKeyFrame(fn1 , v1) , + makeKeyFrame(fn2 , v2) + }; + return makeKeyFrameAnimationHandler(keyFrames[0] , lastOf(keyFrames)); + } + + +//}}} +} //namespace mof + diff --git a/moftmp/stream/Loop.hpp b/moftmp/stream/Loop.hpp new file mode 100755 index 0000000..0d13f58 --- /dev/null +++ b/moftmp/stream/Loop.hpp @@ -0,0 +1,98 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" + + +namespace mof{ + + template< typename T > + class Loop : public Manipulator< T > + { + + public: + + virtual ~Loop( ){} + + virtual T value( FrameNumber frame) const + { + return m_pBody->value( getInnerFrameNumber( frame ) ); + } + + private: + + typename Manipulator::Handler m_pBody; + FrameNumber m_beginLoopFrameNumber; + FrameNumber m_endLoopFrameNumber; + + FrameNumber getInnerFrameNumber(FrameNumber frame) const + { + if(frame < m_beginLoopFrameNumber)return frame; + FrameNumber d = m_endLoopFrameNumber - m_beginLoopFrameNumber; + return (frame - m_beginLoopFrameNumber) % d + m_beginLoopFrameNumber; + } + + Loop(const typename Manipulator::Handler& pBody , FrameNumber endLoopFrameNumber) + : m_pBody(pBody) , m_beginLoopFrameNumber(0) , m_endLoopFrameNumber(endLoopFrameNumber) + { + } + + Loop + ( + const typename Manipulator::Handler& pBody , + FrameNumber beginLoopFrameNumber , + FrameNumber endLoopFrameNumber + ) + : m_pBody(pBody) , m_beginLoopFrameNumber(beginLoopFrameNumber) , m_endLoopFrameNumber(endLoopFrameNumber) + { + if(m_endLoopFrameNumber < m_beginLoopFrameNumber)throw std::invalid_argument("endLoop < beginLoop"); + } + + template friend + typename boost::shared_ptr< Loop< T> > + makeLoopHandler + ( + const typename Manipulator::Handler& pBody , + FrameNumber beginLoopFrameNumber , + FrameNumber endLoopFrameNumber + ); + + template friend + typename boost::shared_ptr< Loop< T> > + makeLoopHandler + ( + const typename Manipulator::Handler& pBody , + FrameNumber endLoopFrameNumber + ); + + }; +//{{{ ヘルパ関数 + template + typename boost::shared_ptr< Loop< T> > + makeLoopHandler + ( + const typename Manipulator::Handler& pBody , + FrameNumber beginLoopFrameNumber , + FrameNumber endLoopFrameNumber + ) + { + return typename Manipulator< T >::Handler + ( + new Loop< T >(pBody , beginLoopFrameNumber , endLoopFrameNumber) + ); + } + + template + typename boost::shared_ptr< Loop< T> > + makeLoopHandler + ( + const typename Manipulator::Handler& pBody , + FrameNumber endLoopFrameNumber + ) + { + return typename Manipulator< T >::Handler + ( + new Loop< T >(pBody , endLoopFrameNumber) + ); + } +//}}} +} //namespace mof + diff --git a/moftmp/stream/Loop.hpp~ b/moftmp/stream/Loop.hpp~ new file mode 100755 index 0000000..bb233a6 --- /dev/null +++ b/moftmp/stream/Loop.hpp~ @@ -0,0 +1,98 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" + + +namespace mof{ + + template< typename T > + class Loop : public Manipulator< T > + { + + public: + + virtual ~Loop( ){} + + virtual T value( FrameNumber frame) const + { + return m_pBody->value( getInnerFrameNumber( frame ) ); + } + + private: + + typename Manipulator::Handler m_pBody; + FrameNumber m_beginLoopFrameNumber; + FrameNumber m_endLoopFrameNumber; + + FrameNumber getInnerFrameNumber(FrameNumber frame) const + { + if(frame < m_beginLoopFrameNumber)return frame; + FrameNumber d = m_endLoopFrameNumber - m_beginLoopFrameNumber; + return (frame - m_beginLoopFrameNumber) % d + m_beginLoopFrameNumber; + } + + Loop(const typename Manipulator::Handler& pBody , FrameNumber endLoopFrameNumber) + : m_pBody(pBody) , m_beginLoopFrameNumber(0) , m_endLoopFrameNumber(endLoopFrameNumber) + { + } + + LoopManipulator + ( + const typename Manipulator::Handler& pBody , + FrameNumber beginLoopFrameNumber , + FrameNumber endLoopFrameNumber + ) + : m_pBody(pBody) , m_beginLoopFrameNumber(beginLoopFrameNumber) , m_endLoopFrameNumber(endLoopFrameNumber) + { + if(m_endLoopFrameNumber < m_beginLoopFrameNumber)throw std::invalid_argument("endLoop < beginLoop"); + } + + template friend + typename boost::shared_ptr< Loop< T> > + makeLoopHandler + ( + const typename Manipulator::Handler& pBody , + FrameNumber beginLoopFrameNumber , + FrameNumber endLoopFrameNumber + ); + + template friend + typename boost::shared_ptr< Loop< T> > + makeLoopHandler + ( + const typename Manipulator::Handler& pBody , + FrameNumber endLoopFrameNumber + ); + + }; +//{{{ ヘルパ関数 + template + typename boost::shared_ptr< Loop< T> > + makeLoopHandler + ( + const typename Manipulator::Handler& pBody , + FrameNumber beginLoopFrameNumber , + FrameNumber endLoopFrameNumber + ) + { + return typename Manipulator< T >::Handler + ( + new Loop< T >(pBody , beginLoopFrameNumber , endLoopFrameNumber) + ); + } + + template + typename boost::shared_ptr< Loop< T> > + makeLoopHandler + ( + const typename Manipulator::Handler& pBody , + FrameNumber endLoopFrameNumber + ) + { + return typename Manipulator< T >::Handler + ( + new Loop< T >(pBody , endLoopFrameNumber) + ); + } +//}}} +} //namespace mof + diff --git a/moftmp/stream/LoopAnimation.hpp~ b/moftmp/stream/LoopAnimation.hpp~ new file mode 100755 index 0000000..1a07990 --- /dev/null +++ b/moftmp/stream/LoopAnimation.hpp~ @@ -0,0 +1,60 @@ + #pragma once + #include "mof/Animation.hpp" + + + namespace mof{ + + template + class LoopAnimation : public Animation{ + typename Animation::Handler m_pBody; + FrameNumber m_beginLoopFrameNumber; + FrameNumber m_endLoopFrameNumber; + + FrameNumber getInnerFrameNumber(FrameNumber frame) const{ + if(frame < m_beginLoopFrameNumber)return frame; + mof::FrameNumber d = m_endLoopFrameNumber - m_beginLoopFrameNumber; + return (frame - m_beginLoopFrameNumber) % d + m_beginLoopFrameNumber; + } + + public: + + LoopAnimation(const typename Animation::Handler& pBody , FrameNumber endLoopFrameNumber) + : m_pBody(pBody) , m_beginLoopFrameNumber(0) , m_endLoopFrameNumber(endLoopFrameNumber) + { + } + + LoopAnimation( + const typename mof::Animation::Handler& pBody , + mof::FrameNumber beginLoopFrameNumber , + mof::FrameNumber endLoopFrameNumber + ) : m_pBody(pBody) , m_beginLoopFrameNumber(beginLoopFrameNumber) , m_endLoopFrameNumber(endLoopFrameNumber) + { + if(m_endLoopFrameNumber < m_beginLoopFrameNumber)throw std::invalid_argument("endLoop < beginLoop"); + } + + + + virtual T getValue( mof::FrameNumber frame) const{ + return m_pBody->getValue(getInnerFrameNumber(frame)); + } + + + + }; + + + template + typename mof::Animation::Handler + makeLoopHandler( + const typename mof::Animation::Handler& pBody , + mof::FrameNumber beginLoopFrameNumber , + mof::FrameNumber endLoopFrameNumber){ + + return typename mof::Animation::Handler( + new mof::LoopAnimation(pBody , beginLoopFrameNumber , endLoopFrameNumber) + ); + } + + + } //namespace mof + diff --git a/moftmp/stream/Manipulator.hpp b/moftmp/stream/Manipulator.hpp new file mode 100755 index 0000000..71c39ba --- /dev/null +++ b/moftmp/stream/Manipulator.hpp @@ -0,0 +1,19 @@ +#pragma once +#include + +namespace mof +{ + typedef unsigned int FrameNumber; + + template + class Manipulator + { + public: + typedef typename boost::shared_ptr< Manipulator > Handler; + virtual ~Manipulator(){} + virtual T value( FrameNumber fn ) const = 0; + + }; + + +} // namespace mof diff --git a/moftmp/stream/Manipulator.hpp~ b/moftmp/stream/Manipulator.hpp~ new file mode 100755 index 0000000..10fcd4f --- /dev/null +++ b/moftmp/stream/Manipulator.hpp~ @@ -0,0 +1,18 @@ +#pragma once +#include + +namespace mof +{ + + template + class Manipulator + { + public: + typedef typename boost::shared_ptr< Manipulator > Handler; + virtual ~Manipulator(){} + virtual T value( FrameNumber fn ) const = 0; + + }; + + +} // namespace mof diff --git a/moftmp/stream/Offset.hpp b/moftmp/stream/Offset.hpp new file mode 100755 index 0000000..dd4e716 --- /dev/null +++ b/moftmp/stream/Offset.hpp @@ -0,0 +1,55 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" + +namespace mof{ + + template< typename T > + class Offset : public Manipulator< T > + { + + public: + typedef typename boost::shared_ptr< Offset > Handler; + + virtual ~Offset( ){} + + virtual T value( FrameNumber frame ) const + { + if( m_offset + frame < 0)return m_pBody->value( 0 ); + else return m_pBody->value( frame + m_offset ); + } + + private: + typename Manipulator::Handler m_pBody; + int m_offset; + + + Offset( const typename Manipulator::Handler& pBody , int offset ) + : m_pBody(pBody) , m_offset(offset) + { + } + + template friend + typename boost::shared_ptr< Offset< T > > makeOffsetHandler + ( + const typename Manipulator::Handler& pBody , + int offset + ); + + }; + + + template< typename T > + boost::shared_ptr< Offset< T > > makeOffsetHandler + ( + const typename Manipulator< T >::Handler& pBody , + int offset + ) + { + return typename Offset< T >::Handler( + new Offset< T >( pBody , offset ) + ); + } + + +} //namespace mof + diff --git a/moftmp/stream/Offset.hpp~ b/moftmp/stream/Offset.hpp~ new file mode 100755 index 0000000..ca92b9a --- /dev/null +++ b/moftmp/stream/Offset.hpp~ @@ -0,0 +1,55 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" + +namespace mof{ + + template< typename T > + class Offset : public Manipulator< T > + { + + public: + typedef typename boost::shared_ptr< Cascade > Handler; + + virtual ~Offset( ){} + + virtual T value( FrameNumber frame ) const + { + if( m_offset + frame < 0)return m_pBody->value( 0 ); + else return m_pBody->value( frame + m_offset ); + } + + private: + typename Manipulator::Handler m_pBody; + int m_offset; + + + Offset( const typename Manipulator::Handler& pBody , int offset ) + : m_pBody(pBody) , m_offset(offset) + { + } + + template friend + typename boost::shared_ptr< Offset< T > > makeOffsetHandler + ( + const typename Manipulator::Handler& pBody , + int offset + ); + + }; + + + template< typename T > + boost::shared_ptr< Offset< T > > makeOffsetHandler + ( + const typename Manipulator< T >::Handler& pBody , + int offset + ) + { + return typename Offset< T >::Handler( + new Offset< T >( pBody , offset ) + ); + } + + +} //namespace mof + diff --git a/moftmp/stream/OffsetAnimation.hpp~ b/moftmp/stream/OffsetAnimation.hpp~ new file mode 100755 index 0000000..b3bb2a8 --- /dev/null +++ b/moftmp/stream/OffsetAnimation.hpp~ @@ -0,0 +1,48 @@ +#pragma once +#include "mof/Animation.hpp" + + +namespace mof{ + + template + class OffsetAnimation : public Animation{ + typename Animation::Handler m_pBody; + int m_offset; + + + public: + + OffsetAnimation(const typename Animation::Handler& pBody , int offset) + : m_pBody(pBody) , m_offset(offset) + { + } + + + + virtual T getValue( mof::FrameNumber frame) const{ + if( m_offset + frame < 0)return m_pBody->getValue( 0 ); + else return m_pBody->getValue(frame + m_offset ); + } + + + + }; + + + template + typename mof::Animation::Handler + makeOffsetHandler + ( + const typename mof::Animation::Handler& pBody , + int offset + ) + { + return typename mof::Animation::Handler + ( + new mof::OffsetAnimation(pBody , offset) + ); + } + + +} //namespace mof + diff --git a/moftmp/stream/ParametricAnimation.hpp b/moftmp/stream/ParametricAnimation.hpp new file mode 100755 index 0000000..ea7d17d --- /dev/null +++ b/moftmp/stream/ParametricAnimation.hpp @@ -0,0 +1,30 @@ + #pragma once + + #include + + namespace mof{ + + + + template + class ParametricAnimation : public mof::Animation{ + const boost::shared_ptr& m_parameter; + public: + + ParametricAnimation(const boost::shared_ptr& parameter) + : m_parameter(parameter){ + } + + virtual T getValue(mof::FrameNumber ) const{ + return *m_parameter; + } + + }; + + template + typename mof::Animation::Handler makeParametricHandler(const boost::shared_ptr& parameter){ + return mof::Animation::Handler(new mof::ParametricAnimation(parameter)); + } + + } //namespace mof + diff --git a/moftmp/stream/ParametricAnimation.hpp~ b/moftmp/stream/ParametricAnimation.hpp~ new file mode 100755 index 0000000..ea7d17d --- /dev/null +++ b/moftmp/stream/ParametricAnimation.hpp~ @@ -0,0 +1,30 @@ + #pragma once + + #include + + namespace mof{ + + + + template + class ParametricAnimation : public mof::Animation{ + const boost::shared_ptr& m_parameter; + public: + + ParametricAnimation(const boost::shared_ptr& parameter) + : m_parameter(parameter){ + } + + virtual T getValue(mof::FrameNumber ) const{ + return *m_parameter; + } + + }; + + template + typename mof::Animation::Handler makeParametricHandler(const boost::shared_ptr& parameter){ + return mof::Animation::Handler(new mof::ParametricAnimation(parameter)); + } + + } //namespace mof + diff --git a/moftmp/stream/Reference.hpp b/moftmp/stream/Reference.hpp new file mode 100755 index 0000000..a83de0f --- /dev/null +++ b/moftmp/stream/Reference.hpp @@ -0,0 +1,52 @@ +#pragma once +#include + +namespace mof +{ + template< typename T > class Reference; + + template< typename T > + boost::shared_ptr< Reference > + makeReferenceHandler(const typename Manipulator::Handler&); + +//{{{ Reference + template + class Reference : public Manipulator + { + public: + typedef typename boost::shared_ptr Handler; + + virtual ~Reference(){} + + virtual T value(FrameNumber fn) const + { + return m_body->value(fn); + } + + void replace(const typename Manipulator::Handler& body) + { + m_body = body; + } + + private: + Manipulator::Handler m_body; + + Reference(const Manipulator::Handler& body) : m_body(body) + {} + + template< typename T > + friend typename boost::shared_ptr< Reference > + makeReferenceHandler(const typename Manipulator::Handler&); + + }; +//}}} +//{{{ ヘルパ関数 + template + boost::shared_ptr< Reference > + makeReferenceHandler(const typename Manipulator::Handler& body) + { + return typename Reference::Handler(new Reference(body)); + } +//}}} + +} // namespace mof diff --git a/moftmp/stream/Reference.hpp~ b/moftmp/stream/Reference.hpp~ new file mode 100755 index 0000000..9dd462c --- /dev/null +++ b/moftmp/stream/Reference.hpp~ @@ -0,0 +1,52 @@ +#pragma once +#include + +namespace mof +{ + template< typename T > class Reference; + + template< typename T > + boost::shared_ptr< Reference > + makeReferenceHandler(const typename Manipulator::Handler&); + +//{{{ Reference + template + class Reference : public Manipulator + { + public: + typedef typename boost::shared_ptr Handler; + + virtual ~Reference(){} + + virtual T value(FrameNumber fn) const + { + return m_body.value(fn); + } + + void replace(const typename Manipulator::Handler& body) + { + m_body = body; + } + + private: + Manipulator::Handler m_body; + + Reference(const Manipulator::Handler& body) : m_body(body) + {} + + template< typename T > + friend typename boost::shared_ptr< Reference > + makeReferenceHandler(const typename Manipulator::Handler&); + + }; +//}}} +//{{{ ヘルパ関数 + template + boost::shared_ptr< Reference > + makeReferenceHandler(const typename Manipulator::Handler& body) + { + return typename Reference::Handler(new Reference(body)); + } +//}}} + +} // namespace mof diff --git a/moftmp/stream/ReferenceWrapper.hpp b/moftmp/stream/ReferenceWrapper.hpp new file mode 100755 index 0000000..d97efe9 --- /dev/null +++ b/moftmp/stream/ReferenceWrapper.hpp @@ -0,0 +1,56 @@ +#pragma once +#include +#include +#include +#include + +namespace mof +{ +//{{{ ReferenceWrapper + template + class ReferenceWrapper + { + public: + + typename Reference::Handler makeRef(const typename Manipulator::Handler& body) + { + m_list.push_back(makeReferenceHandler(body)); + return m_list.back(); + } + + typename Reference::Handler makeRef(const T& body) + { + m_list.push_back(makeReferenceHandler(makeConstantHandler(body))); + return m_list.back(); + } + + + void replace(int index , const typename Manipulator::Handler& body) + { + m_list[index]->replace(body); + //m_list[index]->replace(makeOffsetHandler(body , -1 * (int)m_stream.getCurrentFrameNumber())); + } + + void replace(int index , const T& body) + { + m_list[index]->replace(makeConstantHandler(body)); + //m_list[index]->replace(makeOffsetHandler(makeConstantHandler(body) , -1 * (int)m_stream.getCurrentFrameNumber())); + } + + void replace(int index , const TypeStream& stream , const typename Manipulator::Handler& body) + { + m_list[index]->replace(makeOffsetHandler(body , -1 * stream.getCurrentFrameNumber())); + } + + + typename Reference::Handler getRef(int index) const + { + return m_list[index]; + } + + private: + std::vector::Handler> m_list; + }; +//}}} +} // namespace mof + diff --git a/moftmp/stream/ReferenceWrapper.hpp~ b/moftmp/stream/ReferenceWrapper.hpp~ new file mode 100755 index 0000000..a1fdd64 --- /dev/null +++ b/moftmp/stream/ReferenceWrapper.hpp~ @@ -0,0 +1,56 @@ +#pragma once +#include +#include +#include +#include + +namespace mof +{ +//{{{ ReferenceWrapper + template + class ReferenceWrapper + { + public: + + typename Reference::Handler makeRef(const typename Manipulator::Handler& body) + { + m_list.push_back(makeReferenceHandler(body)); + return m_list.back(); + } + + typename Reference::Handler makeRef(const T& body) + { + m_list.push_back(makeReferenceHandler(makeConstantHandler(body))); + return m_list.back(); + } + + + void replace(int index , const typename Manipulator::Handler& body) + { + m_list[index]->replace(body); + //m_list[index]->replace(makeOffsetHandler(body , -1 * (int)m_stream.getCurrentFrameNumber())); + } + + void replace(int index , const T& body) + { + m_list[index]->replace(makeConstantHandler(body)); + //m_list[index]->replace(makeOffsetHandler(makeConstantHandler(body) , -1 * (int)m_stream.getCurrentFrameNumber())); + } + + void replace(int index , const TypeStream& stream , const typename Manipulator::Handler& body) + { + m_list[index]->replace(makeOffsetHandler(body , -1 * stream.getCurrentFrameNumber())); + } + + + typename Reference::Handler getRef(int index) const + { + return m_list[index]; + } + + private: + std::vector::Handler> m_list; + }; +//}}} +} // namespace mof + diff --git a/moftmp/stream/Rotation2D.hpp b/moftmp/stream/Rotation2D.hpp new file mode 100755 index 0000000..5a8dec9 --- /dev/null +++ b/moftmp/stream/Rotation2D.hpp @@ -0,0 +1,76 @@ +#pragma once +#include "mof/stream/KeyFrameAnimation.hpp" +#include "mof/Matrix2D.hpp" + + +namespace mof{ + + class Rotation2D : public Manipulator< Matrix2D > + { + public: + typedef boost::shared_ptr< Rotation2D > Handler; + + Rotation2D + ( + const std::pair< FrameNumber , mof::Vector2D >& front , + const std::pair< FrameNumber , mof::Vector2D >& back + ) + { + m_body = makeKeyFrameAnimationHandler< Vector2D > + ( + front , back , &linerInterpolate< Vector2D > + ); + } + + Rotation2D + ( + const Manipulator< Vector2D >::Handler& body + ) + : m_body( body ) + { + } + + virtual Matrix2D value( FrameNumber frame ) const + { + return Matrix2D::createRotation( m_body->value(frame) ); + } + + Manipulator::Handler get( ) const + { + return m_body; + } + + void set( const Manipulator< Vector2D >::Handler& handler ) + { + m_body = handler; + } + + private: + Manipulator< Vector2D >::Handler m_body; + + }; +//{{{ ヘルパ関数 + inline Rotation2D::Handler makeRotation2DHandler + ( + const std::pair< FrameNumber , Vector2D >& front , + const std::pair< FrameNumber , Vector2D >& back + ) + { + return Rotation2D::Handler + ( + new Rotation2D( front , back ) + ); + } + + inline Rotation2D::Handler makeRotation2DHandler + ( + const Manipulator< Vector2D >::Handler& body + ) + { + return Rotation2D::Handler + ( + new Rotation2D( body ) + ); + } +//}}} +} // namespace mof diff --git a/moftmp/stream/Rotation2D.hpp~ b/moftmp/stream/Rotation2D.hpp~ new file mode 100755 index 0000000..4cc6c62 --- /dev/null +++ b/moftmp/stream/Rotation2D.hpp~ @@ -0,0 +1,76 @@ +#pragma once +#include "mof/stream/KeyFrameAnimation.hpp" +#include "mof/Matrix2D.hpp" + + +namespace mof{ + + class Rotation2D : public Manipulator< Matrix2D > + { + public: + typedef boost::shared_ptr< Rotation2D > Handler; + + Rotation2D + ( + const std::pair< FrameNumber , mof::Vector2D >& front , + const std::pair< FrameNumber , mof::Vector2D >& back + ) + { + m_body = makeKeyFrameAnimationHandler< Vector2D > + ( + front , back , &linerInterpolate< Vector2D > + ); + } + + Rotation2D + ( + const Manipulator< Vector2D >::Handler& body + ) + : m_body( body ) + { + } + + virtual Matrix2D value( FrameNumber frame ) const + { + return Matrix2D::createRotation( m_body->value(frame) ); + } + + Manipulator::Handler get( ) const + { + return m_body; + } + + void set( const Manipulator< Vector2D >::Handler& handler ) + { + m_body = handler; + } + + private: + Manipulator< Vector2D >::Handler m_body; + + }; +//{{{ ヘルパ関数 + Rotation2D::Handler makeRotation2DHandler + ( + const std::pair< FrameNumber , Vector2D >& front , + const std::pair< FrameNumber , Vector2D >& back + ) + { + return Rotation2D::Handler + ( + new Rotation2D( front , back ) + ); + } + + Rotation2D::Handler makeRotation2DHandler + ( + const Manipulator< Vector2D >::Handler& body + ) + { + return Rotation2D::Handler + ( + new Rotation2D( body ) + ); + } +//}}} +} // namespace mof diff --git a/moftmp/stream/RotationAnimation2D.hpp~ b/moftmp/stream/RotationAnimation2D.hpp~ new file mode 100755 index 0000000..da8fe55 --- /dev/null +++ b/moftmp/stream/RotationAnimation2D.hpp~ @@ -0,0 +1,45 @@ +#ifndef MOF_ROTATION_ANIMATION_2D_HPP +#define MOF_ROTATION_ANIMATION_2D_HPP +#include "mof/KeyFrameAnimation.hpp" +#include +#include +#include +#include "mof/KeyFrameAnimation.hpp" +#include "mof/Matrix2D.hpp" +#include "mof/utilities.hpp" + + +namespace mof{ + + +class RotationAnimation2D : public mof::Animation{ + boost::shared_ptr> m_pBody; +public: + + RotationAnimation2D( + const std::pair& front , + const std::pair& back + ) + { + m_pBody = boost::shared_ptr>( + new mof::KeyFrameAnimation(front , back , &mof::linerInterpolate) + ); + } + + virtual mof::Matrix2D getValue( mof::FrameNumber frame) const{ + return mof::Matrix2D::createRotation(m_pBody->getValue(frame)); + } + + mof::FrameNumber getFinalKeyFrameNumber(){ + return m_pBody->getFinalKeyFrameNumber(); + } + + +}; + + + + +} + +#endif \ No newline at end of file diff --git a/moftmp/stream/RotationAnimation3D.hpp b/moftmp/stream/RotationAnimation3D.hpp new file mode 100755 index 0000000..27dcc12 --- /dev/null +++ b/moftmp/stream/RotationAnimation3D.hpp @@ -0,0 +1,53 @@ + #pragma once + #include "mof/KeyFrameAnimation.hpp" + #include + #include + #include + #include "mof/KeyFrameAnimation.hpp" + #include "mof/Matrix3D.hpp" + + + + namespace mof{ + + + class RotationAnimation3D : public mof::Animation{ + mof::Animation::Handler m_body; + public: + + RotationAnimation3D( + const std::pair& front , + const std::pair& back + ) + { + m_body = mof::Animation::Handler + ( + new mof::KeyFrameAnimation(front , back , &mof::linerInterpolate ) + ); + } + + RotationAnimation3D + ( + const mof::Animation::Handler& body + ) + : m_body( body ) + { + } + + virtual mof::Matrix3D getValue( mof::FrameNumber frame) const{ + return mof::Matrix3D::createRotation(m_body->getValue(frame)); + } + + + /*mof::FrameNumber getFinalKeyFrameNumber(){ + return m_pBody->getFinalKeyFrameNumber(); + }*/ + + + }; + + + + + } //namespace mof + diff --git a/moftmp/stream/RotationAnimation3D.hpp~ b/moftmp/stream/RotationAnimation3D.hpp~ new file mode 100755 index 0000000..27dcc12 --- /dev/null +++ b/moftmp/stream/RotationAnimation3D.hpp~ @@ -0,0 +1,53 @@ + #pragma once + #include "mof/KeyFrameAnimation.hpp" + #include + #include + #include + #include "mof/KeyFrameAnimation.hpp" + #include "mof/Matrix3D.hpp" + + + + namespace mof{ + + + class RotationAnimation3D : public mof::Animation{ + mof::Animation::Handler m_body; + public: + + RotationAnimation3D( + const std::pair& front , + const std::pair& back + ) + { + m_body = mof::Animation::Handler + ( + new mof::KeyFrameAnimation(front , back , &mof::linerInterpolate ) + ); + } + + RotationAnimation3D + ( + const mof::Animation::Handler& body + ) + : m_body( body ) + { + } + + virtual mof::Matrix3D getValue( mof::FrameNumber frame) const{ + return mof::Matrix3D::createRotation(m_body->getValue(frame)); + } + + + /*mof::FrameNumber getFinalKeyFrameNumber(){ + return m_pBody->getFinalKeyFrameNumber(); + }*/ + + + }; + + + + + } //namespace mof + diff --git a/moftmp/stream/Scaling2D.hpp b/moftmp/stream/Scaling2D.hpp new file mode 100755 index 0000000..a21ab0a --- /dev/null +++ b/moftmp/stream/Scaling2D.hpp @@ -0,0 +1,78 @@ +#pragma once +#include "mof/stream/KeyFrameAnimation.hpp" +#include "mof/Matrix2D.hpp" + + +namespace mof{ + + class Scaling2D : public Manipulator< Matrix2D > + { + public: + typedef boost::shared_ptr< Scaling2D > Handler; + + Scaling2D + ( + const std::pair< FrameNumber , mof::Vector2D >& front , + const std::pair< FrameNumber , mof::Vector2D >& back + ) + { + m_body = makeKeyFrameAnimationHandler< Vector2D > + ( + front , back , &linerInterpolate< Vector2D > + ); + } + + Scaling2D + ( + const Manipulator< Vector2D >::Handler& body + ) + : m_body( body ) + { + } + + virtual Matrix2D value( FrameNumber frame ) const + { + return Matrix2D::createScaling( m_body->value(frame) ); + } + + Manipulator::Handler get( ) const + { + return m_body; + } + + void set( const Manipulator< Vector2D >::Handler& handler ) + { + m_body = handler; + } + + private: + Manipulator< Vector2D >::Handler m_body; + + + }; +//{{{ ヘルパ関数 + inline Scaling2D::Handler makeScaling2DHandler + ( + const std::pair< FrameNumber , Vector2D >& front , + const std::pair< FrameNumber , Vector2D >& back + ) + { + return Scaling2D::Handler + ( + new Scaling2D( front , back ) + ); + } + + inline Scaling2D::Handler makeScaling2DHandler + ( + const Manipulator< Vector2D >::Handler& body + ) + { + return Scaling2D::Handler + ( + new Scaling2D( body ) + ); + } +//}}} +} // namespace mof + diff --git a/moftmp/stream/Scaling2D.hpp~ b/moftmp/stream/Scaling2D.hpp~ new file mode 100755 index 0000000..e7480ce --- /dev/null +++ b/moftmp/stream/Scaling2D.hpp~ @@ -0,0 +1,78 @@ +#pragma once +#include "mof/stream/KeyFrameAnimation.hpp" +#include "mof/Matrix2D.hpp" + + +namespace mof{ + + class Scaling2D : public Manipulator< Matrix2D > + { + public: + typedef boost::shared_ptr< Scaling2D > Handler; + + Scaling2D + ( + const std::pair< FrameNumber , mof::Vector2D >& front , + const std::pair< FrameNumber , mof::Vector2D >& back + ) + { + m_body = makeKeyFrameAnimationHandler< Vector2D > + ( + front , back , &linerInterpolate< Vector2D > + ); + } + + Scaling2D + ( + const Manipulator< Vector2D >::Handler& body + ) + : m_body( body ) + { + } + + virtual Matrix2D value( FrameNumber frame ) const + { + return Matrix2D::createScaling( m_body->value(frame) ); + } + + Manipulator::Handler get( ) const + { + return m_body; + } + + void set( const Manipulator< Vector2D >::Handler& handler ) + { + m_body = handler; + } + + private: + Manipulator< Vector2D >::Handler m_body; + + + }; +//{{{ ヘルパ関数 + Scaling2D::Handler makeScaling2DHandler + ( + const std::pair< FrameNumber , Vector2D >& front , + const std::pair< FrameNumber , Vector2D >& back + ) + { + return Scaling2D::Handler + ( + new Scaling2D( front , back ) + ); + } + + Scaling2D::Handler makeScaling2DHandler + ( + const Manipulator< Vector2D >::Handler& body + ) + { + return Scaling2D::Handler + ( + new Scaling2D( body ) + ); + } +//}}} +} // namespace mof + diff --git a/moftmp/stream/ScalingAnimation2D.hpp~ b/moftmp/stream/ScalingAnimation2D.hpp~ new file mode 100755 index 0000000..130829f --- /dev/null +++ b/moftmp/stream/ScalingAnimation2D.hpp~ @@ -0,0 +1,55 @@ +#pragma once +#include +#include "mof/KeyFrameAnimation.hpp" +#include "mof/Matrix2D.hpp" + + +namespace mof{ + + +class ScalingAnimation2D : public mof::Animation{ + mof::Animation::Handler m_body; +public: + typedef boost::shared_ptr< mof::ScalingAnimation2D > Handler; + + ScalingAnimation2D( + const std::pair& front , + const std::pair& back + ) + { + m_body = mof::Animation::Handler + ( + new mof::KeyFrameAnimation(front , back , &mof::linerInterpolate ) + ); + + } + + ScalingAnimation2D + ( + const mof::Animation::Handler& body + ) + : m_body( body ) + { + } + + + virtual mof::Matrix2D getValue( mof::FrameNumber frame) const{ + return mof::Matrix2D::createScaling(m_body->getValue(frame)); + } + + mof::Animation::Handler get( ) const + { + return m_body; + } + + void set( const mof::Animation::Handler& handler ) + { + m_body = handler; + } + + +}; + + +} + diff --git a/moftmp/stream/ScalingAnimation3D.hpp b/moftmp/stream/ScalingAnimation3D.hpp new file mode 100755 index 0000000..90891aa --- /dev/null +++ b/moftmp/stream/ScalingAnimation3D.hpp @@ -0,0 +1,39 @@ + #pragma once + #include "mof/KeyFrameAnimation.hpp" + #include + #include + #include + #include "mof/KeyFrameAnimation.hpp" + #include "mof/Matrix3D.hpp" + + + namespace mof{ + + + class ScalingAnimation3D : public mof::Animation{ + boost::shared_ptr > m_pBody; + public: + + ScalingAnimation3D( + const std::pair& front , + const std::pair& back + ) + { + m_pBody = boost::shared_ptr >( + new mof::KeyFrameAnimation(front , back , &mof::linerInterpolate) + ); + } + + virtual mof::Matrix3D getValue( mof::FrameNumber frame) const{ + return mof::Matrix3D::createScaling(m_pBody->getValue(frame)); + } + + mof::FrameNumber getFinalKeyFrameNumber(){ + return m_pBody->getFinalKeyFrameNumber(); + } + + + }; + + } //namespace mof + diff --git a/moftmp/stream/ScalingAnimation3D.hpp~ b/moftmp/stream/ScalingAnimation3D.hpp~ new file mode 100755 index 0000000..90891aa --- /dev/null +++ b/moftmp/stream/ScalingAnimation3D.hpp~ @@ -0,0 +1,39 @@ + #pragma once + #include "mof/KeyFrameAnimation.hpp" + #include + #include + #include + #include "mof/KeyFrameAnimation.hpp" + #include "mof/Matrix3D.hpp" + + + namespace mof{ + + + class ScalingAnimation3D : public mof::Animation{ + boost::shared_ptr > m_pBody; + public: + + ScalingAnimation3D( + const std::pair& front , + const std::pair& back + ) + { + m_pBody = boost::shared_ptr >( + new mof::KeyFrameAnimation(front , back , &mof::linerInterpolate) + ); + } + + virtual mof::Matrix3D getValue( mof::FrameNumber frame) const{ + return mof::Matrix3D::createScaling(m_pBody->getValue(frame)); + } + + mof::FrameNumber getFinalKeyFrameNumber(){ + return m_pBody->getFinalKeyFrameNumber(); + } + + + }; + + } //namespace mof + diff --git a/moftmp/stream/Stream.hpp~ b/moftmp/stream/Stream.hpp~ new file mode 100755 index 0000000..764c35a --- /dev/null +++ b/moftmp/stream/Stream.hpp~ @@ -0,0 +1,76 @@ +#pragma once +#include +#include "mof/stream/Cascade.hpp" +#include "mof/stream/Constant.hpp" + +namespace mof +{ + + template< typename T , class Cascador = DEFAULT_CASCADOR< T > > + struct TypeStream + { + public: + TypeStream( ) + : m_frameNumber( 0 ) , m_cascade( mof::makeCascadeHandler< T >() ) + { + } + + TypeStream( const typename Cascade< T , Cascador >::Handler& handler ) + : m_frameNumber( 0 ) , m_cascade( handler ) + { + } + + + ~TypeStream( ) + { + } + + typename Cascade< T , Cascador >::Handler& + get() + { + return m_cascador; + } + + typename const Cascade< T , Cascador >::Handler& + get() const + { + return m_cascador; + } + + + TypeStream< T , Cascador >& + operator << + ( + const typename Manipulator< T >::Handler& b + ) + { + m_cascade->add( b ); + return *this; + } + + TypeStream< T , Cascador >& + operator << + ( + const T& b + ) + { + m_cascade->add( mof::makeConstantHandler( b ) ); + return *this; + } + + T value( ) const + { + return m_cascade->value( m_frameNumber ); + } + + void update( ) + { + m_frameNumber++; + } + + private: + FrameNumber m_frameNumber; + typename Cascade< T , Cascador >::Handler m_cascade; + }; + +} // namespace mof diff --git a/moftmp/stream/Translation2D.hpp b/moftmp/stream/Translation2D.hpp new file mode 100755 index 0000000..78a80f9 --- /dev/null +++ b/moftmp/stream/Translation2D.hpp @@ -0,0 +1,80 @@ +#pragma once +#include "mof/stream/KeyFrameAnimation.hpp" +#include "mof/Matrix2D.hpp" + + +namespace mof{ + + class Translation2D : public Manipulator< Matrix2D > + { + public: + typedef boost::shared_ptr< Translation2D > Handler; + + Translation2D + ( + const std::pair< FrameNumber , mof::Vector2D >& front , + const std::pair< FrameNumber , mof::Vector2D >& back + ) + { + m_body = makeKeyFrameAnimationHandler< Vector2D > + ( + front , back , &linerInterpolate< Vector2D > + ); + } + + Translation2D + ( + const Manipulator< Vector2D >::Handler& body + ) + : m_body( body ) + { + } + + virtual Matrix2D value( FrameNumber frame ) const + { + return Matrix2D::createTranslation( m_body->value(frame) ); + } + + Manipulator::Handler get( ) const + { + return m_body; + } + + void set( const Manipulator< Vector2D >::Handler& handler ) + { + m_body = handler; + } + + private: + Manipulator< Vector2D >::Handler m_body; + + + }; + +//{{{ ヘルパ関数 + inline Translation2D::Handler makeTranslation2DHandler + ( + const std::pair< FrameNumber , Vector2D >& front , + const std::pair< FrameNumber , Vector2D >& back + ) + { + return Translation2D::Handler + ( + new Translation2D( front , back ) + ); + } + + inline Translation2D::Handler makeTranslation2DHandler + ( + const Manipulator< Vector2D >::Handler& body + ) + { + return Translation2D::Handler + ( + new Translation2D( body ) + ); + } +//}}} + +} // namespace mof + diff --git a/moftmp/stream/Translation2D.hpp~ b/moftmp/stream/Translation2D.hpp~ new file mode 100755 index 0000000..32574e1 --- /dev/null +++ b/moftmp/stream/Translation2D.hpp~ @@ -0,0 +1,80 @@ +#pragma once +#include "mof/stream/KeyFrameAnimation.hpp" +#include "mof/Matrix2D.hpp" + + +namespace mof{ + + class Translation2D : public Manipulator< Matrix2D > + { + public: + typedef boost::shared_ptr< Translation2D > Handler; + + Translation2D + ( + const std::pair< FrameNumber , mof::Vector2D >& front , + const std::pair< FrameNumber , mof::Vector2D >& back + ) + { + m_body = makeKeyFrameAnimationHandler< Vector2D > + ( + front , back , &linerInterpolate< Vector2D > + ); + } + + Translation2D + ( + const Manipulator< Vector2D >::Handler& body + ) + : m_body( body ) + { + } + + virtual Matrix2D value( FrameNumber frame ) const + { + return Matrix2D::createTranslation( m_body->value(frame) ); + } + + Manipulator::Handler get( ) const + { + return m_body; + } + + void set( const Manipulator< Vector2D >::Handler& handler ) + { + m_body = handler; + } + + private: + Manipulator< Vector2D >::Handler m_body; + + + }; + +//{{{ ヘルパ関数 + Translation2D::Handler makeTranslation2DHandler + ( + const std::pair< FrameNumber , Vector2D >& front , + const std::pair< FrameNumber , Vector2D >& back + ) + { + return Translation2D::Handler + ( + new Translation2D( front , back ) + ); + } + + Translation2D::Handler makeTranslation2DHandler + ( + const Manipulator< Vector2D >::Handler& body + ) + { + return Translation2D::Handler + ( + new Translation2D( body ) + ); + } +//}}} + +} // namespace mof + diff --git a/moftmp/stream/TranslationAnimation2D.hpp~ b/moftmp/stream/TranslationAnimation2D.hpp~ new file mode 100755 index 0000000..91e6bf9 --- /dev/null +++ b/moftmp/stream/TranslationAnimation2D.hpp~ @@ -0,0 +1,96 @@ +#pragma once +#include "mof/stream/KeyFrameAnimation.hpp" +#include "mof/Matrix2D.hpp" + + +namespace mof{ + + class Translation2D : public Manipulator< Matrix2D > + { + public: + typedef boost::shared_ptr< Translation2D > Handler; + + Translation2D + ( + const std::pair< FrameNumber , mof::Vector2D >& front , + const std::pair< FrameNumber , mof::Vector2D >& back + ) + { + m_body = makeKeyFrameAnimationHandler + ( + front , back , &linerInterpolate< Vector2D > + ); + } + + Translation2D + ( + const Manipulator< Vector2D >::Handler& body + ) + : m_body( body ) + { + } + + virtual Matrix2D value( FrameNumber frame ) const + { + return Matrix2D::createTranslation( m_body->value(frame) ); + } + + Manipulator::Handler get( ) const + { + return m_body; + } + + void set( const Manipulator< Vector2D >::Handler& handler ) + { + m_body = handler; + } + + private: + Manipulator< Vector2D >::Handler m_body; + + + }; + +//{{{ ヘルパ関数 + template< typename T > + typename Translation2D< T >::Handler + makeTranslation2DHandler + ( + const std::pair< FrameNumber , T >& front , + const std::pair< FrameNumber , T >& back , + ) + { + return Translation2D< T >::Handler + ( + new Translation2D< T >( front , back ) + ); + } + + template< typename T > + typename Translation2D< T >::Handler + makeTranslation2DHandler + ( + const Manipulator< Vector2D >::Handler& body + ) + { + return Translation2D< T >::Handler + ( + new Translation2D< T >( body ) + ); + } + + template< typename T > + typename KeyFrameAnimation< T >::Handler + makeKeyFrameAnimationHandler + ( + ) + { + return KeyFrameAnimation< T >::Handler + ( + new KeyFrameAnimation< T >( front , back ) + ); + } +//}}} + +} + diff --git a/moftmp/stream/TranslationAnimation3D.hpp b/moftmp/stream/TranslationAnimation3D.hpp new file mode 100755 index 0000000..3761713 --- /dev/null +++ b/moftmp/stream/TranslationAnimation3D.hpp @@ -0,0 +1,53 @@ + #pragma once + #include "mof/KeyFrameAnimation.hpp" + #include + #include + #include + #include "mof/KeyFrameAnimation.hpp" + #include "mof/Matrix3D.hpp" + + + + namespace mof{ + + + class TranslationAnimation3D : public mof::Animation{ + mof::Animation::Handler m_body; + public: + + TranslationAnimation3D + ( + const std::pair& front , + const std::pair& back + ) + { + m_body = mof::Animation::Handler + ( + new mof::KeyFrameAnimation(front , back , &mof::linerInterpolate) + ); + } + + TranslationAnimation3D + ( + const mof::Animation::Handler& body + ) + : m_body( body ) + { + } + + virtual mof::Matrix3D getValue( mof::FrameNumber frame) const{ + return mof::Matrix3D::createTranslation(m_body->getValue(frame)); + } + + /*mof::FrameNumber getFinalKeyFrameNumber(){ + return m_pBody->getFinalKeyFrameNumber(); + }*/ + + + }; + + + + + } //namespace mof + diff --git a/moftmp/stream/TranslationAnimation3D.hpp~ b/moftmp/stream/TranslationAnimation3D.hpp~ new file mode 100755 index 0000000..3761713 --- /dev/null +++ b/moftmp/stream/TranslationAnimation3D.hpp~ @@ -0,0 +1,53 @@ + #pragma once + #include "mof/KeyFrameAnimation.hpp" + #include + #include + #include + #include "mof/KeyFrameAnimation.hpp" + #include "mof/Matrix3D.hpp" + + + + namespace mof{ + + + class TranslationAnimation3D : public mof::Animation{ + mof::Animation::Handler m_body; + public: + + TranslationAnimation3D + ( + const std::pair& front , + const std::pair& back + ) + { + m_body = mof::Animation::Handler + ( + new mof::KeyFrameAnimation(front , back , &mof::linerInterpolate) + ); + } + + TranslationAnimation3D + ( + const mof::Animation::Handler& body + ) + : m_body( body ) + { + } + + virtual mof::Matrix3D getValue( mof::FrameNumber frame) const{ + return mof::Matrix3D::createTranslation(m_body->getValue(frame)); + } + + /*mof::FrameNumber getFinalKeyFrameNumber(){ + return m_pBody->getFinalKeyFrameNumber(); + }*/ + + + }; + + + + + } //namespace mof + diff --git a/moftmp/stream/TypeStream.hpp b/moftmp/stream/TypeStream.hpp new file mode 100755 index 0000000..ea2b497 --- /dev/null +++ b/moftmp/stream/TypeStream.hpp @@ -0,0 +1,94 @@ +#pragma once +#include +#include "mof/stream/Cascade.hpp" +#include "mof/stream/Constant.hpp" +#include "mof/stream/Offset.hpp" + +namespace mof +{ + + template< typename T , class Cascador = DEFAULT_CASCADOR< T > > + class TypeStream + { + public: + TypeStream( ) + : m_frameNumber( 0 ) , m_cascade( mof::makeCascadeHandler< T , Cascador >() ) + {} + + + TypeStream( const typename Manipulator< T >::Handler& handler ) + : m_frameNumber( 0 ) , m_cascade( mof::makeCascadeHandler< T , Cascador >() ) + { + m_cascade << handler; + } + + TypeStream( const T& value ) + : m_frameNumber( 0 ) , m_cascade( mof::makeCascadeHandler< T , Cascador >() ) + { + m_cascade << value; + } + + ~TypeStream( ) + {} + + TypeStream< T , Cascador >& + operator << + ( + const typename Manipulator< T >::Handler& b + ) + { + m_cascade->add + ( + makeOffsetHandler< T >( b , -1 * (int)m_frameNumber) + ); + return *this; + } + + TypeStream< T , Cascador >& + operator << + ( + const TypeStream< T , Cascador >& obj + ) + { + //m_cascade->add( obj.m_cascade ); + m_cascade->add( makeCacheHandler(makeOffsetHandler< T >( obj.m_cascade , obj.m_frameNumber - m_frameNumber) ) ); + return *this; + } + + + TypeStream< T , Cascador >& + operator << + ( + const T& b + ) + { + m_cascade->add( mof::makeConstantHandler( b ) ); + return *this; + } + + T value( ) const + { + return m_cascade->value( m_frameNumber ); + } + + typename Manipulator::Handler toManipulator() + { + return m_cascade; + } + + void update( ) + { + m_frameNumber++; + } + + FrameNumber getCurrentFrameNumber() const + { + return m_frameNumber; + } + + private: + FrameNumber m_frameNumber; + typename Cascade< T , Cascador >::Handler m_cascade; + }; + +} // namespace mof diff --git a/moftmp/stream/TypeStream.hpp~ b/moftmp/stream/TypeStream.hpp~ new file mode 100755 index 0000000..291bbf5 --- /dev/null +++ b/moftmp/stream/TypeStream.hpp~ @@ -0,0 +1,94 @@ +#pragma once +#include +#include "mof/stream/Cascade.hpp" +#include "mof/stream/Constant.hpp" +#include "mof/stream/Offset.hpp" + +namespace mof +{ + + template< typename T , class Cascador = DEFAULT_CASCADOR< T > > + class TypeStream + { + public: + TypeStream( ) + : m_frameNumber( 0 ) , m_cascade( mof::makeCascadeHandler< T , Cascador >() ) + {} + + + TypeStream( const typename Manipulator< T >::Handler& handler ) + : m_frameNumber( 0 ) , m_cascade( mof::makeCascadeHandler< T , Cascador >() ) + { + m_cascade << handler; + } + + TypeStream( const T& value ) + : m_frameNumber( 0 ) , m_cascade( mof::makeCascadeHandler< T , Cascador >() ) + { + m_cascade << value; + } + + ~TypeStream( ) + {} + + TypeStream< T , Cascador >& + operator << + ( + const typename Manipulator< T >::Handler& b + ) + { + m_cascade->add + ( + makeOffsetHandler< T >( b , -1 * (int)m_frameNumber) + ); + return *this; + } + + TypeStream< T , Cascador >& + operator << + ( + const TypeStream< T , Cascador >& obj + ) + { + //m_cascade->add( obj.m_cascade ); + m_cascade->add( makeCacheHandler(makeOffsetHandler< T >( obj.m_cascade , obj.m_frameNumber - m_frameNumber) ) ); + return *this; + } + + + TypeStream< T , Cascador >& + operator << + ( + const T& b + ) + { + m_cascade->add( mof::makeConstantHandler( b ) ); + return *this; + } + + T value( ) const + { + return m_cascade->value( m_frameNumber ); + } + + Manipulator::Handler toManipulator() + { + return m_cascade; + } + + void update( ) + { + m_frameNumber++; + } + + FrameNumber getCurrentFrameNumber() const + { + return m_frameNumber; + } + + private: + FrameNumber m_frameNumber; + typename Cascade< T , Cascador >::Handler m_cascade; + }; + +} // namespace mof diff --git a/moftmp/stream/UniformAnimation.hpp b/moftmp/stream/UniformAnimation.hpp new file mode 100755 index 0000000..4c5b246 --- /dev/null +++ b/moftmp/stream/UniformAnimation.hpp @@ -0,0 +1,48 @@ +#pragma once +#include "mof/Animation.hpp" +#include "mof/Vector3D.hpp" + +namespace mof{ + + class UniformAnimation : public mof::Animation + { + + mof::Vector3D m_initialValue; + mof::Vector3D m_targetValue; + double m_speed; + public: + + UniformAnimation + ( + const mof::Vector3D& initialValue , + const mof::Vector3D& targetValue , + double speed + ) + : m_initialValue(initialValue) , m_targetValue(targetValue) , m_speed(speed) + { + } + + + virtual mof::Vector3D getValue( mof::FrameNumber frame) const + { + + mof::Vector3D direction = ( m_targetValue - m_initialValue ); + direction.normalize(); + mof::Vector3D result = m_initialValue + direction * m_speed * frame;//‘•ª + if( direction.x > 0 && result.x > m_targetValue.x )result.x = m_targetValue.x; + else if( direction.x < 0 && result.x < m_targetValue.x )result.x = m_targetValue.x; + if( direction.y > 0 && result.y > m_targetValue.y )result.y = m_targetValue.y; + else if( direction.y < 0 && result.y < m_targetValue.y )result.y = m_targetValue.y; + if( direction.z > 0 && result.z > m_targetValue.z )result.z = m_targetValue.z; + else if( direction.z < 0 && result.z < m_targetValue.z )result.z = m_targetValue.z; + + return result; + } + + + }; + + + +} //namespace mof + diff --git a/moftmp/stream/UniformAnimation.hpp~ b/moftmp/stream/UniformAnimation.hpp~ new file mode 100755 index 0000000..091c550 --- /dev/null +++ b/moftmp/stream/UniformAnimation.hpp~ @@ -0,0 +1,48 @@ +#pragma once +#include "mof/Animation.hpp" +#include "mof/Vector3D.hpp" + +namespace mof{ + + class UniformAnimation : public mof::Animation + { + + mof::Vector3D m_initialValue; + mof::Vector3D m_targetValue; + double m_speed; + public: + + UniformAnimation + ( + const mof::Vector3D& initialValue , + const mof::Vector3D& targetValue , + double speed + ) + : m_initialValue(initialValue) , m_targetValue(targetValue) , m_speed(speed) + { + } + + + virtual mof::Vector3D getValue( mof::FrameNumber frame) const + { + + mof::Vector3D direction = ( m_targetValue - m_initialValue ); + direction.normalize(); + mof::Vector3D result = m_initialValue + direction * m_speed * frame;//増分 + if( direction.x > 0 && result.x > m_targetValue.x )result.x = m_targetValue.x; + else if( direction.x < 0 && result.x < m_targetValue.x )result.x = m_targetValue.x; + if( direction.y > 0 && result.y > m_targetValue.y )result.y = m_targetValue.y; + else if( direction.y < 0 && result.y < m_targetValue.y )result.y = m_targetValue.y; + if( direction.z > 0 && result.z > m_targetValue.z )result.z = m_targetValue.z; + else if( direction.z < 0 && result.z < m_targetValue.z )result.z = m_targetValue.z; + + return result; + } + + + }; + + + +} //namespace mof + diff --git a/moftmp/stream/mofAnimations.hpp~ b/moftmp/stream/mofAnimations.hpp~ new file mode 100755 index 0000000..6b89a3b --- /dev/null +++ b/moftmp/stream/mofAnimations.hpp~ @@ -0,0 +1,18 @@ + #pragma once + + #include "mof/ParametricAnimation.hpp" + #include "mof/KeyFrameAnimation.hpp" + #include "mof/RotationAnimation3D.hpp" + #include "mof/TranslationAnimation3D.hpp" + #include "mof/ScalingAnimation3D.hpp" + #include "mof/RotationAnimation2D.hpp" + #include "mof/TranslationAnimation2D.hpp" + #include "mof/ScalingAnimation2D.hpp" + #include "mof/Constant.hpp" + #include "mof/CascadingAnimation.hpp" + #include "mof/LoopAnimation.hpp" + #include "mof/Joint.hpp" + #include "mof/dynamic/utilities.hpp" + #include "mof/BoundsAnimation.hpp" + #include "mof/OffsetAnimation.hpp" + #include "mof/Interpolation.hpp" diff --git a/moftmp/stream/utilities.cpp b/moftmp/stream/utilities.cpp new file mode 100755 index 0000000..3cb5465 --- /dev/null +++ b/moftmp/stream/utilities.cpp @@ -0,0 +1,54 @@ +#include "mof/stream/utilities.hpp" +#include "mof/stream/Joint.hpp" +#include + +namespace +{ + mof::Vector2D matrix2translation( const mof::Matrix2D& matrix ) + { + return mof::Matrix2D::getTranslation( matrix ); + } + + mof::Vector2D matrix2scaling( const mof::Matrix2D& matrix ) + { + return matrix.getDiagonal( ); + } + + mof::Vector2D matrix2rotation( const mof::Matrix2D& matrix ) + { + //TODO implementation + return matrix.getDiagonal( ); + } + +} + + +namespace mof +{ + + Manipulator< Vector2D >::Handler + makeTranslation2DHandler( const Manipulator< Matrix2D >::Handler& handler ) + { + return makeJointHandler( handler , &matrix2translation ); + //return makeJointHandler( handler , boost::bind( &matrix2translation ) ); + } + + Manipulator< Vector2D >::Handler + makeScaling2DHandler( const Manipulator< Matrix2D >::Handler& handler ) + { + return makeJointHandler( handler , &matrix2scaling ); + //return makeJointHandler( handler , boost::bind( &matrix2scaling ) ); + } + + + Manipulator< Vector2D >::Handler + makeRotation2DHandler( const Manipulator< Matrix2D >::Handler& handler ) + { + return makeJointHandler( handler , &matrix2rotation ); + //return makeJointHandler( handler , boost::bind( &matrix2rotation ) ); + } + + + +} // namespace mof + diff --git a/moftmp/stream/utilities.cpp~ b/moftmp/stream/utilities.cpp~ new file mode 100755 index 0000000..0a51d5f --- /dev/null +++ b/moftmp/stream/utilities.cpp~ @@ -0,0 +1,54 @@ +#include "mof/stream/utilities.hpp" +#include "mof/stream/Joint.hpp" +#include + +namespace +{ + mof::Vector2D matrix2translation( const mof::Matrix2D& matrix ) + { + return mof::Matrix2D::getTranslation( matrix ); + } + + mof::Vector2D matrix2scaling( const mof::Matrix2D& matrix ) + { + return matrix.getDiagonal( ); + } + + mof::Vector2D matrix2rotation( const mof::Matrix2D& matrix ) + { + //TODO implementation + return matrix.getDiagonal( ); + } + +} + + +namespace mof +{ + + Animation< Vector2D >::Handler + makeTranslation2DHandler( const Animation< Matrix2D >::Handler& handler ) + { + return makeJointHandler( handler , &matrix2translation ); + //return makeJointHandler( handler , boost::bind( &matrix2translation ) ); + } + + Animation< Vector2D >::Handler + makeScaling2DHandler( const Animation< Matrix2D >::Handler& handler ) + { + return makeJointHandler( handler , &matrix2scaling ); + //return makeJointHandler( handler , boost::bind( &matrix2scaling ) ); + } + + + Animation< Vector2D >::Handler + makeRotation2DHandler( const Animation< Matrix2D >::Handler& handler ) + { + return makeJointHandler( handler , &matrix2rotation ); + //return makeJointHandler( handler , boost::bind( &matrix2rotation ) ); + } + + + +} // namespace mof + diff --git a/moftmp/stream/utilities.hpp b/moftmp/stream/utilities.hpp new file mode 100755 index 0000000..64b2900 --- /dev/null +++ b/moftmp/stream/utilities.hpp @@ -0,0 +1,26 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" +#include "mof/stream/TypeStream.hpp" +#include "mof/Vector2D.hpp" +#include "mof/Matrix2D.hpp" +#include "mof/Color.hpp" +#include "mof/Rectangle.hpp" + +namespace mof +{ + typedef TypeStream< Vector2D , Add< Vector2D > > Vector2DStream; + typedef TypeStream< Color4f , Multiply< Color4f > > ColorStream; + typedef TypeStream< Rectangle< float > , Overwrite< Rectangle< float > > > RectangleStream; + + + Manipulator< Vector2D >::Handler + makeTranslation2DHandler( const Manipulator< Matrix2D >::Handler& handler ); + + Manipulator< Vector2D >::Handler + makeScaling2DHandler( const Manipulator< Matrix2D >::Handler& handler ); + + Manipulator< Vector2D >::Handler + makeRotation2DHandler( const Manipulator< Matrix2D >::Handler& handler ); + + +} // namespace mof diff --git a/moftmp/stream/utilities.hpp~ b/moftmp/stream/utilities.hpp~ new file mode 100755 index 0000000..29116cf --- /dev/null +++ b/moftmp/stream/utilities.hpp~ @@ -0,0 +1,26 @@ +#pragma once +#include "mof/stream/Manipulator.hpp" +#include "mof/stream/TypeStream.hpp" +#include "mof/Vector2D.hpp" +#include "mof/Matrix2D.hpp" +#include "mof/Color.hpp" +#include "mof/Rectangle.hpp" + +namespace mof +{ + typedef TypeStream< Vector2D , Add< Vector2D > > Vector2DStream; + typedef TypeStream< Color4f , Multiply< Color4f > > ColorStream; + typedef TypeStream< Rectangle< float > , Add< Rectangle< float > > > RectangleStream; + + + Manipulator< Vector2D >::Handler + makeTranslation2DHandler( const Manipulator< Matrix2D >::Handler& handler ); + + Manipulator< Vector2D >::Handler + makeScaling2DHandler( const Manipulator< Matrix2D >::Handler& handler ); + + Manipulator< Vector2D >::Handler + makeRotation2DHandler( const Manipulator< Matrix2D >::Handler& handler ); + + +} // namespace mof diff --git a/moftmp/streams.hpp b/moftmp/streams.hpp new file mode 100755 index 0000000..21f08a7 --- /dev/null +++ b/moftmp/streams.hpp @@ -0,0 +1,27 @@ +#pragma once + + +#include "mof/stream/TypeStream.hpp" +#include "mof/stream/Manipulator.hpp" +#include "mof/stream/Cascade.hpp" +#include "mof/stream/Constant.hpp" +#include "mof/stream/KeyFrameAnimation.hpp" +#include "mof/stream/Translation2D.hpp" +#include "mof/stream/Rotation2D.hpp" +#include "mof/stream/Scaling2D.hpp" +#include "mof/stream/Loop.hpp" +#include "mof/stream/Joint.hpp" +#include "mof/stream/Offset.hpp" +#include "mof/stream/Reference.hpp" +#include "mof/stream/Filter.hpp" +#include "mof/stream/ReferenceWrapper.hpp" +#include "mof/stream/Cache.hpp" +#include "mof/stream/utilities.hpp" + +/* +#include "mof/ParametricAnimation.hpp" +#include "mof/RotationAnimation3D.hpp" +#include "mof/TranslationAnimation3D.hpp" +#include "mof/ScalingAnimation3D.hpp" +#include "mof/BoundsAnimation.hpp" +*/ diff --git a/moftmp/tests/Alltests.cpp b/moftmp/tests/Alltests.cpp new file mode 100755 index 0000000..3085e77 --- /dev/null +++ b/moftmp/tests/Alltests.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include +#include + +int main( int argc, char* argv[] ) { + // ƒCƒxƒ“ƒgEƒ}ƒl[ƒWƒƒ‚ƃeƒXƒgEƒRƒ“ƒgƒ[ƒ‰‚𐶐¬‚·‚é + CPPUNIT_NS::TestResult controller; + + // ƒeƒXƒgŒ‹‰ÊŽûWƒŠƒXƒi‚ðƒRƒ“ƒgƒ[ƒ‰‚ɃAƒ^ƒbƒ`‚·‚é + CPPUNIT_NS::TestResultCollector result; + controller.addListener( &result ); + + // u.v‚Őisó‹µ‚ðo—Í‚·‚郊ƒXƒi‚ðƒAƒ^ƒbƒ`‚·‚é + CPPUNIT_NS::BriefTestProgressListener progress; + controller.addListener( &progress ); + + // ƒeƒXƒgEƒ‰ƒ“ƒi[‚ɃeƒXƒgŒQ‚ð—^‚¦AƒeƒXƒg‚·‚é + CPPUNIT_NS::TestRunner runner; + runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() ); + runner.run( controller ); + + // ƒeƒXƒgŒ‹‰Ê‚ð•W€o—Í‚É“f‚«o‚· + CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() ); + outputter.write(); + + + return result.wasSuccessful() ? 0 : 1; +} \ No newline at end of file diff --git a/moftmp/tests/SceneGraphTest.cpp b/moftmp/tests/SceneGraphTest.cpp new file mode 100755 index 0000000..bf52ac7 --- /dev/null +++ b/moftmp/tests/SceneGraphTest.cpp @@ -0,0 +1,39 @@ +#include +#include "mof/SceneGraph.hpp" +#include "mof/tstring.hpp" + +class SceneGraphTest : public CPPUNIT_NS::TestFixture { + CPPUNIT_TEST_SUITE( SceneGraphTest ); + CPPUNIT_TEST( test_run ); + CPPUNIT_TEST_SUITE_END(); + +protected: + mof::SceneGraph* c_; + +public: + void setUp(); // + void tearDown(); // + +protected: + void test_run(); // + +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION( SceneGraphTest ); // + +// ŠeƒeƒXƒgEƒP[ƒX‚ÌŽÀs’¼‘O‚ɌĂ΂ê‚é +void SceneGraphTest::setUp() { + c_ = new mof::SceneGraph(); +} + +// ŠeƒeƒXƒgEƒP[ƒX‚ÌŽÀs’¼Œã‚ɌĂ΂ê‚é +void SceneGraphTest::tearDown() { + delete c_; +} + +// ‚±‚êˆÈ~‚̓eƒXƒgEƒP[ƒX‚ÌŽÀ‘•“à—e + +void SceneGraphTest::test_run() { + //CPPUNIT_ASSERT_EQUAL(0, c_->run(NULL)); // +} diff --git a/moftmp/tests/TimerTest.cpp b/moftmp/tests/TimerTest.cpp new file mode 100755 index 0000000..2f686f6 --- /dev/null +++ b/moftmp/tests/TimerTest.cpp @@ -0,0 +1,32 @@ +#include +#include "mof/Timer.hpp" +#include "mof/tstring.hpp" +#include + +class TimerTest : public CPPUNIT_NS::TestFixture { + CPPUNIT_TEST_SUITE( TimerTest ); + CPPUNIT_TEST( test_run ); + CPPUNIT_TEST_SUITE_END(); + +protected: + std::auto_ptr m_pTarget; + +public: + void setUp(); + +protected: + void test_run(); + +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION( TimerTest ); + +void TimerTest::setUp() { + m_pTarget = std::auto_ptr(new mof::Timer()); +} + + +void TimerTest::test_run(){ + +} \ No newline at end of file diff --git a/moftmp/tstring.hpp b/moftmp/tstring.hpp new file mode 100755 index 0000000..89c095e --- /dev/null +++ b/moftmp/tstring.hpp @@ -0,0 +1,13 @@ +#ifndef TSTRING_HPP +#define TSTRING_HPP + +#include +#include +#include + +namespace mof { + typedef std::basic_string tstring; + typedef std::basic_ostringstream otstringstream; +}; + +#endif diff --git a/moftmp/utilities.hpp b/moftmp/utilities.hpp new file mode 100755 index 0000000..17ac91f --- /dev/null +++ b/moftmp/utilities.hpp @@ -0,0 +1,53 @@ +#pragma once +#define _USE_MATH_DEFINES +#include +#include +#define foreach BOOST_FOREACH + +namespace mof{ + + inline float deg2rad( float deg ) + { + return deg / 180.0f * static_cast(M_PI); + } + + inline float rad2deg( float rad ) + { + return rad / static_cast(M_PI) * 180.0f; + } + + template< typename T , int N > + int lengthOf( T (&)[N] ) + { + return N; + } + + template< typename T , int N > + T& lastOf( T(&arr)[N] ) + { + return arr[N-1]; + } + + template< typename T > + void safe_delete( T* (&p) ) + { + delete p; + p = NULL; + } + + template< typename T > + void safe_delete_array( T* (&p) ) + { + delete[] p; + p = NULL; + } + + inline int rotation_mod(int a , unsigned int b) + { + return a >= 0 ? a % b : b - (-a % b); + } + + + +} // namespace mof + diff --git a/moftmp/widget/ButtonWidgetView.hpp~ b/moftmp/widget/ButtonWidgetView.hpp~ new file mode 100755 index 0000000..7199387 --- /dev/null +++ b/moftmp/widget/ButtonWidgetView.hpp~ @@ -0,0 +1,18 @@ +#pragma once +#include "mof/widget/WdigetView.hpp" + +namespace mof +{ + + + class ButtonWidgetView + : + public WidgetView , + { + public: + + virtual FrameNumber blur( bool imidiately = false ) = 0; + + }; + +} diff --git a/moftmp/widget/Container.cpp b/moftmp/widget/Container.cpp new file mode 100755 index 0000000..8ec0825 --- /dev/null +++ b/moftmp/widget/Container.cpp @@ -0,0 +1,174 @@ +#include +#include "mof/mofGraphics.hpp" +#include "mof/utilities.hpp" +#include "mof/widgets.hpp" +#include "mof/streams.hpp" +#include +#include +#include +#include + +using std::auto_ptr; +using boost::shared_ptr; + +namespace mof +{ +namespace widget +{ +//{{{ struct Impl + struct Container::Impl + { + std::vector< shared_ptr > children; + auto_ptr pLayout; + + + Impl() : pLayout(NULL){} + ~Impl(){} + + }; +//}}} +//{{{ constructor + Container::Container + ( + const shared_ptr& front , + const shared_ptr& back , + const FactoryMethod& layout + ) + : + m_pImpl( new Impl( ) ) + { + + int length = (&back - &front) +1; + for(int i = 0 ; i < length ; i++) + { + m_pImpl->children.push_back( (&front)[i] ); + } + + m_pImpl->pLayout = auto_ptr( layout() ); + foreach(shared_ptr pView , m_pImpl->children) + { + m_pImpl->pLayout->add(pView); + } + m_sizeStream << m_pImpl->pLayout->getPreferredSize(); + m_pImpl->pLayout->connect(this); + + for(int i = 0 ; i < length ; i++) + { + m_pImpl->children[i]->getColorStream() << getColorStream(); + } + } +//}}} +//{{{ destructor + Container::~Container() + { + } +//}}} +//{{{ update + void Container::update( ) + { + m_positionStream.update( ); + m_sizeStream.update( ); + m_colorStream.update( ); + foreach(shared_ptr value , m_pImpl->children) + { + value->update(); + } + } +//}}} +//{{{ draw + void Container::draw( ) const + { + foreach(shared_ptr value , m_pImpl->children) + { + value->draw(); + } + + } +//}}} +//{{{ show + FrameNumber Container::show(bool imidiately) + { + unsigned int maxFrame = 0; + foreach(shared_ptr value , m_pImpl->children) + { + maxFrame = max(value->show(imidiately) , maxFrame); + } + return maxFrame; + } +//}}} +//{{{ hide + FrameNumber Container::hide(bool imidiately) + { + unsigned int maxFrame = 0; + foreach(shared_ptr value , m_pImpl->children) + { + maxFrame = max(value->hide(imidiately) , maxFrame); + } + return maxFrame; + + } +//}}} +//{{{ focus + FrameNumber Container::focus(bool) + { + return 0; + } +//}}} +//{{{ blur + FrameNumber Container::blur(bool) + { + return 0; + } +//}}} +//{{{ click + FrameNumber Container::click(bool) + { + return 0; + } +//}}} +//{{{ getAt + shared_ptr Container::getAt(int index) const + { + return m_pImpl->children[index]; + } +//}}} +//{{{ getLength + int Container::getLength() const + { + return m_pImpl->children.size(); + } +//}}} +//{{{ getAdjacentAsUp + int Container::getAdjacencyAsUp(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsUp(index); + } +//}}} +//{{{ getAdjacentAsDown + int Container::getAdjacencyAsDown(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsDown(index); + } +//}}} +//{{{ getAdjacentAsLeft + int Container::getAdjacencyAsLeft(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsLeft(index); + } +//}}} +//{{{ getAdjacentAsRight + int Container::getAdjacencyAsRight(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsRight(index); + } +//}}} +//{{{ add + void Container::add(shared_ptr pView) + { + //children.push_back( pView ); + //m_pImpl->pLayout = adaptWidgetViewAndLayout( m_pImpl->children.begin( ) , m_pImpl->children.end( ) , layout); + } +//}}} + +} +} // namespace mof diff --git a/moftmp/widget/Container.cpp~ b/moftmp/widget/Container.cpp~ new file mode 100755 index 0000000..6e1f7e6 --- /dev/null +++ b/moftmp/widget/Container.cpp~ @@ -0,0 +1,175 @@ +#include +#include "mof/mofGraphics.hpp" +#include "mof/utilities.hpp" +#include "mof/widgets.hpp" +#include "mof/streams.hpp" +#include +#include +#include +#include + +using std::auto_ptr; +using boost::shared_ptr; + +namespace mof +{ +namespace widget +{ +//{{{ struct Impl + struct Container::Impl + { + std::vector< shared_ptr > children; + auto_ptr pLayout; + + + Impl() : pLayout(NULL){} + ~Impl(){} + + }; +//}}} +//{{{ constructor + Container::Container + ( + const shared_ptr& front , + const shared_ptr& back , + const FactoryMethod& layout + ) + : + m_pImpl( new Impl( ) ) + { + + int length = (&back - &front) +1; + for(int i = 0 ; i < length ; i++) + { + m_pImpl->children.push_back( (&front)[i] ); + } + + m_pImpl->pLayout = auto_ptr( layout() ); + foreach(shared_ptr pView , m_pImpl->children) + { + m_pImpl->pLayout->add(pView); + } + DEBUG_PRINT( m_pImpl->pLayout->getPreferredSize()); + m_sizeStream << m_pImpl->pLayout->getPreferredSize(); + m_pImpl->pLayout->connect(this); + + for(int i = 0 ; i < length ; i++) + { + m_pImpl->children[i]->getColorStream() << getColorStream(); + } + } +//}}} +//{{{ destructor + Container::~Container() + { + } +//}}} +//{{{ update + void Container::update( ) + { + m_positionStream.update( ); + m_sizeStream.update( ); + m_colorStream.update( ); + foreach(shared_ptr value , m_pImpl->children) + { + value->update(); + } + } +//}}} +//{{{ draw + void Container::draw( ) const + { + foreach(shared_ptr value , m_pImpl->children) + { + value->draw(); + } + + } +//}}} +//{{{ show + FrameNumber Container::show(bool imidiately) + { + unsigned int maxFrame = 0; + foreach(shared_ptr value , m_pImpl->children) + { + maxFrame = max(value->show(imidiately) , maxFrame); + } + return maxFrame; + } +//}}} +//{{{ hide + FrameNumber Container::hide(bool imidiately) + { + unsigned int maxFrame = 0; + foreach(shared_ptr value , m_pImpl->children) + { + maxFrame = max(value->hide(imidiately) , maxFrame); + } + return maxFrame; + + } +//}}} +//{{{ focus + FrameNumber Container::focus(bool) + { + return 0; + } +//}}} +//{{{ blur + FrameNumber Container::blur(bool) + { + return 0; + } +//}}} +//{{{ click + FrameNumber Container::click(bool) + { + return 0; + } +//}}} +//{{{ getAt + shared_ptr Container::getAt(int index) const + { + return m_pImpl->children[index]; + } +//}}} +//{{{ getLength + int Container::getLength() const + { + return m_pImpl->children.size(); + } +//}}} +//{{{ getAdjacentAsUp + int Container::getAdjacencyAsUp(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsUp(index); + } +//}}} +//{{{ getAdjacentAsDown + int Container::getAdjacencyAsDown(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsDown(index); + } +//}}} +//{{{ getAdjacentAsLeft + int Container::getAdjacencyAsLeft(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsLeft(index); + } +//}}} +//{{{ getAdjacentAsRight + int Container::getAdjacencyAsRight(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsRight(index); + } +//}}} +//{{{ add + void Container::add(shared_ptr pView) + { + //children.push_back( pView ); + //m_pImpl->pLayout = adaptWidgetViewAndLayout( m_pImpl->children.begin( ) , m_pImpl->children.end( ) , layout); + } +//}}} + +} +} // namespace mof diff --git a/moftmp/widget/Container.hpp b/moftmp/widget/Container.hpp new file mode 100755 index 0000000..f4b2c31 --- /dev/null +++ b/moftmp/widget/Container.hpp @@ -0,0 +1,55 @@ +#pragma once +#include "mof/widget/WidgetView.hpp" +#include +#include "mof/FactoryMethod.hpp" +#include "mof/graphics/utilities.hpp" +#include "mof/tstring.hpp" +#include +#include + + + +namespace mof +{ + class Font; + +namespace widget +{ + + class Container + : + public WidgetView + { + public: + + Container + ( + const boost::shared_ptr& front , + const boost::shared_ptr& back , + const FactoryMethod& layout + ); + virtual ~Container( ); + + virtual FrameNumber show( bool imidiately = false ); + virtual FrameNumber hide( bool imidiately = false ); + virtual FrameNumber focus( bool imidiately = false ); + virtual FrameNumber blur( bool imidiately = false ); + virtual FrameNumber click( bool imidiately = false ); + virtual void update( ); + virtual void draw( ) const; + boost::shared_ptr getAt(int index) const; + int getLength() const; + int getAdjacencyAsUp(int index) const; + int getAdjacencyAsDown(int index) const; + int getAdjacencyAsLeft(int index) const; + int getAdjacencyAsRight(int index) const; + void add(boost::shared_ptr pView); + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; + +} +} diff --git a/moftmp/widget/Container.hpp~ b/moftmp/widget/Container.hpp~ new file mode 100755 index 0000000..30c74bf --- /dev/null +++ b/moftmp/widget/Container.hpp~ @@ -0,0 +1,55 @@ +#pragma once +#include "mof/widget/WidgetView.hpp" +#include +#include "mof/FactoryMethod.hpp" +#include "mof/graphics/utilities.hpp" +#include "mof/tstring.hpp" +#include +#include + + + +namespace mof +{ + class Font; + +namespace widget +{ + + class Container + : + public WidgetView + { + public: + + Container + ( + boost::shared_ptr pTop , + const FactoryMethod& last , + const FactoryMethod& layout + ); + virtual ~Container( ); + + virtual FrameNumber show( bool imidiately = false ); + virtual FrameNumber hide( bool imidiately = false ); + virtual FrameNumber focus( bool imidiately = false ); + virtual FrameNumber blur( bool imidiately = false ); + virtual FrameNumber click( bool imidiately = false ); + virtual void update( ); + virtual void draw( ) const; + boost::shared_ptr getAt(int index) const; + int getLength() const; + int getAdjacencyAsUp(int index) const; + int getAdjacencyAsDown(int index) const; + int getAdjacencyAsLeft(int index) const; + int getAdjacencyAsRight(int index) const; + void add(boost::shared_ptr pView); + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; + +} +} diff --git a/moftmp/widget/ContainerWidgetView.cpp~ b/moftmp/widget/ContainerWidgetView.cpp~ new file mode 100755 index 0000000..47b924a --- /dev/null +++ b/moftmp/widget/ContainerWidgetView.cpp~ @@ -0,0 +1,160 @@ +#include +#include "mof/mofGraphics.hpp" +#include +#include "mof/utilities.hpp" +#include "mof/widgets.hpp" +#include "mof/streams.hpp" +#include +#include + +namespace mof +{ +//{{{ struct Impl + struct ContainerWidgetView::Impl + { + std::vector children; + mof::Layout* pLayout; + + Impl() : pLayout(NULL){} + ~Impl(){} + + }; +//}}} +//{{{ constructor + ContainerWidgetView::ContainerWidgetView + ( + const FactoryMethod& front , + const FactoryMethod& last , + const FactoryMethod& layout + ) + : + m_pImpl( new Impl( ) ) + { + + int length = (&last - &front) +1; + for(int i = 0 ; i < length ; i++) + { + m_pImpl->children.push_back((&front)[i]()); + } + + m_pImpl->pLayout = adaptWidgetViewAndLayout(m_pImpl->children , layout); + m_sizeStream << m_pImpl->pLayout->getBounds(); + + for(int i = 0 ; i < length ; i++) + { + m_pImpl->children[i]->getPositionStream() << getPositionStream(); + m_pImpl->children[i]->getColorStream() << getColorStream(); + } + } +//}}} +//{{{ destructor + ContainerWidgetView::~ContainerWidgetView() + { + foreach(WidgetView* value , m_pImpl->children) + { + delete value; + } + } +//}}} +//{{{ update + void ContainerWidgetView::update( ) + { + m_positionStream.update( ); + m_sizeStream.update( ); + m_colorStream.update( ); + foreach(WidgetView* value , m_pImpl->children) + { + value->update(); + } + } +//}}} +//{{{ draw + void ContainerWidgetView::draw( ) const + { + foreach(WidgetView* value , m_pImpl->children) + { + value->draw(); + } + + } +//}}} +//{{{ show + FrameNumber ContainerWidgetView::show(bool imidiately) + { + unsigned int maxFrame = 0; + foreach(WidgetView* value , m_pImpl->children) + { + maxFrame = max(value->show(imidiately) , maxFrame); + } + return maxFrame; + } +//}}} +//{{{ hide + FrameNumber ContainerWidgetView::hide(bool imidiately) + { + int maxFrame = 0; + foreach(WidgetView* value , m_pImpl->children) + { + maxFrame = max(value->hide(imidiately) , maxFrame); + } + return maxFrame; + + } +//}}} +//{{{ focus + FrameNumber ContainerWidgetView::focus(bool) + { + return 0; + } +//}}} +//{{{ blur + FrameNumber ContainerWidgetView::blur(bool) + { + return 0; + } +//}}} +//{{{ click + FrameNumber ContainerWidgetView::click(bool) + { + return 0; + } +//}}} +//{{{ getAt + WidgetView* ContainerWidgetView::getAt(int index) const + { + return m_pImpl->children[index]; + } +//}}} +//{{{ getLength + int ContainerWidgetView::getLength() const + { + return m_pImpl->children.size(); + } +//}}} +//{{{ getAdjacentAsUp + int ContainerWidgetView::getAdjacencyAsUp(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsUp(index); + } +//}}} +//{{{ getAdjacentAsDown + int ContainerWidgetView::getAdjacencyAsDown(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsDown(index); + } +//}}} +//{{{ getAdjacentAsLeft + int ContainerWidgetView::getAdjacencyAsLeft(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsLeft(index); + } +//}}} +//{{{ getAdjacentAsRight + int ContainerWidgetView::getAdjacencyAsRight(int index) const + { + return m_pImpl->pLayout->getAdjacencyAsRight(index); + } +//}}} + + +} // namespace mof diff --git a/moftmp/widget/ContainerWidgetView.hpp~ b/moftmp/widget/ContainerWidgetView.hpp~ new file mode 100755 index 0000000..3b39334 --- /dev/null +++ b/moftmp/widget/ContainerWidgetView.hpp~ @@ -0,0 +1,46 @@ +#pragma once +#include "mof/widget/WidgetView.hpp" +#include +#include "mof/FactoryMethod.hpp" +#include "mof/graphics/utilities.hpp" +#include "mof/tstring.hpp" +#include + +namespace mof +{ + class Font; + + class ContainerWidgetView + : + public WidgetView + { + public: + ContainerWidgetView + ( + const FactoryMethod& front , + const FactoryMethod& last , + const FactoryMethod& layout + ); + virtual ~ContainerWidgetView( ); + + virtual FrameNumber show( bool imidiately = false ); + virtual FrameNumber hide( bool imidiately = false ); + virtual FrameNumber focus( bool imidiately = false ); + virtual FrameNumber blur( bool imidiately = false ); + virtual void update( ); + virtual void draw( ) const; + WidgetView* getAt(int index) const; + int getLength() const; + int getAdjacencyAsUp(int index) const; + int getAdjacencyAsDown(int index) const; + int getAdjacencyAsLeft(int index) const; + int getAdjacencyAsRight(int index) const; + + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; + +} diff --git a/moftmp/widget/Effect.cpp b/moftmp/widget/Effect.cpp new file mode 100755 index 0000000..10db4f3 --- /dev/null +++ b/moftmp/widget/Effect.cpp @@ -0,0 +1,109 @@ +#include "mof/widget/Effect.hpp" +#include +#include "mof/Sprite.hpp" +#include "mof/Drawable.hpp" +#include "mof/utilities.hpp" +#include + +typedef std::map SpriteMap; +typedef std::pair SpriteMapPair; +typedef std::map DrawableMap; +typedef std::pair DrawableMapPair; + + +struct mof::Effect::Impl +{ + SpriteMap spriteMap; + DrawableMap drawableMap; + + Impl(){ + + } + + ~Impl(){ + deleteAll(); + } + + void deleteAll(){ + foreach(DrawableMapPair pair , drawableMap){ + delete pair.second; + } + drawableMap.clear(); + + foreach(SpriteMapPair pair , spriteMap){ + delete pair.second; + } + spriteMap.clear(); + } +}; + + +mof::Effect::Effect() +: m_pImpl(new Impl()) +{ +} + +mof::Effect::~Effect(){ +} + +mof::Sprite* mof::Effect::getSpriteByName(const mof::tstring &name) { + SpriteMap::iterator result = m_pImpl->spriteMap.find(name); + if(result == m_pImpl->spriteMap.end())throw std::invalid_argument(name + "is not exists"); + return result->second; +} + +void mof::Effect::addSprite(const mof::tstring& name , mof::Sprite* pSprite){ + SpriteMap::iterator result = m_pImpl->spriteMap.find(name); + if(result != m_pImpl->spriteMap.end())throw std::invalid_argument(name + "is already exists"); + m_pImpl->spriteMap.insert(SpriteMapPair(name , pSprite)); +} + +void mof::Effect::addDrawable( const mof::tstring& name , mof::Drawable* pDrawable ) +{ + DrawableMap::iterator result = m_pImpl->drawableMap.find(name); + if(result != m_pImpl->drawableMap.end())throw std::invalid_argument(name + "is already exists"); + m_pImpl->drawableMap.insert(DrawableMapPair(name , pDrawable)); +} + +void mof::Effect::remove(const mof::tstring& name ){ + { + SpriteMap::iterator result = m_pImpl->spriteMap.find(name); + if(result != m_pImpl->spriteMap.end()) + { + m_pImpl->spriteMap.erase(name); + return; + } + } + { + DrawableMap::iterator result = m_pImpl->drawableMap.find(name); + if(result != m_pImpl->drawableMap.end()) + { + m_pImpl->drawableMap.erase(name); + return; + } + } + throw std::invalid_argument(name + "is not exists"); +} + +void mof::Effect::deleteAll(){ + m_pImpl->deleteAll(); +} + +void mof::Effect::draw() const +{ + foreach(DrawableMapPair pair , m_pImpl->drawableMap){ + pair.second->draw(); + } + foreach(SpriteMapPair pair , m_pImpl->spriteMap){ + pair.second->draw(); + } +} + + +void mof::Effect::update(){ + foreach(SpriteMapPair pair , m_pImpl->spriteMap){ + pair.second->update(); + } +} + + diff --git a/moftmp/widget/Effect.cpp~ b/moftmp/widget/Effect.cpp~ new file mode 100755 index 0000000..f8bd495 --- /dev/null +++ b/moftmp/widget/Effect.cpp~ @@ -0,0 +1,108 @@ +#include "mof/widget/Effect.hpp" +#include +#include "mof/Sprite.hpp" +#include "mof/Drawable.hpp" +#include "mof/utilities.hpp" +#include + +typedef std::map SpriteMap; +typedef std::pair SpriteMapPair; +typedef std::map DrawableMap; +typedef std::pair DrawableMapPair; + + +struct mof::Effect::Impl +{ + SpriteMap spriteMap; + DrawableMap drawableMap; + + Impl(){ + + } + + ~Impl(){ + deleteAll(); + } + + void deleteAll(){ + foreach(DrawableMapPair pair , drawableMap){ + delete pair.second; + } + drawableMap.clear(); + + foreach(SpriteMapPair pair , spriteMap){ + delete pair.second; + } + spriteMap.clear(); + } +}; + + +mof::Effect::Effect() +: m_pImpl(new Impl()) +{ +} + +mof::Effect::~Effect(){ +} + +mof::Sprite* mof::Effect::getSpriteByName(const mof::tstring &name) { + SpriteMap::iterator result = m_pImpl->spriteMap.find(name); + if(result == m_pImpl->spriteMap.end())throw std::invalid_argument(name + "is not exists"); + return result->second; +} + +void mof::Effect::addSprite(const mof::tstring& name , mof::Sprite* pSprite){ + SpriteMap::iterator result = m_pImpl->spriteMap.find(name); + if(result != m_pImpl->spriteMap.end())throw std::invalid_argument(name + "is already exists"); + m_pImpl->spriteMap.insert(SpriteMapPair(name , pSprite)); +} + +void mof::Effect::addDrawable( const mof::tstring& name , mof::Drawable* pDrawable ) +{ + DrawableMap::iterator result = m_pImpl->drawableMap.find(name); + if(result != m_pImpl->drawableMap.end())throw std::invalid_argument(name + "is already exists"); + m_pImpl->drawableMap.insert(DrawableMapPair(name , pDrawable)); +} + +void mof::Effect::remove(const mof::tstring& name ){ + { + SpriteMap::iterator result = m_pImpl->spriteMap.find(name); + if(result != m_pImpl->spriteMap.end()) + { + m_pImpl->spriteMap.erase(name); + return; + } + } + { + DrawableMap::iterator result = m_pImpl->drawableMap.find(name); + if(result != m_pImpl->drawableMap.end()) + { + m_pImpl->drawableMap.erase(name); + return; + } + } + throw std::invalid_argument(name + "is not exists"); +} + +void mof::Effect::deleteAll(){ + m_pImpl->deleteAll(); +} + +void mof::Effect::draw() const{ + foreach(DrawableMapPair pair , m_pImpl->drawableMap){ + pair.second->draw(); + } + foreach(SpriteMapPair pair , m_pImpl->spriteMap){ + pair.second->draw(); + } +} + + +void mof::Effect::update(){ + foreach(SpriteMapPair pair , m_pImpl->spriteMap){ + pair.second->update(); + } +} + + diff --git a/moftmp/widget/Effect.hpp b/moftmp/widget/Effect.hpp new file mode 100755 index 0000000..4f59aad --- /dev/null +++ b/moftmp/widget/Effect.hpp @@ -0,0 +1,27 @@ +#pragma once +#include +#include +#include "mof/tstring.hpp" + +namespace mof{ + class Sprite; + class Drawable; + + class Effect : boost::noncopyable{ + struct Impl; + boost::scoped_ptr m_pImpl; + public: + Effect(); + ~Effect(); + mof::Sprite* getSpriteByName(const mof::tstring& name); + void addSprite(const mof::tstring& name , mof::Sprite* pSprite); + void addDrawable( const mof::tstring& name , mof::Drawable* pDrawable ); + void remove(const mof::tstring& name); + void deleteAll(); + + void draw() const; + void update(); + }; + + +} diff --git a/moftmp/widget/Effect.hpp~ b/moftmp/widget/Effect.hpp~ new file mode 100755 index 0000000..4f59aad --- /dev/null +++ b/moftmp/widget/Effect.hpp~ @@ -0,0 +1,27 @@ +#pragma once +#include +#include +#include "mof/tstring.hpp" + +namespace mof{ + class Sprite; + class Drawable; + + class Effect : boost::noncopyable{ + struct Impl; + boost::scoped_ptr m_pImpl; + public: + Effect(); + ~Effect(); + mof::Sprite* getSpriteByName(const mof::tstring& name); + void addSprite(const mof::tstring& name , mof::Sprite* pSprite); + void addDrawable( const mof::tstring& name , mof::Drawable* pDrawable ); + void remove(const mof::tstring& name); + void deleteAll(); + + void draw() const; + void update(); + }; + + +} diff --git a/moftmp/widget/Frame.cpp b/moftmp/widget/Frame.cpp new file mode 100755 index 0000000..d7ade2e --- /dev/null +++ b/moftmp/widget/Frame.cpp @@ -0,0 +1,126 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace mof::widget; +using boost::shared_ptr; +using boost::make_shared; +using mof::lastOf; +using std::vector; + +namespace mof +{ +namespace widget +{ +//{{{ Impl + struct Frame::Impl + { + shared_ptr pCaptionView; + shared_ptr pContentBackgroundView; + shared_ptr pTitleBackgroundView; + shared_ptr pContainer; + + Impl() + : + pCaptionView( ) , + pContentBackgroundView( ) , + pContainer( ) + {} + }; +//}}} +//{{{ constructor + Frame::Frame + ( + const mof::tstring& caption , const mof::Font& font , + shared_ptr pContentView , + const FactoryMethod& contentBackground , + const FactoryMethod& titleBackground + ) + : m_pImpl(new Impl) + { + m_pImpl->pCaptionView = make_shared( caption , font ); + m_pImpl->pContentBackgroundView = shared_ptr( contentBackground( ) ); + m_pImpl->pTitleBackgroundView = shared_ptr( titleBackground( ) ); + + { + shared_ptr children[] = { + m_pImpl->pTitleBackgroundView , + m_pImpl->pCaptionView , + }; + m_pImpl->pContainer = make_shared( + children[0] , + lastOf( children ) , + makeFactoryMethod( m_pImpl->pCaptionView->getSizeStream().value() ) + ); + } + + { + shared_ptr children[] = { + m_pImpl->pContainer , + pContentView , + }; + m_pImpl->pContainer = make_shared( + children[0] , + lastOf( children ) , + makeFactoryMethod( GridLayout::VERTICAL , 0 , 10) + ); + } + + { + shared_ptr children[] = { + m_pImpl->pContentBackgroundView , + m_pImpl->pContainer , + }; + m_pImpl->pContainer = make_shared( + children[0] , + lastOf( children ) , + makeFactoryMethod( m_pImpl->pContainer->getSizeStream().value() ) + ); + } + + } +//}}} +//{{{ destructor + Frame::~Frame() + { + } +//}}} +//{{{ show + mof::FrameNumber Frame::show(bool imidiately) + { + return m_pImpl->pContainer->show(imidiately); + } +//}}} +//{{{ hide + mof::FrameNumber Frame::hide(bool imidiately) + { + return m_pImpl->pContainer->hide(imidiately); + } +//}}} +//{{{ getView + const boost::shared_ptr Frame::getView( ) const + { + return m_pImpl->pContainer; + } +//}}} +//{{{ getView + boost::shared_ptr Frame::getView( ) + { + return m_pImpl->pContainer; + } +//}}} +//{{{ update + void Frame::update() + { + m_pImpl->pContainer->update(); + } +//}}} + +} +} diff --git a/moftmp/widget/Frame.cpp~ b/moftmp/widget/Frame.cpp~ new file mode 100755 index 0000000..0bc2f23 --- /dev/null +++ b/moftmp/widget/Frame.cpp~ @@ -0,0 +1,126 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace mof::widget; +using boost::shared_ptr; +using boost::make_shared; +using mof::lastOf; +using std::vector; + +namespace mof +{ +namespace widget +{ +//{{{ Impl + struct Frame::Impl + { + shared_ptr pCaptionView; + shared_ptr pContentBackgroundView; + shared_ptr pTitleBackgroundView; + shared_ptr pContainer; + + Impl() + : + pCaptionView( ) , + pContentBackgroundView( ) , + pContainer( ) + {} + }; +//}}} +//{{{ constructor + Frame::Frame + ( + const mof::tstring& caption , const mof::Font& font , + shared_ptr pContentView , + const FactoryMethod& contentBackground , + const FactoryMethod& titleBackground + ) + : m_pImpl(new Impl) + { + m_pImpl->pCaptionView = make_shared( caption , font ); + m_pImpl->pContentBackgroundView = shared_ptr( contentBackground( ) ); + m_pImpl->pTitleBackgroundView = shared_ptr( titleBackground( ) ); + + { + shared_ptr children[] = { + m_pImpl->pTitleBackgroundView , + m_pImpl->pCaptionView , + }; + m_pImpl->pContainer = make_shared( + children[0] , + lastOf( children ) , + makeFactoryMethod( m_pImpl->pCaptionView->getSizeStream().value() ) + ); + } + + { + shared_ptr children[] = { + m_pImpl->pContainer , + pContentView , + }; + m_pImpl->pContainer = make_shared( + children[0] , + lastOf( children ) , + makeFactoryMethod( GridLayout::VERTICAL , 0 , 20) + ); + } + + { + shared_ptr children[] = { + m_pImpl->pContentBackgroundView , + m_pImpl->pContainer , + }; + m_pImpl->pContainer = make_shared( + children[0] , + lastOf( children ) , + makeFactoryMethod( m_pImpl->pContainer->getSizeStream().value() ) + ); + } + + } +//}}} +//{{{ destructor + Frame::~Frame() + { + } +//}}} +//{{{ show + mof::FrameNumber Frame::show(bool imidiately) + { + return m_pImpl->pContainer->show(imidiately); + } +//}}} +//{{{ hide + mof::FrameNumber Frame::hide(bool imidiately) + { + return m_pImpl->pContainer->hide(imidiately); + } +//}}} +//{{{ getView + const boost::shared_ptr Frame::getView( ) const + { + return m_pImpl->pContainer; + } +//}}} +//{{{ getView + boost::shared_ptr Frame::getView( ) + { + return m_pImpl->pContainer; + } +//}}} +//{{{ update + void Frame::update() + { + m_pImpl->pContainer->update(); + } +//}}} + +} +} diff --git a/moftmp/widget/Frame.hpp b/moftmp/widget/Frame.hpp new file mode 100755 index 0000000..656ecb9 --- /dev/null +++ b/moftmp/widget/Frame.hpp @@ -0,0 +1,43 @@ +#pragma once +#include +#include +#include +#include + +namespace mof +{ + class Font; + +namespace widget +{ + + class Frame : public Widget + { + public: + Frame + ( + const tstring& title , + const Font& font , + boost::shared_ptr content , + const FactoryMethod& contentBackground , + const FactoryMethod& titleBackground + ); + + virtual ~Frame(); + virtual FrameNumber show(bool imidiately = false); + virtual FrameNumber hide(bool imidiately = false); + virtual const boost::shared_ptr getView( ) const; + virtual boost::shared_ptr getView( ); + virtual void update(); + + + + protected: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; + + +} // namespace widget +} // namespace mof diff --git a/moftmp/widget/Frame.hpp~ b/moftmp/widget/Frame.hpp~ new file mode 100755 index 0000000..2f478bd --- /dev/null +++ b/moftmp/widget/Frame.hpp~ @@ -0,0 +1,43 @@ +#pragma once +#include +#include +#include +#include + +namespace mof +{ + class Font; + +namespace widget +{ + + class Frame : public Widget + { + public: + Frame + ( + const tstring& title , + const Font& font , + boost::shared_ptr content , + const FactoryMethod& contentBackground , + const FactoryMethod& titleBackground + ); + + virtual ~Frame(); + virtual FrameNumber show(bool imidiately = false); + virtual FrameNumber hide(bool imidiately = false); + virtual const boost::shared_ptr getView( ) const; + virtual boost::shared_ptr getView( ); + virtual void update(); + + + + protected: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; + + +} // namespace widget +} // namespace mof diff --git a/moftmp/widget/FrameBuilder.hpp b/moftmp/widget/FrameBuilder.hpp new file mode 100755 index 0000000..d6226c0 --- /dev/null +++ b/moftmp/widget/FrameBuilder.hpp @@ -0,0 +1,33 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include + +namespace mof +{ + class Font; +namespace widget +{ + + class FrameBuilder : boost::noncopyable + { + public: + FrameBuilder(); + ~FrameBuilder(); + + void setTitle( const mof::tstring& title , const mof::Font& font ); + void setContentBackgroundView( const mof::FactoryMethod& contentBackground ); + void setTitleBackgroundView( const mof::FactoryMethod& titleBackground ); + std::auto_ptr create( ); + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; // class FrameBuilder +} // namespace widget +} // namespace mof diff --git a/moftmp/widget/FrameBuilder.hpp~ b/moftmp/widget/FrameBuilder.hpp~ new file mode 100755 index 0000000..0a9359a --- /dev/null +++ b/moftmp/widget/FrameBuilder.hpp~ @@ -0,0 +1,33 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include + +namespace mof +{ + class Font; +namespace widget +{ + + class FrameBuilder : boost::noncopyable + { + public: + FrameBuilder(); + ~FrameBuilder(); + + void setTitle( const mof::tstring& title , const mof::Font& font ); + void setContentBackgroundView( const FactoryMethod& contentBackground ); + void setTitleBackgroundView( const FactoryMethod& titleBackground ); + std::auto_ptr create( ); + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; // class FrameBuilder +} // namespace widget +} // namespace mof diff --git a/moftmp/widget/GridLayout.cpp b/moftmp/widget/GridLayout.cpp new file mode 100755 index 0000000..d50e35e --- /dev/null +++ b/moftmp/widget/GridLayout.cpp @@ -0,0 +1,144 @@ +#include +#include +#include +#include +#include "mof/ConsoleIO.hpp" +#include +#include + +using boost::shared_ptr; + +//{{{ Impl +struct mof::widget::GridLayout::Impl +{ + + mof::widget::GridLayout::Direction direction; + int span , margin; + int width , height;// preferredSize + std::vector< shared_ptr > views; + std::vector positions; + + Impl(Direction _direction , int span_ , int margin_ ) + : + direction(_direction) , span(span_) , margin(margin_) , + width(0) , height(0) + {} + + + ~Impl() + { + } +}; +//}}} +//{{{ GridLayout +mof::widget::GridLayout::GridLayout +( + Direction direction , int span , int margin +) +: m_pImpl( new Impl( direction , span , margin ) ) +{ +} +//}}} +//{{{ ~GridLayout +mof::widget::GridLayout::~GridLayout( ) +{ +} +//}}} +//{{{ add +void mof::widget::GridLayout::add(shared_ptr pView) +{ + mof::Vector2D size = pView->getSizeStream().value(); + m_pImpl->views.push_back(pView); + + if(m_pImpl->direction == VERTICAL) + { + m_pImpl->positions.push_back( mof::Vector2D(0 , m_pImpl->height)); + if( !m_pImpl->views.empty( ) )m_pImpl->height += m_pImpl->margin; + m_pImpl->width = m_pImpl->width < size.x + ? mof::real2int(size.x) + : m_pImpl->width; + m_pImpl->height += mof::real2int(size.y); + } + else if(m_pImpl->direction == HORIZONTAL) + { + m_pImpl->positions.push_back( mof::Vector2D(m_pImpl->width , 0)); + if( !m_pImpl->views.empty( ) )m_pImpl->width += m_pImpl->margin; + m_pImpl->width += mof::real2int(size.x); + m_pImpl->height = m_pImpl->height < size.y + ? mof::real2int(size.y) + : m_pImpl->height; + } +} +//}}} +//{{{ getLength +size_t mof::widget::GridLayout::getLength() const +{ + return m_pImpl->positions.size(); +} +//}}} +//{{{ getPreferredSize +mof::Vector2D mof::widget::GridLayout::getPreferredSize() const +{ + return mof::Vector2D(m_pImpl->width , m_pImpl->height); +} +//}}} +//{{{ getSizeDependencyType +mof::widget::Layout::DependencyType mof::widget::GridLayout::getSizeDependencyType() const +{ + return mof::widget::Layout::PARENT_LEADING; +} +//}}} +//{{{ connect +void mof::widget::GridLayout::connect(WidgetView* pParentView) +{ + size_t i = 0; + if(m_pImpl->direction == VERTICAL) + { + foreach(shared_ptr pView , m_pImpl->views) + { + pView->getPositionStream() << m_pImpl->positions[i++] << pParentView->getPositionStream(); + mof::Vector2D filter(1 , 0); + mof::Vector2D offset(-1.0f * pView->getSizeStream().value().x , 0.0f); + pView->getSizeStream() + << offset + << mof::makeFilterHandler(pParentView->getSizeStream().toManipulator() , filter); + } + } + else + { + foreach(shared_ptr pView , m_pImpl->views) + { + pView->getPositionStream() << m_pImpl->positions[i++] << pParentView->getPositionStream(); + pView->getSizeStream() << -pView->getSizeStream().value() << pParentView->getSizeStream(); + } + } +} +//}}} +//{{{ getAdjacencyAsUp +int mof::widget::GridLayout::getAdjacencyAsUp(int index) const +{ + if(m_pImpl->direction == VERTICAL)return mof::rotation_mod(index-1 , m_pImpl->positions.size()); + else return index; +} +//}}} +//{{{ getAdjacencyAsDown +int mof::widget::GridLayout::getAdjacencyAsDown(int index) const +{ + if(m_pImpl->direction == VERTICAL)return mof::rotation_mod(index+1 , m_pImpl->positions.size()); + else return index; +} +//}}} +//{{{ getAdjacencyAsLeft +int mof::widget::GridLayout::getAdjacencyAsLeft(int index) const +{ + if(m_pImpl->direction == HORIZONTAL)return mof::rotation_mod(index-1 , m_pImpl->positions.size()); + else return index; +} +//}}} +//{{{ getAdjacencyAsRight +int mof::widget::GridLayout::getAdjacencyAsRight(int index) const +{ + if(m_pImpl->direction == HORIZONTAL)return mof::rotation_mod(index+1 , m_pImpl->positions.size()); + else return index; +} +//}}} diff --git a/moftmp/widget/GridLayout.cpp~ b/moftmp/widget/GridLayout.cpp~ new file mode 100755 index 0000000..cf524cd --- /dev/null +++ b/moftmp/widget/GridLayout.cpp~ @@ -0,0 +1,144 @@ +#include +#include +#include +#include +#include "mof/ConsoleIO.hpp" +#include +#include + +using boost::shared_ptr; + +//{{{ Impl +struct mof::widget::GridLayout::Impl +{ + + mof::widget::GridLayout::Direction direction; + int span , margin; + int width , height;// preferredSize + std::vector< shared_ptr > views; + std::vector positions; + + Impl(Direction _direction , int span_ , int margin_ ) + : + direction(_direction) , span(span_) , margin(margin_) , + width(0) , height(0) + {} + + + ~Impl() + { + } +}; +//}}} +//{{{ GridLayout +mof::widget::GridLayout::GridLayout +( + Direction direction , int span , int margin +) +: m_pImpl( new Impl( direction , span , margin ) ) +{ +} +//}}} +//{{{ ~GridLayout +mof::widget::GridLayout::~GridLayout( ) +{ +} +//}}} +//{{{ add +void mof::widget::GridLayout::add(shared_ptr pView) +{ + mof::Vector2D size = pView->getSizeStream().value(); + m_pImpl->views.push_back(pView); + + if(m_pImpl->direction == VERTICAL) + { + //if( !m_pImpl->views.empty( ) )m_pImpl->height += m_pImpl->margin; + m_pImpl->positions.push_back( mof::Vector2D(0 , m_pImpl->height)); + m_pImpl->width = m_pImpl->width < size.x + ? mof::real2int(size.x) + : m_pImpl->width; + m_pImpl->height += mof::real2int(size.y); + } + else if(m_pImpl->direction == HORIZONTAL) + { + if( !m_pImpl->views.empty( ) )m_pImpl->width += m_pImpl->margin; + m_pImpl->positions.push_back( mof::Vector2D(m_pImpl->width , 0)); + m_pImpl->width += mof::real2int(size.x); + m_pImpl->height = m_pImpl->height < size.y + ? mof::real2int(size.y) + : m_pImpl->height; + } +} +//}}} +//{{{ getLength +size_t mof::widget::GridLayout::getLength() const +{ + return m_pImpl->positions.size(); +} +//}}} +//{{{ getPreferredSize +mof::Vector2D mof::widget::GridLayout::getPreferredSize() const +{ + return mof::Vector2D(m_pImpl->width , m_pImpl->height); +} +//}}} +//{{{ getSizeDependencyType +mof::widget::Layout::DependencyType mof::widget::GridLayout::getSizeDependencyType() const +{ + return mof::widget::Layout::PARENT_LEADING; +} +//}}} +//{{{ connect +void mof::widget::GridLayout::connect(WidgetView* pParentView) +{ + size_t i = 0; + if(m_pImpl->direction == VERTICAL) + { + foreach(shared_ptr pView , m_pImpl->views) + { + pView->getPositionStream() << m_pImpl->positions[i++] << pParentView->getPositionStream(); + mof::Vector2D filter(1 , 0); + mof::Vector2D offset(-1.0f * pView->getSizeStream().value().x , 0.0f); + pView->getSizeStream() + << offset + << mof::makeFilterHandler(pParentView->getSizeStream().toManipulator() , filter); + } + } + else + { + foreach(shared_ptr pView , m_pImpl->views) + { + pView->getPositionStream() << m_pImpl->positions[i++] << pParentView->getPositionStream(); + pView->getSizeStream() << -pView->getSizeStream().value() << pParentView->getSizeStream(); + } + } +} +//}}} +//{{{ getAdjacencyAsUp +int mof::widget::GridLayout::getAdjacencyAsUp(int index) const +{ + if(m_pImpl->direction == VERTICAL)return mof::rotation_mod(index-1 , m_pImpl->positions.size()); + else return index; +} +//}}} +//{{{ getAdjacencyAsDown +int mof::widget::GridLayout::getAdjacencyAsDown(int index) const +{ + if(m_pImpl->direction == VERTICAL)return mof::rotation_mod(index+1 , m_pImpl->positions.size()); + else return index; +} +//}}} +//{{{ getAdjacencyAsLeft +int mof::widget::GridLayout::getAdjacencyAsLeft(int index) const +{ + if(m_pImpl->direction == HORIZONTAL)return mof::rotation_mod(index-1 , m_pImpl->positions.size()); + else return index; +} +//}}} +//{{{ getAdjacencyAsRight +int mof::widget::GridLayout::getAdjacencyAsRight(int index) const +{ + if(m_pImpl->direction == HORIZONTAL)return mof::rotation_mod(index+1 , m_pImpl->positions.size()); + else return index; +} +//}}} diff --git a/moftmp/widget/GridLayout.hpp b/moftmp/widget/GridLayout.hpp new file mode 100755 index 0000000..0557194 --- /dev/null +++ b/moftmp/widget/GridLayout.hpp @@ -0,0 +1,38 @@ +#pragma once +#include +#include + +namespace mof +{ +namespace widget +{ + + class GridLayout : public Layout + { + + public: + enum Direction + { + HORIZONTAL , VERTICAL + }; + + GridLayout(Direction direction , int span , int margin = 0 ); + virtual ~GridLayout(); + virtual void add(boost::shared_ptr pView); + virtual Vector2D getPreferredSize() const; + virtual DependencyType getSizeDependencyType() const; + virtual void connect(WidgetView* pParentView); + virtual size_t getLength( ) const; + virtual int getAdjacencyAsUp(int index) const; + virtual int getAdjacencyAsDown(int index) const; + virtual int getAdjacencyAsLeft(int index) const; + virtual int getAdjacencyAsRight(int index) const; + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} +} // namepsace mof + diff --git a/moftmp/widget/GridLayout.hpp~ b/moftmp/widget/GridLayout.hpp~ new file mode 100755 index 0000000..011b511 --- /dev/null +++ b/moftmp/widget/GridLayout.hpp~ @@ -0,0 +1,38 @@ +#pragma once +#include +#include + +namespace mof +{ +namespace widget +{ + + class GridLayout : public Layout + { + + public: + enum Direction + { + HORIZONTAL , VERTICAL + }; + + GridLayout(Direction direction , int span , int margin = 0 ); + virtual ~GridLayout(); + virtual void add(boost::shared_ptr pView); + virtual Vector2D getPreferredSize() const; + virtual DependencyType getSizeDependencyType() const; + virtual void connect( boost::shared_ptr pParentView); + virtual size_t getLength( ) const; + virtual int getAdjacencyAsUp(int index) const; + virtual int getAdjacencyAsDown(int index) const; + virtual int getAdjacencyAsLeft(int index) const; + virtual int getAdjacencyAsRight(int index) const; + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} +} // namepsace mof + diff --git a/moftmp/widget/ImageView.cpp b/moftmp/widget/ImageView.cpp new file mode 100755 index 0000000..ef1c434 --- /dev/null +++ b/moftmp/widget/ImageView.cpp @@ -0,0 +1,117 @@ +#include +#include "mof/mofGraphics.hpp" +#include "mof/Font.hpp" +#include "mof/Sprite.hpp" +#include "mof/widget/Effect.hpp" +#include "mof/utilities.hpp" +#include "mof/widgets.hpp" +#include "mof/streams.hpp" + +namespace mof +{ +namespace widget +{ +//{{{ struct Impl + struct ImageView::Impl + { + Sprite* pSprite; + + Impl( ) + : pSprite( NULL ) + { + } + + ~Impl() + { + delete pSprite; + } + + }; +//}}} +//{{{ constructor + ImageView::ImageView + ( + const tstring& caption , + const Font& font + ) + : + m_pImpl( new Impl ) + { + { // 画像の生成 + m_pImpl->pSprite = Sprite::createTextSprite( font , caption ); + m_pImpl->pSprite->getPositionStream( ) << getPositionStream( ); + m_pImpl->pSprite->getColorStream( ) << getColorStream( ); + m_sizeStream << m_pImpl->pSprite->getSizeStream( ); //ビューのサイズを設定 + } + } +//}}} +//{{{ constructor + ImageView::ImageView + ( + const TextureHandler& texture , + const Rectangle& tRect + ) + : + m_pImpl( new Impl( ) ) + { + { // 画像の生成 + m_pImpl->pSprite = new Sprite( texture , tRect ); + m_pImpl->pSprite->getPositionStream( ) << getPositionStream( ); + m_pImpl->pSprite->getColorStream( ) << getColorStream( ); + m_sizeStream << m_pImpl->pSprite->getSizeStream( ); //ビューのサイズを設定 + } + + } +//}}} +//{{{ destructor + ImageView::~ImageView() + { + } +//}}} +//{{{ update + void ImageView::update( ) + { + m_positionStream.update( ); + m_sizeStream.update( ); + m_colorStream.update( ); + m_pImpl->pSprite->update(); + } +//}}} +//{{{ draw + void ImageView::draw( ) const + { + m_pImpl->pSprite->draw( ); + } +//}}} +//{{{ show + FrameNumber ImageView::show(bool) + { + return 0; + } +//}}} +//{{{ hide + FrameNumber ImageView::hide(bool) + { + return 0; + } +//}}} +//{{{ focus + FrameNumber ImageView::focus(bool) + { + return 0; + } +//}}} +//{{{ blur + FrameNumber ImageView::blur(bool imidiately) + { + return 0; + } +//}}} +//{{{ click + FrameNumber ImageView::click(bool) + { + return 0; + } +//}}} +} +} // namespace mof diff --git a/moftmp/widget/ImageView.cpp~ b/moftmp/widget/ImageView.cpp~ new file mode 100755 index 0000000..cb35bc5 --- /dev/null +++ b/moftmp/widget/ImageView.cpp~ @@ -0,0 +1,118 @@ +#include +#include "mof/mofGraphics.hpp" +#include "mof/Font.hpp" +#include "mof/Sprite.hpp" +#include "mof/widget/Effect.hpp" +#include "mof/utilities.hpp" +#include "mof/widgets.hpp" +#include "mof/streams.hpp" + +namespace mof +{ +namespace widget +{ +//{{{ struct Impl + struct ImageView::Impl + { + Sprite* pSprite; + + Impl( ) + : pSprite( NULL ) + { + } + + ~Impl() + { + delete pSprite; + } + + }; +//}}} +//{{{ constructor + ImageView::ImageView + ( + const tstring& caption , + const Font& font + ) + : + m_pImpl( new Impl ) + { + { // 画像の生成 + m_pImpl->pSprite = Sprite::createTextSprite( font , caption ); + m_pImpl->pSprite->getPositionStream( ) << getPositionStream( ); + m_pImpl->pSprite->getColorStream( ) << getColorStream( ); + m_sizeStream << m_pImpl->pSprite->getSizeStream( ); //ビューのサイズを設定 + } + } +//}}} +//{{{ constructor + ImageView::ImageView + ( + const TextureHandler& texture , + const Rectangle& tRect + ) + : + m_pImpl( new Impl( ) ) + { + { // 画像の生成 + m_pImpl->pSprite = new Sprite( texture , tRect ); + m_pImpl->pSprite->getPositionStream( ) << getPositionStream( ); + m_pImpl->pSprite->getColorStream( ) << getColorStream( ); + m_sizeStream << m_pImpl->pSprite->getSizeStream( ); //ビューのサイズを設定 + } + + } +//}}} +//{{{ destructor + ImageView::~ImageView() + { + } +//}}} +//{{{ update + void ImageView::update( ) + { + m_positionStream.update( ); + m_sizeStream.update( ); + m_colorStream.update( ); + m_pImpl->pSprite->update(); + } +//}}} +//{{{ draw + void ImageView::draw( ) const + { + m_pImpl->pSprite->draw( ); + } +//}}} +//{{{ show + FrameNumber ImageView::show(bool) + { + return 0; + } +//}}} +//{{{ hide + FrameNumber ImageView::hide(bool) + { + return 0; + } +//}}} +//{{{ focus + FrameNumber ImageView::focus(bool) + { + return 0; + } +//}}} +//{{{ blur + FrameNumber ImageView::blur(bool imidiately) + { + return 0; + } +//}}} +//{{{ click + FrameNumber ImageView::click(bool) + { + return 0; + } +//}}} + +} +} // namespace mof diff --git a/moftmp/widget/ImageView.hpp b/moftmp/widget/ImageView.hpp new file mode 100755 index 0000000..337aca3 --- /dev/null +++ b/moftmp/widget/ImageView.hpp @@ -0,0 +1,38 @@ +#pragma once +#include "mof/widget/WidgetView.hpp" +#include "mof/graphics/utilities.hpp" +#include "mof/tstring.hpp" +#include + +namespace mof +{ + class Font; + +namespace widget +{ + + class ImageView + : + public WidgetView + { + public: + ImageView( const tstring& caption , const Font& font ); + ImageView( const TextureHandler& texture , const Rectangle& tRect ); + virtual ~ImageView( ); + + virtual FrameNumber show( bool imidiately = false ); + virtual FrameNumber hide( bool imidiately = false ); + virtual FrameNumber focus( bool imidiately = false ); + virtual FrameNumber blur( bool imidiately = false ); + virtual FrameNumber click( bool imidiately = false ); + virtual void update( ); + virtual void draw( ) const; + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; + +} +} diff --git a/moftmp/widget/ImageView.hpp~ b/moftmp/widget/ImageView.hpp~ new file mode 100755 index 0000000..f69f2dd --- /dev/null +++ b/moftmp/widget/ImageView.hpp~ @@ -0,0 +1,38 @@ +#pragma once +#include "mof/widget/WidgetView.hpp" +#include "mof/graphics/utilities.hpp" +#include "mof/tstring.hpp" +#include + +namespace mof +{ +namespace widget +{ + + class Font; + + class ImageView + : + public WidgetView + { + public: + ImageView( const tstring& caption , const Font& font ); + ImageView( const TextureHandler& texture , const Rectangle& tRect ); + virtual ~ImageView( ); + + virtual FrameNumber show( bool imidiately = false ); + virtual FrameNumber hide( bool imidiately = false ); + virtual FrameNumber focus( bool imidiately = false ); + virtual FrameNumber blur( bool imidiately = false ); + virtual FrameNumber click( bool imidiately = false ); + virtual void update( ); + virtual void draw( ) const; + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; + +} +} diff --git a/moftmp/widget/ImageWidgetView.cpp~ b/moftmp/widget/ImageWidgetView.cpp~ new file mode 100755 index 0000000..86999b7 --- /dev/null +++ b/moftmp/widget/ImageWidgetView.cpp~ @@ -0,0 +1,115 @@ +#include +#include "mof/mofGraphics.hpp" +#include "mof/Font.hpp" +#include "mof/Sprite.hpp" +#include "mof/widget/Effect.hpp" +#include "mof/utilities.hpp" +#include "mof/widgets.hpp" +#include "mof/streams.hpp" + +namespace mof +{ +//{{{ struct Impl + struct ImageWidgetView::Impl + { + Sprite* pSprite; + + Impl( ) + : pSprite( NULL ) + { + } + + ~Impl() + { + delete pSprite; + } + + }; +//}}} +//{{{ constructor + ImageWidgetView::ImageWidgetView + ( + const tstring& caption , + const Font& font + ) + : + m_pImpl( new Impl( ) ) + { + { // 画像の生成 + m_pImpl->pSprite = Sprite::createTextSprite( font , caption ); + m_pImpl->pSprite->getPositionStream( ) << getPositionStream( ); + m_pImpl->pSprite->getColorStream( ) << getColorStream( ); + m_sizeStream << m_pImpl->pSprite->getSizeStream( ); //ビューのサイズを設定 + } + } +//}}} +//{{{ constructor + ImageWidgetView::ImageWidgetView + ( + const TextureHandler& texture , + const Rectangle& tRect + ) + : + m_pImpl( new Impl( ) ) + { + { // 画像の生成 + m_pImpl->pSprite = new Sprite( texture , tRect ); + m_pImpl->pSprite->getPositionStream( ) << getPositionStream( ); + m_pImpl->pSprite->getColorStream( ) << getColorStream( ); + m_sizeStream << m_pImpl->pSprite->getSizeStream( ); //ビューのサイズを設定 + } + + } +//}}} +//{{{ destructor + ImageWidgetView::~ImageWidgetView() + { + } +//}}} +//{{{ update + void ImageWidgetView::update( ) + { + m_positionStream.update( ); + m_sizeStream.update( ); + m_colorStream.update( ); + m_pImpl->pSprite->update(); + } +//}}} +//{{{ draw + void ImageWidgetView::draw( ) const + { + m_pImpl->pSprite->draw( ); + } +//}}} +//{{{ show + FrameNumber ImageWidgetView::show( bool imidiately ) + { + return 0; + } +//}}} +//{{{ hide + FrameNumber ImageWidgetView::hide( bool imidiately ) + { + return 0; + } +//}}} +//{{{ focus + FrameNumber ImageWidgetView::focus( bool imidiately ) + { + return 0; + } +//}}} +//{{{ blur + FrameNumber ImageWidgetView::blur( bool imidiately ) + { + return 0; + } +//}}} +//{{{ click + FrameNumber ImageWidgetView::click( bool imidiately ) + { + return 0; + } +//}}} + +} // namespace mof diff --git a/moftmp/widget/ImageWidgetView.hpp~ b/moftmp/widget/ImageWidgetView.hpp~ new file mode 100755 index 0000000..e6f7d69 --- /dev/null +++ b/moftmp/widget/ImageWidgetView.hpp~ @@ -0,0 +1,33 @@ +#pragma once +#include "mof/widget/WidgetView.hpp" +#include "mof/graphics/utilities.hpp" +#include "mof/tstring.hpp" +#include + +namespace mof +{ + class Font; + + class ImageWidgetView + : + public WidgetView + { + public: + ImageWidgetView( const tstring& caption , const Font& font ); + ImageWidgetView( const TextureHandler& texture , const Rectangle& tRect ); + virtual ~ImageWidgetView( ); + + virtual FrameNumber show( bool imidiately = false ); + virtual FrameNumber hide( bool imidiately = false ); + virtual FrameNumber focus( bool imidiately = false ); + virtual FrameNumber blur( bool imidiately = false ); + virtual void update( ); + virtual void draw( ) const; + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + + }; + +} diff --git a/moftmp/widget/Layout.hpp b/moftmp/widget/Layout.hpp new file mode 100755 index 0000000..3abfb3b --- /dev/null +++ b/moftmp/widget/Layout.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include "mof/Vector2D.hpp" +#include "mof/Rectangle.hpp" +#include + +namespace mof +{ +namespace widget +{ + class WidgetView; + + class Layout + { + + public: + enum DependencyType + { + PARENT_LEADING , + CHILD_LEADING + }; + + virtual ~Layout(){} + virtual void add(boost::shared_ptr pView) = 0; + virtual Vector2D getPreferredSize() const = 0; + virtual DependencyType getSizeDependencyType() const = 0; + virtual void connect( WidgetView* pParentView) = 0; + virtual size_t getLength() const = 0; + virtual int getAdjacencyAsUp(int index) const = 0; + virtual int getAdjacencyAsDown(int index) const = 0; + virtual int getAdjacencyAsLeft(int index) const = 0; + virtual int getAdjacencyAsRight(int index) const = 0; + }; +} +} diff --git a/moftmp/widget/Layout.hpp~ b/moftmp/widget/Layout.hpp~ new file mode 100755 index 0000000..3abfb3b --- /dev/null +++ b/moftmp/widget/Layout.hpp~ @@ -0,0 +1,35 @@ +#pragma once + +#include "mof/Vector2D.hpp" +#include "mof/Rectangle.hpp" +#include + +namespace mof +{ +namespace widget +{ + class WidgetView; + + class Layout + { + + public: + enum DependencyType + { + PARENT_LEADING , + CHILD_LEADING + }; + + virtual ~Layout(){} + virtual void add(boost::shared_ptr pView) = 0; + virtual Vector2D getPreferredSize() const = 0; + virtual DependencyType getSizeDependencyType() const = 0; + virtual void connect( WidgetView* pParentView) = 0; + virtual size_t getLength() const = 0; + virtual int getAdjacencyAsUp(int index) const = 0; + virtual int getAdjacencyAsDown(int index) const = 0; + virtual int getAdjacencyAsLeft(int index) const = 0; + virtual int getAdjacencyAsRight(int index) const = 0; + }; +} +} diff --git a/moftmp/widget/LayoutManager.cpp~ b/moftmp/widget/LayoutManager.cpp~ new file mode 100755 index 0000000..55ab9d0 --- /dev/null +++ b/moftmp/widget/LayoutManager.cpp~ @@ -0,0 +1,73 @@ +#include "mof/LayoutManager.hpp" +#include "mof/ConsoleIO.hpp" + + + + +struct mof::LayoutManager::Impl{ + + mof::LayoutManager::Direction direction; + int span; + int length; + unsigned int width; + unsigned int height; + mof::Vector2D* positions; + + + Impl( Direction _direction , int _n ) + : direction(_direction) , span(_n) , + width(0) , height(0) , length(0) , positions(NULL) + { + } + + ~Impl(){ + delete[] positions; + } +}; + + +mof::LayoutManager::LayoutManager +( + Direction direction , int n +) +: m_pImpl( new Impl( direction , n ) ) +{ +} + + +mof::LayoutManager::~LayoutManager( ) +{ +} + +void mof::LayoutManager::replace +( + unsigned int width , + unsigned int height, + const mof::Rectangle &front , + const mof::Rectangle &back +) +{ + m_pImpl->width = width; + m_pImpl->height = height; + m_pImpl->length = &back - &front + 1; + if(m_pImpl->length <= 0)throw std::invalid_argument("the length of front-back is less than zero"); + + delete[] m_pImpl->positions; + m_pImpl->positions = new mof::Vector2D[m_pImpl->length]; + + //TODO X Layout + int sumOfY = 0; + for(int i = 0 ; i < m_pImpl->length ; ++i){ + m_pImpl->positions[i] = mof::Vector2D( 0 , sumOfY ); + sumOfY += (&front)[i].endY - (&front)[i].beginY; + } + +} + +mof::Vector2D mof::LayoutManager::getPosition(int index) const{ + if(m_pImpl->positions == NULL)throw std::runtime_error("layout has not initialized yet"); + return m_pImpl->positions[index]; +} + + + diff --git a/moftmp/widget/LayoutManager.hpp~ b/moftmp/widget/LayoutManager.hpp~ new file mode 100755 index 0000000..b028855 --- /dev/null +++ b/moftmp/widget/LayoutManager.hpp~ @@ -0,0 +1,24 @@ +#pragma once + +#include +#include "mof/Vector2D.hpp" +#include "mof/Rectangle.hpp" + +namespace mof{ + + class LayoutManager{ + struct Impl; + boost::scoped_ptr m_pImpl; + + public: + enum Direction{ + HORIZONTAL , VERTICAL + }; + LayoutManager( Direction direction , int n); + virtual ~LayoutManager(); + void replace(unsigned int width , unsigned int height , const mof::Rectangle& front , const mof::Rectangle& back); + + mof::Vector2D getPosition(int index) const ; + int getLength( ) const ; + }; +} diff --git a/moftmp/widget/Menu.cpp b/moftmp/widget/Menu.cpp new file mode 100755 index 0000000..9df1de2 --- /dev/null +++ b/moftmp/widget/Menu.cpp @@ -0,0 +1,158 @@ +#pragma once +#include +#include +#include +#include + +using mof::widget::Container; +using mof::widget::WidgetView; +using mof::widget::GridLayout; +using mof::widget::MenuItem; + +namespace mof +{ +namespace widget +{ +//{{{ Impl + struct Menu::Impl + { + std::vector< boost::function0 > actions; + boost::shared_ptr pView; + int currentIndex; + + Impl() + : pView() , currentIndex(0) + {} + }; +//}}} +//{{{ constructor + Menu::Menu + ( + const MenuItem& front , + const MenuItem& back + ) + : m_pImpl(new Impl) + { + int length = &back - &front + 1; + std::vector< boost::shared_ptr > views; + for(int i = 0 ; i < length ; i++) + { + views.push_back( boost::shared_ptr( (&front + i)->view( ) ) ); + } + + m_pImpl->pView = boost::make_shared + ( + views.front() , views.back() , + makeFactoryMethod(GridLayout::VERTICAL , 0) + ); + + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ constructor + Menu::Menu + ( + const MenuItem& front , + const MenuItem& back , + const FactoryMethod& layout + ) + : m_pImpl(new Impl) + { + int length = &back - &front + 1; + std::vector< boost::shared_ptr > views; + for(int i = 0 ; i < length ; i++) + { + views.push_back( boost::shared_ptr( (&front + i)->view( ) ) ); + } + + m_pImpl->pView = boost::make_shared + ( + views.front() , views.back() , layout + ); + + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ destructor + Menu::~Menu() + { + } +//}}} +//{{{ show + mof::FrameNumber Menu::show(bool imidiately) + { + return m_pImpl->pView->show(imidiately); + } +//}}} +//{{{ hide + mof::FrameNumber Menu::hide(bool imidiately) + { + return m_pImpl->pView->hide(imidiately); + } +//}}} +//{{{ getView + const boost::shared_ptr Menu::getView( ) const + { + return m_pImpl->pView; + } +//}}} +//{{{ getView + boost::shared_ptr Menu::getView( ) + { + return m_pImpl->pView; + } +//}}} +//{{{ update + void Menu::update() + { + m_pImpl->pView->update(); + } +//}}} +//{{{ up + void Menu::up() + { + int index = m_pImpl->pView->getAdjacencyAsUp(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ down + void Menu::down() + { + int index = m_pImpl->pView->getAdjacencyAsDown(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ left + void Menu::left() + { + int index = m_pImpl->pView->getAdjacencyAsLeft(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ right + void Menu::right() + { + int index = m_pImpl->pView->getAdjacencyAsRight(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ performAction + void Menu::performAction() const + { + m_pImpl->actions[m_pImpl->currentIndex](); + } +//}}} +} +} diff --git a/moftmp/widget/Menu.cpp~ b/moftmp/widget/Menu.cpp~ new file mode 100755 index 0000000..12e8c31 --- /dev/null +++ b/moftmp/widget/Menu.cpp~ @@ -0,0 +1,157 @@ +#pragma once +#include +#include +#include + +using mof::widget::Container; +using mof::widget::WidgetView; +using mof::widget::GridLayout; +using mof::widget::MenuItem; + +namespace mof +{ +namespace widget +{ +//{{{ Impl + struct Menu::Impl + { + std::vector< boost::function0 > actions; + boost::shared_ptr pView; + int currentIndex; + + Impl() + : pView() , currentIndex(0) + {} + }; +//}}} +//{{{ constructor + Menu::Menu + ( + const MenuItem& front , + const MenuItem& back + ) + : m_pImpl(new Impl) + { + int length = &back - &front + 1; + std::vector< boost::shared_ptr > views; + for(int i = 0 ; i < length ; i++) + { + views.push_back( boost::shared_ptr( (&front + i)->view( ) ) ); + } + + m_pImpl->pView = boost::make_shared + ( + views.front() , views.back() , + makeFactoryMethod(GridLayout::VERTICAL , 0) + ); + + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ constructor + Menu::Menu + ( + const MenuItem& front , + const MenuItem& back , + const FactoryMethod& layout + ) + : m_pImpl(new Impl) + { + int length = &back - &front + 1; + std::vector< boost::shared_ptr > views; + for(int i = 0 ; i < length ; i++) + { + views.push_back( boost::shared_ptr( (&front + i)->view( ) ) ); + } + + m_pImpl->pView = boost::make_shared + ( + views.front() , views.back() , layout + ); + + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ destructor + Menu::~Menu() + { + } +//}}} +//{{{ show + mof::FrameNumber Menu::show(bool imidiately) + { + return m_pImpl->pView->show(imidiately); + } +//}}} +//{{{ hide + mof::FrameNumber Menu::hide(bool imidiately) + { + return m_pImpl->pView->hide(imidiately); + } +//}}} +//{{{ getView + const boost::shared_ptr Menu::getView( ) const + { + return m_pImpl->pView; + } +//}}} +//{{{ getView + boost::shared_ptr Menu::getView( ) + { + return m_pImpl->pView; + } +//}}} +//{{{ update + void Menu::update() + { + m_pImpl->pView->update(); + } +//}}} +//{{{ up + void Menu::up() + { + int index = m_pImpl->pView->getAdjacencyAsUp(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ down + void Menu::down() + { + int index = m_pImpl->pView->getAdjacencyAsDown(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ left + void Menu::left() + { + int index = m_pImpl->pView->getAdjacencyAsLeft(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ right + void Menu::right() + { + int index = m_pImpl->pView->getAdjacencyAsRight(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ performAction + void Menu::performAction() const + { + m_pImpl->actions[m_pImpl->currentIndex](); + } +//}}} +} +} diff --git a/moftmp/widget/Menu.hpp b/moftmp/widget/Menu.hpp new file mode 100755 index 0000000..4afeb3f --- /dev/null +++ b/moftmp/widget/Menu.hpp @@ -0,0 +1,68 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace mof +{ +namespace widget +{ + + inline void emptyFunc(){} + + struct MenuItem + { + mof::FactoryMethod view; + boost::function0 action; + + MenuItem + ( + const mof::FactoryMethod& view_ , + const boost::function0& action_ + ) + : view(view_) , action(action_) + { + } + + MenuItem + ( + const mof::FactoryMethod& view_ + ) + : view(view_) , action(emptyFunc) + { + } + + }; + + class Menu : public Widget + { + public: + Menu(const MenuItem& front , const MenuItem& back ); + Menu + ( + const MenuItem& front , + const MenuItem& back , + const FactoryMethod& layout + ); + + virtual ~Menu(); + virtual FrameNumber show(bool imidiately = false); + virtual FrameNumber hide(bool imidiately = false); + virtual const boost::shared_ptr getView( ) const; + virtual boost::shared_ptr getView( ); + virtual void update(); + + virtual void up(); + virtual void down(); + virtual void left(); + virtual void right(); + virtual void performAction() const; + protected: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} +} // namespace mof diff --git a/moftmp/widget/Menu.hpp~ b/moftmp/widget/Menu.hpp~ new file mode 100755 index 0000000..11f697d --- /dev/null +++ b/moftmp/widget/Menu.hpp~ @@ -0,0 +1,68 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace mof +{ +namespace widget +{ + + inline void emptyFunc(){} + + struct MenuItem + { + mof::FactoryMethod view; + boost::function0 action; + + MenuItem + ( + const mof::FactoryMethod& view_ , + const boost::function0& action_ + ) + : view(view_) , action(action_) + { + } + + MenuItem + ( + const mof::FactoryMethod& view_ + ) + : view(view_) , action(emptyFunc) + { + } + + }; + + class Menu : public Widget + { + public: + Menu(const MenuItem& front , const MenuItem& back ); + Menu + ( + const MenuItem& front , + const MenuItem& back , + const FactoryMethod& layout + ); + + virtual ~Menu(); + virtual FrameNumber show(bool imidiately = false); + virtual FrameNumber hide(bool imidiately = false); + virtual const boost::shared_ptr getView() const = 0; + virtual boost::shared_ptr getView() = 0; + virtual void update(); + + virtual void up(); + virtual void down(); + virtual void left(); + virtual void right(); + virtual void performAction() const; + protected: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} +} // namespace mof diff --git a/moftmp/widget/MenuWidget.cpp~ b/moftmp/widget/MenuWidget.cpp~ new file mode 100755 index 0000000..37dc288 --- /dev/null +++ b/moftmp/widget/MenuWidget.cpp~ @@ -0,0 +1,150 @@ +#pragma once +#include "widget/MenuWidget.hpp" +#include +#include + +namespace mof +{ +//{{{ Impl + struct MenuWidget::Impl + { + std::vector< boost::function0 > actions; + mof::ContainerWidgetView* pView; + int currentIndex; + + Impl() + : pView(NULL) , currentIndex(0) + {} + }; +//}}} +//{{{ constructor + MenuWidget::MenuWidget + ( + const mof::MenuItem& front , + const mof::MenuItem& back + ) + : m_pImpl(new Impl) + { + int length = &back - &front + 1; + std::vector< mof::FactoryMethod > views; + for(int i = 0 ; i < length ; i++) + { + views.push_back((&front + i)->view); + } + + m_pImpl->pView = new mof::ContainerWidgetView + ( + views.front() , views.back() , + makeFactoryMethod(mof::GridLayout::VERTICAL , 0) + ); + + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ constructor + MenuWidget::MenuWidget + ( + const mof::MenuItem& front , + const mof::MenuItem& back , + const FactoryMethod& layout + ) + : m_pImpl(new Impl) + { + int length = &back - &front + 1; + std::vector< mof::FactoryMethod > views; + for(int i = 0 ; i < length ; i++) + { + views.push_back((&front + i)->view); + } + + m_pImpl->pView = new mof::ContainerWidgetView + ( + views.front() , views.back() , layout + ); + + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ destructor + MenuWidget::~MenuWidget() + { + delete m_pImpl->pView; + } +//}}} +//{{{ show + mof::FrameNumber MenuWidget::show(bool imidiately) + { + return m_pImpl->pView->show(imidiately); + } +//}}} +//{{{ hide + mof::FrameNumber MenuWidget::hide(bool imidiately) + { + return m_pImpl->pView->hide(imidiately); + } +//}}} +//{{{ getView + const mof::WidgetView& MenuWidget::getView() const + { + return *m_pImpl->pView; + } +//}}} +//{{{ getView + mof::WidgetView& MenuWidget::getView() + { + return *m_pImpl->pView; + } +//}}} +//{{{ update + void MenuWidget::update() + { + m_pImpl->pView->update(); + } +//}}} +//{{{ up + void MenuWidget::up() + { + int index = m_pImpl->pView->getAdjacencyAsUp(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ down + void MenuWidget::down() + { + int index = m_pImpl->pView->getAdjacencyAsDown(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ left + void MenuWidget::left() + { + int index = m_pImpl->pView->getAdjacencyAsLeft(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ right + void MenuWidget::right() + { + int index = m_pImpl->pView->getAdjacencyAsRight(m_pImpl->currentIndex); + if(index == m_pImpl->currentIndex)return; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->blur(); + m_pImpl->currentIndex = index; + m_pImpl->pView->getAt(m_pImpl->currentIndex)->focus(); + } +//}}} +//{{{ performAction + void MenuWidget::performAction() const + { + m_pImpl->actions[m_pImpl->currentIndex](); + } +//}}} +} diff --git a/moftmp/widget/MenuWidget.hpp~ b/moftmp/widget/MenuWidget.hpp~ new file mode 100755 index 0000000..43131d5 --- /dev/null +++ b/moftmp/widget/MenuWidget.hpp~ @@ -0,0 +1,64 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace mof{ + + inline void emptyFunc(){} + + struct MenuItem + { + mof::FactoryMethod view; + boost::function0 action; + + MenuItem + ( + const mof::FactoryMethod& view_ , + const boost::function0& action_ + ) + : view(view_) , action(action_) + { + } + + MenuItem + ( + const mof::FactoryMethod& view_ + ) + : view(view_) , action(emptyFunc) + { + } + + }; + + class MenuWidget + { + public: + MenuWidget(const MenuItem& front , const MenuItem& back ); + MenuWidget + ( + const MenuItem& front , + const MenuItem& back , + const FactoryMethod& layout + ); + + virtual ~MenuWidget(); + virtual FrameNumber show(bool imidiately = false); + virtual FrameNumber hide(bool imidiately = false); + virtual const WidgetView& getView() const; + virtual WidgetView& getView(); + virtual void update(); + + virtual void up(); + virtual void down(); + virtual void left(); + virtual void right(); + virtual void performAction() const; + protected: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} // namespace mof diff --git a/moftmp/widget/Message.hpp b/moftmp/widget/Message.hpp new file mode 100755 index 0000000..98a5c48 --- /dev/null +++ b/moftmp/widget/Message.hpp @@ -0,0 +1,29 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace mof +{ +namespace widget +{ + + class Message : public Widget + { + public: + Message(mof::tstring& message); + virtual ~Message(); + virtual FrameNumber show(bool imidiately = false); + virtual FrameNumber hide(bool imidiately = false); + virtual const boost::shared_ptr getView() const; + virtual boost::shared_ptr getView(); + virtual void update(); + private: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} +} diff --git a/moftmp/widget/Message.hpp~ b/moftmp/widget/Message.hpp~ new file mode 100755 index 0000000..732a846 --- /dev/null +++ b/moftmp/widget/Message.hpp~ @@ -0,0 +1,29 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace mof +{ +namespace widget +{ + + class Message : public Widget + { + public: + Message(); + virtual ~Message(); + virtual FrameNumber show(bool imidiately = false); + virtual FrameNumber hide(bool imidiately = false); + virtual const boost::shared_ptr getView() const; + virtual boost::shared_ptr getView(); + virtual void update(); + private: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} +} diff --git a/moftmp/widget/MessageWidget.cpp b/moftmp/widget/MessageWidget.cpp new file mode 100755 index 0000000..0edce2b --- /dev/null +++ b/moftmp/widget/MessageWidget.cpp @@ -0,0 +1,238 @@ +#include "mof/MessageWidget.hpp" +#include "mof/Effect.hpp" +#include "mof/utilities.hpp" +#include "mof/LayoutManager.hpp" +#include +#include "mof/ConsoleIO.hpp" +#include "mof/WidgetView.hpp" +#include "mof/TextView.hpp" +#include "mof/GraphicsDevice.hpp" +#include "mof/mofAnimations.hpp" +#include "mof/TextCompiler.hpp" +#include "mof/widgets.hpp" + +namespace mof +{ + + struct MessageWidget::Impl + { + mof::WidgetView* pBackgroundView; + mof::TextView* pTitleView; + mof::LayoutManager* pLayout; + //boost::shared_ptr pTranslation; + mof::TranslationAnimation2D::Handler translation; + mof::ScalingAnimation2D::Handler scaling; + mof::Pager* pPager; + mof::FrameNumber frame; + //int width; + //int height; + +//{{{ Impl + Impl() + : + pBackgroundView(NULL) , + pTitleView(NULL) , + pLayout(NULL) , + pPager( NULL ) , + frame( 0 ) + { + translation = mof::TranslationAnimation2D::Handler + ( + new mof::TranslationAnimation2D + ( + mof::makeConstantHandler + ( + mof::Vector2D( 0 , 0 ) + ) + ) + ); + + scaling = mof::ScalingAnimation2D::Handler + ( + new mof::ScalingAnimation2D + ( + mof::makeConstantHandler + ( + mof::Vector2D( 0 , 0 ) + ) + ) + ); + + } +//}}} +//{{{ ~Impl + ~Impl() + { + delete pLayout; + delete pBackgroundView; + delete pTitleView; + delete pPager; + } + +//}}} + }; +//{{{ MessageWidget + MessageWidget::MessageWidget + ( + mof::WidgetView* pBackgroundView , + const mof::Rectangle& bounds , + mof::LayoutManager* pLayout + ) + : m_pImpl( new Impl( ) ) + { + m_pImpl->pLayout = pLayout; + m_pImpl->pBackgroundView = pBackgroundView; + m_pImpl->pBackgroundView->setBounds( bounds ); + m_pImpl->translation->set( m_pImpl->pBackgroundView->getPosition( ) ); + m_pImpl->scaling->set( m_pImpl->pBackgroundView->getSize( ) ); + + { // ƒ^ƒCƒgƒ‹‚̏‰Šú‰» + if( true ) + { + m_pImpl->pTitleView = new mof::TextView + ( + _T("Title") , mof::Font( mof::Font::MS_P_GOTHIC , 25 ) + ); + m_pImpl->pTitleView->initialize(); + mof::Rectangle tmp( bounds.beginX , bounds.beginY , bounds.endX , bounds.beginY + 32 ); + m_pImpl->pTitleView->setBounds( tmp ); + + } + } + { // ƒy[ƒWƒƒ‚̐¶¬ + mof::LayoutManager* pLayout = new mof::LayoutManager( mof::LayoutManager::HORIZONTAL , 1); + m_pImpl->pPager = new mof::Pager( bounds , pLayout ); + } + } +//}}} +//{{{ ~MessageWidget + MessageWidget::~MessageWidget(){ + + } +//}}} +//{{{ show + void MessageWidget::show(){ + m_pImpl->pPager->show(); + m_pImpl->pBackgroundView->show(); + if( m_pImpl->pTitleView )m_pImpl->pTitleView->show(); + } +//}}} +//{{{ close + void MessageWidget::close() + { + m_pImpl->pPager->close(); + m_pImpl->pBackgroundView->close(); + if( m_pImpl->pTitleView )m_pImpl->pTitleView->close(); + } +//}}} +//{{{ nextPage + void MessageWidget::nextPage(){ + if( !m_pImpl->pPager->hasNextPage( ) )close(); + else if( !m_pImpl->pPager->hasPreviousPage() )show(); + else m_pImpl->pPager->nextPage(); + } +//}}} +//{{{ addPage + void MessageWidget::addPage( const PageRequest& page ){ + + m_pImpl->pPager->addPage( page ); + + std::vector > boundList; + if( m_pImpl->pTitleView )boundList.push_back( mof::Rectangle( 0 , 0 , 1 , 32) ); + boundList.push_back( m_pImpl->pPager->getBounds( ) ); + + mof::Vector2D scaling = m_pImpl->scaling->get( )->getValue( m_pImpl->frame ); + m_pImpl->pLayout->replace + ( + scaling.x , scaling.y , + boundList.front() , boundList.back() + ); + + int i = 0; + if( m_pImpl->pTitleView ) + { + mof::Animation::Handler children[] = + { + mof::makeConstantHandler + ( + mof::Matrix2D::createScaling + ( + mof::Vector2D(boundList.at(i).getWidth( ) , boundList.at(i).getHeight( ) ) + ) + ) , + m_pImpl->translation , + mof::makeConstantHandler + ( + mof::Matrix2D::createTranslation( m_pImpl->pLayout->getPosition(i) ) + ) + }; // array children + + mof::Animation::Handler handler + ( + new mof::CascadingAnimation( children[0] , mof::lastOf( children ) ) + ); + i++; + //m_pImpl->pTitleView->setWorldTransform( handler ); + //m_pImpl->pTitleView->setColor(mof::Color4f(0 , 1 , 1 , 1)); + + } // if + { + const mof::Animation::Handler children[] = + { + //mof::makeConstantHandler( mof::Vector2D( 300 , 300) ) , + m_pImpl->translation->get( ) , + mof::makeConstantHandler + ( + m_pImpl->pLayout->getPosition(i) + ) + }; // array children + + mof::Animation::Handler handler + ( + new mof::CascadingAnimation >( children[0] , mof::lastOf( children ) ) + ); + m_pImpl->pPager->setPosition( handler ); + //m_pImpl->pTitleView->setWorldTransform( handler ); + //m_pImpl->pTitleView->setColor(mof::Color4f(0 , 1 , 1 , 1)); + + } // for + + + } +//}}} +//{{{ draw + void MessageWidget::draw() const{ + m_pImpl->pBackgroundView->draw(); + + { // •`‰æ—̈æ‚𐧌À + mof::Vector2D scaling = m_pImpl->scaling->get( )->getValue( m_pImpl->frame ); + mof::Vector2D translation = m_pImpl->translation->get( )->getValue( m_pImpl->frame ); + mof::GraphicsDevice::setViewport + ( + mof::Rectangle( translation.x , translation.y , translation.x + scaling.x , translation.y + scaling.y ) + ); + } + + if( m_pImpl->pTitleView )m_pImpl->pTitleView->getEffect()->draw(); + m_pImpl->pPager->draw(); + mof::GraphicsDevice::setViewport(mof::Rectangle(0 , 0 , 640 , 480));//TODO + + } +//}}} +//{{{ update + void MessageWidget::update() { + + m_pImpl->pBackgroundView->update(); + if( m_pImpl->pTitleView )m_pImpl->pTitleView->update(); + m_pImpl->pPager->update(); + m_pImpl->frame++; + } +//}}} +//{{{ hasNextPage + bool MessageWidget::hasNextPage( ){ + return m_pImpl->pPager->hasNextPage( ); + + } +//}}} +} //namespace mof + diff --git a/moftmp/widget/MessageWidget.cpp20090811 b/moftmp/widget/MessageWidget.cpp20090811 new file mode 100755 index 0000000..2c09778 --- /dev/null +++ b/moftmp/widget/MessageWidget.cpp20090811 @@ -0,0 +1,250 @@ +#include "mof/MessageWidget.hpp" +#include "mof/Effect.hpp" +#include "mof/utilities.hpp" +#include "mof/LayoutManager.hpp" +#include +#include "mof/ConsoleIO.hpp" +#include "mof/WidgetView.hpp" +#include "mof/TextView.hpp" +#include "mof/GraphicsDevice.hpp" +#include "mof/mofAnimations.hpp" +#include "mof/TextCompiler.hpp" +#include "mof/widgets.hpp" + +struct mof::MessageWidget::Impl{ + mof::WidgetView* pBackgroundView; + mof::TextView* pTitleView; + mof::LayoutManager* pLayout; + boost::shared_ptr pTranslation; + int width; + int height; + + std::vector > pages; + int currentPage; + + Impl(const mof::Rectangle& _bounds) + : + pBackgroundView(NULL) , + pTitleView(NULL) , + width(_bounds.endX - _bounds.beginX) , + height(_bounds.endY - _bounds.beginY) , + currentPage(-1) , + pLayout(NULL) + { + pTranslation = boost::shared_ptr + ( + new mof::Matrix2D + ( + mof::Matrix2D::createTranslation + ( + mof::Vector2D(_bounds.beginX , _bounds.beginY ) + ) + ) + ); + } + + ~Impl(){ + delete pLayout; + delete pBackgroundView; + delete pTitleView; + foreach(std::vector& page , pages ){ + foreach(mof::Sprite*& pSprite , page ){ + delete pSprite; + } + } + } + + void showPage(bool first){ + mof::KeyFrameAnimation::KeyFrame keyFrames[] = { + mof::makeKeyFrame(first ? 0 : 10*2 , mof::Color4f(0 , 1 , 1 , 1) ) , + mof::makeKeyFrame(first ? 30*2 : 90 , mof::Color4f(1 , 1 , 1 , 1) ) + }; + mof::Animation::Handler handler(new mof::KeyFrameAnimation(keyFrames[0] , keyFrames[1])); + foreach(mof::Sprite*& pSprite , pages.at(currentPage) ){ + pSprite->setColor(handler); + pSprite->setFrameNumber(0); + } + } + + void closePage(bool last){ + mof::KeyFrameAnimation::KeyFrame keyFrames[] = { + mof::makeKeyFrame(0 , mof::Color4f(1 , 1 , 1 , 1) ) , + mof::makeKeyFrame(last ? 10*2 : 10*2 , mof::Color4f(0 , 1 , 1 , 1) ) + }; + mof::Animation::Handler handler(new mof::KeyFrameAnimation(keyFrames[0] , keyFrames[1])); + foreach(mof::Sprite*& pSprite , pages.at(currentPage) ){ + pSprite->setColor(handler); + pSprite->setFrameNumber(0); + } + } + + + +}; + +//{{{ MessageWidget +mof::MessageWidget::MessageWidget +( + mof::WidgetView* pBackgroundView , + const mof::Rectangle& bounds , + mof::LayoutManager* pLayout +) +: m_pImpl( new Impl( bounds) ) +{ + m_pImpl->pLayout = pLayout; + m_pImpl->pBackgroundView = pBackgroundView; + + { // ƒ^ƒCƒgƒ‹‚̏‰Šú‰» + if( true ) + { + m_pImpl->pTitleView = new mof::TextView + ( + _T("Title") , mof::Font( mof::Font::MS_P_GOTHIC , 25 ) + ); + m_pImpl->pTitleView->initialize(); + mof::Rectangle tmp( bounds.beginX , bounds.beginY , bounds.endX , bounds.beginY + 32 ); + m_pImpl->pTitleView->setBounds( tmp ); + + } + } + + m_pImpl->pBackgroundView->setBounds(bounds); +} +//}}} +//{{{ ~MessageWidget +mof::MessageWidget::~MessageWidget(){ + +} +//}}} +//{{{ show +void mof::MessageWidget::show(){ + m_pImpl->currentPage = -1; + m_pImpl->pBackgroundView->show(); + if( m_pImpl->pTitleView )m_pImpl->pTitleView->show(); + m_pImpl->currentPage++; + m_pImpl->showPage(true); +} +//}}} +//{{{ close +void mof::MessageWidget::close(){ + + m_pImpl->pBackgroundView->close(); + if( m_pImpl->pTitleView )m_pImpl->pTitleView->close(); + if(m_pImpl->currentPage < 0)return; + m_pImpl->closePage(true); +} +//}}} +//{{{ nextPage +void mof::MessageWidget::nextPage(){ + if(m_pImpl->currentPage < 0){ + show(); + return; + } + m_pImpl->closePage(false); + if(m_pImpl->currentPage >= static_cast(m_pImpl->pages.size()) -1 ){ + close(); + return; + } + m_pImpl->currentPage++; + m_pImpl->showPage(false); +} +//}}} +//{{{ addPage +void mof::MessageWidget::addPage( const Page& page ){ + + m_pImpl->pages.push_back(std::vector()); + mof::compileText( page.message , page.font , m_pImpl->pages.back() ); + + std::vector > boundList; + if( m_pImpl->pTitleView )boundList.push_back( mof::Rectangle( 0 , 0 , 1 , 32) ); + //if( m_pImpl->pTitleView )boundList.push_back( m_pImpl->pTitle->getBounds() ); + + foreach(mof::Sprite*& pSprite , m_pImpl->pages.back() ){ + mof::Rectangle bounds = pSprite->getWorldTransform().toBoundingBox(); + boundList.push_back(bounds); + } + m_pImpl->pLayout->replace(m_pImpl->width , m_pImpl->height , boundList.front() , boundList.back() ); + + //TODO: LayoutAnimation‚ð‚‚­‚é + for(unsigned int j = 0 ; j < m_pImpl->pLayout->getLength( ) ; ++j) + { + const mof::Animation::Handler children[] = + { + mof::makeConstantHandler + ( + mof::Matrix2D::createScaling + ( + mof::Vector2D(boundList.at(j).endX - boundList.at(j).beginX , boundList.at(j).endY - boundList.at(j).beginY) + ) + ) , + mof::makeParametricHandler(m_pImpl->pTranslation) , + mof::makeConstantHandler + ( + mof::Matrix2D::createTranslation( m_pImpl->pLayout->getPosition(j) ) + ) + }; // array children + + mof::Animation::Handler handler + ( + new mof::CascadingAnimation( children[0] , mof::lastOf( children ) ) + ); + + //if( m_pImpl->pTitleView && j == 0 )m_pImpl->pTitleView->setPosition( handler ); + if( m_pImpl->pTitleView && j != 0 ) + { + m_pImpl->pages.back().at(j-1)->setWorldTransform( handler ); + m_pImpl->pages.back().at(j-1)->setColor(mof::Color4f(0 , 1 , 1 , 1)); + } + else if( NULL != m_pImpl->pTitleView ) + { + m_pImpl->pages.back().at(j)->setWorldTransform( handler ); + m_pImpl->pages.back().at(j)->setColor(mof::Color4f(0 , 1 , 1 , 1)); + } + + } // for + + +} +//}}} +//{{{ draw +void mof::MessageWidget::draw() const{ + m_pImpl->pBackgroundView->draw(); + if( m_pImpl->pTitleView )m_pImpl->pTitleView->getEffect()->draw(); + if(m_pImpl->currentPage < 0)return; + + if(m_pImpl->currentPage > 0){ + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage-1) ){ + pSprite->draw(); + } + } + mof::GraphicsDevice::setViewport(m_pImpl->pBackgroundView->getBounds()); + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage) ){ + pSprite->draw(); + } + mof::GraphicsDevice::setViewport(mof::Rectangle(0 , 0 , 640 , 480));//TODO + +} +//}}} +//{{{ update +void mof::MessageWidget::update() { + + m_pImpl->pBackgroundView->update(); + if( m_pImpl->pTitleView )m_pImpl->pTitleView->update(); + if(m_pImpl->currentPage < 0)return; + if(m_pImpl->currentPage > 0){ + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage-1) ){ + pSprite->update(); + } + } + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage) ){ + pSprite->update(); + } +} +//}}} +//{{{ hasNextPage +bool mof::MessageWidget::hasNextPage(){ + return m_pImpl->currentPage < static_cast(m_pImpl->pages.size()) -1; + +} +//}}} + diff --git a/moftmp/widget/MessageWidget.cpp~ b/moftmp/widget/MessageWidget.cpp~ new file mode 100755 index 0000000..0edce2b --- /dev/null +++ b/moftmp/widget/MessageWidget.cpp~ @@ -0,0 +1,238 @@ +#include "mof/MessageWidget.hpp" +#include "mof/Effect.hpp" +#include "mof/utilities.hpp" +#include "mof/LayoutManager.hpp" +#include +#include "mof/ConsoleIO.hpp" +#include "mof/WidgetView.hpp" +#include "mof/TextView.hpp" +#include "mof/GraphicsDevice.hpp" +#include "mof/mofAnimations.hpp" +#include "mof/TextCompiler.hpp" +#include "mof/widgets.hpp" + +namespace mof +{ + + struct MessageWidget::Impl + { + mof::WidgetView* pBackgroundView; + mof::TextView* pTitleView; + mof::LayoutManager* pLayout; + //boost::shared_ptr pTranslation; + mof::TranslationAnimation2D::Handler translation; + mof::ScalingAnimation2D::Handler scaling; + mof::Pager* pPager; + mof::FrameNumber frame; + //int width; + //int height; + +//{{{ Impl + Impl() + : + pBackgroundView(NULL) , + pTitleView(NULL) , + pLayout(NULL) , + pPager( NULL ) , + frame( 0 ) + { + translation = mof::TranslationAnimation2D::Handler + ( + new mof::TranslationAnimation2D + ( + mof::makeConstantHandler + ( + mof::Vector2D( 0 , 0 ) + ) + ) + ); + + scaling = mof::ScalingAnimation2D::Handler + ( + new mof::ScalingAnimation2D + ( + mof::makeConstantHandler + ( + mof::Vector2D( 0 , 0 ) + ) + ) + ); + + } +//}}} +//{{{ ~Impl + ~Impl() + { + delete pLayout; + delete pBackgroundView; + delete pTitleView; + delete pPager; + } + +//}}} + }; +//{{{ MessageWidget + MessageWidget::MessageWidget + ( + mof::WidgetView* pBackgroundView , + const mof::Rectangle& bounds , + mof::LayoutManager* pLayout + ) + : m_pImpl( new Impl( ) ) + { + m_pImpl->pLayout = pLayout; + m_pImpl->pBackgroundView = pBackgroundView; + m_pImpl->pBackgroundView->setBounds( bounds ); + m_pImpl->translation->set( m_pImpl->pBackgroundView->getPosition( ) ); + m_pImpl->scaling->set( m_pImpl->pBackgroundView->getSize( ) ); + + { // ƒ^ƒCƒgƒ‹‚̏‰Šú‰» + if( true ) + { + m_pImpl->pTitleView = new mof::TextView + ( + _T("Title") , mof::Font( mof::Font::MS_P_GOTHIC , 25 ) + ); + m_pImpl->pTitleView->initialize(); + mof::Rectangle tmp( bounds.beginX , bounds.beginY , bounds.endX , bounds.beginY + 32 ); + m_pImpl->pTitleView->setBounds( tmp ); + + } + } + { // ƒy[ƒWƒƒ‚̐¶¬ + mof::LayoutManager* pLayout = new mof::LayoutManager( mof::LayoutManager::HORIZONTAL , 1); + m_pImpl->pPager = new mof::Pager( bounds , pLayout ); + } + } +//}}} +//{{{ ~MessageWidget + MessageWidget::~MessageWidget(){ + + } +//}}} +//{{{ show + void MessageWidget::show(){ + m_pImpl->pPager->show(); + m_pImpl->pBackgroundView->show(); + if( m_pImpl->pTitleView )m_pImpl->pTitleView->show(); + } +//}}} +//{{{ close + void MessageWidget::close() + { + m_pImpl->pPager->close(); + m_pImpl->pBackgroundView->close(); + if( m_pImpl->pTitleView )m_pImpl->pTitleView->close(); + } +//}}} +//{{{ nextPage + void MessageWidget::nextPage(){ + if( !m_pImpl->pPager->hasNextPage( ) )close(); + else if( !m_pImpl->pPager->hasPreviousPage() )show(); + else m_pImpl->pPager->nextPage(); + } +//}}} +//{{{ addPage + void MessageWidget::addPage( const PageRequest& page ){ + + m_pImpl->pPager->addPage( page ); + + std::vector > boundList; + if( m_pImpl->pTitleView )boundList.push_back( mof::Rectangle( 0 , 0 , 1 , 32) ); + boundList.push_back( m_pImpl->pPager->getBounds( ) ); + + mof::Vector2D scaling = m_pImpl->scaling->get( )->getValue( m_pImpl->frame ); + m_pImpl->pLayout->replace + ( + scaling.x , scaling.y , + boundList.front() , boundList.back() + ); + + int i = 0; + if( m_pImpl->pTitleView ) + { + mof::Animation::Handler children[] = + { + mof::makeConstantHandler + ( + mof::Matrix2D::createScaling + ( + mof::Vector2D(boundList.at(i).getWidth( ) , boundList.at(i).getHeight( ) ) + ) + ) , + m_pImpl->translation , + mof::makeConstantHandler + ( + mof::Matrix2D::createTranslation( m_pImpl->pLayout->getPosition(i) ) + ) + }; // array children + + mof::Animation::Handler handler + ( + new mof::CascadingAnimation( children[0] , mof::lastOf( children ) ) + ); + i++; + //m_pImpl->pTitleView->setWorldTransform( handler ); + //m_pImpl->pTitleView->setColor(mof::Color4f(0 , 1 , 1 , 1)); + + } // if + { + const mof::Animation::Handler children[] = + { + //mof::makeConstantHandler( mof::Vector2D( 300 , 300) ) , + m_pImpl->translation->get( ) , + mof::makeConstantHandler + ( + m_pImpl->pLayout->getPosition(i) + ) + }; // array children + + mof::Animation::Handler handler + ( + new mof::CascadingAnimation >( children[0] , mof::lastOf( children ) ) + ); + m_pImpl->pPager->setPosition( handler ); + //m_pImpl->pTitleView->setWorldTransform( handler ); + //m_pImpl->pTitleView->setColor(mof::Color4f(0 , 1 , 1 , 1)); + + } // for + + + } +//}}} +//{{{ draw + void MessageWidget::draw() const{ + m_pImpl->pBackgroundView->draw(); + + { // •`‰æ—̈æ‚𐧌À + mof::Vector2D scaling = m_pImpl->scaling->get( )->getValue( m_pImpl->frame ); + mof::Vector2D translation = m_pImpl->translation->get( )->getValue( m_pImpl->frame ); + mof::GraphicsDevice::setViewport + ( + mof::Rectangle( translation.x , translation.y , translation.x + scaling.x , translation.y + scaling.y ) + ); + } + + if( m_pImpl->pTitleView )m_pImpl->pTitleView->getEffect()->draw(); + m_pImpl->pPager->draw(); + mof::GraphicsDevice::setViewport(mof::Rectangle(0 , 0 , 640 , 480));//TODO + + } +//}}} +//{{{ update + void MessageWidget::update() { + + m_pImpl->pBackgroundView->update(); + if( m_pImpl->pTitleView )m_pImpl->pTitleView->update(); + m_pImpl->pPager->update(); + m_pImpl->frame++; + } +//}}} +//{{{ hasNextPage + bool MessageWidget::hasNextPage( ){ + return m_pImpl->pPager->hasNextPage( ); + + } +//}}} +} //namespace mof + diff --git a/moftmp/widget/MessageWidget.hpp b/moftmp/widget/MessageWidget.hpp new file mode 100755 index 0000000..d7f099c --- /dev/null +++ b/moftmp/widget/MessageWidget.hpp @@ -0,0 +1,48 @@ +#pragma once +#include +#include +#include +//#include "mof/MenuView.hpp" +#include "mof/widget/WidgetView.hpp" +#include "mof/Font.hpp" + +namespace mof +{ + struct PageRequest + { + tstring message; + Font font; + + PageRequest(const tstring& message_ , const Font& font_ ) + : message(message_) , font(font_) + { + } + }; + + class LayoutManager; + class WidgetView; + class Pager; + struct Page; + + class MessageWidget : boost::noncopyable{ + struct Impl; + boost::scoped_ptr m_pImpl; + public: + + MessageWidget + ( + WidgetView* pBackgroundView , + const Rectangle< int >& bounds , LayoutManager* pLayout + ); + + ~MessageWidget(); + void show(); + void close(); + void nextPage(); + void addPage( const PageRequest& page ); + void draw() const; + void update(); + bool hasNextPage(); + + }; +} diff --git a/moftmp/widget/MessageWidget.hpp~ b/moftmp/widget/MessageWidget.hpp~ new file mode 100755 index 0000000..21b6f59 --- /dev/null +++ b/moftmp/widget/MessageWidget.hpp~ @@ -0,0 +1,48 @@ +#pragma once +#include +#include +#include +//#include "mof/MenuView.hpp" +#include "mof/WidgetView.hpp" +#include "mof/Font.hpp" + +namespace mof +{ + struct PageRequest + { + tstring message; + Font font; + + PageRequest(const tstring& message_ , const Font& font_ ) + : message(message_) , font(font_) + { + } + }; + + class LayoutManager; + class WidgetView; + class Pager; + struct Page; + + class MessageWidget : boost::noncopyable{ + struct Impl; + boost::scoped_ptr m_pImpl; + public: + + MessageWidget + ( + WidgetView* pBackgroundView , + const Rectangle< int >& bounds , LayoutManager* pLayout + ); + + ~MessageWidget(); + void show(); + void close(); + void nextPage(); + void addPage( const PageRequest& page ); + void draw() const; + void update(); + bool hasNextPage(); + + }; +} diff --git a/moftmp/widget/OverlapLayout.cpp b/moftmp/widget/OverlapLayout.cpp new file mode 100755 index 0000000..e0a7864 --- /dev/null +++ b/moftmp/widget/OverlapLayout.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include + +using boost::shared_ptr; +using mof::widget::WidgetView; +//{{{ Impl +struct mof::widget::OverlapLayout::Impl +{ + + int width , height; + size_t length; + std::vector< shared_ptr > views; + + Impl( const mof::Vector2D& size ) + : + width(size.x) , height(size.y) , length(0) + {} + + + ~Impl() + { + } +}; +//}}} +//{{{ OverlapLayout +mof::widget::OverlapLayout::OverlapLayout( const mof::Vector2D& size ) +: m_pImpl( new Impl( size ) ) +{ +} +//}}} +//{{{ ~OverlapLayout +mof::widget::OverlapLayout::~OverlapLayout( ) +{ +} +//}}} +//{{{ add +void mof::widget::OverlapLayout::add(shared_ptr pView) +{ + /*if(m_pImpl->length == 0 ){ + m_pImpl->width = mof::real2int(size.x); + m_pImpl->width = mof::real2int(size.y); + }*/ + m_pImpl->length++; + m_pImpl->views.push_back(pView); +} +//}}} +//{{{ getLength +size_t mof::widget::OverlapLayout::getLength() const +{ + return m_pImpl->length; +} +//}}} +//{{{ getPreferredSize +mof::Vector2D mof::widget::OverlapLayout::getPreferredSize() const +{ + return mof::Vector2D(m_pImpl->width , m_pImpl->height); +} +//}}} +//{{{ getSizeDependencyType +mof::widget::Layout::DependencyType mof::widget::OverlapLayout::getSizeDependencyType() const +{ + return mof::widget::Layout::PARENT_LEADING; +} +//}}} +//{{{ connect +void mof::widget::OverlapLayout::connect(WidgetView* pParentView) +{ + size_t i = 0; + foreach(shared_ptr pView , m_pImpl->views) + { + pView->getPositionStream() << pParentView->getPositionStream(); + pView->getSizeStream() << pParentView->getSizeStream() << - pView->getSizeStream().value(); + } +} +//}}} +//{{{ getAdjacencyAsUp +int mof::widget::OverlapLayout::getAdjacencyAsUp(int index) const +{ + return mof::rotation_mod(index-1 , m_pImpl->length); +} +//}}} +//{{{ getAdjacencyAsDown +int mof::widget::OverlapLayout::getAdjacencyAsDown(int index) const +{ + return mof::rotation_mod(index+1 , m_pImpl->length ); +} +//}}} +//{{{ getAdjacencyAsLeft +int mof::widget::OverlapLayout::getAdjacencyAsLeft(int index) const +{ + return mof::rotation_mod(index-1 , m_pImpl->length ); +} +//}}} +//{{{ getAdjacencyAsRight +int mof::widget::OverlapLayout::getAdjacencyAsRight(int index) const +{ + return mof::rotation_mod(index+1 , m_pImpl->length ); +} +//}}} diff --git a/moftmp/widget/OverlapLayout.cpp~ b/moftmp/widget/OverlapLayout.cpp~ new file mode 100755 index 0000000..3936671 --- /dev/null +++ b/moftmp/widget/OverlapLayout.cpp~ @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include + +using boost::shared_ptr; +using mof::widget::WidgetView; +//{{{ Impl +struct mof::widget::OverlapLayout::Impl +{ + + int width , height; + size_t length; + std::vector< shared_ptr > views; + + Impl( const mof::Vector2D& size ) + : + width(size.x) , height(size.y) , length(0) + {} + + + ~Impl() + { + } +}; +//}}} +//{{{ OverlapLayout +mof::widget::OverlapLayout::OverlapLayout( const mof::Vector2D& size ) +: m_pImpl( new Impl( size ) ) +{ +} +//}}} +//{{{ ~OverlapLayout +mof::widget::OverlapLayout::~OverlapLayout( ) +{ +} +//}}} +//{{{ add +void mof::widget::OverlapLayout::add(shared_ptr pView) +{ + /*if(m_pImpl->length == 0 ){ + m_pImpl->width = mof::real2int(size.x); + m_pImpl->width = mof::real2int(size.y); + }*/ + m_pImpl->length++; + m_pImpl->views.push_back(pView); +} +//}}} +//{{{ getLength +size_t mof::widget::OverlapLayout::getLength() const +{ + return m_pImpl->length; +} +//}}} +//{{{ getPreferredSize +mof::Vector2D mof::widget::OverlapLayout::getPreferredSize() const +{ + return mof::Vector2D(m_pImpl->width , m_pImpl->height); +} +//}}} +//{{{ getSizeDependencyType +mof::widget::Layout::DependencyType mof::widget::OverlapLayout::getSizeDependencyType() const +{ + return mof::widget::Layout::PARENT_LEADING; +} +//}}} +//{{{ connect +void mof::widget::OverlapLayout::connect(WidgetView* pParentView) +{ + size_t i = 0; + foreach(shared_ptr pView , m_pImpl->views) + { + pView->getPositionStream() << pParentView; + pView->getSizeStream() << pParentView->getSizeStream() << - pView->getSizeStream().value(); + } +} +//}}} +//{{{ getAdjacencyAsUp +int mof::widget::OverlapLayout::getAdjacencyAsUp(int index) const +{ + return mof::rotation_mod(index-1 , m_pImpl->length); +} +//}}} +//{{{ getAdjacencyAsDown +int mof::widget::OverlapLayout::getAdjacencyAsDown(int index) const +{ + return mof::rotation_mod(index+1 , m_pImpl->length ); +} +//}}} +//{{{ getAdjacencyAsLeft +int mof::widget::OverlapLayout::getAdjacencyAsLeft(int index) const +{ + return mof::rotation_mod(index-1 , m_pImpl->length ); +} +//}}} +//{{{ getAdjacencyAsRight +int mof::widget::OverlapLayout::getAdjacencyAsRight(int index) const +{ + return mof::rotation_mod(index+1 , m_pImpl->length ); +} +//}}} diff --git a/moftmp/widget/OverlapLayout.hpp b/moftmp/widget/OverlapLayout.hpp new file mode 100755 index 0000000..294a596 --- /dev/null +++ b/moftmp/widget/OverlapLayout.hpp @@ -0,0 +1,33 @@ +#pragma once +#include +#include + +namespace mof +{ +namespace widget +{ + + class OverlapLayout : public Layout + { + public: + + OverlapLayout( const mof::Vector2D& size ); + virtual ~OverlapLayout(); + virtual void add(boost::shared_ptr pView); + virtual Vector2D getPreferredSize() const; + virtual DependencyType getSizeDependencyType() const; + virtual void connect(WidgetView* pParentView); + virtual size_t getLength( ) const; + virtual int getAdjacencyAsUp(int index) const; + virtual int getAdjacencyAsDown(int index) const; + virtual int getAdjacencyAsLeft(int index) const; + virtual int getAdjacencyAsRight(int index) const; + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} +} // namepsace mof + diff --git a/moftmp/widget/OverlapLayout.hpp~ b/moftmp/widget/OverlapLayout.hpp~ new file mode 100755 index 0000000..98f6189 --- /dev/null +++ b/moftmp/widget/OverlapLayout.hpp~ @@ -0,0 +1,33 @@ +#pragma once +#include +#include + +namespace mof +{ +namespace widget +{ + + class OverlapLayout : public Layout + { + public: + + OverlapLayout( const mof::Vector2D& size ); + virtual ~OverlapLayout(); + virtual void add(boost::shared_ptr pView); + virtual Vector2D getPreferredSize() const; + virtual DependencyType getSizeDependencyType() const; + virtual void connect(boost::shared_ptr pParentView); + virtual size_t getLength( ) const; + virtual int getAdjacencyAsUp(int index) const; + virtual int getAdjacencyAsDown(int index) const; + virtual int getAdjacencyAsLeft(int index) const; + virtual int getAdjacencyAsRight(int index) const; + + private: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} +} // namepsace mof + diff --git a/moftmp/widget/Page.hpp~ b/moftmp/widget/Page.hpp~ new file mode 100755 index 0000000..a7a7c9d --- /dev/null +++ b/moftmp/widget/Page.hpp~ @@ -0,0 +1,86 @@ +#pragma once + +#pragma once +#include +#include "mof/tstring.hpp" +#include "mof/Font.hpp" +#include "mof/Rectangle.hpp" +#include "mof/Animation.hpp" +#include "mof/Vector2D.hpp" + + +namespace mof +{ + struct PageRequest; + class LayoutManager; + + /** ページから + */ + class Page + { + public: + Page + ( + mof::LayoutManager* pLayout + ); + + ~Page( ); + + /** このウィジェットを表示にする + * @note 即座に処理されることは保障されない + */ + void show( ); + + /** このウィジェットを非表示にする + * @note 即座に処理されることは保障されない + */ + void hide( ); + + /** このウィジェットの内容を描画する + * @note setPosition()やsetSize()で指定した領域外にも描画が行われることもある + */ + void draw( ) const; + + /** ウィジェット内のフレームを進める + */ + void update( ); + + /** このウィジェットがとれる最小の大きさに + */ + void pack( ); + + /** ウィジェットの左上の位置を得る + * @note このメソッドで得られるハンドラとsetPosition()で + * 指定したハンドラは同一であると扱える + * @retval このウィジェットの左上の位置を得るためのハンドラ + */ + mof::Animation< mof::Vector2D>::Handler getPosition( ) const; + + /** ウィジェットの大きさを得る + * @note このメソッドで得られるハンドラとsetSize()で + * 指定したハンドラは同一であると扱える + * @retval このウィジェットの大きさを得るためのハンドラ + */ + mof::Animation< mof::Vector2D>::Handler getSize( ) const; + + /** ウィジェットの左上の位置を指定する + * @note このメソッドで指定するハンドラとgetPosition()で + * 得られるハンドラは同一であると扱える + * @retval このウィジェットの左上の位置を得るためのハンドラ + */ + void setPosition( const mof::Animation::Handler& handler ); + + /** ウィジェットの左上の位置を指定する + * @note このメソッドで指定するハンドラとgetPosition()で + * 得られるハンドラは同一であると扱える + * @retval このウィジェットの左上の位置を得るためのハンドラ + */ + void setSize( const mof::Animation::Handler& handler ); + + mof::Rectangle getBounds( ); + private: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} diff --git a/moftmp/widget/Pager.cpp b/moftmp/widget/Pager.cpp new file mode 100755 index 0000000..32ede49 --- /dev/null +++ b/moftmp/widget/Pager.cpp @@ -0,0 +1,254 @@ +#include "mof/Pager.hpp" +#include "mof/Sprite.hpp" +#include "mof/utilities.hpp" +#include +#include "mof/widgets.hpp" +#include "mof/mofAnimations.hpp" +#include "mof/mofGraphics.hpp" +#include "mof/ConsoleIO.hpp" + +namespace mof +{ + struct Pager::Impl + { + std::vector< std::vector > pages; + mof::FrameNumber frame; + int currentPage; + mof::LayoutManager* pLayout; + mof::TranslationAnimation2D::Handler translation; + mof::ScalingAnimation2D::Handler scaling; + +//{{{ Impl + Impl( const mof::Rectangle& _bounds ) + : + currentPage(-1) , + pLayout(NULL) , + frame( 0 ) + { + translation = mof::TranslationAnimation2D::Handler + ( + new mof::TranslationAnimation2D + ( + mof::makeConstantHandler + ( + mof::Vector2D(_bounds.beginX , _bounds.beginY ) + ) + ) + ); + + scaling = mof::ScalingAnimation2D::Handler + ( + new mof::ScalingAnimation2D + ( + mof::makeConstantHandler + ( + mof::Vector2D(_bounds.getWidth( ) , _bounds.getHeight( ) ) + ) + ) + ); + + } +//}}} +//{{{ ~Impl + ~Impl(){ + delete pLayout; + foreach(std::vector& page , pages ){ + foreach(mof::Sprite*& pSprite , page ){ + delete pSprite; + } + } + } +//}}} +//{{{ showPage + void showPage(bool first) + { + mof::KeyFrameAnimation::KeyFrame keyFrames[] = { + mof::makeKeyFrame(first ? 0 : 10*2 , mof::Color4f(0 , 1 , 1 , 1) ) , + mof::makeKeyFrame(first ? 30*2 : 90 , mof::Color4f(1 , 1 , 1 , 1) ) + }; + mof::Animation::Handler handler(new mof::KeyFrameAnimation(keyFrames[0] , keyFrames[1])); + handler = mof::makeOffsetHandler< mof::Color4f >( handler , -frame ); + foreach(mof::Sprite*& pSprite , pages.at(currentPage) ){ + pSprite->setColor(handler); + } + } +//}}} +//{{{ closePage + void closePage(bool last){ + mof::KeyFrameAnimation::KeyFrame keyFrames[] = { + mof::makeKeyFrame(0 , mof::Color4f(1 , 1 , 1 , 1) ) , + mof::makeKeyFrame(last ? 10*2 : 10*2 , mof::Color4f(0 , 1 , 1 , 1) ) + }; + mof::Animation::Handler handler(new mof::KeyFrameAnimation(keyFrames[0] , keyFrames[1])); + DEBUG_PRINT( frame); + handler = mof::makeOffsetHandler< mof::Color4f >( handler , -frame ); + foreach(mof::Sprite*& pSprite , pages.at(currentPage) ){ + pSprite->setColor(handler); + } + } + +//}}} + }; +//{{{ Pager + Pager::Pager + ( + const mof::Rectangle& bounds , + mof::LayoutManager* pLayout + ) + : m_pImpl( new Impl( bounds ) ) + { + m_pImpl->pLayout = pLayout; + } +//}}} +//{{{ ~Pager + Pager::~Pager( ) + { + } +//}}} +//{{{ show + void Pager::show( ) + { + m_pImpl->currentPage = -1; + m_pImpl->currentPage++; + m_pImpl->showPage(true); + } +//}}} +//{{{ close + void Pager::close( ) + { + if(m_pImpl->currentPage < 0)return; + m_pImpl->closePage(true); + } +//}}} +//{{{ nextPage + void Pager::nextPage( ) + { + if(m_pImpl->currentPage < 0){ + show(); + return; + } + m_pImpl->closePage(false); + if(m_pImpl->currentPage >= static_cast(m_pImpl->pages.size()) -1 ){ + close(); + return; + } + m_pImpl->currentPage++; + m_pImpl->showPage(false); + } +//}}} +//{{{ addPage + void Pager::addPage( const mof::PageRequest& page ) + { + m_pImpl->pages.push_back(std::vector()); + mof::compileText( page.message , page.font , m_pImpl->pages.back() ); + + std::vector< mof::Rectangle > boundList; + + foreach(mof::Sprite*& pSprite , m_pImpl->pages.back() ){ + pSprite->setFrameNumber( m_pImpl->frame ); + mof::Rectangle bounds = pSprite->getWorldTransform().toBoundingBox(); + boundList.push_back(bounds); + } + + mof::Vector2D scaling = m_pImpl->scaling->get( )->getValue( m_pImpl->frame ); + m_pImpl->pLayout->replace + ( + scaling.x , scaling.y , + boundList.front() , boundList.back() + ); + + for(unsigned int j = 0 ; j < m_pImpl->pLayout->getLength( ) ; ++j) + { + mof::Animation::Handler children[] = + { + mof::makeConstantHandler + ( + mof::Matrix2D::createScaling + ( + mof::Vector2D(boundList.at(j).getWidth( ) , boundList.at(j).getHeight( ) ) + ) + ) , + m_pImpl->translation , + mof::makeConstantHandler + ( + mof::Matrix2D::createTranslation( m_pImpl->pLayout->getPosition(j) ) + ) + }; // array children + + mof::Animation::Handler handler + ( + new mof::CascadingAnimation( children[0] , mof::lastOf( children ) ) + ); + + m_pImpl->pages.back().at(j)->setWorldTransform( handler ); + m_pImpl->pages.back().at(j)->setColor(mof::Color4f(0 , 1 , 1 , 1)); + + } // for + + } +//}}} +//{{{ draw + void Pager::draw( ) const + { + if(m_pImpl->currentPage < 0)return; + + if(m_pImpl->currentPage > 0){ + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage-1) ){ + pSprite->draw(); + } + } + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage) ){ + pSprite->draw(); + } + } +//}}} +//{{{ update + void Pager::update( ) + { + if(m_pImpl->currentPage < 0)return; + if(m_pImpl->currentPage > 0){ + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage-1) ){ + pSprite->update(); + } + } + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage) ){ + pSprite->update(); + } + m_pImpl->frame++; + } +//}}} +//{{{ hasNextPage + bool Pager::hasNextPage( ) const + { + return m_pImpl->currentPage < static_cast(m_pImpl->pages.size()) -1; + } +//}}} +//{{{ hasPreviousPage + bool Pager::hasPreviousPage( ) const + { + return m_pImpl->currentPage >= 0; + } +//}}} + +//{{{ setPosition + void Pager::setPosition( const mof::Animation::Handler& handler ) + { + m_pImpl->translation->set( handler ); + } +//}}} +//{{{ setSize + void Pager::setSize( const mof::Animation::Handler& handler ) + { + m_pImpl->scaling->set( handler ); + } +//}}} +//{{{ getBounds + mof::Rectangle Pager::getBounds( ) + { + mof::Vector2D scaling = m_pImpl->scaling->get( )->getValue( m_pImpl->frame ); + mof::Vector2D translation = m_pImpl->translation->get( )->getValue( m_pImpl->frame ); + return mof::Rectangle( translation.x , translation.y , translation.x + scaling.x , translation.y + scaling.y ); + } +//}}} +} //namepsace mof + diff --git a/moftmp/widget/Pager.cpp~ b/moftmp/widget/Pager.cpp~ new file mode 100755 index 0000000..32ede49 --- /dev/null +++ b/moftmp/widget/Pager.cpp~ @@ -0,0 +1,254 @@ +#include "mof/Pager.hpp" +#include "mof/Sprite.hpp" +#include "mof/utilities.hpp" +#include +#include "mof/widgets.hpp" +#include "mof/mofAnimations.hpp" +#include "mof/mofGraphics.hpp" +#include "mof/ConsoleIO.hpp" + +namespace mof +{ + struct Pager::Impl + { + std::vector< std::vector > pages; + mof::FrameNumber frame; + int currentPage; + mof::LayoutManager* pLayout; + mof::TranslationAnimation2D::Handler translation; + mof::ScalingAnimation2D::Handler scaling; + +//{{{ Impl + Impl( const mof::Rectangle& _bounds ) + : + currentPage(-1) , + pLayout(NULL) , + frame( 0 ) + { + translation = mof::TranslationAnimation2D::Handler + ( + new mof::TranslationAnimation2D + ( + mof::makeConstantHandler + ( + mof::Vector2D(_bounds.beginX , _bounds.beginY ) + ) + ) + ); + + scaling = mof::ScalingAnimation2D::Handler + ( + new mof::ScalingAnimation2D + ( + mof::makeConstantHandler + ( + mof::Vector2D(_bounds.getWidth( ) , _bounds.getHeight( ) ) + ) + ) + ); + + } +//}}} +//{{{ ~Impl + ~Impl(){ + delete pLayout; + foreach(std::vector& page , pages ){ + foreach(mof::Sprite*& pSprite , page ){ + delete pSprite; + } + } + } +//}}} +//{{{ showPage + void showPage(bool first) + { + mof::KeyFrameAnimation::KeyFrame keyFrames[] = { + mof::makeKeyFrame(first ? 0 : 10*2 , mof::Color4f(0 , 1 , 1 , 1) ) , + mof::makeKeyFrame(first ? 30*2 : 90 , mof::Color4f(1 , 1 , 1 , 1) ) + }; + mof::Animation::Handler handler(new mof::KeyFrameAnimation(keyFrames[0] , keyFrames[1])); + handler = mof::makeOffsetHandler< mof::Color4f >( handler , -frame ); + foreach(mof::Sprite*& pSprite , pages.at(currentPage) ){ + pSprite->setColor(handler); + } + } +//}}} +//{{{ closePage + void closePage(bool last){ + mof::KeyFrameAnimation::KeyFrame keyFrames[] = { + mof::makeKeyFrame(0 , mof::Color4f(1 , 1 , 1 , 1) ) , + mof::makeKeyFrame(last ? 10*2 : 10*2 , mof::Color4f(0 , 1 , 1 , 1) ) + }; + mof::Animation::Handler handler(new mof::KeyFrameAnimation(keyFrames[0] , keyFrames[1])); + DEBUG_PRINT( frame); + handler = mof::makeOffsetHandler< mof::Color4f >( handler , -frame ); + foreach(mof::Sprite*& pSprite , pages.at(currentPage) ){ + pSprite->setColor(handler); + } + } + +//}}} + }; +//{{{ Pager + Pager::Pager + ( + const mof::Rectangle& bounds , + mof::LayoutManager* pLayout + ) + : m_pImpl( new Impl( bounds ) ) + { + m_pImpl->pLayout = pLayout; + } +//}}} +//{{{ ~Pager + Pager::~Pager( ) + { + } +//}}} +//{{{ show + void Pager::show( ) + { + m_pImpl->currentPage = -1; + m_pImpl->currentPage++; + m_pImpl->showPage(true); + } +//}}} +//{{{ close + void Pager::close( ) + { + if(m_pImpl->currentPage < 0)return; + m_pImpl->closePage(true); + } +//}}} +//{{{ nextPage + void Pager::nextPage( ) + { + if(m_pImpl->currentPage < 0){ + show(); + return; + } + m_pImpl->closePage(false); + if(m_pImpl->currentPage >= static_cast(m_pImpl->pages.size()) -1 ){ + close(); + return; + } + m_pImpl->currentPage++; + m_pImpl->showPage(false); + } +//}}} +//{{{ addPage + void Pager::addPage( const mof::PageRequest& page ) + { + m_pImpl->pages.push_back(std::vector()); + mof::compileText( page.message , page.font , m_pImpl->pages.back() ); + + std::vector< mof::Rectangle > boundList; + + foreach(mof::Sprite*& pSprite , m_pImpl->pages.back() ){ + pSprite->setFrameNumber( m_pImpl->frame ); + mof::Rectangle bounds = pSprite->getWorldTransform().toBoundingBox(); + boundList.push_back(bounds); + } + + mof::Vector2D scaling = m_pImpl->scaling->get( )->getValue( m_pImpl->frame ); + m_pImpl->pLayout->replace + ( + scaling.x , scaling.y , + boundList.front() , boundList.back() + ); + + for(unsigned int j = 0 ; j < m_pImpl->pLayout->getLength( ) ; ++j) + { + mof::Animation::Handler children[] = + { + mof::makeConstantHandler + ( + mof::Matrix2D::createScaling + ( + mof::Vector2D(boundList.at(j).getWidth( ) , boundList.at(j).getHeight( ) ) + ) + ) , + m_pImpl->translation , + mof::makeConstantHandler + ( + mof::Matrix2D::createTranslation( m_pImpl->pLayout->getPosition(j) ) + ) + }; // array children + + mof::Animation::Handler handler + ( + new mof::CascadingAnimation( children[0] , mof::lastOf( children ) ) + ); + + m_pImpl->pages.back().at(j)->setWorldTransform( handler ); + m_pImpl->pages.back().at(j)->setColor(mof::Color4f(0 , 1 , 1 , 1)); + + } // for + + } +//}}} +//{{{ draw + void Pager::draw( ) const + { + if(m_pImpl->currentPage < 0)return; + + if(m_pImpl->currentPage > 0){ + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage-1) ){ + pSprite->draw(); + } + } + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage) ){ + pSprite->draw(); + } + } +//}}} +//{{{ update + void Pager::update( ) + { + if(m_pImpl->currentPage < 0)return; + if(m_pImpl->currentPage > 0){ + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage-1) ){ + pSprite->update(); + } + } + foreach(mof::Sprite*& pSprite , m_pImpl->pages.at(m_pImpl->currentPage) ){ + pSprite->update(); + } + m_pImpl->frame++; + } +//}}} +//{{{ hasNextPage + bool Pager::hasNextPage( ) const + { + return m_pImpl->currentPage < static_cast(m_pImpl->pages.size()) -1; + } +//}}} +//{{{ hasPreviousPage + bool Pager::hasPreviousPage( ) const + { + return m_pImpl->currentPage >= 0; + } +//}}} + +//{{{ setPosition + void Pager::setPosition( const mof::Animation::Handler& handler ) + { + m_pImpl->translation->set( handler ); + } +//}}} +//{{{ setSize + void Pager::setSize( const mof::Animation::Handler& handler ) + { + m_pImpl->scaling->set( handler ); + } +//}}} +//{{{ getBounds + mof::Rectangle Pager::getBounds( ) + { + mof::Vector2D scaling = m_pImpl->scaling->get( )->getValue( m_pImpl->frame ); + mof::Vector2D translation = m_pImpl->translation->get( )->getValue( m_pImpl->frame ); + return mof::Rectangle( translation.x , translation.y , translation.x + scaling.x , translation.y + scaling.y ); + } +//}}} +} //namepsace mof + diff --git a/moftmp/widget/Pager.hpp b/moftmp/widget/Pager.hpp new file mode 100755 index 0000000..15300e2 --- /dev/null +++ b/moftmp/widget/Pager.hpp @@ -0,0 +1,44 @@ +#pragma once +#include +#include "mof/tstring.hpp" +#include "mof/Font.hpp" +#include "mof/Rectangle.hpp" +#include "mof/stream/Manipulator.hpp" +#include "mof/Vector2D.hpp" + + +namespace mof +{ + struct PageRequest; + class LayoutManager; + + /** ƒy[ƒW‚©‚ç + */ + class Pager + { + public: + Pager + ( + const mof::Rectangle& bounds , + mof::LayoutManager* pLayout + ); + + ~Pager( ); + + void show( ); + void close( ); + void nextPage( ); + void addPage( const mof::PageRequest& page ); + void draw( ) const; + void update( ); + bool hasNextPage( ) const; + bool hasPreviousPage( ) const; + void setPosition( const mof::Animation::Handler& handler ); + void setSize( const mof::Animation::Handler& handler ); + mof::Rectangle getBounds( ); + private: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} diff --git a/moftmp/widget/Pager.hpp~ b/moftmp/widget/Pager.hpp~ new file mode 100755 index 0000000..9403a68 --- /dev/null +++ b/moftmp/widget/Pager.hpp~ @@ -0,0 +1,44 @@ +#pragma once +#include +#include "mof/tstring.hpp" +#include "mof/Font.hpp" +#include "mof/Rectangle.hpp" +#include "mof/Animation.hpp" +#include "mof/Vector2D.hpp" + + +namespace mof +{ + struct PageRequest; + class LayoutManager; + + /** ƒy[ƒW‚©‚ç + */ + class Pager + { + public: + Pager + ( + const mof::Rectangle& bounds , + mof::LayoutManager* pLayout + ); + + ~Pager( ); + + void show( ); + void close( ); + void nextPage( ); + void addPage( const mof::PageRequest& page ); + void draw( ) const; + void update( ); + bool hasNextPage( ) const; + bool hasPreviousPage( ) const; + void setPosition( const mof::Animation::Handler& handler ); + void setSize( const mof::Animation::Handler& handler ); + mof::Rectangle getBounds( ); + private: + struct Impl; + boost::scoped_ptr m_pImpl; + }; + +} diff --git a/moftmp/widget/Widget.hpp b/moftmp/widget/Widget.hpp new file mode 100755 index 0000000..734c96f --- /dev/null +++ b/moftmp/widget/Widget.hpp @@ -0,0 +1,24 @@ +#pragma once +#include +#include +#include +#include + +namespace mof +{ +namespace widget +{ + + class Widget : public boost::noncopyable + { + public: + virtual ~Widget(){} + virtual FrameNumber show(bool imidiately = false) = 0; + virtual FrameNumber hide(bool imidiately = false) = 0; + virtual const boost::shared_ptr getView() const = 0; + virtual boost::shared_ptr getView() = 0; + virtual void update() = 0; + }; + +} +} diff --git a/moftmp/widget/Widget.hpp~ b/moftmp/widget/Widget.hpp~ new file mode 100755 index 0000000..ac27e42 --- /dev/null +++ b/moftmp/widget/Widget.hpp~ @@ -0,0 +1,24 @@ +#pragma once +#include +#include +#include +#include + +namespace mof +{ +namespace widget +{ + + class Widget : public boost::noncopyable + { + public: + virtual ~Widget(){} + virtual FrameNumber show(bool imidiately = false) = 0; + virtual FrameNumber hide(bool imidiately = false) = 0; + virtual const shared_ptr getView() const = 0; + virtual shared_ptr getView() = 0; + virtual void update() = 0; + }; + +} +} diff --git a/moftmp/widget/WidgetView.hpp b/moftmp/widget/WidgetView.hpp new file mode 100755 index 0000000..1ac57cf --- /dev/null +++ b/moftmp/widget/WidgetView.hpp @@ -0,0 +1,36 @@ +#pragma once +#include "mof/Component2D.hpp" +#include "mof/ColorComponent.hpp" +#include "mof/Drawable.hpp" + +namespace mof +{ +namespace widget +{ + + class WidgetView + : + public Component2D , + public ColorComponent , + public Drawable + { + public: + + virtual ~WidgetView(){}; + + // TODO ƒŒƒCƒAƒEƒg‚̃Aƒjƒ‚ƃCƒxƒ“ƒgŽž‚̃AƒjƒA‚»‚ꂼ‚ê‚Ç‚±‚łǂ̂悤‚ɐݒ肷‚é‚© + // TODO ƒGƒtƒFƒNƒg‚ðŠO‚©‚çÝ’è‚Å‚«‚é‚悤‚É‚·‚é + // TODO “ÁŽê‚ȃRƒ“ƒ|[ƒlƒ“ƒg‚àŠO‚©‚çÝ’è‚Å‚«‚é‚悤‚É + // TODO ƒXƒvƒ‰ƒCƒg‚Í‚Ç‚±‚ªŽ‚‚© + virtual FrameNumber show( bool imidiately = false ) = 0; + virtual FrameNumber hide( bool imidiately = false ) = 0; + virtual FrameNumber focus( bool imidiately = false ) = 0; + virtual FrameNumber blur( bool imidiately = false ) = 0; + virtual FrameNumber click( bool imidiately = false ) = 0; + + virtual void update() = 0; + virtual void draw() const = 0; + }; + +} +} diff --git a/moftmp/widget/WidgetView.hpp~ b/moftmp/widget/WidgetView.hpp~ new file mode 100755 index 0000000..359f58b --- /dev/null +++ b/moftmp/widget/WidgetView.hpp~ @@ -0,0 +1,36 @@ +#pragma once +#include "mof/Component2D.hpp" +#include "mof/ColorComponent.hpp" +#include "mof/Drawable.hpp" + +namespace mof +{ +namespace widget +{ + + class WidgetView + : + public Component2D , + public ColorComponent , + public Drawable + { + public: + + virtual ~WidgetView() = 0; + + // TODO ƒŒƒCƒAƒEƒg‚̃Aƒjƒ‚ƃCƒxƒ“ƒgŽž‚̃AƒjƒA‚»‚ꂼ‚ê‚Ç‚±‚łǂ̂悤‚ɐݒ肷‚é‚© + // TODO ƒGƒtƒFƒNƒg‚ðŠO‚©‚çÝ’è‚Å‚«‚é‚悤‚É‚·‚é + // TODO “ÁŽê‚ȃRƒ“ƒ|[ƒlƒ“ƒg‚àŠO‚©‚çÝ’è‚Å‚«‚é‚悤‚É + // TODO ƒXƒvƒ‰ƒCƒg‚Í‚Ç‚±‚ªŽ‚‚© + virtual FrameNumber show( bool imidiately = false ) = 0; + virtual FrameNumber hide( bool imidiately = false ) = 0; + virtual FrameNumber focus( bool imidiately = false ) = 0; + virtual FrameNumber blur( bool imidiately = false ) = 0; + virtual FrameNumber click( bool imidiately = false ) = 0; + + virtual void update() = 0; + virtual void draw() const = 0; + }; + +} +} diff --git a/moftmp/widget/[ b/moftmp/widget/[ new file mode 100755 index 0000000..0d5a87f --- /dev/null +++ b/moftmp/widget/[ @@ -0,0 +1,39 @@ +#pragma once + +#include "mof/Vector2D.hpp" +#include "mof/Rectangle.hpp" +#include + +namespace mof +{ +namespace widget +{ + class WidgetView; + + class Layout + { + + public: + enum DependencyType + { + PARENT_LEADING , + CHILD_LEADING + }; + + virtual ~Layout(){} + //virtual void add(const Vector2D& size) = 0; + //virtual Vector2D getPositionOf(int index) const = 0 ; + //virtual Vector2D getSizeOf(int index) const = 0 ; + //virtual Vector2D getBounds() const = 0; + virtual void add(boost::shared_ptr pView) = 0; + virtual Vector2D getPreferredSize() = 0; + virtual DependencyType getSizeDependencyType() = 0; + virtual void connect( boost::shared_ptr pParentView) = 0; + virtual size_t getLength() const = 0; + virtual int getAdjacencyAsUp(int index) const = 0; + virtual int getAdjacencyAsDown(int index) const = 0; + virtual int getAdjacencyAsLeft(int index) const = 0; + virtual int getAdjacencyAsRight(int index) const = 0; + }; +} +} diff --git a/moftmp/widget/utilities.cpp b/moftmp/widget/utilities.cpp new file mode 100755 index 0000000..a059edb --- /dev/null +++ b/moftmp/widget/utilities.cpp @@ -0,0 +1,20 @@ +#include "mof/widget/utilities.hpp" +#include "mof/widget/WidgetView.hpp" +#include "mof/Sprite.hpp" + +namespace mof +{ +/* + void setStreamAsChild( Sprite* sprite , const WidgetView* view ) + { + sprite->getColorStream( ) << view->getColorStream( ); + sprite->getPositionStream() << view->getPositionStream( ); + } + + void setStreamAsChild( WidgetView* child , const WidgetView* parent ) + { + child->getColorStream() << parent->getColorStream( ); + child->getPositionStream() << parent->getPositionStream( ); + } +*/ +} diff --git a/moftmp/widget/utilities.cpp~ b/moftmp/widget/utilities.cpp~ new file mode 100755 index 0000000..20a2a60 --- /dev/null +++ b/moftmp/widget/utilities.cpp~ @@ -0,0 +1,20 @@ +#include "mof/widget/utilities.hpp" +#include "mof/widget/WidgetView.hpp" +#include "mof/Sprite.hpp" + +namespace mof +{ + + void setStreamAsChild( Sprite* sprite , const WidgetView* view ) + { + sprite->getColorStream( ) << view->getColorStream( ); + sprite->getPositionStream() << view->getPositionStream( ); + } + + void setStreamAsChild( WidgetView* child , const WidgetView* parent ) + { + child->getColorStream() << parent->getColorStream( ); + child->getPositionStream() << parent->getPositionStream( ); + } + +} diff --git a/moftmp/widget/utilities.hpp b/moftmp/widget/utilities.hpp new file mode 100755 index 0000000..1c11ef7 --- /dev/null +++ b/moftmp/widget/utilities.hpp @@ -0,0 +1,19 @@ +#pragma once +#include +#include + + +namespace mof +{ + class WidgetView; + class Sprite; +/* + void setStreamAsChild( Sprite* spritem , const WidgetView* view ); + + void setStreamAsChild( WidgetView* child , const WidgetView* parent ); +*/ +} + + + + diff --git a/moftmp/widget/utilities.hpp~ b/moftmp/widget/utilities.hpp~ new file mode 100755 index 0000000..d8be549 --- /dev/null +++ b/moftmp/widget/utilities.hpp~ @@ -0,0 +1,21 @@ +#pragma once +#include +#include +#include + + +namespace mof +{ + class WidgetView; + class Sprite; + typedef WidgetViewFactoryMethod; +/* + void setStreamAsChild( Sprite* spritem , const WidgetView* view ); + + void setStreamAsChild( WidgetView* child , const WidgetView* parent ); +*/ +} + + + + diff --git a/moftmp/widgets.hpp b/moftmp/widgets.hpp new file mode 100755 index 0000000..b02112f --- /dev/null +++ b/moftmp/widgets.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "mof/Message.hpp" +//#include "mof/Pager.hpp" +//#include "mof/Page.hpp" +//#include "mof/PlainWidgetView.hpp" +//#include "mof/TextCompiler.hpp" +#include "mof/widget/Widget.hpp" +#include "mof/widget/Menu.hpp" +#include "mof/widget/Frame.hpp" +#include "mof/widget/FrameBuilder.hpp" +#include "mof/widget/WidgetView.hpp" +#include "mof/widget/ImageView.hpp" +#include "mof/widget/Container.hpp" +#include "mof/widget/Layout.hpp" +#include "mof/widget/GridLayout.hpp" +#include "mof/widget/OverlapLayout.hpp" +#include "mof/widget/Widget.hpp" +#include "mof/widget/utilities.hpp" -- 2.11.0