Commit 75a2d55d authored by nanahira's avatar nanahira

Merge branch 'patch-imagebutton' of github.com:mercury233/ygopro

parents 519a0c54 7eb2e82e
...@@ -97,8 +97,10 @@ void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core:: ...@@ -97,8 +97,10 @@ void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core::
CGUIImageButton::CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle) CGUIImageButton::CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: CGUIButton(environment, parent, id, rectangle) { : CGUIButton(environment, parent, id, rectangle) {
isDrawImage = true; isDrawImage = true;
isFixedSize = false;
imageRotation = 0.0f; imageRotation = 0.0f;
imageScale = core::vector2df(1.0f, 1.0f); imageScale = core::vector2df(1.0f, 1.0f);
imageSize = core::dimension2di(rectangle.getWidth(), rectangle.getHeight());
} }
CGUIImageButton* CGUIImageButton::addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id) { CGUIImageButton* CGUIImageButton::addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id) {
CGUIImageButton* button = new CGUIImageButton(env, parent ? parent : 0, id, rectangle); CGUIImageButton* button = new CGUIImageButton(env, parent ? parent : 0, id, rectangle);
...@@ -129,6 +131,23 @@ void CGUIImageButton::draw() { ...@@ -129,6 +131,23 @@ void CGUIImageButton::draw() {
irr::gui::Draw2DImageRotation(driver, Image, ImageRect, pos, center, imageRotation, imageScale); irr::gui::Draw2DImageRotation(driver, Image, ImageRect, pos, center, imageRotation, imageScale);
IGUIElement::draw(); IGUIElement::draw();
} }
void CGUIImageButton::setImage(video::ITexture* image)
{
if(image)
image->grab();
if(Image)
Image->drop();
Image = image;
if(image) {
ImageRect = core::rect<s32>(core::position2d<s32>(0, 0), image->getOriginalSize());
if(isFixedSize)
imageScale = core::vector2df((irr::f32)imageSize.Width / image->getSize().Width, (irr::f32)imageSize.Height / image->getSize().Height);
}
if(!PressedImage)
setPressedImage(Image);
}
void CGUIImageButton::setDrawImage(bool b) { void CGUIImageButton::setDrawImage(bool b) {
isDrawImage = b; isDrawImage = b;
} }
...@@ -138,6 +157,10 @@ void CGUIImageButton::setImageRotation(f32 r) { ...@@ -138,6 +157,10 @@ void CGUIImageButton::setImageRotation(f32 r) {
void CGUIImageButton::setImageScale(core::vector2df s) { void CGUIImageButton::setImageScale(core::vector2df s) {
imageScale = s; imageScale = s;
} }
void CGUIImageButton::setImageSize(core::dimension2di s) {
isFixedSize = true;
imageSize = s;
}
IGUIFont* CGUIImageButton::getOverrideFont( void ) const IGUIFont* CGUIImageButton::getOverrideFont( void ) const
{ {
......
...@@ -17,16 +17,20 @@ public: ...@@ -17,16 +17,20 @@ public:
CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle); CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle);
static CGUIImageButton* addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id); static CGUIImageButton* addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
virtual void draw(); virtual void draw();
virtual void setImage(video::ITexture* image = 0);
virtual void setDrawImage(bool b); virtual void setDrawImage(bool b);
virtual void setImageRotation(f32 r); virtual void setImageRotation(f32 r);
virtual void setImageScale(core::vector2df s); virtual void setImageScale(core::vector2df s);
virtual void setImageSize(core::dimension2di s);
virtual IGUIFont* getOverrideFont(void) const; virtual IGUIFont* getOverrideFont(void) const;
virtual IGUIFont* getActiveFont() const; virtual IGUIFont* getActiveFont() const;
private: private:
bool isDrawImage; bool isDrawImage;
bool isFixedSize;
f32 imageRotation; f32 imageRotation;
core::vector2df imageScale; core::vector2df imageScale;
core::dimension2di imageSize;
}; };
} }
......
...@@ -449,15 +449,15 @@ bool Game::Initialize() { ...@@ -449,15 +449,15 @@ bool Game::Initialize() {
wPosSelect->getCloseButton()->setVisible(false); wPosSelect->getCloseButton()->setVisible(false);
wPosSelect->setVisible(false); wPosSelect->setVisible(false);
btnPSAU = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(10, 45, 150, 185), wPosSelect, BUTTON_POS_AU); btnPSAU = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(10, 45, 150, 185), wPosSelect, BUTTON_POS_AU);
btnPSAU->setImageScale(core::vector2df(0.5, 0.5)); btnPSAU->setImageSize(core::dimension2di(CARD_IMG_WIDTH * 0.5f, CARD_IMG_HEIGHT * 0.5f));
btnPSAD = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(155, 45, 295, 185), wPosSelect, BUTTON_POS_AD); btnPSAD = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(155, 45, 295, 185), wPosSelect, BUTTON_POS_AD);
btnPSAD->setImageScale(core::vector2df(0.5, 0.5)); btnPSAD->setImageSize(core::dimension2di(CARD_IMG_WIDTH * 0.5f, CARD_IMG_HEIGHT * 0.5f));
btnPSAD->setImage(imageManager.tCover[2]); btnPSAD->setImage(imageManager.tCover[2]);
btnPSDU = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(300, 45, 440, 185), wPosSelect, BUTTON_POS_DU); btnPSDU = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(300, 45, 440, 185), wPosSelect, BUTTON_POS_DU);
btnPSDU->setImageScale(core::vector2df(0.5, 0.5)); btnPSDU->setImageSize(core::dimension2di(CARD_IMG_WIDTH * 0.5f, CARD_IMG_HEIGHT * 0.5f));
btnPSDU->setImageRotation(270); btnPSDU->setImageRotation(270);
btnPSDD = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(445, 45, 585, 185), wPosSelect, BUTTON_POS_DD); btnPSDD = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(445, 45, 585, 185), wPosSelect, BUTTON_POS_DD);
btnPSDD->setImageScale(core::vector2df(0.5, 0.5)); btnPSDD->setImageSize(core::dimension2di(CARD_IMG_WIDTH * 0.5f, CARD_IMG_HEIGHT * 0.5f));
btnPSDD->setImageRotation(270); btnPSDD->setImageRotation(270);
btnPSDD->setImage(imageManager.tCover[2]); btnPSDD->setImage(imageManager.tCover[2]);
//card select //card select
...@@ -469,7 +469,7 @@ bool Game::Initialize() { ...@@ -469,7 +469,7 @@ bool Game::Initialize() {
stCardPos[i]->setBackgroundColor(0xffffffff); stCardPos[i]->setBackgroundColor(0xffffffff);
stCardPos[i]->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); stCardPos[i]->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
btnCardSelect[i] = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(30 + 125 * i, 55, 150 + 125 * i, 225), wCardSelect, BUTTON_CARD_0 + i); btnCardSelect[i] = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(30 + 125 * i, 55, 150 + 125 * i, 225), wCardSelect, BUTTON_CARD_0 + i);
btnCardSelect[i]->setImageScale(core::vector2df(0.6f, 0.6f)); btnCardSelect[i]->setImageSize(core::dimension2di(CARD_IMG_WIDTH * 0.6f, CARD_IMG_HEIGHT * 0.6f));
} }
scrCardList = env->addScrollBar(true, rect<s32>(30, 235, 650, 255), wCardSelect, SCROLL_CARD_SELECT); scrCardList = env->addScrollBar(true, rect<s32>(30, 235, 650, 255), wCardSelect, SCROLL_CARD_SELECT);
btnSelectOK = env->addButton(rect<s32>(300, 265, 380, 290), wCardSelect, BUTTON_CARD_SEL_OK, dataManager.GetSysString(1211)); btnSelectOK = env->addButton(rect<s32>(300, 265, 380, 290), wCardSelect, BUTTON_CARD_SEL_OK, dataManager.GetSysString(1211));
...@@ -482,7 +482,7 @@ bool Game::Initialize() { ...@@ -482,7 +482,7 @@ bool Game::Initialize() {
stDisplayPos[i]->setBackgroundColor(0xffffffff); stDisplayPos[i]->setBackgroundColor(0xffffffff);
stDisplayPos[i]->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); stDisplayPos[i]->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
btnCardDisplay[i] = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(30 + 125 * i, 55, 150 + 125 * i, 225), wCardDisplay, BUTTON_DISPLAY_0 + i); btnCardDisplay[i] = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(30 + 125 * i, 55, 150 + 125 * i, 225), wCardDisplay, BUTTON_DISPLAY_0 + i);
btnCardDisplay[i]->setImageScale(core::vector2df(0.6f, 0.6f)); btnCardDisplay[i]->setImageSize(core::dimension2di(CARD_IMG_WIDTH * 0.6f, CARD_IMG_HEIGHT * 0.6f));
} }
scrDisplayList = env->addScrollBar(true, rect<s32>(30, 235, 650, 255), wCardDisplay, SCROLL_CARD_DISPLAY); scrDisplayList = env->addScrollBar(true, rect<s32>(30, 235, 650, 255), wCardDisplay, SCROLL_CARD_DISPLAY);
btnDisplayOK = env->addButton(rect<s32>(300, 265, 380, 290), wCardDisplay, BUTTON_CARD_DISP_OK, dataManager.GetSysString(1211)); btnDisplayOK = env->addButton(rect<s32>(300, 265, 380, 290), wCardDisplay, BUTTON_CARD_DISP_OK, dataManager.GetSysString(1211));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment