From 9813f97ff97dc717fb9dfa4fa8fdfe9338b3bf5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 4 Jul 2006 09:32:48 +0000 Subject: [PATCH] added a test showing the R5 bug that ignores the internal coordinate system given by BBitmap::Bounds() when drawing bitmaps (Haiku copies this bug) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18022 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/servers/app/Jamfile | 3 + src/tests/servers/app/bitmap_bounds/Jamfile | 16 +++ src/tests/servers/app/bitmap_bounds/main.cpp | 132 +++++++++++++++++++ src/tests/servers/app/bitmap_bounds/run | 17 +++ 4 files changed, 168 insertions(+) create mode 100644 src/tests/servers/app/bitmap_bounds/Jamfile create mode 100644 src/tests/servers/app/bitmap_bounds/main.cpp create mode 100755 src/tests/servers/app/bitmap_bounds/run diff --git a/src/tests/servers/app/Jamfile b/src/tests/servers/app/Jamfile index 04432dca92..de4c91358e 100644 --- a/src/tests/servers/app/Jamfile +++ b/src/tests/servers/app/Jamfile @@ -142,13 +142,16 @@ HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : haiku_app_server } # if $(TARGET_PLATFORM) = libbe_test +SubInclude HAIKU_TOP src tests servers app archived_view ; SubInclude HAIKU_TOP src tests servers app avoid_focus ; +SubInclude HAIKU_TOP src tests servers app bitmap_bounds ; SubInclude HAIKU_TOP src tests servers app bitmap_drawing ; SubInclude HAIKU_TOP src tests servers app code_to_name ; SubInclude HAIKU_TOP src tests servers app copy_bits ; SubInclude HAIKU_TOP src tests servers app cursor_test ; SubInclude HAIKU_TOP src tests servers app desktop_window ; SubInclude HAIKU_TOP src tests servers app event_mask ; +SubInclude HAIKU_TOP src tests servers app first_show ; SubInclude HAIKU_TOP src tests servers app following ; SubInclude HAIKU_TOP src tests servers app look_and_feel ; SubInclude HAIKU_TOP src tests servers app painter ; diff --git a/src/tests/servers/app/bitmap_bounds/Jamfile b/src/tests/servers/app/bitmap_bounds/Jamfile new file mode 100644 index 0000000000..bf7c0532f6 --- /dev/null +++ b/src/tests/servers/app/bitmap_bounds/Jamfile @@ -0,0 +1,16 @@ +SubDir HAIKU_TOP src tests servers app bitmap_bounds ; + +SetSubDirSupportedPlatformsBeOSCompatible ; +AddSubDirSupportedPlatforms libbe_test ; + +UseHeaders [ FDirName os app ] ; +UseHeaders [ FDirName os interface ] ; + +SimpleTest BitmapBounds : + main.cpp + : be ; + +if ( $(TARGET_PLATFORM) = libbe_test ) { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : BitmapBounds + : tests!apps ; +} diff --git a/src/tests/servers/app/bitmap_bounds/main.cpp b/src/tests/servers/app/bitmap_bounds/main.cpp new file mode 100644 index 0000000000..3aa7e6160d --- /dev/null +++ b/src/tests/servers/app/bitmap_bounds/main.cpp @@ -0,0 +1,132 @@ +// main.cpp + +#include + +#include +#include +#include +#include + +class TestView : public BView { + + public: + TestView(BRect frame, const char* name, + uint32 resizeFlags, uint32 flags); + + virtual void Draw(BRect updateRect); + + private: + BBitmap* fBitmap; +}; + +//#define LEFT_OFFSET 0 +//#define TOP_OFFSET 0 +#define LEFT_OFFSET 30 +#define TOP_OFFSET 30 + +// constructor +TestView::TestView(BRect frame, const char* name, + uint32 resizeFlags, uint32 flags) + : BView(frame, name, resizeFlags, flags), + + fBitmap(new BBitmap(BRect(0 + LEFT_OFFSET, + 0 + TOP_OFFSET, + 99 + LEFT_OFFSET, + 99 + TOP_OFFSET), + B_BITMAP_CLEAR_TO_WHITE, + B_RGB32)) +{ + SetViewColor(216, 216, 216); + + uint8* bits = (uint8*)fBitmap->Bits(); + uint32 width = fBitmap->Bounds().IntegerWidth() + 1; + uint32 height = fBitmap->Bounds().IntegerHeight() + 1; + uint32 bpr = fBitmap->BytesPerRow(); + + // top row -> red + uint8* b = bits; + for (uint32 x = 0; x < width; x++) { + b[0] = 0; + b[1] = 0; + b += 4; + } + + // left/right edge pixels -> red + b = bits + bpr; + for (uint32 y = 1; y < height - 1; y++) { + b[0] = 0; + b[1] = 0; + b[(width - 1) * 4 + 0] = 0; + b[(width - 1) * 4 + 1] = 0; + b += bpr; + } + + // bottom row -> red + for (uint32 x = 0; x < width; x++) { + b[0] = 0; + b[1] = 0; + b += 4; + } +} + +// Draw +void +TestView::Draw(BRect updateRect) +{ +// DrawBitmap(BBitmap*, BRect source, BRect destination); +// +// BeBook: +// If a source rectangle is given, only that part of the +// bitmap image is drawn. Otherwise, the entire bitmap +// is placed in the view. The source rectangle is stated +// in the internal coordinates of the BBitmap object. + +// Test 1: + // if the above was true, then we should see the left + // top area of the bitmap... +// BRect view(0, 0, 50, 50); +// BRect bitmap = view.OffsetByCopy(fBitmap->Bounds().LeftTop()); +// +// DrawBitmap(fBitmap, bitmap, view); + +// Test 2: + // if the above was true, we should simply see the entire + // bitmap at the left top corner of the view + BRect bitmap = fBitmap->Bounds(); + BRect view = bitmap.OffsetToCopy(B_ORIGIN); + + DrawBitmap(fBitmap, bitmap, view); + +} + + +// show_window +void +show_window(BRect frame, const char* name) +{ + BWindow* window = new BWindow(frame, name, + B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE); + + BView* view = new TestView(window->Bounds(), "test", + B_FOLLOW_ALL, B_WILL_DRAW); + window->AddChild(view); + + window->Show(); +} + +// main +int +main(int argc, char** argv) +{ + BApplication* app = new BApplication( + "application/x.vnd-Haiku.BitmapBounds"); + + BRect frame(50.0, 50.0, 300.0, 250.0); + show_window(frame, "Bitmap-Bounds Test"); + + app->Run(); + + delete app; + return 0; +} diff --git a/src/tests/servers/app/bitmap_bounds/run b/src/tests/servers/app/bitmap_bounds/run new file mode 100755 index 0000000000..e867c23e04 --- /dev/null +++ b/src/tests/servers/app/bitmap_bounds/run @@ -0,0 +1,17 @@ +#!/bin/sh + +../../../../../generated/tests/libbe_test/x86/apps/run_haiku_registrar || exit + +if test -f ../../../../../generated/tests/libbe_test/x86/apps/haiku_app_server; then + ../../../../../generated/tests/libbe_test/x86/apps/haiku_app_server & +else + echo "You need to \"TARGET_PLATFORM=libbe_test jam install-test-apps\" first." +fi + +sleep 1s + +if test -f ../../../../../generated/tests/libbe_test/x86/apps/BitmapBounds; then + ../../../../../generated/tests/libbe_test/x86/apps/BitmapBounds +else + echo "You need to \"TARGET_PLATFORM=libbe_test jam install-test-apps\" first." +fi