2 * Copyright 2009 Vincent Duvert, vincent.duvert@free.fr
3 * Copyright 2014 Haiku, Inc. All rights reserved.
5 * Distributed under the terms of the MIT License.
8 * Vincent Duvert, vincent.duvert@free.fr
9 * John Scipione, jscipione@gmail.com
13 #include "IconDisplay.h"
18 #include <IconUtils.h>
21 #include "VectorIcon.h"
24 #define RAND_BETWEEN(a, b) ((rand() % ((b) - (a) + 1) + (a)))
25 #define SHOW_TICKS_MIN 20
26 #define SHOW_TICKS_MAX 50
27 #define STAY_TICKS_MIN 50
28 #define STAY_TICKS_MAX 100
29 #define HIDE_TICKS_MIN 20
30 #define HIDE_TICKS_MAX 50
33 IconDisplay::IconDisplay()
41 IconDisplay::~IconDisplay()
48 IconDisplay::Run(vector_icon
* icon
, BRect frame
)
52 fBitmap
= new BBitmap(BRect(0, 0, frame
.Width(), frame
.Height()), 0,
54 if (BIconUtils::GetVectorIcon(icon
->data
, icon
->size
, fBitmap
) != B_OK
)
59 fDelay
= RAND_BETWEEN(SHOW_TICKS_MIN
, SHOW_TICKS_MAX
);
67 IconDisplay::ClearOn(BView
* view
)
69 if (!fIsRunning
|| fState
== 2)
72 view
->FillRect(fFrame
);
77 IconDisplay::DrawOn(BView
* view
, uint32 delta
)
84 rgb_color backColor
= view
->HighColor();
88 // progressive showing
90 backColor
.alpha
= (fTicks
* 255) / fDelay
;
98 backColor
.alpha
= 255;
100 fDelay
= RAND_BETWEEN(STAY_TICKS_MIN
, STAY_TICKS_MAX
);
110 backColor
.alpha
= 255;
111 fDelay
= RAND_BETWEEN(HIDE_TICKS_MIN
, HIDE_TICKS_MAX
);
117 // progressive hiding
118 if (fTicks
< fDelay
) {
119 backColor
.alpha
= 255 - (fTicks
* 255) / fDelay
;
133 view
->SetHighColor(backColor
);
134 view
->DrawBitmap(fBitmap
, BPoint(fFrame
.left
, fFrame
.top
));
135 backColor
.alpha
= 255;
136 view
->SetHighColor(backColor
);