00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pent_include.h"
00020 #include "JPRenderedText.h"
00021
00022 #include "ShapeFont.h"
00023 #include "RenderSurface.h"
00024
00025 #include "encoding.h"
00026 #include "ShapeFrame.h"
00027 #include "PaletteManager.h"
00028
00029 DEFINE_RUNTIME_CLASSTYPE_CODE(JPRenderedText,RenderedText);
00030
00031
00032 JPRenderedText::JPRenderedText(std::list<PositionedText>& lines_,
00033 int width_, int height_, int vlead_,
00034 ShapeFont* font_, unsigned int fontnum_)
00035 : lines(lines_), font(font_), fontnum(fontnum_)
00036 {
00037 width = width_;
00038 height = height_;
00039 vlead = vlead_;
00040 }
00041
00042 JPRenderedText::~JPRenderedText()
00043 {
00044
00045 }
00046
00047 void JPRenderedText::draw(RenderSurface* surface, int x, int y, bool )
00048 {
00049
00050
00051 PaletteManager* palman = PaletteManager::get_instance();
00052 PaletteManager::PalIndex fontpal = static_cast<PaletteManager::PalIndex>
00053 (PaletteManager::Pal_JPFontStart+fontnum);
00054 Pentagram::Palette* pal = palman->getPalette(fontpal);
00055 const Pentagram::Palette* savepal = font->getPalette();
00056 font->setPalette(pal);
00057
00058 std::list<PositionedText>::iterator iter;
00059
00060 for (iter = lines.begin(); iter != lines.end(); ++iter)
00061 {
00062 int line_x = x + iter->dims.x;
00063 int line_y = y + iter->dims.y;
00064
00065 std::size_t textsize = iter->text.size();
00066
00067 for (std::size_t i = 0; i < textsize; ++i) {
00068 uint16 sjis = iter->text[i] & 0xFF;
00069 if (sjis >= 0x80) {
00070 uint16 t = iter->text[++i] & 0xFF;
00071 sjis += (t << 8);
00072 }
00073 uint16 u8char = Pentagram::shiftjis_to_ultima8(sjis);
00074 surface->Paint(font, u8char, line_x, line_y);
00075
00076 if (i == iter->cursor) {
00077 surface->Fill32(0xFF000000, line_x, line_y-font->getBaseline(),
00078 1, iter->dims.h);
00079 }
00080
00081 line_x += (font->getFrame(u8char))->width-font->getHlead();
00082 }
00083
00084 if (iter->cursor == textsize) {
00085 surface->Fill32(0xFF000000, line_x, line_y-font->getBaseline(),
00086 1, iter->dims.h);
00087 }
00088 }
00089
00090 font->setPalette(savepal);
00091 }
00092
00093 void JPRenderedText::drawBlended(RenderSurface* surface, int x, int y,
00094 uint32 col, bool )
00095 {
00096
00097
00098 PaletteManager* palman = PaletteManager::get_instance();
00099 PaletteManager::PalIndex fontpal = static_cast<PaletteManager::PalIndex>
00100 (PaletteManager::Pal_JPFontStart+fontnum);
00101 Pentagram::Palette* pal = palman->getPalette(fontpal);
00102 const Pentagram::Palette* savepal = font->getPalette();
00103 font->setPalette(pal);
00104
00105 std::list<PositionedText>::iterator iter;
00106
00107 for (iter = lines.begin(); iter != lines.end(); ++iter)
00108 {
00109 int line_x = x + iter->dims.x;
00110 int line_y = y + iter->dims.y;
00111
00112 std::size_t textsize = iter->text.size();
00113
00114 for (std::size_t i = 0; i < textsize; ++i) {
00115 uint16 sjis = iter->text[i] & 0xFF;
00116 if (sjis >= 0x80) {
00117 uint16 t = iter->text[++i] & 0xFF;
00118 sjis += (t << 8);
00119 }
00120 uint16 u8char = Pentagram::shiftjis_to_ultima8(sjis);
00121
00122 surface->PaintHighlight(font, u8char, line_x, line_y,
00123 false, false, col);
00124 line_x += (font->getFrame(u8char))->width-font->getHlead();
00125 }
00126
00127 }
00128
00129 font->setPalette(savepal);
00130 }