Skip to content

Commit

Permalink
Merge pull request #10 from humdingerb/backs
Browse files Browse the repository at this point in the history
Always draw a background bitmap
  • Loading branch information
scottmc authored Sep 19, 2018
2 parents 64af87e + 81fc09d commit f545e15
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 52 deletions.
Binary file added Backgrounds.wonderbrush
Binary file not shown.
29 changes: 17 additions & 12 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
* Copyright 2018 Humdinger
* Copyright 2017-2018 Owen
* Copyright 2009-2017 Scott McCreary
* Copyright 2014-2016 Puck Meerburg
* Copyright 2013 Luke (noryb009)
Expand All @@ -18,7 +20,9 @@
#include <Bitmap.h>
#include <TranslationUtils.h>
#include <Roster.h>
#include <StringList.h>
#include <Path.h>
#include <PathFinder.h>
#include <Entry.h>
#include <Directory.h>
#include <Box.h>
Expand Down Expand Up @@ -70,15 +74,18 @@ MainWindow::MainWindow(void)
fGrid(NULL),
fWorkGrid(NULL)
{
app_info ai;
be_app->GetAppInfo(&ai);
BPath path(&ai.ref);
path.GetParent(&path);
path.Append("backgrounds");
fBackPath = path.Path();
BPath path;
BPathFinder pathFinder;
BStringList paths;

status_t error = pathFinder.FindPaths(B_FIND_PATH_DATA_DIRECTORY,
"hexvexed/backgrounds", paths);

if (error == B_OK && path.SetTo(paths.StringAt(0)) == B_OK)
fBackPath = path.Path();

fBackPath << "/";

static const rgb_color beos_blue = {51,102,152,255};
Preferences::Init();
Preferences::LockPreferences();
Preferences::Load();
Expand All @@ -99,10 +106,8 @@ MainWindow::MainWindow(void)
Preferences::Message().AddInt8("numberbase", fNumberBase);
}

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

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

if(Preferences::Message().FindString("background",&fBackName) == B_OK)
SetBackground(fBackName.String());
else
SetBackground("Grass.png"); //default

Preferences::UnlockPreferences();
}
Expand Down Expand Up @@ -511,8 +518,6 @@ void MainWindow::ScanBackgrounds(void)

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

BDirectory dir(fBackPath.String());
dir.Rewind();
Expand Down
41 changes: 1 addition & 40 deletions MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,6 @@

class HexGrid;

class BackView : public BView
{
public:
BackView(BRect r, const char* t, uint32 fl, uint32 fl2)
: BView(r, t, fl, fl2) {
fBackgroundColor = BScreen().DesktopColor();
app_info info;
be_roster->GetActiveAppInfo(&info);
BEntry entry(&info.ref);
BPath path;
entry.GetPath(&path);
path.Append("backgrounds/background.png");
bitmap = BTranslationUtils::GetBitmap(path.Path());
}



void Draw(BRect rect) {
SetHighColor(fBackgroundColor);
FillRect(Bounds());
if (bitmap)
DrawBitmap(bitmap, bitmap->Bounds(), Bounds());
SetLowColor(fBackgroundColor);
}

void SetBackgroundColor(rgb_color color) {
fBackgroundColor = color;
Invalidate();
}

rgb_color BackgroundColor() {
return fBackgroundColor;
}

private:
rgb_color fBackgroundColor;
BBitmap *bitmap;
};

class MainWindow : public BWindow
{
public:
Expand All @@ -78,7 +39,7 @@ class MainWindow : public BWindow
void SetBackground(const char *name);

HexGrid *fGrid, *fWorkGrid;
BackView *fBack;
BView *fBack;
BMenuBar *fMenuBar;
BMenu *fBackMenu;
TimerView *fTimer;
Expand Down
Binary file removed background.png
Binary file not shown.
Binary file added backgrounds/Fire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backgrounds/Gold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backgrounds/Grass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backgrounds/Sky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f545e15

Please sign in to comment.