Cleanup test code. Use a message and run the easter egg from MessageReceived(). USe find_directory() to find the fortune file.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39241 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -643,10 +643,8 @@ void
|
||||
AboutView::MouseDown(BPoint point)
|
||||
{
|
||||
BRect r(92, 26, 105, 31);
|
||||
if (r.Contains(point)) {
|
||||
printf("Easter egg\n");
|
||||
PickRandomHaiku();
|
||||
}
|
||||
if (r.Contains(point))
|
||||
BMessenger(this).SendMessage('eegg');
|
||||
|
||||
if (Bounds().Contains(point)) {
|
||||
fLastActionTime = system_time();
|
||||
@@ -691,6 +689,12 @@ AboutView::MessageReceived(BMessage* msg)
|
||||
break;
|
||||
}
|
||||
|
||||
case 'eegg':
|
||||
{
|
||||
printf("Easter egg\n");
|
||||
PickRandomHaiku();
|
||||
}
|
||||
|
||||
default:
|
||||
BView::MessageReceived(msg);
|
||||
break;
|
||||
@@ -789,18 +793,19 @@ AboutView::AddCopyrightEntry(const char* name, const char* text,
|
||||
void
|
||||
AboutView::PickRandomHaiku()
|
||||
{
|
||||
BFile fortunes(
|
||||
#ifdef __HAIKU__
|
||||
"/etc/fortunes/Haiku",
|
||||
#else
|
||||
"data/etc/fortunes/Haiku",
|
||||
#endif
|
||||
B_READ_ONLY);
|
||||
BPath path;
|
||||
if (find_directory(B_SYSTEM_DATA_DIRECTORY, &path) != B_OK)
|
||||
path = "/system/data";
|
||||
path.Append("fortunes");
|
||||
path.Append("Haiku");
|
||||
|
||||
BFile fortunes(path.Path(), B_READ_ONLY);
|
||||
struct stat st;
|
||||
if (fortunes.InitCheck() < B_OK)
|
||||
return;
|
||||
if (fortunes.GetStat(&st) < B_OK)
|
||||
return;
|
||||
|
||||
char* buff = (char*)malloc((size_t)st.st_size + 1);
|
||||
if (!buff)
|
||||
return;
|
||||
@@ -822,6 +827,7 @@ AboutView::PickRandomHaiku()
|
||||
free(buff);
|
||||
if (haikuList.CountItems() < 1)
|
||||
return;
|
||||
|
||||
BString* s = (BString*)haikuList.ItemAt(rand() % haikuList.CountItems());
|
||||
BFont font(be_bold_font);
|
||||
font.SetSize(be_bold_font->Size());
|
||||
|
||||
Reference in New Issue
Block a user