[haiku-commits] r37535 - haiku/trunk/src/apps/terminal

  • From: stefano.ceccherini@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 16 Jul 2010 13:52:36 +0200 (CEST)

Author: jackburton
Date: 2010-07-16 13:52:35 +0200 (Fri, 16 Jul 2010)
New Revision: 37535
Changeset: http://dev.haiku-os.org/changeset/37535

Added:
   haiku/trunk/src/apps/terminal/Colors.cpp
   haiku/trunk/src/apps/terminal/Colors.h
Modified:
   haiku/trunk/src/apps/terminal/AppearPrefView.cpp
   haiku/trunk/src/apps/terminal/AppearPrefView.h
   haiku/trunk/src/apps/terminal/Jamfile
Log:
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!


Modified: haiku/trunk/src/apps/terminal/AppearPrefView.cpp
===================================================================
--- haiku/trunk/src/apps/terminal/AppearPrefView.cpp    2010-07-16 01:27:27 UTC 
(rev 37534)
+++ haiku/trunk/src/apps/terminal/AppearPrefView.cpp    2010-07-16 11:52:35 UTC 
(rev 37535)
@@ -25,6 +25,7 @@
 #include <TextControl.h>
 #include <View.h>
 
+#include "Colors.h"
 #include "PrefHandler.h"
 #include "TermConst.h"
 
@@ -72,30 +73,15 @@
        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 @@
 
        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 @@
                                .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 @@
        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 @@
 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 @@
 
        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 @@
                        }
                        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 @@
                        }
                        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 @@
 }
 
 
+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,22 +410,48 @@
 
 
 /*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++;
+       }
+       return menu;
+}

Modified: haiku/trunk/src/apps/terminal/AppearPrefView.h
===================================================================
--- haiku/trunk/src/apps/terminal/AppearPrefView.h      2010-07-16 01:27:27 UTC 
(rev 37534)
+++ haiku/trunk/src/apps/terminal/AppearPrefView.h      2010-07-16 11:52:35 UTC 
(rev 37535)
@@ -19,7 +19,9 @@
 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';
 const ulong MSG_HISTORY_CHANGED         = 'mhst';
@@ -27,6 +29,7 @@
 const ulong MSG_PREF_MODIFIED          = 'mpmo';
 
 
+struct color_schema;
 class BColorControl;
 class BMenu;
 class BMenuField;
@@ -45,6 +48,11 @@
                                                                        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 @@
                                                                        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;
 

Added: haiku/trunk/src/apps/terminal/Colors.cpp
===================================================================
--- haiku/trunk/src/apps/terminal/Colors.cpp                            (rev 0)
+++ haiku/trunk/src/apps/terminal/Colors.cpp    2010-07-16 11:52:35 UTC (rev 
37535)
@@ -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;
+}

Added: haiku/trunk/src/apps/terminal/Colors.h
===================================================================
--- haiku/trunk/src/apps/terminal/Colors.h                              (rev 0)
+++ haiku/trunk/src/apps/terminal/Colors.h      2010-07-16 11:52:35 UTC (rev 
37535)
@@ -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

Modified: haiku/trunk/src/apps/terminal/Jamfile
===================================================================
--- haiku/trunk/src/apps/terminal/Jamfile       2010-07-16 01:27:27 UTC (rev 
37534)
+++ haiku/trunk/src/apps/terminal/Jamfile       2010-07-16 11:52:35 UTC (rev 
37535)
@@ -8,6 +8,7 @@
        AppearPrefView.cpp
        Arguments.cpp
        BasicTerminalBuffer.cpp
+       Colors.cpp
        Encoding.cpp
        FindWindow.cpp
        Globals.cpp


Other related posts:

  • » [haiku-commits] r37535 - haiku/trunk/src/apps/terminal - stefano . ceccherini