Skip to content

Commit f545e15

Browse files
authored
Merge pull request #10 from humdingerb/backs
Always draw a background bitmap
2 parents 64af87e + 81fc09d commit f545e15

File tree

8 files changed

+18
-52
lines changed

8 files changed

+18
-52
lines changed

Backgrounds.wonderbrush

4.33 MB
Binary file not shown.

MainWindow.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
* Copyright 2018 Humdinger
3+
* Copyright 2017-2018 Owen
24
* Copyright 2009-2017 Scott McCreary
35
* Copyright 2014-2016 Puck Meerburg
46
* Copyright 2013 Luke (noryb009)
@@ -18,7 +20,9 @@
1820
#include <Bitmap.h>
1921
#include <TranslationUtils.h>
2022
#include <Roster.h>
23+
#include <StringList.h>
2124
#include <Path.h>
25+
#include <PathFinder.h>
2226
#include <Entry.h>
2327
#include <Directory.h>
2428
#include <Box.h>
@@ -70,15 +74,18 @@ MainWindow::MainWindow(void)
7074
fGrid(NULL),
7175
fWorkGrid(NULL)
7276
{
73-
app_info ai;
74-
be_app->GetAppInfo(&ai);
75-
BPath path(&ai.ref);
76-
path.GetParent(&path);
77-
path.Append("backgrounds");
78-
fBackPath = path.Path();
77+
BPath path;
78+
BPathFinder pathFinder;
79+
BStringList paths;
80+
81+
status_t error = pathFinder.FindPaths(B_FIND_PATH_DATA_DIRECTORY,
82+
"hexvexed/backgrounds", paths);
83+
84+
if (error == B_OK && path.SetTo(paths.StringAt(0)) == B_OK)
85+
fBackPath = path.Path();
86+
7987
fBackPath << "/";
8088

81-
static const rgb_color beos_blue = {51,102,152,255};
8289
Preferences::Init();
8390
Preferences::LockPreferences();
8491
Preferences::Load();
@@ -99,10 +106,8 @@ MainWindow::MainWindow(void)
99106
Preferences::Message().AddInt8("numberbase", fNumberBase);
100107
}
101108

102-
fBack = new BackView(Bounds(),"background",B_FOLLOW_ALL,B_WILL_DRAW | B_DRAW_ON_CHILDREN);
109+
fBack = new BView(Bounds(),"background",B_FOLLOW_ALL,B_WILL_DRAW | B_DRAW_ON_CHILDREN);
103110
AddChild(fBack);
104-
rgb_color randa = {rand() % 255, rand() % 255, rand() % 255, 255};
105-
fBack->SetViewColor(B_TRANSPARENT_COLOR);
106111

107112
fMenuBar = new BMenuBar(BRect(0,0,Bounds().Width(),20),"menubar");
108113
fBack->AddChild(fMenuBar);
@@ -229,6 +234,8 @@ MainWindow::MainWindow(void)
229234

230235
if(Preferences::Message().FindString("background",&fBackName) == B_OK)
231236
SetBackground(fBackName.String());
237+
else
238+
SetBackground("Grass.png"); //default
232239

233240
Preferences::UnlockPreferences();
234241
}
@@ -511,8 +518,6 @@ void MainWindow::ScanBackgrounds(void)
511518

512519
BMessage *msg = new BMessage(M_SET_BACKGROUND);
513520
msg->AddString("name","");
514-
fBackMenu->AddItem(new BMenuItem("None",msg));
515-
fBackMenu->AddSeparatorItem();
516521

517522
BDirectory dir(fBackPath.String());
518523
dir.Rewind();

MainWindow.h

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,6 @@
2626

2727
class HexGrid;
2828

29-
class BackView : public BView
30-
{
31-
public:
32-
BackView(BRect r, const char* t, uint32 fl, uint32 fl2)
33-
: BView(r, t, fl, fl2) {
34-
fBackgroundColor = BScreen().DesktopColor();
35-
app_info info;
36-
be_roster->GetActiveAppInfo(&info);
37-
BEntry entry(&info.ref);
38-
BPath path;
39-
entry.GetPath(&path);
40-
path.Append("backgrounds/background.png");
41-
bitmap = BTranslationUtils::GetBitmap(path.Path());
42-
}
43-
44-
45-
46-
void Draw(BRect rect) {
47-
SetHighColor(fBackgroundColor);
48-
FillRect(Bounds());
49-
if (bitmap)
50-
DrawBitmap(bitmap, bitmap->Bounds(), Bounds());
51-
SetLowColor(fBackgroundColor);
52-
}
53-
54-
void SetBackgroundColor(rgb_color color) {
55-
fBackgroundColor = color;
56-
Invalidate();
57-
}
58-
59-
rgb_color BackgroundColor() {
60-
return fBackgroundColor;
61-
}
62-
63-
private:
64-
rgb_color fBackgroundColor;
65-
BBitmap *bitmap;
66-
};
67-
6829
class MainWindow : public BWindow
6930
{
7031
public:
@@ -78,7 +39,7 @@ class MainWindow : public BWindow
7839
void SetBackground(const char *name);
7940

8041
HexGrid *fGrid, *fWorkGrid;
81-
BackView *fBack;
42+
BView *fBack;
8243
BMenuBar *fMenuBar;
8344
BMenu *fBackMenu;
8445
TimerView *fTimer;

background.png

-745 KB
Binary file not shown.

backgrounds/Fire.png

453 KB
Loading

backgrounds/Gold.png

48.4 KB
Loading

backgrounds/Grass.png

41.9 KB
Loading

backgrounds/Sky.png

42.9 KB
Loading

0 commit comments

Comments
 (0)