Permalink
Browse files

Added embedded typeface handling to CustomLookAndFeel

Added typeface initialization to CustomLookAndFeel, and implemented
getTypefaceForFont().

Fonts can now be created using a more centralized method, by calling the
Font(String("Typeface Name"), fontHeight, Font::style) constructor.  Names for
the typefaces ("Default Light", "Paragraph") should be regarded as tentative.

There's also simpler code to do the same thing that should be uncommented after
the 2.0 update (it uses HashMap, which is not currently in our library code,
even though it's in the 1.53 docs.)
  • Loading branch information...
1 parent d61c1f5 commit 65582386faff6b5bd24658e7cfcbb349522d0b00 @akmokhtari committed Nov 23, 2012
Showing with 147 additions and 53 deletions.
  1. +87 −11 Source/UI/CustomLookAndFeel.cpp
  2. +60 −42 Source/UI/CustomLookAndFeel.h
@@ -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,
}
-}
+}
@@ -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 @@ class CustomLookAndFeel : public LookAndFeel
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 @@ class CustomLookAndFeel : public LookAndFeel
// ======== 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;
};

0 comments on commit 6558238

Please sign in to comment.