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