diff --git a/Source/UI/CustomLookAndFeel.cpp b/Source/UI/CustomLookAndFeel.cpp index 5602ae15165c060eec4d67c0125decb62f82cfe4..6d6375752c2b77b4eb8327eea68019a6aac2bdd7 100755 --- a/Source/UI/CustomLookAndFeel.cpp +++ b/Source/UI/CustomLookAndFeel.cpp @@ -23,10 +23,50 @@ #include "CustomLookAndFeel.h" -CustomLookAndFeel::CustomLookAndFeel() +CustomLookAndFeel::CustomLookAndFeel() : + // third argument to MIS means don't copy the binary data to make a new stream + cpmonoExtraLightStream(BinaryData::cpmonoextralightserialized, + BinaryData::cpmonoextralightserializedSize, + false), + cpmonoLightStream(BinaryData::cpmonolightserialized, + BinaryData::cpmonolightserializedSize, + false), + cpmonoPlainStream(BinaryData::cpmonoplainserialized, + BinaryData::cpmonoplainserializedSize, + false), + cpmonoBoldStream(BinaryData::cpmonoboldserialized, + BinaryData::cpmonoboldserializedSize, + false), + cpmonoBlackStream(BinaryData::cpmonoblackserialized, + BinaryData::cpmonoblackserializedSize, + false), + misoRegularStream(BinaryData::misoserialized, + BinaryData::misoserializedSize, + false), + silkscreenStream(BinaryData::silkscreenserialized, + BinaryData::silkscreenserializedSize, + false), + // heap allocation is necessary here, because otherwise the typefaces are + // deleted too soon (there's a singleton typefacecache that holds references + // to them whenever they're used). + cpmonoExtraLight(new CustomTypeface(cpmonoExtraLightStream)), + cpmonoLight(new CustomTypeface(cpmonoLightStream)), + cpmonoPlain(new CustomTypeface(cpmonoPlainStream)), + cpmonoBold(new CustomTypeface(cpmonoBoldStream)), + cpmonoBlack(new CustomTypeface(cpmonoBlackStream)), + misoRegular(new CustomTypeface(misoRegularStream)), + silkscreen(new CustomTypeface(silkscreenStream)) + { - MemoryInputStream mis(BinaryData::misoserialized, BinaryData::misoserializedSize, false); - Miso = new CustomTypeface(mis); + + // UNCOMMENT AFTER UPDATE + // typefaceMap.set(String("Default Extra Light"), cpmonoExtraLight); + // typefaceMap.set(String("Default Light"), cpmonoLight); + // typefaceMap.set(String("Default"), cpmonoPlain); + // typefaceMap.set(String("Default Bold"), cpmonoBold); + // typefaceMap.set(String("Default Black"), cpmonoBlack); + // typefaceMap.set(String("Paragraph"), misoRegular); + // typefaceMap.set(String("Silkscreen"), silkscreen); enum { PROCESSOR_COLOR = 0x801, @@ -47,21 +87,57 @@ CustomLookAndFeel::CustomLookAndFeel() setColour(PopupMenu::highlightedBackgroundColourId, Colours::grey); setColour(PopupMenu::highlightedTextColourId, Colours::yellow); - } CustomLookAndFeel::~CustomLookAndFeel() {} -// =============== -// const Typeface::Ptr CustomLookAndFeel::getTypefaceForFont (const Font& font) -// { - -// return Miso; +//============================================================================== +// FONT/TYPEFACE METHODS : +//============================================================================== -// } +const Typeface::Ptr CustomLookAndFeel::getTypefaceForFont (const Font& font) +{ + String typefaceName = font.getTypefaceName(); + // some of these names might be unnecessary, and there may be good ones + // missing. adjust as needed + if (typefaceName.equalsIgnoreCase("Default Extra Light")) + { + return cpmonoExtraLight; + } else if (typefaceName.equalsIgnoreCase("Default Light")) + { + return cpmonoLight; + } else if (typefaceName.equalsIgnoreCase("Default")) + { + return cpmonoPlain; + } else if (typefaceName.equalsIgnoreCase("Default Bold")) + { + return cpmonoBold; + } else if (typefaceName.equalsIgnoreCase("Default Black")) + { + return cpmonoBlack; + } else if (typefaceName.equalsIgnoreCase("Paragraph")) + { + return misoRegular; + } else if (typefaceName.equalsIgnoreCase("Small Text")) + { + return silkscreen; + } else // default + { + return LookAndFeel::getTypefaceForFont(font); + } + + // UNCOMMENT AFTER UPDATE + // if (typefaceMap.contains(typefaceName)) + // return typefaceMap[typefaceName]; + // else + // return LookAndFeel::getTypefaceForFont(font); +} //============================================================================== +// TAB METHODS : +//============================================================================== + int CustomLookAndFeel::getTabButtonOverlap (int tabDepth) { return 0; //1 + tabDepth / 4; @@ -616,4 +692,4 @@ void CustomLookAndFeel::drawComboBox (Graphics& g, int width, int height, } -} \ No newline at end of file +} diff --git a/Source/UI/CustomLookAndFeel.h b/Source/UI/CustomLookAndFeel.h index e2fd3ac847f4030e1764bdcb7c2765c477b769d5..0424093f0c43249ba885b8f8737861413ec9210e 100755 --- a/Source/UI/CustomLookAndFeel.h +++ b/Source/UI/CustomLookAndFeel.h @@ -31,24 +31,23 @@ /** - Used to modify the appearance of the application. + Used to modify the appearance of the application. - Currently contains methods for drawing custom tabs, custom - scroll bars, and custom sliders. + Currently contains methods for drawing custom tabs, scroll bars, and sliders. + It also takes care of custom fonts via getTypefaceForFont(). - @see MainWindow + @see MainWindow */ class CustomLookAndFeel : public LookAndFeel - { public: - CustomLookAndFeel(); + CustomLookAndFeel(); ~CustomLookAndFeel(); - // ======== custom fonts ================ - Typeface::Ptr Miso; + // ======== custom typeface getter: ============================= + const Typeface::Ptr getTypefaceForFont (const Font& font); // ======== custom tab methods: ============================= @@ -74,9 +73,9 @@ public: bool isFrontTab); int getTabButtonBestWidth (int tabIndex, - const String& text, - int tabDepth, - Button& button); + const String& text, + int tabDepth, + Button& button); int getTabButtonSpaceAroundImage (); @@ -111,50 +110,69 @@ public: // ======== custom slider methods: ============================= void drawLinearSliderThumb (Graphics& g, - int x, int y, - int width, int height, - float sliderPos, - float minSliderPos, - float maxSliderPos, - const Slider::SliderStyle style, - Slider& slider); + int x, int y, + int width, int height, + float sliderPos, + float minSliderPos, + float maxSliderPos, + const Slider::SliderStyle style, + Slider& slider); void drawLinearSliderBackground (Graphics& g, - int x, int y, - int width, int height, - float /*sliderPos*/, - float /*minSliderPos*/, - float /*maxSliderPos*/, - const Slider::SliderStyle /*style*/, - Slider& slider); + int x, int y, + int width, int height, + float /*sliderPos*/, + float /*minSliderPos*/, + float /*maxSliderPos*/, + const Slider::SliderStyle /*style*/, + Slider& slider); int getSliderThumbRadius (Slider& slider); void drawSliderKnob (Graphics& g, - const float x, const float y, - const float diameter, - const Colour& colour, - const float outlineThickness) throw(); + const float x, const float y, + const float diameter, + const Colour& colour, + const float outlineThickness) throw(); void drawGlassPointer (Graphics& g, - const float x, const float y, - const float diameter, - const Colour& colour, const float outlineThickness, - const int direction) throw(); - - // const Typeface::Ptr getTypefaceForFont (const Font& font); + const float x, const float y, + const float diameter, + const Colour& colour, const float outlineThickness, + const int direction) throw(); // ======== custom combo box methods: ============================= void drawComboBox (Graphics& g, int width, int height, - const bool isButtonDown, - int buttonX, int buttonY, - int buttonW, int buttonH, - ComboBox& box); - -private: - + const bool isButtonDown, + int buttonX, int buttonY, + int buttonW, int buttonH, + ComboBox& box); + +private: + + // UNCOMMENT AFTER UPDATE + // this maps strings to customtypeface pointers + //HashMap<String, Typeface::Ptr> typefaceMap; + + MemoryInputStream + cpmonoExtraLightStream, + cpmonoLightStream, + cpmonoPlainStream, + cpmonoBoldStream, + cpmonoBlackStream, + misoRegularStream, + silkscreenStream; + + Typeface::Ptr + cpmonoExtraLight, + cpmonoLight, + cpmonoPlain, + cpmonoBold, + cpmonoBlack, + misoRegular, + silkscreen; };