From 9cc58f8d917f00a29434ef3cba1ceaa0a465f80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=AF=E6=AD=8C?= Date: Mon, 22 Jul 2024 15:33:42 +0800 Subject: [PATCH] remove widget/pagetransformers.cc,moved to apps/samples --- apps/samples/CMakeLists.txt | 1 + .../samples}/pagetransformers.h | 0 apps/samples/viewpager1.cc | 2 +- apps/samples/viewpager3.cc | 2 +- apps/samples/viewpagervert.cc | 2 +- src/gui/drawables/drawable.cc | 4 +- src/gui/widget/pagetransformers.cc | 215 ------------------ 7 files changed, 6 insertions(+), 220 deletions(-) rename {src/gui/widget => apps/samples}/pagetransformers.h (100%) delete mode 100644 src/gui/widget/pagetransformers.cc diff --git a/apps/samples/CMakeLists.txt b/apps/samples/CMakeLists.txt index 63edc6d1..eb723a1d 100755 --- a/apps/samples/CMakeLists.txt +++ b/apps/samples/CMakeLists.txt @@ -6,6 +6,7 @@ find_package(PLPLOT) find_package(CDROID) find_package(Freetype) include_directories( + ./ ${CDROID_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS} ${FONTCONFIG_INCLUDE_DIRS} diff --git a/src/gui/widget/pagetransformers.h b/apps/samples/pagetransformers.h similarity index 100% rename from src/gui/widget/pagetransformers.h rename to apps/samples/pagetransformers.h diff --git a/apps/samples/viewpager1.cc b/apps/samples/viewpager1.cc index 95618ac1..aba282fa 100755 --- a/apps/samples/viewpager1.cc +++ b/apps/samples/viewpager1.cc @@ -1,6 +1,6 @@ #include #include -#include +#include static int mPageCount=5; class MyPageAdapter:public PagerAdapter{ public: diff --git a/apps/samples/viewpager3.cc b/apps/samples/viewpager3.cc index 2b134518..59ffe4f0 100755 --- a/apps/samples/viewpager3.cc +++ b/apps/samples/viewpager3.cc @@ -1,6 +1,6 @@ #include #include -#include +#include #include using namespace Cairo; class MyPageAdapter:public PagerAdapter{ diff --git a/apps/samples/viewpagervert.cc b/apps/samples/viewpagervert.cc index 5986761c..5d0398f0 100755 --- a/apps/samples/viewpagervert.cc +++ b/apps/samples/viewpagervert.cc @@ -1,6 +1,6 @@ #include #include -#include +#include static int mPageCount=5; class MyPageAdapter:public PagerAdapter{ public: diff --git a/src/gui/drawables/drawable.cc b/src/gui/drawables/drawable.cc index c66e01f0..4d7cdba0 100644 --- a/src/gui/drawables/drawable.cc +++ b/src/gui/drawables/drawable.cc @@ -613,8 +613,8 @@ static void endElement(void *userData, const XML_Char *name) { LayerDrawable* ld = dynamic_cast(parent); const int idx = ld->addLayer(topchild); ld->setLayerAttributes(idx,atts); - LOGV("%p add %s %p to Layer/TransitionDrawable %p index=%d id=%d gravity=%x size=%dx%d",pd,name,topchild, - parent,idx,id,ld->getLayerGravity(idx),ld->getLayerWidth(idx),ld->getLayerHeight(idx)); + LOGV("%p add %s %p to Layer/TransitionDrawable %p index=%d gravity=%x size=%dx%d",pd,name,topchild, + parent,idx,ld->getLayerGravity(idx),ld->getLayerWidth(idx),ld->getLayerHeight(idx)); } else if(dynamic_cast(parent)) { AnimationDrawable* ad = (AnimationDrawable*)parent; const int duration = atts.getInt("duration",0); diff --git a/src/gui/widget/pagetransformers.cc b/src/gui/widget/pagetransformers.cc deleted file mode 100644 index 8d209457..00000000 --- a/src/gui/widget/pagetransformers.cc +++ /dev/null @@ -1,215 +0,0 @@ -#include -#include -namespace cdroid{ - -void ABaseTransformer::transformPage(View& page, float position) { - onPreTransform(page, position); - onTransform(page, position); - onPostTransform(page, position); -} - -bool ABaseTransformer::hideOffscreenPages(){ - return true; -} - -bool ABaseTransformer::isPagingEnabled(){ - return false; -} - -void ABaseTransformer::onPreTransform(View& page, float position) { - const float width = page.getWidth(); - - page.setRotationX(0); - page.setRotationY(0); - page.setRotation(0); - page.setScaleX(1); - page.setScaleY(1); - page.setPivotX(0); - page.setPivotY(0); - page.setTranslationY(0); - page.setTranslationX(isPagingEnabled() ? .0f : -width * position); - - if (hideOffscreenPages()) { - page.setAlpha(position <= -1.f || position >= 1.f ? .0f : 1.f); - //page.setEnabled(false); - } else { - //page.setEnabled(true); - page.setAlpha(1.f); - } -} - -void ABaseTransformer::onPostTransform(View& page, float position){ -} - -void AccordionTransformer::onTransform(View& view, float position) { - view.setPivotX(position < 0 ? 0 : view.getWidth()); - view.setScaleX(position < 0 ? 1.f + position : 1.f - position); -} - - -void CubeInTransformer::onTransform(View& view, float position) { - LOGD("cubein %d,%d",view.getWidth(),view.getHeight()); - // Rotate the fragment on the left or right edge - view.setPivotX(position > 0 ? 0 : view.getWidth()); - view.setPivotY(0); - view.setRotationY(-90.f * position); -} - -bool CubeInTransformer::isPagingEnabled() { - return true; -} - -void CubeOutTransformer::onTransform(View& view, float position) { - view.setPivotX(position < .0f ? view.getWidth() : .0f); - view.setPivotY(view.getHeight() * 0.5f); - view.setRotationY(90.f * position); -} - -bool CubeOutTransformer::isPagingEnabled() { - return true; -} - -void DefaultTransformer::onTransform(View& view, float position){} -bool DefaultTransformer::isPagingEnabled(){return true;} - - -void FlipHorizontalTransformer::onTransform(View& view, float position){ - const float rotation = 180.f * position; - - view.setAlpha(rotation > 90.f || rotation < -90.f ? 0 : 1); - view.setPivotX(view.getWidth() * 0.5f); - view.setPivotY(view.getHeight() * 0.5f); - view.setRotationY(rotation); -} - -void FlipHorizontalTransformer::onPostTransform(View& page, float position){ - ABaseTransformer::onPostTransform(page, position); - - //resolve problem: new page can't handle click event! - page.setVisibility((position > -0.5f && position < 0.5f)?View::VISIBLE:View::INVISIBLE); -} - -void FlipVerticalTransformer::onTransform(View& view, float position) { - const float rotation = -180.f * position; - - view.setAlpha(rotation > 90.f || rotation < -90.f ? .0f : 1.f); - view.setPivotX(view.getWidth() * 0.5f); - view.setPivotY(view.getHeight() * 0.5f); - view.setRotationX(rotation); -} - -void FlipVerticalTransformer::onPostTransform(View& page, float position) { - ABaseTransformer::onPostTransform(page, position); - - page.setVisibility((position > -0.5f && position < 0.5f)?View::VISIBLE:View::INVISIBLE); -} - -void ParallaxTransformer::transformPage(View& page, float position){ - const int width = page.getWidth(); - if (position < -1) { - page.setScrollX((int) (width * 0.75 * -1)); - } else if (position <= 1) { - if (position < 0) { - page.setScrollX((int) (width * 0.75 * position)); - } else { - page.setScrollX((int) (width * 0.75 * position)); - } - } else { - page.setScrollX((int) (width * 0.75)); - } -} - -void RotateDownTransformer::onTransform(View& view, float position) { - const float width = view.getWidth(); - const float height = view.getHeight(); - const float rotation = ROT_MOD * position * -1.25f; - - view.setPivotX(width * 0.5f); - view.setPivotY(height); - view.setRotation(rotation); -} - -bool RotateDownTransformer::isPagingEnabled() { - return true; -} - -void RotateUpTransformer::onTransform(View& view, float position) { - const float width = view.getWidth(); - const float rotation = ROT_MOD * position; - - view.setPivotX(width * 0.5f); - view.setPivotY(.0f); - view.setTranslationX(.0f); - view.setRotation(rotation); -} - -bool RotateUpTransformer::isPagingEnabled() { - return true; -} - -void ScaleInOutTransformer::onTransform(View& view, float position){ - view.setPivotX(position < 0 ? 0 : view.getWidth()); - view.setPivotY(view.getHeight() / 2.f); - float scale = position < 0 ? 1.f + position : 1.f - position; - view.setScaleX(scale); - view.setScaleY(scale); -} - -void StackTransformer::onTransform(View& view, float position) { - view.setTranslationX(position < 0 ? .0f : -view.getWidth() * position); -} - -void ZoomInTransformer::onTransform(View& view, float position) { - const float scale = position < 0 ? position + 1.f : std::abs(1.f - position); - view.setScaleX(scale); - view.setScaleY(scale); - view.setPivotX(view.getWidth() * 0.5f); - view.setPivotY(view.getHeight()* 0.5f); - view.setAlpha(position < -1.f || position > 1.f ? .0f : 1.f - (scale - 1.f)); -} - -void ZoomOutTransformer::onTransform(View& view, float position) { - const float scale = position < 0 ? position + 1.f : std::abs(1.f - position); - view.setScaleX(scale); - view.setScaleY(scale); - view.setPivotX(view.getWidth() * 0.5f); - view.setPivotY(view.getHeight() * 0.5f); - view.setAlpha(position < -1.f || position > 1.f ? .0f : 1.f - (scale - 1.f)); -} - -ZoomOutSlideTransformer::ZoomOutSlideTransformer():ZoomOutSlideTransformer(.85f,.5f){ -} - -ZoomOutSlideTransformer::ZoomOutSlideTransformer(float minscale,float minalpha){ - mMinScale=minscale; - mMinAlpha=minalpha; -} - -void ZoomOutSlideTransformer::onTransform(View& view, float position) { - if ((position >= -1.f) || (position <= 1.f)) { - // Modify the default slide transition to shrink the page as well - const float height = view.getHeight(); - const float width = view.getWidth(); - const float scaleFactor = std::max(mMinScale, 1.f - std::abs(position)); - const float vertMargin = height * (1.f - scaleFactor) / 2.f; - const float horzMargin = width * (1.f - scaleFactor) / 2.f; - - // Center vertically - view.setPivotY(0.5f * height); - view.setPivotX(0.5f * width); - - if (position < 0) { - view.setTranslationX(horzMargin - vertMargin / 2.f); - } else { - view.setTranslationX(-horzMargin+ vertMargin / 2.f); - } - - // Scale the page down (between MIN_SCALE and 1) - view.setScaleX(scaleFactor); - view.setScaleY(scaleFactor); - - // Fade the page relative to its size. - view.setAlpha(mMinAlpha + (scaleFactor - mMinScale) / (1.f - mMinScale) * (1.f - mMinAlpha)); - } -} -}//endof namespace