* A number of adjustments about fonts.
This commit is contained in:
jean.chalard
2009-01-04 02:49:08 +00:00
parent 45e143dd0c
commit 0d14207247
14 changed files with 186 additions and 103 deletions

View File

@@ -5,21 +5,27 @@
#include "../include/GameApp.h"
const unsigned SimpleMenu::SIDE_SIZE = 7;
const unsigned SimpleMenu::VMARGIN = 8;
const unsigned SimpleMenu::VMARGIN = 12;
const unsigned SimpleMenu::HMARGIN = 27;
const unsigned SimpleMenu::LINE_HEIGHT = 20;
const signed SimpleMenu::LINE_HEIGHT = 16;
const char* SimpleMenu::spadeLPath = "graphics/spade_ul.png";
const char* SimpleMenu::spadeRPath = "graphics/spade_ur.png";
const char* SimpleMenu::jewelPath = "graphics/jewel.png";
const char* SimpleMenu::sidePath = "graphics/menuside.png";
const char* SimpleMenu::titleFontPath = "graphics/smallface";
JQuad* SimpleMenu::spadeR = NULL;
JQuad* SimpleMenu::spadeL = NULL;
JQuad* SimpleMenu::jewel = NULL;
JQuad* SimpleMenu::side = NULL;
JLBFont* SimpleMenu::titleFont = NULL;
hgeParticleSystem* SimpleMenu::stars = NULL;
unsigned int SimpleMenu::refCount = 0;
// Here comes the magic of jewel graphics
PIXEL_TYPE SimpleMenu::jewelGraphics[9] = {0x3FFFFFFF,0x63645AEA,0x610D0D98,
0x63645AEA,0xFF635AD5,0xFF110F67,
0x610D0D98,0xFF110F67,0xFD030330};
SimpleMenu::SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int y, const char * _title, int _maxItems): JGuiController(id, listener){
mHeight = 2 * VMARGIN;
@@ -34,26 +40,45 @@ SimpleMenu::SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int
selectionT = 0;
timeOpen = 0;
closed = false;
++refCount;
JRenderer* renderer = JRenderer::GetInstance();
static JTexture* spadeLTex = renderer->LoadTexture(spadeLPath, TEX_TYPE_USE_VRAM);
static JTexture* spadeRTex = renderer->LoadTexture(spadeRPath, TEX_TYPE_USE_VRAM);
static JTexture* jewelTex = renderer->LoadTexture(jewelPath, TEX_TYPE_USE_VRAM);
static JTexture* jewelTex = renderer->CreateTexture(5, 5, TEX_TYPE_USE_VRAM);
static JTexture* sideTex = renderer->LoadTexture(sidePath, TEX_TYPE_USE_VRAM);
if (NULL == spadeL) spadeL = NEW JQuad(spadeLTex, 2, 1, 16, 13);
if (NULL == spadeR) spadeR = NEW JQuad(spadeRTex, 2, 1, 16, 13);
if (NULL == jewel) jewel = NEW JQuad(jewelTex, 0, 0, 3, 3);
if (NULL == jewel) jewel = NEW JQuad(jewelTex, 1, 1, 3, 3);
if (NULL == side) side = NEW JQuad(sideTex, 0, 1, 1, 7);
if (NULL == titleFont)
{
GameApp::CommonRes->LoadJLBFont(titleFontPath, 7);
titleFont = GameApp::CommonRes->GetJLBFont(titleFontPath);
}
if (NULL == stars) stars = NEW hgeParticleSystem("graphics/stars.psi", GameApp::CommonRes->GetQuad("stars"));
stars = NEW hgeParticleSystem("graphics/stars.psi", GameApp::CommonRes->GetQuad("stars"));
stars->MoveTo(mX, mY);
}
inline void SimpleMenu::MogrifyJewel()
{
PIXEL_TYPE tmpBuf[sizeof(jewelGraphics)/sizeof(jewelGraphics[0])];
if (!(random() & 0x7E))
for (int i = sizeof(jewelGraphics) / sizeof(jewelGraphics[0]) - 1; i >= 0; --i)
{
unsigned int v = jewelGraphics[i];
if (v & 0x80) tmpBuf[i] = 0xFF; else tmpBuf[i] = v & 0xFF;
if (v & 0x8000) tmpBuf[i] += 0xFF00; else tmpBuf[i] += (v & 0x7F00) << 1;
if (v & 0x800000) tmpBuf[i] += 0xFF0000; else tmpBuf[i] += (v & 0x7F0000) << 1;
tmpBuf[i] += v & 0xFF000000;
}
else
for (int i = sizeof(jewelGraphics) / sizeof(jewelGraphics[0]) - 1; i >= 0; --i)
tmpBuf[i] = jewelGraphics[i];
jewel->mTex->UpdateBits(1, 1, 3, 3, tmpBuf);
}
void SimpleMenu::drawHorzPole(int x, int y, int width)
{
JRenderer* renderer = JRenderer::GetInstance();
@@ -64,7 +89,9 @@ void SimpleMenu::drawHorzPole(int x, int y, int width)
renderer->RenderQuad(spadeR, x - 9, y - 6);
renderer->RenderQuad(spadeL, x + width - 5, y - 6);
renderer->RenderQuad(jewel, x - 1, y - 1);
MogrifyJewel();
renderer->RenderQuad(jewel, x, y - 1);
renderer->RenderQuad(jewel, x + width - 1, y - 1);
}
void SimpleMenu::drawVertPole(int x, int y, int height)
@@ -77,6 +104,8 @@ void SimpleMenu::drawVertPole(int x, int y, int height)
renderer->RenderQuad(spadeR, x - 6, y + 7, -M_PI/2);
renderer->RenderQuad(spadeL, x - 6, y + height + 11, -M_PI/2);
MogrifyJewel();
renderer->RenderQuad(jewel, x - 1, y - 1);
renderer->RenderQuad(jewel, x - 1, y + height - 1);
}
@@ -89,6 +118,7 @@ void SimpleMenu::Render(){
int width = (static_cast<SimpleMenuItem*>(mObjects[i]))->GetWidth();
if (mWidth < width) mWidth = width;
}
if ((!title.empty()) && (mWidth < titleFont->GetStringWidth(title.c_str()))) mWidth = titleFont->GetStringWidth(title.c_str());
mWidth += 2*HMARGIN;
for (int i = startId; i < startId + mCount; ++i)
static_cast<SimpleMenuItem*>(mObjects[i])->Relocate(mX + mWidth / 2, mY + VMARGIN + i * LINE_HEIGHT);
@@ -108,6 +138,12 @@ void SimpleMenu::Render(){
drawVertPole(mX, mY - 16, height + 32);
drawVertPole(mX + mWidth, mY - 16, height + 32);
drawHorzPole(mX - 16, mY, mWidth + 32);
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_DST_ALPHA);
stars->Render();
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
mFont->SetScale(1.0f);
if (!title.empty())
titleFont->DrawString(title.c_str(), mX+mWidth/2, mY - 3, JGETEXT_CENTER);
for (int i = startId; i < startId + maxItems ; i++){
@@ -115,9 +151,6 @@ void SimpleMenu::Render(){
if ((static_cast<SimpleMenuItem*>(mObjects[i]))->mY - LINE_HEIGHT * startId < mY + height - LINE_HEIGHT + 7)
(static_cast<SimpleMenuItem*>(mObjects[i]))->RenderWithOffset(-LINE_HEIGHT*startId);
}
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_DST_ALPHA);
stars->Render();
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
drawHorzPole(mX - 25, mY + height, mWidth + 50);
}
@@ -140,6 +173,7 @@ void SimpleMenu::Update(float dt){
}
else
{
closed = false;
timeOpen += dt * 10;
}
}
@@ -152,4 +186,5 @@ void SimpleMenu::Add(int id, const char * text){
void SimpleMenu::Close()
{
timeOpen = -1.0;
stars->Stop(true);
}