Add a menufield to select color combinations, and add obvious
"white on black" and "black on white". For some reason these aren't applied live, like when you chose a custom combo. I'm not really fond of the code, and will rework it in the next few days. But at least it works! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37535 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
3aea1d4f53
commit
80490c776a
@ -25,6 +25,7 @@
|
||||
#include <TextControl.h>
|
||||
#include <View.h>
|
||||
|
||||
#include "Colors.h"
|
||||
#include "PrefHandler.h"
|
||||
#include "TermConst.h"
|
||||
|
||||
@ -72,30 +73,15 @@ AppearancePrefView::AppearancePrefView(const char* name,
|
||||
BView(name, B_WILL_DRAW),
|
||||
fTerminalMessenger(messenger)
|
||||
{
|
||||
const char* kColorTable[] = {
|
||||
const char* kColorTable[] = {
|
||||
PREF_TEXT_FORE_COLOR,
|
||||
PREF_TEXT_BACK_COLOR,
|
||||
PREF_CURSOR_FORE_COLOR,
|
||||
PREF_CURSOR_BACK_COLOR,
|
||||
PREF_SELECT_FORE_COLOR,
|
||||
PREF_SELECT_BACK_COLOR,
|
||||
#if 0
|
||||
"",
|
||||
PREF_IM_FORE_COLOR,
|
||||
PREF_IM_BACK_COLOR,
|
||||
PREF_IM_SELECT_COLOR,
|
||||
"",
|
||||
PREF_ANSI_BLACK_COLOR,
|
||||
PREF_ANSI_RED_COLOR,
|
||||
PREF_ANSI_GREEN_COLOR,
|
||||
PREF_ANSI_YELLOW_COLOR,
|
||||
PREF_ANSI_BLUE_COLOR,
|
||||
PREF_ANSI_MAGENTA_COLOR,
|
||||
PREF_ANSI_CYAN_COLOR,
|
||||
PREF_ANSI_WHITE_COLOR,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
};
|
||||
|
||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||
|
||||
@ -108,9 +94,18 @@ AppearancePrefView::AppearancePrefView(const char* name,
|
||||
|
||||
fFont = new BMenuField(B_TRANSLATE("Font:"), fontMenu);
|
||||
fFontSize = new BMenuField(B_TRANSLATE("Size:"), sizeMenu);
|
||||
|
||||
BPopUpMenu *schemasPopUp =_MakeColorSchemaMenu(MSG_COLOR_SCHEMA_CHANGED, gPredefinedSchemas,
|
||||
gPredefinedSchemas[0]);
|
||||
fColorSchemaField = new BMenuField(B_TRANSLATE("Color schema:"),
|
||||
schemasPopUp);
|
||||
|
||||
BPopUpMenu *colorsPopUp =_MakeMenu(MSG_COLOR_FIELD_CHANGED, kColorTable,
|
||||
kColorTable[0]);
|
||||
|
||||
fColorField = new BMenuField(B_TRANSLATE("Color:"),
|
||||
_MakeMenu(MSG_COLOR_FIELD_CHANGED, kColorTable,
|
||||
kColorTable[0]));
|
||||
colorsPopUp);
|
||||
fColorField->SetEnabled(false);
|
||||
|
||||
BView* layoutView = BLayoutBuilder::Group<>()
|
||||
.SetInsets(5, 5, 5, 5)
|
||||
@ -120,8 +115,10 @@ AppearancePrefView::AppearancePrefView(const char* name,
|
||||
.Add(fFont->CreateMenuBarLayoutItem(), 1, 0)
|
||||
.Add(fFontSize->CreateLabelLayoutItem(), 0, 1)
|
||||
.Add(fFontSize->CreateMenuBarLayoutItem(), 1, 1)
|
||||
.Add(fColorField->CreateLabelLayoutItem(), 0, 2)
|
||||
.Add(fColorField->CreateMenuBarLayoutItem(), 1, 2)
|
||||
.Add(fColorSchemaField->CreateLabelLayoutItem(), 0, 2)
|
||||
.Add(fColorSchemaField->CreateMenuBarLayoutItem(), 1, 2)
|
||||
.Add(fColorField->CreateLabelLayoutItem(), 0, 3)
|
||||
.Add(fColorField->CreateMenuBarLayoutItem(), 1, 3)
|
||||
)
|
||||
.AddGroup(B_VERTICAL, 5)
|
||||
.AddGlue()
|
||||
@ -135,7 +132,9 @@ AppearancePrefView::AppearancePrefView(const char* name,
|
||||
fFont->SetAlignment(B_ALIGN_RIGHT);
|
||||
fFontSize->SetAlignment(B_ALIGN_RIGHT);
|
||||
fColorField->SetAlignment(B_ALIGN_RIGHT);
|
||||
fColorSchemaField->SetAlignment(B_ALIGN_RIGHT);
|
||||
|
||||
fColorControl->SetEnabled(false);
|
||||
fColorControl->SetValue(PrefHandler::Default()->getRGB(PREF_TEXT_FORE_COLOR));
|
||||
|
||||
BTextControl* redInput = (BTextControl*)fColorControl->ChildAt(0);
|
||||
@ -162,7 +161,7 @@ AppearancePrefView::GetPreferredSize(float* _width, float* _height)
|
||||
void
|
||||
AppearancePrefView::Revert()
|
||||
{
|
||||
fColorField->Menu()->ItemAt(0)->SetMarked(true);
|
||||
fColorSchemaField->Menu()->ItemAt(0)->SetMarked(true);
|
||||
fColorControl->SetValue(PrefHandler::Default()->
|
||||
getRGB(PREF_TEXT_FORE_COLOR));
|
||||
|
||||
@ -181,6 +180,14 @@ AppearancePrefView::AttachedToWindow()
|
||||
|
||||
fColorControl->SetTarget(this);
|
||||
fColorField->Menu()->SetTargetForItems(this);
|
||||
fColorSchemaField->Menu()->SetTargetForItems(this);
|
||||
|
||||
_SetCurrentColorSchema(fColorSchemaField);
|
||||
bool enableCustomColors =
|
||||
!strcmp(fColorSchemaField->Menu()->FindMarked()->Label(),
|
||||
"Custom");
|
||||
|
||||
_EnableCustomColors(enableCustomColors);
|
||||
}
|
||||
|
||||
|
||||
@ -220,7 +227,8 @@ AppearancePrefView::MessageReceived(BMessage* msg)
|
||||
}
|
||||
break;
|
||||
|
||||
case MSG_COLOR_CHANGED: {
|
||||
case MSG_COLOR_CHANGED:
|
||||
{
|
||||
rgb_color oldColor = PrefHandler::Default()->getRGB(
|
||||
fColorField->Menu()->FindMarked()->Label());
|
||||
if (oldColor != fColorControl->ValueAsColor()) {
|
||||
@ -232,6 +240,19 @@ AppearancePrefView::MessageReceived(BMessage* msg)
|
||||
}
|
||||
break;
|
||||
|
||||
case MSG_COLOR_SCHEMA_CHANGED:
|
||||
{
|
||||
color_schema *newSchema = NULL;
|
||||
msg->FindPointer("color_schema", (void**)&newSchema);
|
||||
if (newSchema == &gCustomSchema)
|
||||
_EnableCustomColors(true);
|
||||
else
|
||||
_EnableCustomColors(false);
|
||||
_ChangeColorSchema(newSchema);
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case MSG_COLOR_FIELD_CHANGED:
|
||||
fColorControl->SetValue(PrefHandler::Default()->getRGB(
|
||||
fColorField->Menu()->FindMarked()->Label()));
|
||||
@ -251,6 +272,63 @@ AppearancePrefView::MessageReceived(BMessage* msg)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AppearancePrefView::_EnableCustomColors(bool enable)
|
||||
{
|
||||
fColorField->SetEnabled(enable);
|
||||
fColorControl->SetEnabled(enable);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AppearancePrefView::_ChangeColorSchema(color_schema* schema)
|
||||
{
|
||||
PrefHandler *pref = PrefHandler::Default();
|
||||
|
||||
pref->setRGB(PREF_TEXT_FORE_COLOR, schema->text_fore_color);
|
||||
pref->setRGB(PREF_TEXT_BACK_COLOR, schema->text_back_color);
|
||||
pref->setRGB(PREF_CURSOR_FORE_COLOR, schema->cursor_fore_color);
|
||||
pref->setRGB(PREF_CURSOR_BACK_COLOR, schema->cursor_back_color);
|
||||
pref->setRGB(PREF_SELECT_FORE_COLOR, schema->select_fore_color);
|
||||
pref->setRGB(PREF_SELECT_BACK_COLOR, schema->select_back_color);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AppearancePrefView::_SetCurrentColorSchema(BMenuField *field)
|
||||
{
|
||||
PrefHandler *pref = PrefHandler::Default();
|
||||
|
||||
gCustomSchema.text_fore_color = pref->getRGB(PREF_TEXT_FORE_COLOR);
|
||||
gCustomSchema.text_back_color = pref->getRGB(PREF_TEXT_BACK_COLOR);
|
||||
gCustomSchema.cursor_fore_color = pref->getRGB(PREF_CURSOR_FORE_COLOR);
|
||||
gCustomSchema.cursor_back_color = pref->getRGB(PREF_CURSOR_BACK_COLOR);
|
||||
gCustomSchema.select_fore_color = pref->getRGB(PREF_SELECT_FORE_COLOR);
|
||||
gCustomSchema.select_back_color = pref->getRGB(PREF_SELECT_BACK_COLOR);
|
||||
|
||||
const char *currentSchemaName = NULL;
|
||||
|
||||
color_schema **schemas = const_cast<color_schema**>(gPredefinedSchemas);
|
||||
while (*schemas) {
|
||||
if (gCustomSchema == **schemas) {
|
||||
currentSchemaName = (*schemas)->name;
|
||||
break;
|
||||
}
|
||||
schemas++;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for (int32 i = 0; i < fColorSchemaField->Menu()->CountItems(); i++) {
|
||||
BMenuItem *item = fColorSchemaField->Menu()->ItemAt(i);
|
||||
if (!strcmp(item->Label(), currentSchemaName)) {
|
||||
item->SetMarked(true);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*static*/ BMenu*
|
||||
AppearancePrefView::_MakeFontMenu(uint32 command,
|
||||
const char* defaultFamily, const char* defaultStyle)
|
||||
@ -332,19 +410,45 @@ AppearancePrefView::_MakeSizeMenu(uint32 command, uint8 defaultSize)
|
||||
|
||||
|
||||
/*static*/ BPopUpMenu*
|
||||
AppearancePrefView::_MakeMenu(uint32 msg, const char** items,
|
||||
AppearancePrefView::_MakeMenu(uint32 msg, const char **items,
|
||||
const char* defaultItemName)
|
||||
{
|
||||
BPopUpMenu* menu = new BPopUpMenu("");
|
||||
|
||||
int32 i = 0;
|
||||
while (*items) {
|
||||
if (!strcmp(*items, ""))
|
||||
if (!strcmp((*items), ""))
|
||||
menu->AddSeparatorItem();
|
||||
else
|
||||
menu->AddItem(new BMenuItem(*items, new BMessage(msg)));
|
||||
if (!strcmp(*items, defaultItemName))
|
||||
menu->ItemAt(i)->SetMarked(true);
|
||||
else {
|
||||
BMessage *message = new BMessage(msg);
|
||||
menu->AddItem(new BMenuItem((*items), message));
|
||||
}
|
||||
|
||||
items++;
|
||||
i++;
|
||||
}
|
||||
|
||||
menu->FindItem(defaultItemName)->SetMarked(true);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ BPopUpMenu*
|
||||
AppearancePrefView::_MakeColorSchemaMenu(uint32 msg, const color_schema **items,
|
||||
const color_schema* defaultItemName)
|
||||
{
|
||||
BPopUpMenu* menu = new BPopUpMenu("");
|
||||
|
||||
int32 i = 0;
|
||||
while (*items) {
|
||||
if (!strcmp((*items)->name, ""))
|
||||
menu->AddSeparatorItem();
|
||||
else {
|
||||
BMessage *message = new BMessage(msg);
|
||||
message->AddPointer("color_schema", (const void*)*items);
|
||||
menu->AddItem(new BMenuItem((*items)->name, message));
|
||||
}
|
||||
|
||||
items++;
|
||||
i++;
|
||||
|
@ -19,6 +19,8 @@ const ulong MSG_FULL_FONT_CHANGED = 'mcff';
|
||||
const ulong MSG_FULL_SIZE_CHANGED = 'mcfs';
|
||||
const ulong MSG_COLOR_FIELD_CHANGED = 'mccf';
|
||||
const ulong MSG_COLOR_CHANGED = 'mcbc';
|
||||
const ulong MSG_COLOR_SCHEMA_CHANGED = 'mccs';
|
||||
|
||||
|
||||
const ulong MSG_COLS_CHANGED = 'mccl';
|
||||
const ulong MSG_ROWS_CHANGED = 'mcrw';
|
||||
@ -27,6 +29,7 @@ const ulong MSG_HISTORY_CHANGED = 'mhst';
|
||||
const ulong MSG_PREF_MODIFIED = 'mpmo';
|
||||
|
||||
|
||||
struct color_schema;
|
||||
class BColorControl;
|
||||
class BMenu;
|
||||
class BMenuField;
|
||||
@ -45,6 +48,11 @@ public:
|
||||
float *_height);
|
||||
|
||||
private:
|
||||
void _EnableCustomColors(bool enable);
|
||||
|
||||
void _ChangeColorSchema(color_schema *schema);
|
||||
void _SetCurrentColorSchema(BMenuField *field);
|
||||
|
||||
static BMenu* _MakeFontMenu(uint32 command,
|
||||
const char *defaultFamily,
|
||||
const char *defaultStyle);
|
||||
@ -52,11 +60,15 @@ private:
|
||||
uint8 defaultSize);
|
||||
|
||||
static BPopUpMenu* _MakeMenu(uint32 msg, const char **items,
|
||||
const char *defaultItemName);
|
||||
const char *defaultItem);
|
||||
|
||||
static BPopUpMenu* _MakeColorSchemaMenu(uint32 msg, const color_schema **schemas,
|
||||
const color_schema *defaultItemName);
|
||||
|
||||
BMenuField *fFont;
|
||||
BMenuField *fFontSize;
|
||||
|
||||
BMenuField *fColorSchemaField;
|
||||
BMenuField *fColorField;
|
||||
BColorControl *fColorControl;
|
||||
|
||||
|
52
src/apps/terminal/Colors.cpp
Normal file
52
src/apps/terminal/Colors.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "Colors.h"
|
||||
|
||||
const rgb_color kBlack= { 0, 0, 0, 255 };
|
||||
const rgb_color kWhite = { 255, 255, 255, 255 };
|
||||
|
||||
const struct color_schema kBlackOnWhite = {
|
||||
"Black on White",
|
||||
kBlack,
|
||||
kWhite,
|
||||
kWhite,
|
||||
kBlack,
|
||||
kWhite,
|
||||
kBlack
|
||||
};
|
||||
|
||||
|
||||
const struct color_schema kWhiteOnBlack = {
|
||||
"White on Black",
|
||||
kWhite,
|
||||
kBlack,
|
||||
kBlack,
|
||||
kWhite,
|
||||
kBlack,
|
||||
kWhite
|
||||
};
|
||||
|
||||
|
||||
struct color_schema gCustomSchema = {
|
||||
"Custom"
|
||||
};
|
||||
|
||||
const color_schema *gPredefinedSchemas[] = {
|
||||
&kBlackOnWhite,
|
||||
&kWhiteOnBlack,
|
||||
&gCustomSchema,
|
||||
};
|
||||
|
||||
|
||||
bool
|
||||
color_schema::operator==(const color_schema &color)
|
||||
{
|
||||
if (text_fore_color == color.text_fore_color
|
||||
&& text_back_color == color.text_back_color)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
29
src/apps/terminal/Colors.h
Normal file
29
src/apps/terminal/Colors.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _COLORS_H
|
||||
#define _COLORS_H
|
||||
|
||||
#include <InterfaceDefs.h>
|
||||
|
||||
struct color_schema {
|
||||
const char *name;
|
||||
rgb_color text_fore_color;
|
||||
rgb_color text_back_color;
|
||||
rgb_color cursor_fore_color;
|
||||
rgb_color cursor_back_color;
|
||||
rgb_color select_fore_color;
|
||||
rgb_color select_back_color;
|
||||
bool operator==(const color_schema &color);
|
||||
};
|
||||
|
||||
|
||||
extern const rgb_color kBlack;
|
||||
extern const rgb_color kWhite;
|
||||
|
||||
extern color_schema gCustomSchema;
|
||||
extern const color_schema *gPredefinedSchemas[];
|
||||
|
||||
|
||||
#endif // _COLORS_H
|
@ -8,6 +8,7 @@ Application Terminal :
|
||||
AppearPrefView.cpp
|
||||
Arguments.cpp
|
||||
BasicTerminalBuffer.cpp
|
||||
Colors.cpp
|
||||
Encoding.cpp
|
||||
FindWindow.cpp
|
||||
Globals.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user