* Copyright 2014 Haiku, Inc.
* Distributed under the terms of the MIT license.
*
* Authors:
* Adrien Destugues <pulkomandy@pulkomandy.tk>
*/
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <Application.h>
#include <GradientLinear.h>
#include <GradientRadial.h>
#include <LayoutBuilder.h>
#include <List.h>
#include <Message.h>
#include <Picture.h>
#include <PopUpMenu.h>
#include <Roster.h>
#include <ScrollView.h>
#include <String.h>
#include <StringView.h>
#include <View.h>
#include <Window.h>
#include "harness.h"
static const char* kAppSignature = "application/x-vnd.Haiku-Gradients";
class RadialGradientTest : public Test {
public:
RadialGradientTest()
:
Test("Radial Gradient")
{
}
virtual void Draw(BView* view, BRect updateRect)
{
BGradientRadial g1(100, 100, 50);
BGradientRadial g2(300, 100, 100);
g1.AddColor(make_color(0,0,0,255), 0);
g1.AddColor(make_color(255,255,255,255), 255);
g2.AddColor(make_color(0,0,0,255), 0);
g2.AddColor(make_color(255,255,255,255), 255);
BRect r1(0, 0, 200, 200);
BRect r2(200, 0, 400, 200);
view->FillRect(r1, g1);
view->FillRect(r2, g2);
r1.InsetBy(50, 50);
view->StrokeEllipse(r1);
view->StrokeEllipse(r2);
}
};
class AlphaGradientTest : public Test {
public:
AlphaGradientTest()
:
Test("Alpha gradients")
{
}
virtual void Draw(BView* view, BRect updateRect)
{
view->SetDrawingMode(B_OP_ALPHA);
BPoint center(50, 50);
float radius = 50.0;
BGradientRadial g(center, radius);
g.AddColor((rgb_color){ 255, 0, 0, 255 }, 0.0);
g.AddColor((rgb_color){ 0, 255, 0, 0 }, 255.0);
view->FillEllipse(center, radius, radius, g);
BPoint from(100, 0);
BPoint to(200, 0);
BGradientLinear l(from, to);
l.AddColor((rgb_color){ 255, 0, 0, 0 }, 0.0);
l.AddColor((rgb_color){ 0, 255, 0, 255 }, 255.0);
view->FillRect(BRect(100, 0, 200, 100), l);
BPoint top(0, 0);
BPoint bot(0, 100);
BGradientLinear v(top, bot);
v.AddColor((rgb_color){ 255, 0, 0, 0 }, 0.0);
v.AddColor((rgb_color){ 0, 255, 0, 255 }, 255.0);
view->FillRect(BRect(200, 0, 300, 100), v);
view->SetOrigin(BPoint(0, 100));
BGradientRadial go(center, radius);
go.AddColor((rgb_color){ 255, 0, 0, 0 }, 0.0);
go.AddColor((rgb_color){ 0, 255, 0, 255 }, 255.0);
view->FillEllipse(center, radius, radius, go);
BGradientLinear lo(from, to);
lo.AddColor((rgb_color){ 255, 0, 0, 255 }, 0.0);
lo.AddColor((rgb_color){ 0, 255, 0, 0 }, 255.0);
view->FillRect(BRect(100, 0, 200, 100), lo);
BGradientLinear vo(top, bot);
vo.AddColor((rgb_color){ 255, 0, 0, 255 }, 0.0);
vo.AddColor((rgb_color){ 0, 255, 0, 0 }, 255.0);
view->FillRect(BRect(200, 0, 300, 100), vo);
view->SetOrigin(BPoint(0, 0));
view->SetDrawingMode(B_OP_COPY);
BPicture picture;
view->BeginPicture(&picture);
view->SetHighColor(make_color(0,0,0,255));
view->FillRect(BRect(0, 200, 300, 300));
view->EndPicture();
view->ClipToPicture(&picture);
view->SetOrigin(BPoint(0, 200));
view->SetDrawingMode(B_OP_ALPHA);
view->FillEllipse(center, radius, radius, g);
view->FillRect(BRect(100, 0, 200, 100), l);
view->FillRect(BRect(200, 0, 300, 100), v);
}
};
class OutOfBoundsGradientTest : public Test {
public:
OutOfBoundsGradientTest()
:
Test("Out of bounds gradients")
{
}
virtual void Draw(BView* view, BRect updateRect)
{
{
BPoint from(275, 10);
BPoint to(275, 138);
BGradientLinear l(from, to);
l.AddColor((rgb_color){ 255, 0, 0, 255 }, 100.0);
l.AddColor((rgb_color){ 255, 255, 0, 255 }, 156.0);
view->FillRect(BRect(275, 10, 2*265, 265), l);
}
{
BPoint from(10, 10);
BPoint to(138, 10);
BGradientLinear l(from, to);
l.AddColor((rgb_color){ 255, 0, 0, 255 }, 100.0);
l.AddColor((rgb_color){ 255, 255, 0, 255 }, 156.0);
view->FillRect(BRect(10, 10, 265, 265), l);
}
}
};
int
main(int argc, char** argv)
{
BApplication app(kAppSignature);
TestWindow* window = new TestWindow("Gradient tests");
window->AddTest(new RadialGradientTest());
window->AddTest(new AlphaGradientTest());
window->AddTest(new OutOfBoundsGradientTest());
window->SetToTest(0);
window->Show();
app.Run();
return 0;
}