GIFTranslator: Layout GIFView better
http://25.media.tumblr.com/9aa37387e4240aa5828d34b4dc7163af/tumblr_n20583ipj11r0f0hfo1_500.png Also delete controls in destructor to not leak memory
This commit is contained in:
@@ -23,10 +23,18 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <Box.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <InterfaceKit.h>
|
#include <CheckBox.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
|
#include <MenuField.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
|
#include <RadioButton.h>
|
||||||
|
#include <SpaceLayoutItem.h>
|
||||||
|
#include <StringView.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <TextControl.h>
|
||||||
|
|
||||||
#include "GIFTranslator.h"
|
#include "GIFTranslator.h"
|
||||||
#include "SavePalette.h"
|
#include "SavePalette.h"
|
||||||
@@ -43,9 +51,8 @@ GIFView::GIFView(TranslatorSettings* settings)
|
|||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
BStringView* title = new BStringView("Title",
|
fTitle = new BStringView("Title", B_TRANSLATE("GIF image translator"));
|
||||||
B_TRANSLATE("GIF image translator"));
|
fTitle->SetFont(be_bold_font);
|
||||||
title->SetFont(be_bold_font);
|
|
||||||
|
|
||||||
char version_string[100];
|
char version_string[100];
|
||||||
snprintf(version_string, sizeof(version_string),
|
snprintf(version_string, sizeof(version_string),
|
||||||
@@ -54,12 +61,11 @@ GIFView::GIFView(TranslatorSettings* settings)
|
|||||||
int(B_TRANSLATION_MINOR_VERSION(GIF_TRANSLATOR_VERSION)),
|
int(B_TRANSLATION_MINOR_VERSION(GIF_TRANSLATOR_VERSION)),
|
||||||
int(B_TRANSLATION_REVISION_VERSION(GIF_TRANSLATOR_VERSION)),
|
int(B_TRANSLATION_REVISION_VERSION(GIF_TRANSLATOR_VERSION)),
|
||||||
__DATE__);
|
__DATE__);
|
||||||
|
fVersion = new BStringView("Version", version_string);
|
||||||
BStringView* version = new BStringView("Version", version_string);
|
|
||||||
|
|
||||||
const char* copyrightString
|
const char* copyrightString
|
||||||
= "©2003 Daniel Switkin, [email protected]";
|
= "©2003 Daniel Switkin, [email protected]";
|
||||||
BStringView* copyright = new BStringView("Copyright", copyrightString);
|
fCopyright = new BStringView("Copyright", copyrightString);
|
||||||
|
|
||||||
// menu fields (Palette & Colors)
|
// menu fields (Palette & Colors)
|
||||||
fWebSafeMI = new BMenuItem(B_TRANSLATE("Websafe"),
|
fWebSafeMI = new BMenuItem(B_TRANSLATE("Websafe"),
|
||||||
@@ -91,15 +97,21 @@ GIFView::GIFView(TranslatorSettings* settings)
|
|||||||
}
|
}
|
||||||
fColorCount256MI = fColorCountMI[7];
|
fColorCount256MI = fColorCountMI[7];
|
||||||
|
|
||||||
fPaletteMF = new BMenuField(B_TRANSLATE("Palette"), fPaletteM);
|
fPaletteMF = new BMenuField(B_TRANSLATE("Palette:"), fPaletteM);
|
||||||
fColorCountMF = new BMenuField(B_TRANSLATE("Colors"), fColorCountM);
|
fPaletteMF->SetAlignment(B_ALIGN_RIGHT);
|
||||||
|
fColorCountMF = new BMenuField(B_TRANSLATE("Colors:"), fColorCountM);
|
||||||
|
fColorCountMF->SetAlignment(B_ALIGN_RIGHT);
|
||||||
|
|
||||||
// check boxes
|
// check boxes
|
||||||
fUseDitheringCB = new BCheckBox(B_TRANSLATE("Use dithering"),
|
fUseDitheringCB = new BCheckBox(B_TRANSLATE("Use dithering"),
|
||||||
new BMessage(GV_USE_DITHERING));
|
new BMessage(GV_USE_DITHERING));
|
||||||
|
fDitheringBox = new BBox("dithering", B_WILL_DRAW, B_NO_BORDER);
|
||||||
|
fDitheringBox->SetLabel(fUseDitheringCB);
|
||||||
|
|
||||||
fInterlacedCB = new BCheckBox(B_TRANSLATE("Write interlaced images"),
|
fInterlacedCB = new BCheckBox(B_TRANSLATE("Write interlaced images"),
|
||||||
new BMessage(GV_INTERLACED));
|
new BMessage(GV_INTERLACED));
|
||||||
|
fInterlacedBox = new BBox("interlaced", B_WILL_DRAW, B_NO_BORDER);
|
||||||
|
fInterlacedBox->SetLabel(fInterlacedCB);
|
||||||
|
|
||||||
fUseTransparentCB = new BCheckBox(B_TRANSLATE("Write transparent images"),
|
fUseTransparentCB = new BCheckBox(B_TRANSLATE("Write transparent images"),
|
||||||
new BMessage(GV_USE_TRANSPARENT));
|
new BMessage(GV_USE_TRANSPARENT));
|
||||||
@@ -112,55 +124,62 @@ GIFView::GIFView(TranslatorSettings* settings)
|
|||||||
fUseTransparentColorRB = new BRadioButton(B_TRANSLATE("Use RGB color"),
|
fUseTransparentColorRB = new BRadioButton(B_TRANSLATE("Use RGB color"),
|
||||||
new BMessage(GV_USE_TRANSPARENT_COLOR));
|
new BMessage(GV_USE_TRANSPARENT_COLOR));
|
||||||
|
|
||||||
fTransparentRedTC = new BTextControl("", "0",
|
// text controls
|
||||||
|
fRedTextControl = new BTextControl("", "0",
|
||||||
new BMessage(GV_TRANSPARENT_RED));
|
new BMessage(GV_TRANSPARENT_RED));
|
||||||
fTransparentGreenTC = new BTextControl("", "0",
|
fGreenTextControl = new BTextControl("", "0",
|
||||||
new BMessage(GV_TRANSPARENT_GREEN));
|
new BMessage(GV_TRANSPARENT_GREEN));
|
||||||
fTransparentBlueTC = new BTextControl("", "0",
|
fBlueTextControl = new BTextControl("", "0",
|
||||||
new BMessage(GV_TRANSPARENT_BLUE));
|
new BMessage(GV_TRANSPARENT_BLUE));
|
||||||
|
|
||||||
BTextView* tr = fTransparentRedTC->TextView();
|
fTransparentBox = new BBox(B_FANCY_BORDER,
|
||||||
BTextView* tg = fTransparentGreenTC->TextView();
|
BLayoutBuilder::Grid<>(3.0f, 5.0f)
|
||||||
BTextView* tb = fTransparentBlueTC->TextView();
|
.Add(fUseTransparentAutoRB, 0, 0, 4, 1)
|
||||||
|
.Add(fUseTransparentColorRB, 0, 1)
|
||||||
|
.Add(fRedTextControl, 1, 1)
|
||||||
|
.Add(fGreenTextControl, 2, 1)
|
||||||
|
.Add(fBlueTextControl, 3, 1)
|
||||||
|
.SetInsets(10.0f, 6.0f, 10.0f, 10.0f)
|
||||||
|
.View());
|
||||||
|
fTransparentBox->SetLabel(fUseTransparentCB);
|
||||||
|
|
||||||
|
BTextView* redTextView = fRedTextControl->TextView();
|
||||||
|
BTextView* greenTextView = fGreenTextControl->TextView();
|
||||||
|
BTextView* bluetextView = fBlueTextControl->TextView();
|
||||||
|
|
||||||
for (uint32 x = 0; x < 256; x++) {
|
for (uint32 x = 0; x < 256; x++) {
|
||||||
if (x < '0' || x > '9') {
|
if (x < '0' || x > '9') {
|
||||||
tr->DisallowChar(x);
|
redTextView->DisallowChar(x);
|
||||||
tg->DisallowChar(x);
|
greenTextView->DisallowChar(x);
|
||||||
tb->DisallowChar(x);
|
bluetextView->DisallowChar(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 7)
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 10.0f)
|
||||||
.SetInsets(5)
|
.SetInsets(10.0f)
|
||||||
.AddGrid(10, 10)
|
.AddGrid(10.0f, 5.0f)
|
||||||
.Add(title, 0, 0)
|
.Add(fTitle, 0, 0)
|
||||||
.Add(version, 1, 0)
|
.Add(fVersion, 1, 0)
|
||||||
|
.Add(fCopyright, 0, 1, 2, 1)
|
||||||
.End()
|
.End()
|
||||||
.Add(copyright)
|
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
|
|
||||||
.AddGrid(10, 10)
|
.AddGrid(10.0f, 5.0f)
|
||||||
.Add(fPaletteMF->CreateLabelLayoutItem(), 0, 0)
|
.Add(fPaletteMF->CreateLabelLayoutItem(), 0, 0)
|
||||||
.Add(fPaletteMF->CreateMenuBarLayoutItem(), 1, 0)
|
.Add(fPaletteMF->CreateMenuBarLayoutItem(), 1, 0)
|
||||||
|
|
||||||
.Add(fColorCountMF->CreateLabelLayoutItem(), 0, 1)
|
.Add(fColorCountMF->CreateLabelLayoutItem(), 0, 1)
|
||||||
.Add(fColorCountMF->CreateMenuBarLayoutItem(), 1, 1)
|
.Add(fColorCountMF->CreateMenuBarLayoutItem(), 1, 1)
|
||||||
|
|
||||||
|
.Add(BSpaceLayoutItem::CreateHorizontalStrut(10.0f), 1, 2)
|
||||||
|
|
||||||
|
.Add(fDitheringBox, 1, 3)
|
||||||
|
.Add(fInterlacedBox, 1, 4)
|
||||||
|
.Add(fTransparentBox, 1, 5)
|
||||||
|
|
||||||
.End()
|
.End()
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
|
.End();
|
||||||
.Add(fUseDitheringCB)
|
|
||||||
.Add(fInterlacedCB)
|
|
||||||
.Add(fUseTransparentCB)
|
|
||||||
|
|
||||||
.Add(fUseTransparentAutoRB)
|
|
||||||
.AddGrid(10, 10)
|
|
||||||
.Add(fUseTransparentColorRB, 0, 0)
|
|
||||||
.Add(fTransparentRedTC, 1, 0)
|
|
||||||
.Add(fTransparentGreenTC, 2, 0)
|
|
||||||
.Add(fTransparentBlueTC, 3, 0)
|
|
||||||
.End()
|
|
||||||
.AddGlue();
|
|
||||||
|
|
||||||
BFont font;
|
BFont font;
|
||||||
GetFont(&font);
|
GetFont(&font);
|
||||||
@@ -174,6 +193,15 @@ GIFView::GIFView(TranslatorSettings* settings)
|
|||||||
GIFView::~GIFView()
|
GIFView::~GIFView()
|
||||||
{
|
{
|
||||||
fSettings->Release();
|
fSettings->Release();
|
||||||
|
delete fTitle;
|
||||||
|
delete fVersion;
|
||||||
|
delete fCopyright;
|
||||||
|
delete fPaletteMF;
|
||||||
|
delete fColorCountMF;
|
||||||
|
delete fDitheringBox;
|
||||||
|
delete fInterlacedBox;
|
||||||
|
delete fInterlacedBox;
|
||||||
|
delete fTransparentBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -240,30 +268,30 @@ GIFView::RestorePrefs()
|
|||||||
if (fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT)) {
|
if (fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT)) {
|
||||||
fUseTransparentAutoRB->SetEnabled(true);
|
fUseTransparentAutoRB->SetEnabled(true);
|
||||||
fUseTransparentColorRB->SetEnabled(true);
|
fUseTransparentColorRB->SetEnabled(true);
|
||||||
fTransparentRedTC->SetEnabled(
|
fRedTextControl->SetEnabled(
|
||||||
!fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT_AUTO));
|
!fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT_AUTO));
|
||||||
fTransparentGreenTC->SetEnabled(
|
fGreenTextControl->SetEnabled(
|
||||||
!fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT_AUTO));
|
!fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT_AUTO));
|
||||||
fTransparentBlueTC->SetEnabled(
|
fBlueTextControl->SetEnabled(
|
||||||
!fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT_AUTO));
|
!fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT_AUTO));
|
||||||
} else {
|
} else {
|
||||||
fUseTransparentAutoRB->SetEnabled(false);
|
fUseTransparentAutoRB->SetEnabled(false);
|
||||||
fUseTransparentColorRB->SetEnabled(false);
|
fUseTransparentColorRB->SetEnabled(false);
|
||||||
fTransparentRedTC->SetEnabled(false);
|
fRedTextControl->SetEnabled(false);
|
||||||
fTransparentGreenTC->SetEnabled(false);
|
fGreenTextControl->SetEnabled(false);
|
||||||
fTransparentBlueTC->SetEnabled(false);
|
fBlueTextControl->SetEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
char temp[4];
|
char temp[4];
|
||||||
sprintf(temp, "%d",
|
sprintf(temp, "%d",
|
||||||
(int)fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_RED));
|
(int)fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_RED));
|
||||||
fTransparentRedTC->SetText(temp);
|
fRedTextControl->SetText(temp);
|
||||||
sprintf(temp, "%d",
|
sprintf(temp, "%d",
|
||||||
(int)fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_GREEN));
|
(int)fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_GREEN));
|
||||||
fTransparentGreenTC->SetText(temp);
|
fGreenTextControl->SetText(temp);
|
||||||
sprintf(temp, "%d",
|
sprintf(temp, "%d",
|
||||||
(int)fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_BLUE));
|
(int)fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_BLUE));
|
||||||
fTransparentBlueTC->SetText(temp);
|
fBlueTextControl->SetText(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -277,9 +305,9 @@ GIFView::AllAttached()
|
|||||||
fUseTransparentCB->SetTarget(msgr);
|
fUseTransparentCB->SetTarget(msgr);
|
||||||
fUseTransparentAutoRB->SetTarget(msgr);
|
fUseTransparentAutoRB->SetTarget(msgr);
|
||||||
fUseTransparentColorRB->SetTarget(msgr);
|
fUseTransparentColorRB->SetTarget(msgr);
|
||||||
fTransparentRedTC->SetTarget(msgr);
|
fRedTextControl->SetTarget(msgr);
|
||||||
fTransparentGreenTC->SetTarget(msgr);
|
fGreenTextControl->SetTarget(msgr);
|
||||||
fTransparentBlueTC->SetTarget(msgr);
|
fBlueTextControl->SetTarget(msgr);
|
||||||
fPaletteM->SetTargetForItems(msgr);
|
fPaletteM->SetTargetForItems(msgr);
|
||||||
fColorCountM->SetTargetForItems(msgr);
|
fColorCountM->SetTargetForItems(msgr);
|
||||||
}
|
}
|
||||||
@@ -365,15 +393,15 @@ GIFView::MessageReceived(BMessage* message)
|
|||||||
if (value) {
|
if (value) {
|
||||||
fUseTransparentAutoRB->SetEnabled(true);
|
fUseTransparentAutoRB->SetEnabled(true);
|
||||||
fUseTransparentColorRB->SetEnabled(true);
|
fUseTransparentColorRB->SetEnabled(true);
|
||||||
fTransparentRedTC->SetEnabled(fUseTransparentColorRB->Value());
|
fRedTextControl->SetEnabled(fUseTransparentColorRB->Value());
|
||||||
fTransparentGreenTC->SetEnabled(fUseTransparentColorRB->Value());
|
fGreenTextControl->SetEnabled(fUseTransparentColorRB->Value());
|
||||||
fTransparentBlueTC->SetEnabled(fUseTransparentColorRB->Value());
|
fBlueTextControl->SetEnabled(fUseTransparentColorRB->Value());
|
||||||
} else {
|
} else {
|
||||||
fUseTransparentAutoRB->SetEnabled(false);
|
fUseTransparentAutoRB->SetEnabled(false);
|
||||||
fUseTransparentColorRB->SetEnabled(false);
|
fUseTransparentColorRB->SetEnabled(false);
|
||||||
fTransparentRedTC->SetEnabled(false);
|
fRedTextControl->SetEnabled(false);
|
||||||
fTransparentGreenTC->SetEnabled(false);
|
fGreenTextControl->SetEnabled(false);
|
||||||
fTransparentBlueTC->SetEnabled(false);
|
fBlueTextControl->SetEnabled(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -382,9 +410,9 @@ GIFView::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
bool value = true;
|
bool value = true;
|
||||||
fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT_AUTO, &value);
|
fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT_AUTO, &value);
|
||||||
fTransparentRedTC->SetEnabled(false);
|
fRedTextControl->SetEnabled(false);
|
||||||
fTransparentGreenTC->SetEnabled(false);
|
fGreenTextControl->SetEnabled(false);
|
||||||
fTransparentBlueTC->SetEnabled(false);
|
fBlueTextControl->SetEnabled(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,29 +420,29 @@ GIFView::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
bool value = false;
|
bool value = false;
|
||||||
fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT_AUTO, &value);
|
fSettings->SetGetBool(GIF_SETTING_USE_TRANSPARENT_AUTO, &value);
|
||||||
fTransparentRedTC->SetEnabled(true);
|
fRedTextControl->SetEnabled(true);
|
||||||
fTransparentGreenTC->SetEnabled(true);
|
fGreenTextControl->SetEnabled(true);
|
||||||
fTransparentBlueTC->SetEnabled(true);
|
fBlueTextControl->SetEnabled(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case GV_TRANSPARENT_RED:
|
case GV_TRANSPARENT_RED:
|
||||||
{
|
{
|
||||||
int32 value = CheckInput(fTransparentRedTC);
|
int32 value = CheckInput(fRedTextControl);
|
||||||
fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_RED, &value);
|
fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_RED, &value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case GV_TRANSPARENT_GREEN:
|
case GV_TRANSPARENT_GREEN:
|
||||||
{
|
{
|
||||||
int32 value = CheckInput(fTransparentGreenTC);
|
int32 value = CheckInput(fGreenTextControl);
|
||||||
fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_GREEN, &value);
|
fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_GREEN, &value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case GV_TRANSPARENT_BLUE:
|
case GV_TRANSPARENT_BLUE:
|
||||||
{
|
{
|
||||||
int32 value = CheckInput(fTransparentBlueTC);
|
int32 value = CheckInput(fBlueTextControl);
|
||||||
fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_BLUE, &value);
|
fSettings->SetGetInt32(GIF_SETTING_TRANSPARENT_BLUE, &value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,13 +43,17 @@
|
|||||||
const BRect kRectView(110, 110, 339, 339);
|
const BRect kRectView(110, 110, 339, 339);
|
||||||
|
|
||||||
|
|
||||||
class BMenuField;
|
class BBox;
|
||||||
class BPopUpMenu;
|
|
||||||
class BMenuItem;
|
|
||||||
class BCheckBox;
|
class BCheckBox;
|
||||||
|
class BPopUpMenu;
|
||||||
|
class BMenuField;
|
||||||
|
class BMenuItem;
|
||||||
class BRadioButton;
|
class BRadioButton;
|
||||||
|
class BStringView;
|
||||||
class BTextControl;
|
class BTextControl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GIFView : public BView {
|
class GIFView : public BView {
|
||||||
public:
|
public:
|
||||||
GIFView(TranslatorSettings* settings);
|
GIFView(TranslatorSettings* settings);
|
||||||
@@ -64,6 +68,10 @@ private:
|
|||||||
|
|
||||||
TranslatorSettings* fSettings;
|
TranslatorSettings* fSettings;
|
||||||
|
|
||||||
|
BStringView* fTitle;
|
||||||
|
BStringView* fVersion;
|
||||||
|
BStringView* fCopyright;
|
||||||
|
|
||||||
BMenuField* fPaletteMF;
|
BMenuField* fPaletteMF;
|
||||||
BPopUpMenu* fPaletteM;
|
BPopUpMenu* fPaletteM;
|
||||||
BMenuItem* fWebSafeMI;
|
BMenuItem* fWebSafeMI;
|
||||||
@@ -83,9 +91,13 @@ private:
|
|||||||
BRadioButton* fUseTransparentAutoRB;
|
BRadioButton* fUseTransparentAutoRB;
|
||||||
BRadioButton* fUseTransparentColorRB;
|
BRadioButton* fUseTransparentColorRB;
|
||||||
|
|
||||||
BTextControl* fTransparentRedTC;
|
BBox* fDitheringBox;
|
||||||
BTextControl* fTransparentGreenTC;
|
BBox* fInterlacedBox;
|
||||||
BTextControl* fTransparentBlueTC;
|
BBox* fTransparentBox;
|
||||||
|
|
||||||
|
BTextControl* fRedTextControl;
|
||||||
|
BTextControl* fGreenTextControl;
|
||||||
|
BTextControl* fBlueTextControl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user