Merge branch 'master' into ref
commit
4986b7d65d
File diff suppressed because it is too large
Load Diff
@ -1,28 +1,33 @@
|
||||
#ifndef EDITORPAGE_H
|
||||
#define EDITORPAGE_H
|
||||
#ifndef EDITORPAGE_HPP
|
||||
#define EDITORPAGE_HPP
|
||||
|
||||
#include "support.hpp"
|
||||
#include "abstractpage.hpp"
|
||||
|
||||
class QGroupBox;
|
||||
|
||||
namespace CSVSettings {
|
||||
|
||||
class UserSettings;
|
||||
class AbstractBlock;
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
class EditorPage : public AbstractPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditorPage(QWidget *parent = 0);
|
||||
|
||||
EditorPage(QWidget *parent = 0);
|
||||
|
||||
void setupUi();
|
||||
void initializeWidgets (const CSMSettings::SettingMap &settings);
|
||||
void setupUi();
|
||||
|
||||
private:
|
||||
|
||||
/// User preference view of the record status delegate's icon / text setting
|
||||
GroupBlockDef *setupRecordStatusDisplay();
|
||||
|
||||
signals:
|
||||
|
||||
/// Signals up for changes to editor application-level settings
|
||||
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||
|
||||
public slots:
|
||||
};
|
||||
}
|
||||
#endif //EDITORPAGE_H
|
||||
|
||||
#endif // EDITORPAGE_HPP
|
||||
|
@ -0,0 +1,144 @@
|
||||
#include "windowpage.hpp"
|
||||
|
||||
#include <QList>
|
||||
#include <QListView>
|
||||
#include <QGroupBox>
|
||||
#include <QRadioButton>
|
||||
#include <QDockWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QStyle>
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include <QPlastiqueStyle>
|
||||
#endif
|
||||
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
#include "groupblock.hpp"
|
||||
#include "toggleblock.hpp"
|
||||
#include "../../view/settings/abstractblock.hpp"
|
||||
|
||||
CSVSettings::WindowPage::WindowPage(QWidget *parent):
|
||||
AbstractPage("Window", parent)
|
||||
{
|
||||
// Hacks to get the stylesheet look properly
|
||||
#ifdef Q_OS_MAC
|
||||
QPlastiqueStyle *style = new QPlastiqueStyle;
|
||||
//profilesComboBox->setStyle(style);
|
||||
#endif
|
||||
|
||||
setupUi();
|
||||
}
|
||||
|
||||
CSVSettings::GroupBlockDef * CSVSettings::WindowPage::buildDefinedWindowSize()
|
||||
{
|
||||
GroupBlockDef *block = new GroupBlockDef ( "Defined Size");
|
||||
|
||||
SettingsItemDef *widthByHeightItem = new SettingsItemDef ("Window Size", "640x480");
|
||||
WidgetDef widthByHeightWidget = WidgetDef (Widget_ComboBox);
|
||||
widthByHeightWidget.widgetWidth = 90;
|
||||
*(widthByHeightItem->valueList) << "640x480" << "800x600" << "1024x768" << "1440x900";
|
||||
|
||||
QStringList *widthProxy = new QStringList;
|
||||
QStringList *heightProxy = new QStringList;
|
||||
|
||||
(*widthProxy) << "Width" << "640" << "800" << "1024" << "1440";
|
||||
(*heightProxy) << "Height" << "480" << "600" << "768" << "900";
|
||||
|
||||
*(widthByHeightItem->proxyList) << widthProxy << heightProxy;
|
||||
|
||||
widthByHeightItem->widget = widthByHeightWidget;
|
||||
|
||||
block->settingItems << widthByHeightItem;
|
||||
block->isProxy = true;
|
||||
block->isVisible = false;
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
CSVSettings::GroupBlockDef *CSVSettings::WindowPage::buildCustomWindowSize()
|
||||
{
|
||||
GroupBlockDef *block = new GroupBlockDef ("Custom Size");
|
||||
|
||||
//custom width
|
||||
SettingsItemDef *widthItem = new SettingsItemDef ("Width", "640");
|
||||
widthItem->widget = WidgetDef (Widget_LineEdit);
|
||||
widthItem->widget.widgetWidth = 45;
|
||||
widthItem->widget.inputMask = "9999";
|
||||
|
||||
//custom height
|
||||
SettingsItemDef *heightItem = new SettingsItemDef ("Height", "480");
|
||||
heightItem->widget = WidgetDef (Widget_LineEdit);
|
||||
heightItem->widget.widgetWidth = 45;
|
||||
heightItem->widget.caption = "x";
|
||||
heightItem->widget.inputMask = "9999";
|
||||
|
||||
block->settingItems << widthItem << heightItem;
|
||||
block->widgetOrientation = Orient_Horizontal;
|
||||
block->isVisible = false;
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
CSVSettings::GroupBlockDef *CSVSettings::WindowPage::buildWindowSizeToggle()
|
||||
{
|
||||
GroupBlockDef *block = new GroupBlockDef ("Window Size");
|
||||
|
||||
// window size toggle
|
||||
block->captions << "Pre-Defined" << "Custom";
|
||||
block->widgetOrientation = Orient_Vertical;
|
||||
block->isVisible = false;
|
||||
|
||||
//define a widget for each group in the toggle
|
||||
for (int i = 0; i < 2; i++)
|
||||
block->widgets << new WidgetDef (Widget_RadioButton);
|
||||
|
||||
block->widgets.at(0)->isDefault = false;
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
CSVSettings::CustomBlockDef *CSVSettings::WindowPage::buildWindowSize(GroupBlockDef *toggle_def,
|
||||
GroupBlockDef *defined_def,
|
||||
GroupBlockDef *custom_def)
|
||||
{
|
||||
CustomBlockDef *block = new CustomBlockDef(QString ("Window Size"));
|
||||
|
||||
block->blockDefList << toggle_def << defined_def << custom_def;
|
||||
block->defaultValue = "Custom";
|
||||
|
||||
return block;
|
||||
|
||||
}
|
||||
|
||||
void CSVSettings::WindowPage::setupUi()
|
||||
{
|
||||
CustomBlockDef *windowSize = buildWindowSize(buildWindowSizeToggle(),
|
||||
buildDefinedWindowSize(),
|
||||
buildCustomWindowSize()
|
||||
);
|
||||
|
||||
mAbstractBlocks << buildBlock<ToggleBlock> (windowSize);
|
||||
|
||||
foreach (AbstractBlock *block, mAbstractBlocks)
|
||||
{
|
||||
connect (block, SIGNAL (signalUpdateSetting (const QString &, const QString &)),
|
||||
this, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)) );
|
||||
}
|
||||
|
||||
connect ( this,
|
||||
SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)),
|
||||
&(CSMSettings::UserSettings::instance()),
|
||||
SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CSVSettings::WindowPage::initializeWidgets (const CSMSettings::SettingMap &settings)
|
||||
{
|
||||
//iterate each item in each blocks in this section
|
||||
//validate the corresponding setting against the defined valuelist if any.
|
||||
for (AbstractBlockList::Iterator it_block = mAbstractBlocks.begin();
|
||||
it_block != mAbstractBlocks.end(); ++it_block)
|
||||
(*it_block)->updateSettings (settings);
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
#ifndef WINDOWPAGE_H
|
||||
#define WINDOWPAGE_H
|
||||
|
||||
#include "abstractpage.hpp"
|
||||
|
||||
class QGroupBox;
|
||||
|
||||
namespace CSVSettings {
|
||||
|
||||
class UserSettings;
|
||||
class AbstractBlock;
|
||||
|
||||
class WindowPage : public AbstractPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
WindowPage(QWidget *parent = 0);
|
||||
|
||||
void setupUi();
|
||||
void initializeWidgets (const CSMSettings::SettingMap &settings);
|
||||
|
||||
///
|
||||
GroupBlockDef *buildCustomWindowSize();
|
||||
GroupBlockDef *buildDefinedWindowSize();
|
||||
GroupBlockDef *buildWindowSizeToggle();
|
||||
CustomBlockDef *buildWindowSize (GroupBlockDef *, GroupBlockDef *, GroupBlockDef *);
|
||||
|
||||
signals:
|
||||
void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||
};
|
||||
}
|
||||
#endif //WINDOWPAGE_H
|
@ -0,0 +1,122 @@
|
||||
#include "recordstatusdelegate.hpp"
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
#include <QUndoStack>
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
|
||||
CSVWorld::RecordStatusDelegate::RecordStatusDelegate(QUndoStack &undoStack, QObject *parent)
|
||||
: CommandDelegate (undoStack, parent)
|
||||
{
|
||||
mModifiedIcon = new QIcon (":./modified.png");
|
||||
mAddedIcon = new QIcon (":./added.png");
|
||||
mDeletedIcon = new QIcon (":./removed.png");
|
||||
mBaseIcon = new QIcon (":./base.png");
|
||||
mIconSize = 16;
|
||||
|
||||
//Offset values are most likely device-dependent.
|
||||
//Need to replace with device-independent references.
|
||||
mTextLeftOffset = 3;
|
||||
mIconTopOffset = -3;
|
||||
|
||||
mStatusDisplay = 0; //icons and text by default. Remove when implemented as a user preference
|
||||
|
||||
mFont = QApplication::font();
|
||||
mFont.setPointSize(10);
|
||||
|
||||
mFontMetrics = new QFontMetrics(mFont);
|
||||
|
||||
mTextAlignment.setAlignment (Qt::AlignLeft | Qt::AlignVCenter );
|
||||
}
|
||||
|
||||
void CSVWorld::RecordStatusDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
QString text = "";
|
||||
QIcon *icon = 0;
|
||||
|
||||
switch (index.data().toInt())
|
||||
{
|
||||
case 0: // State_BaseOnly
|
||||
text = "Base";
|
||||
icon = mBaseIcon;
|
||||
break;
|
||||
|
||||
case 1: // State_Modified
|
||||
text = "Modified";
|
||||
icon = mModifiedIcon;
|
||||
break;
|
||||
|
||||
case 2: // State_Modified_Only
|
||||
text = "Added";
|
||||
icon = mAddedIcon;
|
||||
break;
|
||||
|
||||
case 3: // State_Deleted
|
||||
|
||||
case 4: // State_Erased
|
||||
text = "Deleted";
|
||||
icon = mDeletedIcon;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
QRect textRect = option.rect;
|
||||
QRect iconRect = option.rect;
|
||||
|
||||
//for icon-only (1), default option.rect centers icon left-to-right
|
||||
//otherwise, size option.rect to fit the icon, forcing left-alignment with text
|
||||
iconRect.setTop (iconRect.top() + mIconTopOffset);
|
||||
iconRect.setBottom (iconRect.top() + mIconSize);
|
||||
|
||||
if (mStatusDisplay == 0 && (icon) )
|
||||
{
|
||||
iconRect.setRight (iconRect.left()+ mIconSize*2);
|
||||
textRect.setLeft (iconRect.right() + mTextLeftOffset *1.25);
|
||||
}
|
||||
else
|
||||
textRect.setLeft (textRect.left() + mTextLeftOffset );
|
||||
|
||||
if ( (mStatusDisplay == 0 || mStatusDisplay == 1) && (icon) )
|
||||
painter->drawPixmap(iconRect.center().x()-10,iconRect.center().y()+2, icon->pixmap(mIconSize, mIconSize));
|
||||
|
||||
// icon + text or text only, or force text if no icon exists for status
|
||||
if (mStatusDisplay == 0 || mStatusDisplay == 2 || !(icon) )
|
||||
{
|
||||
painter->setFont(mFont);
|
||||
painter->drawText(textRect, text, mTextAlignment);
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QSize CSVWorld::RecordStatusDelegate::sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return QSize();
|
||||
}
|
||||
|
||||
CSVWorld::CommandDelegate *CSVWorld::RecordStatusDelegateFactory::makeDelegate (QUndoStack& undoStack,
|
||||
QObject *parent) const
|
||||
{
|
||||
return new RecordStatusDelegate (undoStack, parent);
|
||||
}
|
||||
|
||||
void CSVWorld::RecordStatusDelegate::updateEditorSetting (const QString &settingName, const QString &settingValue)
|
||||
{
|
||||
if (settingName == "Record Status Display")
|
||||
{
|
||||
if (settingValue == "Icon and Text")
|
||||
mStatusDisplay = 0;
|
||||
|
||||
else if (settingValue == "Icon Only")
|
||||
mStatusDisplay = 1;
|
||||
|
||||
else if (settingValue == "Text Only")
|
||||
mStatusDisplay = 2;
|
||||
|
||||
else
|
||||
mStatusDisplay = 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
#ifndef RECORDSTATUSDELEGATE_H
|
||||
#define RECORDSTATUSDELEGATE_H
|
||||
|
||||
#include "util.hpp"
|
||||
#include <QTextOption>
|
||||
#include <QFont>
|
||||
|
||||
class QIcon;
|
||||
class QFont;
|
||||
class QFontMetrics;
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class RecordStatusDelegate : public CommandDelegate
|
||||
{
|
||||
QFont mFont;
|
||||
QFontMetrics *mFontMetrics;
|
||||
|
||||
QTextOption mTextAlignment;
|
||||
|
||||
QIcon *mModifiedIcon;
|
||||
QIcon *mAddedIcon;
|
||||
QIcon *mDeletedIcon;
|
||||
QIcon *mBaseIcon;
|
||||
|
||||
int mStatusDisplay;
|
||||
|
||||
int mIconSize;
|
||||
int mIconTopOffset;
|
||||
int mTextLeftOffset;
|
||||
|
||||
public:
|
||||
explicit RecordStatusDelegate(QUndoStack& undoStack, QObject *parent = 0);
|
||||
|
||||
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
void updateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||
|
||||
};
|
||||
|
||||
class RecordStatusDelegateFactory : public CommandDelegateFactory
|
||||
{
|
||||
public:
|
||||
|
||||
virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const;
|
||||
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||
|
||||
};
|
||||
}
|
||||
#endif // RECORDSTATUSDELEGATE_H
|
||||
|
@ -0,0 +1,54 @@
|
||||
#include "controllers.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
namespace Controllers
|
||||
{
|
||||
|
||||
ControllerRepeatClick::ControllerRepeatClick() :
|
||||
mInit(0.5),
|
||||
mStep(0.1),
|
||||
mEnabled(true),
|
||||
mTimeLeft(0)
|
||||
{
|
||||
}
|
||||
|
||||
ControllerRepeatClick::~ControllerRepeatClick()
|
||||
{
|
||||
}
|
||||
|
||||
bool ControllerRepeatClick::addTime(MyGUI::Widget* _widget, float _time)
|
||||
{
|
||||
if(mTimeLeft == 0)
|
||||
mTimeLeft = mInit;
|
||||
|
||||
mTimeLeft -= _time;
|
||||
while (mTimeLeft <= 0)
|
||||
{
|
||||
mTimeLeft += mStep;
|
||||
eventRepeatClick(_widget, this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ControllerRepeatClick::setRepeat(float init, float step)
|
||||
{
|
||||
mInit = init;
|
||||
mStep = step;
|
||||
}
|
||||
|
||||
void ControllerRepeatClick::setEnabled(bool enable)
|
||||
{
|
||||
mEnabled = enable;
|
||||
}
|
||||
|
||||
void ControllerRepeatClick::setProperty(const std::string& _key, const std::string& _value)
|
||||
{
|
||||
}
|
||||
|
||||
void ControllerRepeatClick::prepareItem(MyGUI::Widget* _widget)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
#ifndef MWGUI_CONTROLLERS_H
|
||||
#define MWGUI_CONTROLLERS_H
|
||||
|
||||
#include <MyGUI_Widget.h>
|
||||
#include <MyGUI_ControllerItem.h>
|
||||
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
namespace Controllers
|
||||
{
|
||||
class ControllerRepeatClick :
|
||||
public MyGUI::ControllerItem
|
||||
{
|
||||
MYGUI_RTTI_DERIVED( ControllerRepeatClick )
|
||||
|
||||
public:
|
||||
ControllerRepeatClick();
|
||||
virtual ~ControllerRepeatClick();
|
||||
|
||||
void setRepeat(float init, float step);
|
||||
void setEnabled(bool enable);
|
||||
virtual void setProperty(const std::string& _key, const std::string& _value);
|
||||
|
||||
// Events
|
||||
typedef MyGUI::delegates::CMultiDelegate2<MyGUI::Widget*, MyGUI::ControllerItem*> EventHandle_RepeatClickVoid;
|
||||
|
||||
/** Event : Repeat Click.\n
|
||||
signature : void method(MyGUI::Widget* _sender, MyGUI::ControllerItem *_controller)\n
|
||||
*/
|
||||
EventHandle_RepeatClickVoid eventRepeatClick;
|
||||
|
||||
private:
|
||||
bool addTime(MyGUI::Widget* _widget, float _time);
|
||||
void prepareItem(MyGUI::Widget* _widget);
|
||||
|
||||
private:
|
||||
float mInit;
|
||||
float mStep;
|
||||
bool mEnabled;
|
||||
float mTimeLeft;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,238 @@
|
||||
#include "fontloader.hpp"
|
||||
|
||||
#include <OgreResourceGroupManager.h>
|
||||
#include <OgreTextureManager.h>
|
||||
|
||||
#include <MyGUI_ResourceManager.h>
|
||||
#include <MyGUI_FontManager.h>
|
||||
#include <MyGUI_ResourceManualFont.h>
|
||||
#include <MyGUI_XmlDocument.h>
|
||||
#include <MyGUI_FactoryManager.h>
|
||||
|
||||
#include <components/misc/stringops.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
unsigned long utf8ToUnicode(const std::string& utf8)
|
||||
{
|
||||
size_t i = 0;
|
||||
unsigned long unicode;
|
||||
size_t todo;
|
||||
unsigned char ch = utf8[i++];
|
||||
if (ch <= 0x7F)
|
||||
{
|
||||
unicode = ch;
|
||||
todo = 0;
|
||||
}
|
||||
else if (ch <= 0xBF)
|
||||
{
|
||||
throw std::logic_error("not a UTF-8 string");
|
||||
}
|
||||
else if (ch <= 0xDF)
|
||||
{
|
||||
unicode = ch&0x1F;
|
||||
todo = 1;
|
||||
}
|
||||
else if (ch <= 0xEF)
|
||||
{
|
||||
unicode = ch&0x0F;
|
||||
todo = 2;
|
||||
}
|
||||
else if (ch <= 0xF7)
|
||||
{
|
||||
unicode = ch&0x07;
|
||||
todo = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::logic_error("not a UTF-8 string");
|
||||
}
|
||||
for (size_t j = 0; j < todo; ++j)
|
||||
{
|
||||
unsigned char ch = utf8[i++];
|
||||
if (ch < 0x80 || ch > 0xBF)
|
||||
throw std::logic_error("not a UTF-8 string");
|
||||
unicode <<= 6;
|
||||
unicode += ch & 0x3F;
|
||||
}
|
||||
if (unicode >= 0xD800 && unicode <= 0xDFFF)
|
||||
throw std::logic_error("not a UTF-8 string");
|
||||
if (unicode > 0x10FFFF)
|
||||
throw std::logic_error("not a UTF-8 string");
|
||||
|
||||
return unicode;
|
||||
}
|
||||
}
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
FontLoader::FontLoader(ToUTF8::FromType encoding)
|
||||
{
|
||||
if (encoding == ToUTF8::WINDOWS_1252)
|
||||
mEncoding = ToUTF8::CP437;
|
||||
else
|
||||
mEncoding = encoding;
|
||||
}
|
||||
|
||||
void FontLoader::loadAllFonts()
|
||||
{
|
||||
Ogre::StringVector groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups ();
|
||||
for (Ogre::StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
|
||||
{
|
||||
Ogre::StringVectorPtr resourcesInThisGroup = Ogre::ResourceGroupManager::getSingleton ().findResourceNames (*it, "*.fnt");
|
||||
for (Ogre::StringVector::iterator resource = resourcesInThisGroup->begin(); resource != resourcesInThisGroup->end(); ++resource)
|
||||
{
|
||||
loadFont(*resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
} Point;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float u1; // appears unused, always 0
|
||||
Point top_left;
|
||||
Point top_right;
|
||||
Point bottom_left;
|
||||
Point bottom_right;
|
||||
float width;
|
||||
float height;
|
||||
float u2; // appears unused, always 0
|
||||
float kerning;
|
||||
float ascent;
|
||||
} GlyphInfo;
|
||||
|
||||
void FontLoader::loadFont(const std::string &fileName)
|
||||
{
|
||||
Ogre::DataStreamPtr file = Ogre::ResourceGroupManager::getSingleton().openResource(fileName);
|
||||
|
||||
float fontSize;
|
||||
int one;
|
||||
file->read(&fontSize, sizeof(fontSize));
|
||||
|
||||
file->read(&one, sizeof(int));
|
||||
assert(one == 1);
|
||||
file->read(&one, sizeof(int));
|
||||
assert(one == 1);
|
||||
|
||||
char name_[284];
|
||||
file->read(name_, sizeof(name_));
|
||||
std::string name(name_);
|
||||
|
||||
GlyphInfo data[256];
|
||||
file->read(data, sizeof(data));
|
||||
file->close();
|
||||
|
||||
// Create the font texture
|
||||
std::string bitmapFilename = "Fonts/" + std::string(name) + ".tex";
|
||||
Ogre::DataStreamPtr bitmapFile = Ogre::ResourceGroupManager::getSingleton().openResource(bitmapFilename);
|
||||
|
||||
int width, height;
|
||||
bitmapFile->read(&width, sizeof(int));
|
||||
bitmapFile->read(&height, sizeof(int));
|
||||
|
||||
std::vector<Ogre::uchar> textureData;
|
||||
textureData.resize(width*height*4);
|
||||
bitmapFile->read(&textureData[0], width*height*4);
|
||||
bitmapFile->close();
|
||||
|
||||
std::string textureName = name;
|
||||
Ogre::Image image;
|
||||
image.loadDynamicImage(&textureData[0], width, height, Ogre::PF_BYTE_RGBA);
|
||||
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(textureName,
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
Ogre::TEX_TYPE_2D,
|
||||
width, height, 0, Ogre::PF_BYTE_RGBA);
|
||||
texture->loadImage(image);
|
||||
|
||||
// Register the font with MyGUI
|
||||
MyGUI::ResourceManualFont* font = static_cast<MyGUI::ResourceManualFont*>(
|
||||
MyGUI::FactoryManager::getInstance().createObject("Resource", "ResourceManualFont"));
|
||||
// We need to emulate loading from XML because the data members are private as of mygui 3.2.0
|
||||
MyGUI::xml::Document xmlDocument;
|
||||
MyGUI::xml::ElementPtr root = xmlDocument.createRoot("ResourceManualFont");
|
||||
|
||||
if (name.size() >= 5 && Misc::StringUtils::ciEqual(name.substr(0, 5), "magic"))
|
||||
root->addAttribute("name", "Magic Cards");
|
||||
else if (name.size() >= 7 && Misc::StringUtils::ciEqual(name.substr(0, 7), "century"))
|
||||
root->addAttribute("name", "Century Gothic");
|
||||
else if (name.size() >= 7 && Misc::StringUtils::ciEqual(name.substr(0, 7), "daedric"))
|
||||
root->addAttribute("name", "Daedric");
|
||||
else
|
||||
return; // no point in loading it, since there is no way of using additional fonts
|
||||
|
||||
MyGUI::xml::ElementPtr defaultHeight = root->createChild("Property");
|
||||
defaultHeight->addAttribute("key", "DefaultHeight");
|
||||
defaultHeight->addAttribute("value", fontSize);
|
||||
MyGUI::xml::ElementPtr source = root->createChild("Property");
|
||||
source->addAttribute("key", "Source");
|
||||
source->addAttribute("value", std::string(textureName));
|
||||
MyGUI::xml::ElementPtr codes = root->createChild("Codes");
|
||||
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
int x1 = data[i].top_left.x*width;
|
||||
int y1 = data[i].top_left.y*height;
|
||||
int w = data[i].top_right.x*width - x1;
|
||||
int h = data[i].bottom_left.y*height - y1;
|
||||
|
||||
ToUTF8::Utf8Encoder encoder(mEncoding);
|
||||
unsigned long unicodeVal = utf8ToUnicode(encoder.getUtf8(std::string(1, (unsigned char)(i))));
|
||||
|
||||
MyGUI::xml::ElementPtr code = codes->createChild("Code");
|
||||
code->addAttribute("index", unicodeVal);
|
||||
code->addAttribute("coord", MyGUI::utility::toString(x1) + " "
|
||||
+ MyGUI::utility::toString(y1) + " "
|
||||
+ MyGUI::utility::toString(w) + " "
|
||||
+ MyGUI::utility::toString(h));
|
||||
code->addAttribute("advance", data[i].width);
|
||||
code->addAttribute("bearing", MyGUI::utility::toString(data[i].kerning) + " "
|
||||
+ MyGUI::utility::toString((fontSize-data[i].ascent)));
|
||||
|
||||
// ASCII vertical bar, use this as text input cursor
|
||||
if (i == 124)
|
||||
{
|
||||
MyGUI::xml::ElementPtr cursorCode = codes->createChild("Code");
|
||||
cursorCode->addAttribute("index", MyGUI::FontCodeType::Cursor);
|
||||
cursorCode->addAttribute("coord", MyGUI::utility::toString(x1) + " "
|
||||
+ MyGUI::utility::toString(y1) + " "
|
||||
+ MyGUI::utility::toString(w) + " "
|
||||
+ MyGUI::utility::toString(h));
|
||||
cursorCode->addAttribute("advance", data[i].width);
|
||||
cursorCode->addAttribute("bearing", MyGUI::utility::toString(data[i].kerning) + " "
|
||||
+ MyGUI::utility::toString((fontSize-data[i].ascent)));
|
||||
}
|
||||
}
|
||||
|
||||
// These are required as well, but the fonts don't provide them
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
MyGUI::FontCodeType::Enum type;
|
||||
if(i == 0)
|
||||
type = MyGUI::FontCodeType::Selected;
|
||||
else if (i == 1)
|
||||
type = MyGUI::FontCodeType::SelectedBack;
|
||||
else if (i == 2)
|
||||
type = MyGUI::FontCodeType::NotDefined;
|
||||
|
||||
MyGUI::xml::ElementPtr cursorCode = codes->createChild("Code");
|
||||
cursorCode->addAttribute("index", type);
|
||||
cursorCode->addAttribute("coord", "0 0 0 0");
|
||||
cursorCode->addAttribute("advance", "0");
|
||||
cursorCode->addAttribute("bearing", "0 0");
|
||||
|
||||
}
|
||||
|
||||
font->deserialization(root, MyGUI::Version(3,2,0));
|
||||
|
||||
MyGUI::ResourceManager::getInstance().addResource(font);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#ifndef MWGUI_FONTLOADER_H
|
||||
#define MWGUI_FONTLOADER_H
|
||||
|
||||
#include <components/to_utf8/to_utf8.hpp>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
|
||||
/// @brief loads Morrowind's .fnt/.tex fonts for use with MyGUI and Ogre
|
||||
class FontLoader
|
||||
{
|
||||
public:
|
||||
FontLoader (ToUTF8::FromType encoding);
|
||||
void loadAllFonts ();
|
||||
|
||||
private:
|
||||
ToUTF8::FromType mEncoding;
|
||||
|
||||
void loadFont (const std::string& fileName);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue