1 /* 2 * Copyright 2006, Haiku Inc. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include <Application.h> 11 #include <Bitmap.h> 12 #include <Cursor.h> 13 #include <Debug.h> 14 #include <String.h> 15 #include <View.h> 16 #include <Window.h> 17 18 #include <algorithm> 19 #include <ctype.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 23 #include "bitmap.h" 24 25 26 class View : public BView { 27 public: 28 View(BRect rect); 29 virtual ~View(); 30 31 virtual void AttachedToWindow(); 32 }; 33 34 35 bool gHide = false; 36 37 38 View::View(BRect rect) 39 : BView(rect, "desktop view", B_FOLLOW_ALL, B_WILL_DRAW) 40 { 41 SetViewColor(0, 150, 0); 42 } 43 44 45 View::~View() 46 { 47 } 48 49 50 void 51 View::AttachedToWindow() 52 { 53 } 54 55 56 // #pragma mark - 57 58 59 class Window : public BWindow { 60 public: 61 Window(); 62 virtual ~Window(); 63 64 virtual bool QuitRequested(); 65 }; 66 67 68 Window::Window() 69 : BWindow(BRect(100, 100, 400, 400), "Cursor-Test", 70 B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) 71 { 72 BView *view = new View(Bounds().InsetByCopy(30, 30)); 73 AddChild(view); 74 } 75 76 77 Window::~Window() 78 { 79 } 80 81 82 bool 83 Window::QuitRequested() 84 { 85 be_app->PostMessage(B_QUIT_REQUESTED); 86 return true; 87 } 88 89 90 // #pragma mark - 91 92 93 class Application : public BApplication { 94 public: 95 Application(); 96 97 virtual void ReadyToRun(); 98 }; 99 100 101 Application::Application() 102 : BApplication("application/x-vnd.haiku-cursor_test") 103 { 104 } 105 106 107 void 108 Application::ReadyToRun() 109 { 110 Window *window = new Window(); 111 window->Show(); 112 113 if (gHide) 114 HideCursor(); 115 else { 116 BBitmap* bitmap = new BBitmap( 117 BRect(0, 0, kBitmapWidth - 1, kBitmapHeight - 1), 0,kBitmapFormat); 118 bitmap->ImportBits(kBitmapBits, sizeof(kBitmapBits), kBitmapWidth * 4, 119 0, kBitmapFormat); 120 BPoint hotspot(8, 8); 121 BCursor cursor(bitmap, hotspot); 122 SetCursor(&cursor); 123 } 124 } 125 126 127 // #pragma mark - 128 129 130 int 131 main(int argc, char **argv) 132 { 133 if (argc > 1 && !strcmp(argv[1], "hide")) 134 gHide = true; 135 136 Application app; 137 138 app.Run(); 139 return 0; 140 } 141