15487SN/A/* 29330SN/A * Copyright 2005, Haiku Inc. 35487SN/A * Distributed under the terms of the MIT License. 45487SN/A * 55487SN/A * Authors: 65487SN/A * Axel D��rfler, axeld@pinc-software.de 75487SN/A */ 85487SN/A 95487SN/A 105487SN/A#include <Application.h> 115487SN/A#include <String.h> 125487SN/A#include <View.h> 135487SN/A#include <Window.h> 145487SN/A 155487SN/A#include <ctype.h> 165487SN/A#include <stdio.h> 175487SN/A#include <stdlib.h> 185487SN/A 195487SN/A 205487SN/Abool gAvoid = true; 215487SN/A 225487SN/A 235487SN/Aclass View : public BView { 245487SN/A public: 255487SN/A View(BRect rect); 265487SN/A virtual ~View(); 275487SN/A 288162SN/A virtual void AttachedToWindow(); 298162SN/A 308162SN/A virtual void KeyDown(const char* bytes, int32 numBytes); 318162SN/A virtual void KeyUp(const char* bytes, int32 numBytes); 328162SN/A 338162SN/A virtual void MouseDown(BPoint where); 3413050Schegar virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); 358162SN/A 365487SN/A virtual void Draw(BRect updateRect); 375487SN/A virtual void Pulse(); 385487SN/A 395487SN/A private: 405487SN/A BString fChar; 415487SN/A bool fPressed; 425487SN/A}; 435487SN/A 445487SN/A 455487SN/AView::View(BRect rect) 465487SN/A : BView(rect, "desktop view", B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED) 475487SN/A{ 485487SN/A SetViewColor(255, 255, 255); 495487SN/A SetHighColor(0, 0, 0); 505487SN/A SetLowColor(ViewColor()); 515487SN/A} 525487SN/A 535487SN/A 545487SN/AView::~View() 555487SN/A{ 565487SN/A} 578162SN/A 588162SN/A 595487SN/Avoid 605487SN/AView::AttachedToWindow() 615487SN/A{ 625487SN/A MakeFocus(true); 635487SN/A KeyDown("<>", 2); 645487SN/A fPressed = false; 655487SN/A} 665487SN/A 675487SN/A 685487SN/Avoid 695487SN/AView::KeyDown(const char* bytes, int32 numBytes) 705487SN/A{ 715487SN/A fChar = bytes; 725487SN/A fPressed = true; 735487SN/A SetHighColor(0, 0, 0); 745487SN/A Window()->SetPulseRate(200000); 755487SN/A Invalidate(); 765487SN/A} 775487SN/A 785487SN/A 795487SN/Avoid 805487SN/AView::KeyUp(const char* bytes, int32 numBytes) 815487SN/A{ 825487SN/A fPressed = false; 835487SN/A Invalidate(); 845487SN/A} 855487SN/A 865487SN/A 875487SN/Avoid 885487SN/AView::MouseDown(BPoint where) 895487SN/A{ 905487SN/A SetHighColor(0, 250, 0); 915487SN/A Invalidate(); 925487SN/A Window()->SetPulseRate(150000); 935487SN/A} 945487SN/A 955487SN/A 965487SN/Avoid 975487SN/AView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) 985487SN/A{ 995487SN/A if (transit == B_ENTERED_VIEW) 1005487SN/A SetHighColor(0, 150, 150); 1015487SN/A else 1025487SN/A SetHighColor(0, 0, 150); 1035487SN/A 1045487SN/A Invalidate(); 1055487SN/A Window()->SetPulseRate(10000); 1065487SN/A} 1075487SN/A 1085487SN/A 1095487SN/Avoid 1105487SN/AView::Draw(BRect updateRect) 1115487SN/A{ 1125487SN/A BFont font; 1135487SN/A font.SetSize(200); 1145487SN/A 1155487SN/A font_height fontHeight; 1165487SN/A font.GetHeight(&fontHeight); 1175487SN/A 1185487SN/A SetFont(&font); 1195487SN/A MovePenTo(20, ceilf(20 + fontHeight.ascent)); 1205487SN/A 1215487SN/A DrawString(fChar.String()); 1225487SN/A} 1235487SN/A 1245487SN/A 1255487SN/Avoid 1265487SN/AView::Pulse() 1275487SN/A{ 1285487SN/A if (fPressed) 1295487SN/A return; 1305487SN/A 1315487SN/A rgb_color color = HighColor(); 1325487SN/A SetHighColor(tint_color(color, B_LIGHTEN_2_TINT)); 1335487SN/A Invalidate(); 1345487SN/A 1355487SN/A if (color.red > 253) 1365487SN/A Window()->SetPulseRate(0); 1375487SN/A} 1385487SN/A 1395487SN/A 1405487SN/A// #pragma mark - 1415487SN/A 1425487SN/A 1435487SN/Aclass Window : public BWindow { 1445487SN/A public: 1455487SN/A Window(); 1465487SN/A virtual ~Window(); 1475487SN/A 1485487SN/A virtual bool QuitRequested(); 1495487SN/A}; 1505487SN/A 1515487SN/A 1525487SN/AWindow::Window() 1535487SN/A : BWindow(BRect(100, 100, 400, 400), "AvoidFocus-Test", 1545487SN/A B_TITLED_WINDOW, (gAvoid ? B_AVOID_FOCUS : 0) | B_ASYNCHRONOUS_CONTROLS) 1555487SN/A{ 1565487SN/A BView *view = new View(Bounds()); 1575487SN/A AddChild(view); 1585487SN/A} 1595487SN/A 1605487SN/A 1615487SN/AWindow::~Window() 1625487SN/A{ 1635487SN/A} 1645487SN/A 1655487SN/A 1665487SN/Abool 1675487SN/AWindow::QuitRequested() 1685487SN/A{ 1695487SN/A be_app->PostMessage(B_QUIT_REQUESTED); 1705487SN/A return true; 1715487SN/A} 1725487SN/A 1735487SN/A 1745487SN/A// #pragma mark - 1755487SN/A 1765487SN/A 1775487SN/Aclass Application : public BApplication { 1785487SN/A public: 1795487SN/A Application(); 1805487SN/A 1815487SN/A virtual void ReadyToRun(); 1825487SN/A}; 1835487SN/A 1845487SN/A 1855487SN/AApplication::Application() 1865487SN/A : BApplication("application/x-vnd.haiku-avoid_focus") 1875487SN/A{ 1885487SN/A} 1895487SN/A 1905487SN/A 1915487SN/Avoid 1925487SN/AApplication::ReadyToRun() 1935487SN/A{ 1945487SN/A Window *window = new Window(); 1955487SN/A window->Show(); 1965487SN/A} 1975487SN/A 1985487SN/A 1995487SN/A// #pragma mark - 2005487SN/A 2015487SN/A 2025487SN/Aint 2035487SN/Amain(int argc, char **argv) 2045487SN/A{ 2055487SN/A if (argc > 1 && (!strcmp(argv[1], "false") || (isdigit(argv[1][0]) && atoi(argv[1]) == 0))) 2065487SN/A gAvoid = false; 2075487SN/A 2085487SN/A Application app; 2095487SN/A 2105487SN/A app.Run(); 2115487SN/A return 0; 2125487SN/A} 2135487SN/A