1#include <stdio.h> 2#include <stdlib.h> 3 4#include <Application.h> 5#include <View.h> 6#include <Window.h> 7 8 9class PulsedView : public BView { 10public: 11 PulsedView(BRect frame) 12 : 13 BView(frame, "pulsed view", B_FOLLOW_ALL, B_WILL_DRAW) 14 { 15 } 16 17 virtual void Draw(BRect updateRect) 18 { 19 SetHighColor(rand() % 255, rand() % 255, rand() % 255, 255); 20 FillRect(updateRect); 21 } 22}; 23 24 25class PulsedApplication : public BApplication { 26public: 27 PulsedApplication() 28 : 29 BApplication("application/x-vnd.haiku.pulsed_drawing") 30 { 31 BRect frame(100, 100, 400, 300); 32 BWindow* window = new BWindow(frame, "Pulsed Drawing", 33 B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_QUIT_ON_WINDOW_CLOSE); 34 35 fView = new PulsedView(frame.OffsetToCopy(0, 0)); 36 window->AddChild(fView); 37 window->Show(); 38 39 SetPulseRate(1 * 1000 * 1000); 40 } 41 42 virtual void Pulse() 43 { 44 if (!fView->LockLooper()) 45 return; 46 47 fView->Invalidate(); 48 fView->UnlockLooper(); 49 } 50 51private: 52 PulsedView* fView; 53}; 54 55 56int 57main(int argc, char* argv[]) 58{ 59 PulsedApplication app; 60 app.Run(); 61 return 0; 62} 63