Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added possibility to switch off the delay - fixed window behaviour #39

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions source/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum
MainWindow::MainWindow()
:
BWindow(BRect(100, 100, 740, 190), B_TRANSLATE_SYSTEM_NAME("Tipster"),
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the | B_NOT_V_RESIZABLE? Now the window can be resized in a way that shows a large grey area.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

This way it is possible to have a smaller window but visible the whole tip.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well... it's not really smaller, it's narrower but has to be taller. You can always have the whole tip visible by making the window wider. We try to keep the tips as short as possible to fit into a reasonably sized window (or replicated view). IMO keeping the window height equal to the icon button height looks much nicer.

| B_AUTO_UPDATE_SIZE_LIMITS)
{
BuildLayout();
Expand All @@ -63,8 +63,7 @@ MainWindow::BuildLayout()
new BMessage(PREVIOUS_TIP)));
fTipMenu->AddItem(new BMenuItem(B_TRANSLATE("Next tip"),
new BMessage(NEXT_TIP)));



fTipMenu->AddItem(fDelaySubMenu);

fMenuBar->AddItem(fTipsterMenu);
Expand All @@ -75,15 +74,16 @@ MainWindow::BuildLayout()
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
.Add(fMenuBar)
.Add(fTipsterView)
.AddGlue();

// .AddGlue()
thaflo marked this conversation as resolved.
Show resolved Hide resolved
.End();
// After the creation of Tipster because we need the delay
// time saved in the settings

AddDelaySubMenuItem(30000000, B_TRANSLATE("30 seconds"));
AddDelaySubMenuItem(60000000, B_TRANSLATE("1 minute"));
AddDelaySubMenuItem(120000000, B_TRANSLATE("2 minutes"));
AddDelaySubMenuItem(300000000, B_TRANSLATE("5 minutes"));
AddDelaySubMenuItem(0, B_TRANSLATE("Off"));

fDelaySubMenu->SetRadioMode(true);
}
Expand All @@ -108,14 +108,12 @@ MainWindow::QuitRequested()
}


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "About"

void
MainWindow::MessageReceived(BMessage* message)
{
switch(message->what)
switch (message->what)
{

case SHOW_ABOUT:
{
BAboutWindow* about = new AboutTipster();
Expand All @@ -136,8 +134,8 @@ MainWindow::MessageReceived(BMessage* message)
{
int64 delay = 60000000;
message->FindInt64("delay", &delay);

fTipsterView->SetDelay(delay);
// printf("delay: %d \n", delay);
break;
}
case MSG_QUIT:
Expand All @@ -147,6 +145,7 @@ MainWindow::MessageReceived(BMessage* message)
}
default:
BWindow::MessageReceived(message);
message->PrintToStream();
thaflo marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
30 changes: 20 additions & 10 deletions source/Tipster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Shuffle.h"

#include <Application.h>
#include <Alert.h>
#include <Bitmap.h>
#include <Catalog.h>
#include <ControlLook.h>
Expand Down Expand Up @@ -44,7 +45,6 @@ enum

const float kDraggerSize = 7.0f;


Tipster::Tipster()
:
BGroupView("Tipster")
Expand All @@ -62,15 +62,21 @@ Tipster::Tipster()

fTipsterTextView = new TipsterText();
fIcon = new BButton("iconview", "", new BMessage(OPEN_URL));
fIcon -> SetToolTip( B_TRANSLATE("Open the Tipster homepage") );
thaflo marked this conversation as resolved.
Show resolved Hide resolved

BDragger* dragger = new BDragger(this);

BLayoutBuilder::Group<>(this, B_HORIZONTAL, 0)
.SetInsets(-2, -2, 0, -2)
.Add(fIcon)
.SetInsets(1, 1, 1, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those insets were on purpose to avoid the smal spacing around the icon and have it flush with the view borders. It should be kept as is, IMO.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that's a question to discuss about :-) For me this way looks more as a button as when it's completely attached

.AddGroup(B_VERTICAL,0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does putting the icon in a Group solve? I don't see a dfference...

.Add(fIcon)
.AddGlue()
.End()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for an empty line, I think. The indentation is obvious enough to distinguish separate elements.

.AddStrut(be_control_look->DefaultItemSpacing())
.AddGroup(B_VERTICAL,0)
.Add(fTipsterTextView)

thaflo marked this conversation as resolved.
Show resolved Hide resolved
.AddGroup(B_HORIZONTAL, 0)
.AddGlue()
.Add(dragger)
Expand Down Expand Up @@ -198,7 +204,6 @@ Tipster::QuitRequested()
return true;
}


void
Tipster::AttachedToWindow()
{
Expand Down Expand Up @@ -280,9 +285,13 @@ Tipster::_LoadSettings()
void
Tipster::_ResetTimer()
{
BMessage message(UPDATE_TIP);
delete fRunner;
fRunner = new BMessageRunner(this, message, fDelay);
if (fDelay > 0) {
// if delay is set to Off (0), don't send a runner message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This empty line isn't needed.
More importantly: if you go from some delay to "Off", the previous BMessageRunner is still running and keeps changing tips after the the former delay. So you still have to delete the BMessageRunner if delay == 0. Maybe something like this:

	if (fRunner != NULL) {
		delete fRunner;
		fRunner = NULL;
	}
	if (fDelay > 0) {
	// if delay is set to Off (0), don't send a runner message
		BMessage message(UPDATE_TIP);
		fRunner = new BMessageRunner(this, message, fDelay);
	}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a big help for me! Didn't know how to solve it ...

BMessage message(UPDATE_TIP);
delete fRunner;
fRunner = new BMessageRunner(this, message, fDelay);
}
}


Expand Down Expand Up @@ -372,7 +381,6 @@ Tipster::MouseDown(BPoint point)
}
}


void
Tipster::UpdateIcon(BString artwork, BString url)
{
Expand Down Expand Up @@ -489,9 +497,11 @@ Tipster::GetTipsFile()

for (int32 i = 0; (language = message.GetString("language", i, NULL))
!= NULL; i++) {
if (getLocalTipsFile(ref, language))
printf("lang: %s \n", language);
thaflo marked this conversation as resolved.
Show resolved Hide resolved
if (getLocalTipsFile(ref, language)) //
return ref;
else if (getLocalTipsFile(ref, BString(language,
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding style says "else if" on one line.

if (getLocalTipsFile(ref, BString(language,
BString(language).FindFirst("_"))))
return ref;
}
Expand Down
2 changes: 1 addition & 1 deletion source/Tipster.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Tipster : public BGroupView
int32 fTipIndex;
std::vector<int> fRandomSeq1;
std::vector<int> fRandomSeq2;

BString* fPreviousTip;
BString* fCurrentTip;

Expand Down
20 changes: 12 additions & 8 deletions source/TipsterText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

enum
{
UPDATE_TIP = 'uptp'
UPDATE_TIP = 'uptp',
NEXT_TIP = 'nxtp',
PREVIOUS_TIP = 'pvtp'
};


Expand Down Expand Up @@ -42,12 +44,12 @@ TipsterText::Instantiate(BMessage *data)
{
if (!validate_instantiation(data, "TipsterText")) {
printf("Could not complete instantiation...\n");

return NULL;
}

printf("Instantiation validated...\n");

return new TipsterText(data);
}

Expand All @@ -56,7 +58,7 @@ void
TipsterText::AttachedToWindow()
{
fMessenger = new BMessenger(this->Parent());

SetViewColor(Parent()->ViewColor());

BTextView::AttachedToWindow();
Expand All @@ -71,8 +73,10 @@ TipsterText::MouseDown(BPoint point)
GetMouse(&temp, &buttons);

if (Bounds().Contains(temp)) {
BMessage message(UPDATE_TIP);

fMessenger->SendMessage(&message);
if (buttons == 1) //left mouse button
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insted of a comment, you can use the constants B_PRIMARY_MOUSE_BUTTON and B_SECONDARY_MOUSE_BUTTON.

fMessenger->SendMessage(NEXT_TIP);
if (buttons == 2) //right mouse button
fMessenger->SendMessage(PREVIOUS_TIP);

}
}