PSDTranslator: Add compression settings
This commit is contained in:
@@ -9,18 +9,36 @@
|
|||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <SpaceLayoutItem.h>
|
#include <SpaceLayoutItem.h>
|
||||||
#include <ControlLook.h>
|
#include <ControlLook.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "PSDLoader.h"
|
||||||
|
|
||||||
|
|
||||||
ConfigView::ConfigView(TranslatorSettings *settings)
|
ConfigView::ConfigView(TranslatorSettings *settings)
|
||||||
: BGroupView("PSDTranslator Settings", B_VERTICAL, 0)
|
: BGroupView("PSDTranslator Settings", B_VERTICAL, 0)
|
||||||
{
|
{
|
||||||
fSettings = settings;
|
fSettings = settings;
|
||||||
|
|
||||||
|
BPopUpMenu* popupMenu = new BPopUpMenu("popup_compression");
|
||||||
|
|
||||||
|
uint32 currentCompression =
|
||||||
|
fSettings->SetGetInt32(PSD_SETTING_COMPRESSION);
|
||||||
|
|
||||||
|
_AddItemToMenu(popupMenu, "Uncompressed",
|
||||||
|
PSD_COMPRESSED_RAW, currentCompression);
|
||||||
|
_AddItemToMenu(popupMenu, "RLE",
|
||||||
|
PSD_COMPRESSED_RLE, currentCompression);
|
||||||
|
|
||||||
|
fCompressionField = new BMenuField("compression",
|
||||||
|
"Compression: ", popupMenu);
|
||||||
|
|
||||||
BAlignment leftAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET);
|
BAlignment leftAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET);
|
||||||
|
|
||||||
BStringView *stringView = new BStringView("title", "Photoshop image translator");
|
BStringView *stringView = new BStringView("title",
|
||||||
|
"Photoshop image translator");
|
||||||
stringView->SetFont(be_bold_font);
|
stringView->SetFont(be_bold_font);
|
||||||
stringView->SetExplicitAlignment(leftAlignment);
|
stringView->SetExplicitAlignment(leftAlignment);
|
||||||
AddChild(stringView);
|
AddChild(stringView);
|
||||||
@@ -48,6 +66,8 @@ ConfigView::ConfigView(TranslatorSettings *settings)
|
|||||||
stringView->SetExplicitAlignment(leftAlignment);
|
stringView->SetExplicitAlignment(leftAlignment);
|
||||||
AddChild(stringView);
|
AddChild(stringView);
|
||||||
|
|
||||||
|
AddChild(fCompressionField);
|
||||||
|
|
||||||
AddChild(BSpaceLayoutItem::CreateGlue());
|
AddChild(BSpaceLayoutItem::CreateGlue());
|
||||||
GroupLayout()->SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
|
GroupLayout()->SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
|
||||||
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING);
|
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING);
|
||||||
@@ -65,6 +85,7 @@ ConfigView::~ConfigView()
|
|||||||
void
|
void
|
||||||
ConfigView::AllAttached()
|
ConfigView::AllAttached()
|
||||||
{
|
{
|
||||||
|
fCompressionField->Menu()->SetTargetForItems(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,7 +93,27 @@ void
|
|||||||
ConfigView::MessageReceived(BMessage* message)
|
ConfigView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
|
case MSG_COMPRESSION_CHANGED: {
|
||||||
|
int32 value;
|
||||||
|
if (message->FindInt32("value", &value) >= B_OK) {
|
||||||
|
fSettings->SetGetInt32(PSD_SETTING_COMPRESSION, &value);
|
||||||
|
fSettings->SaveSettings();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ConfigView::_AddItemToMenu(BMenu* menu, const char* label,
|
||||||
|
uint32 value, uint32 current_value)
|
||||||
|
{
|
||||||
|
BMessage* message = new BMessage(MSG_COMPRESSION_CHANGED);
|
||||||
|
message->AddInt32("value", value);
|
||||||
|
BMenuItem* item = new BMenuItem(label, message);
|
||||||
|
item->SetMarked(value == current_value);
|
||||||
|
menu->AddItem(item);
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <GroupView.h>
|
#include <GroupView.h>
|
||||||
#include <CheckBox.h>
|
#include <CheckBox.h>
|
||||||
|
#include <MenuField.h>
|
||||||
|
|
||||||
|
#define MSG_COMPRESSION_CHANGED 'cchg'
|
||||||
|
|
||||||
class ConfigView : public BGroupView {
|
class ConfigView : public BGroupView {
|
||||||
public:
|
public:
|
||||||
@@ -23,7 +26,12 @@ class ConfigView : public BGroupView {
|
|||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _AddItemToMenu(BMenu* menu, const char* label,
|
||||||
|
uint32 value, uint32 current_value);
|
||||||
|
|
||||||
BTextView* fCopyrightView;
|
BTextView* fCopyrightView;
|
||||||
|
BMenuField* fCompressionField;
|
||||||
|
|
||||||
TranslatorSettings *fSettings;
|
TranslatorSettings *fSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ static const translation_format sOutputFormats[] = {
|
|||||||
|
|
||||||
static const TranSetting sDefaultSettings[] = {
|
static const TranSetting sDefaultSettings[] = {
|
||||||
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
{B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false}
|
{B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false},
|
||||||
|
{PSD_SETTING_COMPRESSION, TRAN_SETTING_INT32, PSD_COMPRESSED_RLE}
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32 kNumInputFormats = sizeof(sInputFormats)
|
const uint32 kNumInputFormats = sizeof(sInputFormats)
|
||||||
@@ -142,8 +143,11 @@ PSDTranslator::DerivedTranslate(BPositionIO *source,
|
|||||||
{
|
{
|
||||||
if (outType == PSD_IMAGE_FORMAT) {
|
if (outType == PSD_IMAGE_FORMAT) {
|
||||||
PSDWriter psdFile(source);
|
PSDWriter psdFile(source);
|
||||||
psdFile.SetCompression(PSD_COMPRESSED_RLE);
|
uint32 compression =
|
||||||
return psdFile.Encode(target);
|
fSettings->SetGetInt32(PSD_SETTING_COMPRESSION);
|
||||||
|
psdFile.SetCompression(compression);
|
||||||
|
if (psdFile.IsReady())
|
||||||
|
return psdFile.Encode(target);
|
||||||
}
|
}
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#define DOCUMENT_COUNT "/documentCount"
|
#define DOCUMENT_COUNT "/documentCount"
|
||||||
#define DOCUMENT_INDEX "/documentIndex"
|
#define DOCUMENT_INDEX "/documentIndex"
|
||||||
|
|
||||||
|
#define PSD_SETTING_COMPRESSION "psd /compression"
|
||||||
|
|
||||||
#define PSD_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(1, 2, 1)
|
#define PSD_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(1, 2, 1)
|
||||||
#define PSD_IMAGE_FORMAT 'PSD '
|
#define PSD_IMAGE_FORMAT 'PSD '
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user