Allow Magnify to resize to smaller sizes more gracefully.
Fixes ticket #4146 Signed-off-by: Matt Madia <mattmadia@gmail.com>
This commit is contained in:
parent
819c63ad65
commit
da2db35956
@ -222,6 +222,7 @@ TWindow::TWindow(int32 pixelCount)
|
||||
fInfo->SetMagView(fFatBits);
|
||||
|
||||
ResizeWindow(fHPixelCount, fVPixelCount);
|
||||
UpdateInfoBarOnResize();
|
||||
|
||||
AddShortcut('S', B_COMMAND_KEY, new BMessage(msg_save));
|
||||
AddShortcut('C', B_COMMAND_KEY, new BMessage(msg_copy_image));
|
||||
@ -251,8 +252,10 @@ TWindow::MessageReceived(BMessage* m)
|
||||
|
||||
switch (m->what) {
|
||||
case msg_show_info:
|
||||
if (active)
|
||||
if (active) {
|
||||
fInfoBarState = !fInfoBarState;
|
||||
ShowInfo(!fShowInfo);
|
||||
}
|
||||
break;
|
||||
|
||||
case msg_toggle_grid:
|
||||
@ -440,6 +443,7 @@ ALMOST_DONE: // clean up and try to position the window
|
||||
DONE:
|
||||
fShowGrid = showGrid;
|
||||
fShowInfo = showInfo;
|
||||
fInfoBarState = showInfo;
|
||||
fHPixelCount = (overridePixelCount == -1) ? hPixelCount : overridePixelCount;
|
||||
fVPixelCount = (overridePixelCount == -1) ? vPixelCount : overridePixelCount;
|
||||
fPixelSize = pixelSize;
|
||||
@ -487,6 +491,7 @@ TWindow::FrameResized(float w, float h)
|
||||
{
|
||||
CalcViewablePixels();
|
||||
fFatBits->InitBuffers(fHPixelCount, fVPixelCount, fPixelSize, ShowGrid());
|
||||
UpdateInfoBarOnResize();
|
||||
}
|
||||
|
||||
|
||||
@ -633,6 +638,7 @@ TWindow::ShowInfo(bool i)
|
||||
|
||||
fFatBits->SetSelection(fShowInfo);
|
||||
ResizeWindow(fHPixelCount, fVPixelCount);
|
||||
fInfo->SetInfoTextVisible(i);
|
||||
}
|
||||
|
||||
|
||||
@ -650,6 +656,21 @@ TWindow::UpdateInfo()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TWindow::UpdateInfoBarOnResize()
|
||||
{
|
||||
float infoWidth, infoHeight;
|
||||
fInfo->GetPreferredSize(&infoWidth, &infoHeight);
|
||||
|
||||
if (infoWidth > Bounds().Width() ||
|
||||
infoHeight > Bounds().Height()) {
|
||||
ShowInfo(false);
|
||||
} else {
|
||||
ShowInfo(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TWindow::AddCrossHair()
|
||||
{
|
||||
@ -771,6 +792,8 @@ TInfoView::TInfoView(BRect frame)
|
||||
fRGBStr[0] = 0;
|
||||
fCH1Str[0] = 0;
|
||||
fCH2Str[0] = 0;
|
||||
|
||||
fInfoTextVisible = true;
|
||||
}
|
||||
|
||||
|
||||
@ -821,7 +844,9 @@ TInfoView::Draw(BRect updateRect)
|
||||
FillRect(invalRect);
|
||||
SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
|
||||
strcpy(fInfoStr, dimensionsInfo);
|
||||
DrawString(fInfoStr);
|
||||
if (fInfoTextVisible) {
|
||||
DrawString(fInfoStr);
|
||||
}
|
||||
|
||||
rgb_color color = { 0, 0, 0, 255 };
|
||||
if (fMagView)
|
||||
@ -836,7 +861,9 @@ TInfoView::Draw(BRect updateRect)
|
||||
FillRect(invalRect);
|
||||
SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
|
||||
strcpy(fRGBStr,str);
|
||||
DrawString(fRGBStr);
|
||||
if (fInfoTextVisible) {
|
||||
DrawString(fRGBStr);
|
||||
}
|
||||
|
||||
bool ch1Showing, ch2Showing;
|
||||
dynamic_cast<TWindow*>(Window())->CrossHairsShowing(&ch1Showing, &ch2Showing);
|
||||
@ -855,7 +882,9 @@ TInfoView::Draw(BRect updateRect)
|
||||
FillRect(invalRect);
|
||||
SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
|
||||
strcpy(fCH2Str,str);
|
||||
DrawString(fCH2Str);
|
||||
if (fInfoTextVisible) {
|
||||
DrawString(fCH2Str);
|
||||
}
|
||||
}
|
||||
|
||||
if (ch1Showing && ch2Showing) {
|
||||
@ -867,7 +896,9 @@ TInfoView::Draw(BRect updateRect)
|
||||
FillRect(invalRect);
|
||||
SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
|
||||
strcpy(fCH1Str,str);
|
||||
DrawString(fCH1Str);
|
||||
if (fInfoTextVisible) {
|
||||
DrawString(fCH1Str);
|
||||
}
|
||||
} else if (ch1Showing) {
|
||||
MovePenTo(10, h-10);
|
||||
sprintf(str, "x: %li y: %li", (int32)pt1.x, (int32)pt1.y);
|
||||
@ -876,7 +907,9 @@ TInfoView::Draw(BRect updateRect)
|
||||
FillRect(invalRect);
|
||||
SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
|
||||
strcpy(fCH1Str,str);
|
||||
DrawString(fCH1Str);
|
||||
if (fInfoTextVisible) {
|
||||
DrawString(fCH1Str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -965,6 +998,39 @@ TMenu::AttachedToWindow()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TInfoView::GetPreferredSize(float* _width, float* _height)
|
||||
{
|
||||
if(_width) {
|
||||
float str1Width = StringWidth(fCH1Str)
|
||||
+ StringWidth(fCH2Str)
|
||||
+ StringWidth(fRGBStr)
|
||||
+ 30;
|
||||
float str2Width = StringWidth(fInfoStr) + 30;
|
||||
*_width = str1Width > str2Width ? str1Width : str2Width;
|
||||
}
|
||||
|
||||
if(_height) {
|
||||
*_height = fFontHeight * 2 + 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TInfoView::isInfoTextVisible()
|
||||
{
|
||||
return fInfoTextVisible;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TInfoView::SetInfoTextVisible(bool visible)
|
||||
{
|
||||
fInfoTextVisible = visible;
|
||||
Draw(Bounds());
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
|
@ -165,9 +165,12 @@ class TInfoView : public BBox {
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual void GetPreferredSize(float* _width, float* height);
|
||||
|
||||
void AddMenu();
|
||||
void SetMagView(TMagnify* magView);
|
||||
void SetInfoTextVisible(bool visible);
|
||||
bool isInfoTextVisible();
|
||||
|
||||
private:
|
||||
float fFontHeight;
|
||||
@ -188,6 +191,8 @@ class TInfoView : public BBox {
|
||||
char fRGBStr[64];
|
||||
char fCH1Str[64];
|
||||
char fCH2Str[64];
|
||||
|
||||
bool fInfoTextVisible;
|
||||
};
|
||||
|
||||
class TWindow : public BWindow {
|
||||
@ -219,6 +224,7 @@ class TWindow : public BWindow {
|
||||
void ShowInfo(bool);
|
||||
bool InfoIsShowing();
|
||||
void UpdateInfo();
|
||||
void UpdateInfoBarOnResize();
|
||||
|
||||
void AddCrossHair();
|
||||
void RemoveCrossHair();
|
||||
@ -238,6 +244,7 @@ class TWindow : public BWindow {
|
||||
float fFontHeight;
|
||||
|
||||
bool fShowGrid;
|
||||
bool fInfoBarState;
|
||||
|
||||
int32 fHPixelCount;
|
||||
int32 fVPixelCount;
|
||||
|
Loading…
Reference in New Issue
Block a user