Commit eb429945 authored by nanahira's avatar nanahira

Merge branch 'master' of github.com:Fluorohydride/ygopro into develop

parents f05e22b2 d065fad9
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_GUI_BUTTON_H_INCLUDED__
#define __C_GUI_BUTTON_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUIButton.h"
#include "IGUISpriteBank.h"
#include "SColor.h"
namespace irr
{
namespace gui
{
class CGUIButton : public IGUIButton
{
public:
//! constructor
CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip=false);
//! destructor
virtual ~CGUIButton();
//! called if an event happened.
virtual bool OnEvent(const SEvent& event);
//! draws the element and its children
virtual void draw();
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
virtual void setOverrideFont(IGUIFont* font=0);
//! Gets the override font (if any)
virtual IGUIFont* getOverrideFont() const;
//! Get the font which is used right now for drawing
virtual IGUIFont* getActiveFont() const;
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image=0);
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image=0);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets the sprite bank used by the button
virtual void setSpriteBank(IGUISpriteBank* bank=0);
//! Sets the animated sprite for a specific button state
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\param state: State of the button to set the sprite for
\param index: The sprite number from the current sprite bank
\param color: The color of the sprite
*/
virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color=video::SColor(255,255,255,255), bool loop=false);
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
virtual void setIsPushButton(bool isPushButton=true);
//! Checks whether the button is a push button
virtual bool isPushButton() const;
//! Sets the pressed state of the button if this is a pushbutton
virtual void setPressed(bool pressed=true);
//! Returns if the button is currently pressed
virtual bool isPressed() const;
//! Sets if the button should use the skin to draw its border
virtual void setDrawBorder(bool border=true);
//! Checks if the button face and border are being drawn
virtual bool isDrawingBorder() const;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
virtual void setUseAlphaChannel(bool useAlphaChannel=true);
//! Checks if the alpha channel should be used for drawing images on the button
virtual bool isAlphaChannelUsed() const;
//! Sets if the button should scale the button images to fit
virtual void setScaleImage(bool scaleImage=true);
//! Checks whether the button scales the used images
virtual bool isScalingImage() const;
//! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
//! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
protected:
struct ButtonSprite
{
s32 Index;
video::SColor Color;
bool Loop;
};
ButtonSprite ButtonSprites[EGBS_COUNT];
IGUISpriteBank* SpriteBank;
IGUIFont* OverrideFont;
video::ITexture* Image;
video::ITexture* PressedImage;
core::rect<s32> ImageRect;
core::rect<s32> PressedImageRect;
u32 ClickTime, HoverTime, FocusTime;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
};
} // end namespace gui
} // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_
#endif // __C_GUI_BUTTON_H_INCLUDED__
#ifdef _MSC_VER
#pragma warning(disable: 4244)
#endif
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CGUIImageButton.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include <IGUISpriteBank.h>
#include <IGUISkin.h>
#include <IGUIEnvironment.h>
#include <IVideoDriver.h>
#include <IGUIFont.h>
namespace irr {
namespace gui {
......@@ -94,19 +101,213 @@ void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core::
driver->setTransform(irr::video::ETS_PROJECTION, oldProjMat);
driver->setTransform(irr::video::ETS_VIEW, oldViewMat);
}
CGUIImageButton::CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: CGUIButton(environment, parent, id, rectangle) {
CGUIImageButton* CGUIImageButton::addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id) {
CGUIImageButton* button = new CGUIImageButton(env, parent ? parent : 0, id, rectangle);
button->drop();
return button;
}
//! constructor
CGUIImageButton::CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip)
: IGUIButton(environment, parent, id, rectangle),
SpriteBank(0), OverrideFont(0), Image(0), PressedImage(0),
IsPushButton(false), Pressed(false),
UseAlphaChannel(false), DrawBorder(true), ScaleImage(false) {
#ifdef _DEBUG
setDebugName("CGUIImageButton");
#endif
setNotClipped(noclip);
// Initialize the sprites.
for (u32 i = 0; i < EGBS_COUNT; ++i)
ButtonSprites[i].Index = -1;
// This element can be tabbed.
setTabStop(true);
setTabOrder(-1);
isDrawImage = true;
isFixedSize = false;
imageRotation = 0.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* button = new CGUIImageButton(env, parent ? parent : 0, id, rectangle);
button->drop();
return button;
//! destructor
CGUIImageButton::~CGUIImageButton()
{
if (OverrideFont)
OverrideFont->drop();
if (Image)
Image->drop();
if (PressedImage)
PressedImage->drop();
if (SpriteBank)
SpriteBank->drop();
}
//! Sets if the images should be scaled to fit the button
void CGUIImageButton::setScaleImage(bool scaleImage)
{
ScaleImage = scaleImage;
}
//! Returns whether the button scale the used images
bool CGUIImageButton::isScalingImage() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ScaleImage;
}
//! Sets if the button should use the skin to draw its border
void CGUIImageButton::setDrawBorder(bool border)
{
DrawBorder = border;
}
void CGUIImageButton::setSpriteBank(IGUISpriteBank* sprites)
{
if (sprites)
sprites->grab();
if (SpriteBank)
SpriteBank->drop();
SpriteBank = sprites;
}
void CGUIImageButton::setSprite(EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop)
{
if (SpriteBank)
{
ButtonSprites[(u32)state].Index = index;
ButtonSprites[(u32)state].Color = color;
ButtonSprites[(u32)state].Loop = loop;
}
else
{
ButtonSprites[(u32)state].Index = -1;
}
}
//! called if an event happened.
bool CGUIImageButton::OnEvent(const SEvent& event)
{
if (!isEnabled())
return IGUIElement::OnEvent(event);
switch (event.EventType)
{
case EET_KEY_INPUT_EVENT:
if (event.KeyInput.PressedDown &&
(event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE))
{
if (!IsPushButton)
setPressed(true);
else
setPressed(!Pressed);
return true;
}
if (Pressed && !IsPushButton && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE)
{
setPressed(false);
return true;
}
else
if (!event.KeyInput.PressedDown && Pressed &&
(event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE))
{
if (!IsPushButton)
setPressed(false);
if (Parent)
{
SEvent newEvent;
newEvent.EventType = EET_GUI_EVENT;
newEvent.GUIEvent.Caller = this;
newEvent.GUIEvent.Element = 0;
newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED;
Parent->OnEvent(newEvent);
}
return true;
}
break;
case EET_GUI_EVENT:
if (event.GUIEvent.Caller == this)
{
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
{
if (!IsPushButton)
setPressed(false);
}
}
break;
case EET_MOUSE_INPUT_EVENT:
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
if (Environment->hasFocus(this) &&
!AbsoluteClippingRect.isPointInside(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)))
{
Environment->removeFocus(this);
return false;
}
if (!IsPushButton)
setPressed(true);
Environment->setFocus(this);
return true;
}
else
if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
{
bool wasPressed = Pressed;
if (!AbsoluteClippingRect.isPointInside(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)))
{
if (!IsPushButton)
setPressed(false);
return true;
}
if (!IsPushButton)
setPressed(false);
else
{
setPressed(!Pressed);
}
if ((!IsPushButton && wasPressed && Parent) ||
(IsPushButton && wasPressed != Pressed))
{
SEvent newEvent;
newEvent.EventType = EET_GUI_EVENT;
newEvent.GUIEvent.Caller = this;
newEvent.GUIEvent.Element = 0;
newEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED;
Parent->OnEvent(newEvent);
}
return true;
}
break;
default:
break;
}
return Parent ? Parent->OnEvent(event) : false;
}
void CGUIImageButton::draw() {
if (!IsVisible)
return;
......@@ -148,6 +349,14 @@ void CGUIImageButton::setImage(video::ITexture* image)
if(!PressedImage)
setPressedImage(Image);
}
//! Sets the image which should be displayed on the button when it is in its normal state.
void CGUIImageButton::setImage(video::ITexture* image, const core::rect<s32>& pos)
{
setImage(image);
ImageRect = pos;
}
void CGUIImageButton::setDrawImage(bool b) {
isDrawImage = b;
}
......@@ -162,6 +371,21 @@ void CGUIImageButton::setImageSize(core::dimension2di s) {
imageSize = s;
}
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
void CGUIImageButton::setOverrideFont(IGUIFont* font)
{
if (OverrideFont == font)
return;
if (OverrideFont)
OverrideFont->drop();
OverrideFont = font;
if (OverrideFont)
OverrideFont->grab();
}
IGUIFont* CGUIImageButton::getOverrideFont( void ) const
{
IGUISkin* skin = Environment->getSkin();
......@@ -178,5 +402,137 @@ IGUIFont* CGUIImageButton::getActiveFont() const
return skin->getFont();
}
//! Sets an image which should be displayed on the button when it is in pressed state.
void CGUIImageButton::setPressedImage(video::ITexture* image)
{
if (image)
image->grab();
if (PressedImage)
PressedImage->drop();
PressedImage = image;
if (image)
PressedImageRect = core::rect<s32>(core::position2d<s32>(0, 0), image->getOriginalSize());
}
//! Sets the image which should be displayed on the button when it is in its pressed state.
void CGUIImageButton::setPressedImage(video::ITexture* image, const core::rect<s32>& pos)
{
setPressedImage(image);
PressedImageRect = pos;
}
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
void CGUIImageButton::setIsPushButton(bool isPushButton)
{
IsPushButton = isPushButton;
}
//! Returns if the button is currently pressed
bool CGUIImageButton::isPressed() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return Pressed;
}
//! Sets the pressed state of the button if this is a pushbutton
void CGUIImageButton::setPressed(bool pressed)
{
if (Pressed != pressed)
{
Pressed = pressed;
}
}
//! Returns whether the button is a push button
bool CGUIImageButton::isPushButton() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return IsPushButton;
}
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
void CGUIImageButton::setUseAlphaChannel(bool useAlphaChannel)
{
UseAlphaChannel = useAlphaChannel;
}
//! Returns if the alpha channel should be used for drawing images on the button
bool CGUIImageButton::isAlphaChannelUsed() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return UseAlphaChannel;
}
bool CGUIImageButton::isDrawingBorder() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return DrawBorder;
}
//! Writes attributes of the element.
void CGUIImageButton::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options = 0) const
{
IGUIButton::serializeAttributes(out, options);
out->addBool("PushButton", IsPushButton);
if (IsPushButton)
out->addBool("Pressed", Pressed);
out->addTexture("Image", Image);
out->addRect("ImageRect", ImageRect);
out->addTexture("PressedImage", PressedImage);
out->addRect("PressedImageRect", PressedImageRect);
out->addBool("UseAlphaChannel", isAlphaChannelUsed());
out->addBool("Border", isDrawingBorder());
out->addBool("ScaleImage", isScalingImage());
// out->addString ("OverrideFont", OverrideFont);
}
//! Reads attributes of the element
void CGUIImageButton::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options = 0)
{
IGUIButton::deserializeAttributes(in, options);
IsPushButton = in->getAttributeAsBool("PushButton");
Pressed = IsPushButton ? in->getAttributeAsBool("Pressed") : false;
core::rect<s32> rec = in->getAttributeAsRect("ImageRect");
if (rec.isValid())
setImage(in->getAttributeAsTexture("Image"), rec);
else
setImage(in->getAttributeAsTexture("Image"));
rec = in->getAttributeAsRect("PressedImageRect");
if (rec.isValid())
setPressedImage(in->getAttributeAsTexture("PressedImage"), rec);
else
setPressedImage(in->getAttributeAsTexture("PressedImage"));
setDrawBorder(in->getAttributeAsBool("Border"));
setUseAlphaChannel(in->getAttributeAsBool("UseAlphaChannel"));
setScaleImage(in->getAttributeAsBool("ScaleImage"));
// setOverrideFont(in->getAttributeAsString("OverrideFont"));
updateAbsolutePosition();
}
} // end namespace gui
} // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_GUI_IMAGE_BUTTON_H_
#define _C_GUI_IMAGE_BUTTON_H_
#include <irrlicht.h>
#include "CGUIButton.h"
#include <IrrCompileConfig.h>
#ifdef _IRR_COMPILE_WITH_GUI_
#include <IGUIButton.h>
#include <SColor.h>
namespace irr {
namespace video {
class IVideoDriver;
class ITexture;
}
namespace gui {
class IGUISpriteBank;
void Draw2DImageRotation(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> position, core::position2d<s32> rotationPoint, f32 rotation = 0.0f,
core::vector2df scale = core::vector2df(1.0, 1.0), bool useAlphaChannel = true, video::SColor color = 0xffffffff);
void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> corner[4], bool useAlphaChannel = true, video::SColor color = 0xffffffff);
class CGUIImageButton : public CGUIButton {
class CGUIImageButton : public IGUIButton {
public:
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);
virtual void draw();
virtual void setImage(video::ITexture* image = 0);
virtual void setDrawImage(bool b);
virtual void setImageRotation(f32 r);
virtual void setImageScale(core::vector2df s);
virtual void setImageSize(core::dimension2di s);
virtual IGUIFont* getOverrideFont(void) const;
virtual IGUIFont* getActiveFont() const;
private:
static CGUIImageButton* addImageButton(IGUIEnvironment* env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
//! constructor
CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip = false);
//! destructor
~CGUIImageButton() override;
//! called if an event happened.
bool OnEvent(const SEvent& event) override;
//! draws the element and its children
void draw() override;
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
void setOverrideFont(IGUIFont* font = 0) override;
//! Gets the override font (if any)
IGUIFont* getOverrideFont() const override;
//! Get the font which is used right now for drawing
IGUIFont* getActiveFont() const override;
//! Sets an image which should be displayed on the button when it is in normal state.
void setImage(video::ITexture* image = 0) override;
//! Sets an image which should be displayed on the button when it is in normal state.
void setImage(video::ITexture* image, const core::rect<s32>& pos) override;
//! Sets an image which should be displayed on the button when it is in pressed state.
void setPressedImage(video::ITexture* image = 0) override;
//! Sets an image which should be displayed on the button when it is in pressed state.
void setPressedImage(video::ITexture* image, const core::rect<s32>& pos) override;
//! Sets the sprite bank used by the button
void setSpriteBank(IGUISpriteBank* bank = 0) override;
//! Sets the animated sprite for a specific button state
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\param state: State of the button to set the sprite for
\param index: The sprite number from the current sprite bank
\param color: The color of the sprite
*/
void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color = video::SColor(255, 255, 255, 255), bool loop = false) override;
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
void setIsPushButton(bool isPushButton = true) override;
//! Checks whether the button is a push button
bool isPushButton() const override;
//! Sets the pressed state of the button if this is a pushbutton
void setPressed(bool pressed = true) override;
//! Returns if the button is currently pressed
bool isPressed() const override;
//! Sets if the button should use the skin to draw its border
void setDrawBorder(bool border = true) override;
//! Checks if the button face and border are being drawn
bool isDrawingBorder() const override;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
void setUseAlphaChannel(bool useAlphaChannel = true) override;
//! Checks if the alpha channel should be used for drawing images on the button
bool isAlphaChannelUsed() const override;
//! Sets if the button should scale the button images to fit
void setScaleImage(bool scaleImage = true) override;
//! Checks whether the button scales the used images
bool isScalingImage() const override;
//! Writes attributes of the element.
void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const override;
//! Reads attributes of the element
void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) override;
// from ygopro
void setDrawImage(bool b);
void setImageRotation(f32 r);
void setImageScale(core::vector2df s);
void setImageSize(core::dimension2di s);
protected:
struct ButtonSprite
{
s32 Index;
video::SColor Color;
bool Loop;
};
ButtonSprite ButtonSprites[EGBS_COUNT];
IGUISpriteBank* SpriteBank;
IGUIFont* OverrideFont;
video::ITexture* Image;
video::ITexture* PressedImage;
core::rect<s32> ImageRect;
core::rect<s32> PressedImageRect;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
// from ygopro
bool isDrawImage;
bool isFixedSize;
f32 imageRotation;
......@@ -36,4 +155,6 @@ private:
}
}
#endif // _IRR_COMPILE_WITH_GUI_
#endif //_C_GUI_IMAGE_BUTTON_H_
......@@ -50,7 +50,7 @@ inline int _wtoi(const wchar_t * str){
}
#endif
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
......@@ -63,7 +63,7 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
return std::swprintf(buf, N, fmt, args...);
}
inline FILE* myfopen(const wchar_t* filename, const char* mode) {
inline FILE* mywfopen(const wchar_t* filename, const char* mode) {
FILE* fp{};
#ifdef _WIN32
wchar_t wmode[20]{};
......@@ -72,7 +72,7 @@ inline FILE* myfopen(const wchar_t* filename, const char* mode) {
#else
char fname[1024]{};
BufferIO::EncodeUTF8(filename, fname);
fp = fopen(fname, mode);
fp = std::fopen(fname, mode);
#endif
return fp;
}
......
#include "data_manager.h"
#include "game.h"
#include <stdio.h>
#include "spmemvfs/spmemvfs.h"
namespace ygo {
......@@ -109,14 +108,14 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
return ret;
}
bool DataManager::LoadStrings(const char* file) {
FILE* fp = fopen(file, "r");
FILE* fp = std::fopen(file, "r");
if(!fp)
return false;
char linebuf[TEXT_LINE_SIZE]{};
while(fgets(linebuf, sizeof linebuf, fp)) {
while(std::fgets(linebuf, sizeof linebuf, fp)) {
ReadStringConfLine(linebuf);
}
fclose(fp);
std::fclose(fp);
return true;
}
bool DataManager::LoadStrings(irr::io::IReadFile* reader) {
......@@ -140,26 +139,26 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
char strbuf[TEXT_LINE_SIZE]{};
int value{};
wchar_t strBuffer[4096]{};
if (sscanf(linebuf, "!%63s", strbuf) != 1)
if (std::sscanf(linebuf, "!%63s", strbuf) != 1)
return;
if(!std::strcmp(strbuf, "system")) {
if (sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "victory")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "counter")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "setname")) {
//using tab for comment
if (sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer;
......@@ -414,7 +413,7 @@ unsigned char* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
}
unsigned char* DataManager::ScriptReaderExSingle(const char* path, const char* script_name, int* slen, int pre_len, unsigned int use_irr) {
char sname[256];
snprintf(sname, sizeof sname, "%s%s", path, script_name + pre_len); //default script name: ./script/c%d.lua
std::snprintf(sname, sizeof sname, "%s%s", path, script_name + pre_len); //default script name: ./script/c%d.lua
if (use_irr) {
return ReadScriptFromIrrFS(sname, slen);
}
......@@ -438,9 +437,7 @@ unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* sl
return scriptBuffer;
}
unsigned char* DataManager::ReadScriptFromFile(const char* script_name, int* slen) {
wchar_t fname[256]{};
BufferIO::DecodeUTF8(script_name, fname);
FILE* fp = myfopen(fname, "rb");
FILE* fp = std::fopen(script_name, "rb");
if (!fp)
return nullptr;
size_t len = std::fread(scriptBuffer, 1, sizeof scriptBuffer, fp);
......
#include "deck_manager.h"
#include "game.h"
#include "myfilesystem.h"
#include "network.h"
#include "game.h"
#include "base64.h"
namespace ygo {
......@@ -11,30 +11,27 @@ DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) {
auto cur = _lfList.rend();
FILE* fp = fopen(path, "r");
FILE* fp = std::fopen(path, "r");
char linebuf[256]{};
wchar_t strBuffer[256]{};
if(fp) {
while(fgets(linebuf, 256, fp)) {
while(std::fgets(linebuf, 256, fp)) {
if(linebuf[0] == '#')
continue;
if(linebuf[0] == '!') {
int sa = BufferIO::DecodeUTF8(&linebuf[1], strBuffer);
while(strBuffer[sa - 1] == L'\r' || strBuffer[sa - 1] == L'\n' )
sa--;
strBuffer[sa] = 0;
auto len = std::strcspn(linebuf, "\r\n");
linebuf[len] = 0;
BufferIO::DecodeUTF8(&linebuf[1], strBuffer);
LFList newlist;
newlist.listName = strBuffer;
newlist.hash = 0x7dfcee6a;
_lfList.push_back(newlist);
cur = _lfList.rbegin();
cur->listName = strBuffer;
cur->hash = 0x7dfcee6a;
continue;
}
if(linebuf[0] == 0)
continue;
int code = 0;
int count = -1;
if (sscanf(linebuf, "%d %d", &code, &count) != 2)
if (std::sscanf(linebuf, "%d %d", &code, &count) != 2)
continue;
if (code <= 0 || code > MAX_CARD_ID)
continue;
......@@ -46,7 +43,7 @@ void DeckManager::LoadLFListSingle(const char* path) {
cur->content[code] = count;
cur->hash = cur->hash ^ ((hcode << 18) | (hcode >> 14)) ^ ((hcode << (27 + count)) | (hcode >> (5 - count)));
}
fclose(fp);
std::fclose(fp);
}
}
void DeckManager::LoadLFList() {
......@@ -273,16 +270,16 @@ void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory,
}
}
FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
FILE* fp = myfopen(file, mode);
FILE* fp = mywfopen(file, mode);
return fp;
}
IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) {
irr::io::IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) {
#ifdef _WIN32
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(file);
auto reader = DataManager::FileSystem->createAndOpenFile(file);
#else
char file2[256];
BufferIO::EncodeUTF8(file, file2);
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(file2);
auto reader = DataManager::FileSystem->createAndOpenFile(file2);
#endif
return reader;
}
......@@ -326,16 +323,16 @@ bool DeckManager::SaveDeck(Deck& deck, const wchar_t* file) {
FILE* fp = OpenDeckFile(file, "w");
if(!fp)
return false;
fprintf(fp, "#created by ...\n#main\n");
std::fprintf(fp, "#created by ...\n#main\n");
for(size_t i = 0; i < deck.main.size(); ++i)
fprintf(fp, "%d\n", deck.main[i]->first);
fprintf(fp, "#extra\n");
std::fprintf(fp, "%d\n", deck.main[i]->first);
std::fprintf(fp, "#extra\n");
for(size_t i = 0; i < deck.extra.size(); ++i)
fprintf(fp, "%d\n", deck.extra[i]->first);
fprintf(fp, "!side\n");
std::fprintf(fp, "%d\n", deck.extra[i]->first);
std::fprintf(fp, "!side\n");
for(size_t i = 0; i < deck.side.size(); ++i)
fprintf(fp, "%d\n", deck.side[i]->first);
fclose(fp);
std::fprintf(fp, "%d\n", deck.side[i]->first);
std::fclose(fp);
return true;
}
bool DeckManager::DeleteDeck(const wchar_t* file) {
......@@ -419,26 +416,26 @@ bool DeckManager::SaveDeckBuffer(const int deckbuf[], const wchar_t* name) {
int it = 0;
const int mainc = deckbuf[it];
++it;
fprintf(fp, "#created by ...\n#main\n");
std::fprintf(fp, "#created by ...\n#main\n");
for (int i = 0; i < mainc; ++i) {
fprintf(fp, "%d\n", deckbuf[it]);
std::fprintf(fp, "%d\n", deckbuf[it]);
++it;
}
const int extrac = deckbuf[it];
++it;
fprintf(fp, "#extra\n");
std::fprintf(fp, "#extra\n");
for (int i = 0; i < extrac; ++i) {
fprintf(fp, "%d\n", deckbuf[it]);
std::fprintf(fp, "%d\n", deckbuf[it]);
++it;
}
const int sidec = deckbuf[it];
++it;
fprintf(fp, "!side\n");
std::fprintf(fp, "!side\n");
for (int i = 0; i < sidec; ++i) {
fprintf(fp, "%d\n", deckbuf[it]);
std::fprintf(fp, "%d\n", deckbuf[it]);
++it;
}
fclose(fp);
std::fclose(fp);
return true;
}
}
......@@ -70,7 +70,7 @@ public:
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
FILE* OpenDeckFile(const wchar_t* file, const char* mode);
IReadFile* OpenDeckReader(const wchar_t* file);
irr::io::IReadFile* OpenDeckReader(const wchar_t* file);
bool LoadCurrentDeck(const wchar_t* file, bool is_packlist = false);
bool LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool SaveDeck(Deck& deck, const wchar_t* file);
......
......@@ -1399,34 +1399,34 @@ void Game::RefreshBot() {
if(!gameConf.enable_bot_mode)
return;
botInfo.clear();
FILE* fp = fopen(GetLocaleDir("bot.conf"), "r");
FILE* fp = std::fopen(GetLocaleDir("bot.conf"), "r");
if(!fp)
fp = fopen("bot.conf", "r");
fp = std::fopen("bot.conf", "r");
char linebuf[256]{};
char strbuf[256]{};
if(fp) {
while(fgets(linebuf, 256, fp)) {
while(std::fgets(linebuf, 256, fp)) {
if(linebuf[0] == '#')
continue;
if(linebuf[0] == '!') {
BotInfo newinfo;
if (sscanf(linebuf, "!%240[^\n]", strbuf) != 1)
if (std::sscanf(linebuf, "!%240[^\n]", strbuf) != 1)
continue;
BufferIO::DecodeUTF8(strbuf, newinfo.name);
if (!fgets(linebuf, 256, fp))
if (!std::fgets(linebuf, 256, fp))
break;
if (sscanf(linebuf, "%240[^\n]", strbuf) != 1)
if (std::sscanf(linebuf, "%240[^\n]", strbuf) != 1)
continue;
#ifndef _WIN32
bool skipRandom = !!strstr(strbuf, "Random=");
#endif
BufferIO::DecodeUTF8(strbuf, newinfo.command);
if (!fgets(linebuf, 256, fp))
if (!std::fgets(linebuf, 256, fp))
break;
if (sscanf(linebuf, "%240[^\n]", strbuf) != 1)
if (std::sscanf(linebuf, "%240[^\n]", strbuf) != 1)
continue;
BufferIO::DecodeUTF8(strbuf, newinfo.desc);
if (!fgets(linebuf, 256, fp))
if (!std::fgets(linebuf, 256, fp))
break;
#ifndef _WIN32
if(skipRandom) {
......@@ -1445,7 +1445,7 @@ void Game::RefreshBot() {
continue;
}
}
fclose(fp);
std::fclose(fp);
}
lstBotList->clear();
stBotInfo->setText(L"");
......@@ -1462,15 +1462,15 @@ void Game::RefreshBot() {
}
}
bool Game::LoadConfigFromFile(const char* file) {
FILE* fp = fopen(file, "r");
FILE* fp = std::fopen(file, "r");
if(!fp){
return false;
}
char linebuf[CONFIG_LINE_SIZE]{};
char strbuf[64]{};
char valbuf[960]{};
while(fgets(linebuf, sizeof linebuf, fp)) {
if (sscanf(linebuf, "%63s = %959s", strbuf, valbuf) != 2)
while(std::fgets(linebuf, sizeof linebuf, fp)) {
if (std::sscanf(linebuf, "%63s = %959s", strbuf, valbuf) != 2)
continue;
if(!std::strcmp(strbuf, "antialias")) {
gameConf.antialias = strtol(valbuf, nullptr, 10);
......@@ -1485,7 +1485,7 @@ bool Game::LoadConfigFromFile(const char* file) {
enable_log = val & 0xff;
} else if(!std::strcmp(strbuf, "textfont")) {
int textfontsize = 0;
if (sscanf(linebuf, "%63s = %959s %d", strbuf, valbuf, &textfontsize) != 3)
if (std::sscanf(linebuf, "%63s = %959s %d", strbuf, valbuf, &textfontsize) != 3)
continue;
gameConf.textfontsize = textfontsize;
BufferIO::DecodeUTF8(valbuf, gameConf.textfont);
......@@ -1591,7 +1591,7 @@ bool Game::LoadConfigFromFile(const char* file) {
gameConf.skin_index = atoi(valbuf);
} else {
// options allowing multiple words
if (sscanf(linebuf, "%63s = %959[^\n]", strbuf, valbuf) != 2)
if (std::sscanf(linebuf, "%63s = %959[^\n]", strbuf, valbuf) != 2)
continue;
if (!std::strcmp(strbuf, "nickname")) {
BufferIO::DecodeUTF8(valbuf, gameConf.nickname);
......@@ -1735,90 +1735,90 @@ void Game::LoadConfig() {
}
void Game::SaveConfig() {
#ifdef YGOPRO_COMPAT_MYCARD
FILE* fp = fopen("system.conf", "w");
FILE* fp = std::fopen("system.conf", "w");
#else
FILE* fp = fopen("system_user.conf", "w");
FILE* fp = std::fopen("system_user.conf", "w");
#endif //YGOPRO_COMPAT_MYCARD
fprintf(fp, "#config file\n#nickname & gamename should be less than 20 characters\n");
std::fprintf(fp, "#config file\n#nickname & gamename should be less than 20 characters\n");
char linebuf[CONFIG_LINE_SIZE];
fprintf(fp, "use_d3d = %d\n", gameConf.use_d3d ? 1 : 0);
fprintf(fp, "use_image_scale = %d\n", gameConf.use_image_scale ? 1 : 0);
fprintf(fp, "pro_version = %d\n", PRO_VERSION);
fprintf(fp, "antialias = %d\n", gameConf.antialias);
fprintf(fp, "errorlog = %u\n", enable_log);
std::fprintf(fp, "use_d3d = %d\n", gameConf.use_d3d ? 1 : 0);
std::fprintf(fp, "use_image_scale = %d\n", gameConf.use_image_scale ? 1 : 0);
std::fprintf(fp, "pro_version = %d\n", PRO_VERSION);
std::fprintf(fp, "antialias = %d\n", gameConf.antialias);
std::fprintf(fp, "errorlog = %u\n", enable_log);
BufferIO::CopyWideString(ebNickName->getText(), gameConf.nickname);
BufferIO::EncodeUTF8(gameConf.nickname, linebuf);
fprintf(fp, "nickname = %s\n", linebuf);
std::fprintf(fp, "nickname = %s\n", linebuf);
BufferIO::EncodeUTF8(gameConf.gamename, linebuf);
fprintf(fp, "gamename = %s\n", linebuf);
std::fprintf(fp, "gamename = %s\n", linebuf);
BufferIO::EncodeUTF8(gameConf.lastcategory, linebuf);
fprintf(fp, "lastcategory = %s\n", linebuf);
std::fprintf(fp, "lastcategory = %s\n", linebuf);
BufferIO::EncodeUTF8(gameConf.lastdeck, linebuf);
fprintf(fp, "lastdeck = %s\n", linebuf);
std::fprintf(fp, "lastdeck = %s\n", linebuf);
BufferIO::EncodeUTF8(gameConf.textfont, linebuf);
fprintf(fp, "textfont = %s %d\n", linebuf, gameConf.textfontsize);
std::fprintf(fp, "textfont = %s %d\n", linebuf, gameConf.textfontsize);
BufferIO::EncodeUTF8(gameConf.numfont, linebuf);
fprintf(fp, "numfont = %s\n", linebuf);
fprintf(fp, "serverport = %d\n", gameConf.serverport);
std::fprintf(fp, "numfont = %s\n", linebuf);
std::fprintf(fp, "serverport = %d\n", gameConf.serverport);
BufferIO::EncodeUTF8(gameConf.lasthost, linebuf);
fprintf(fp, "lasthost = %s\n", linebuf);
std::fprintf(fp, "lasthost = %s\n", linebuf);
BufferIO::EncodeUTF8(gameConf.lastport, linebuf);
fprintf(fp, "lastport = %s\n", linebuf);
std::fprintf(fp, "lastport = %s\n", linebuf);
BufferIO::EncodeUTF8(gameConf.roompass, linebuf);
fprintf(fp, "roompass = %s\n", linebuf);
std::fprintf(fp, "roompass = %s\n", linebuf);
//settings
fprintf(fp, "automonsterpos = %d\n", (chkMAutoPos->isChecked() ? 1 : 0));
fprintf(fp, "autospellpos = %d\n", (chkSTAutoPos->isChecked() ? 1 : 0));
fprintf(fp, "randompos = %d\n", (chkRandomPos->isChecked() ? 1 : 0));
fprintf(fp, "autochain = %d\n", (chkAutoChain->isChecked() ? 1 : 0));
fprintf(fp, "waitchain = %d\n", (chkWaitChain->isChecked() ? 1 : 0));
fprintf(fp, "showchain = %d\n", (chkDefaultShowChain->isChecked() ? 1 : 0));
fprintf(fp, "mute_opponent = %d\n", (chkIgnore1->isChecked() ? 1 : 0));
fprintf(fp, "mute_spectators = %d\n", (chkIgnore2->isChecked() ? 1 : 0));
fprintf(fp, "use_lflist = %d\n", gameConf.use_lflist);
fprintf(fp, "default_lflist = %d\n", gameConf.default_lflist);
fprintf(fp, "default_rule = %d\n", gameConf.default_rule == YGOPRO_DEFAULT_DUEL_RULE ? 0 : gameConf.default_rule);
fprintf(fp, "hide_setname = %d\n", gameConf.hide_setname);
fprintf(fp, "hide_hint_button = %d\n", gameConf.hide_hint_button);
fprintf(fp, "#control_mode = 0: Key A/S/D/R Chain Buttons. control_mode = 1: MouseLeft/MouseRight/NULL/F9 Without Chain Buttons\n");
fprintf(fp, "control_mode = %d\n", gameConf.control_mode);
fprintf(fp, "draw_field_spell = %d\n", gameConf.draw_field_spell);
fprintf(fp, "separate_clear_button = %d\n", gameConf.separate_clear_button);
fprintf(fp, "#auto_search_limit >= 0: Start search automatically when the user enters N chars\n");
fprintf(fp, "auto_search_limit = %d\n", gameConf.auto_search_limit);
fprintf(fp, "#search_multiple_keywords = 0: Disable. 1: Search mutiple keywords with separator \" \". 2: with separator \"+\"\n");
fprintf(fp, "search_multiple_keywords = %d\n", gameConf.search_multiple_keywords);
fprintf(fp, "search_regex = %d\n", gameConf.search_regex);
fprintf(fp, "ignore_deck_changes = %d\n", (chkIgnoreDeckChanges->isChecked() ? 1 : 0));
fprintf(fp, "default_ot = %d\n", gameConf.defaultOT);
fprintf(fp, "enable_bot_mode = %d\n", gameConf.enable_bot_mode);
std::fprintf(fp, "automonsterpos = %d\n", (chkMAutoPos->isChecked() ? 1 : 0));
std::fprintf(fp, "autospellpos = %d\n", (chkSTAutoPos->isChecked() ? 1 : 0));
std::fprintf(fp, "randompos = %d\n", (chkRandomPos->isChecked() ? 1 : 0));
std::fprintf(fp, "autochain = %d\n", (chkAutoChain->isChecked() ? 1 : 0));
std::fprintf(fp, "waitchain = %d\n", (chkWaitChain->isChecked() ? 1 : 0));
std::fprintf(fp, "showchain = %d\n", (chkDefaultShowChain->isChecked() ? 1 : 0));
std::fprintf(fp, "mute_opponent = %d\n", (chkIgnore1->isChecked() ? 1 : 0));
std::fprintf(fp, "mute_spectators = %d\n", (chkIgnore2->isChecked() ? 1 : 0));
std::fprintf(fp, "use_lflist = %d\n", gameConf.use_lflist);
std::fprintf(fp, "default_lflist = %d\n", gameConf.default_lflist);
std::fprintf(fp, "default_rule = %d\n", gameConf.default_rule == YGOPRO_DEFAULT_DUEL_RULE ? 0 : gameConf.default_rule);
std::fprintf(fp, "hide_setname = %d\n", gameConf.hide_setname);
std::fprintf(fp, "hide_hint_button = %d\n", gameConf.hide_hint_button);
std::fprintf(fp, "#control_mode = 0: Key A/S/D/R Chain Buttons. control_mode = 1: MouseLeft/MouseRight/NULL/F9 Without Chain Buttons\n");
std::fprintf(fp, "control_mode = %d\n", gameConf.control_mode);
std::fprintf(fp, "draw_field_spell = %d\n", gameConf.draw_field_spell);
std::fprintf(fp, "separate_clear_button = %d\n", gameConf.separate_clear_button);
std::fprintf(fp, "#auto_search_limit >= 0: Start search automatically when the user enters N chars\n");
std::fprintf(fp, "auto_search_limit = %d\n", gameConf.auto_search_limit);
std::fprintf(fp, "#search_multiple_keywords = 0: Disable. 1: Search mutiple keywords with separator \" \". 2: with separator \"+\"\n");
std::fprintf(fp, "search_multiple_keywords = %d\n", gameConf.search_multiple_keywords);
std::fprintf(fp, "search_regex = %d\n", gameConf.search_regex);
std::fprintf(fp, "ignore_deck_changes = %d\n", (chkIgnoreDeckChanges->isChecked() ? 1 : 0));
std::fprintf(fp, "default_ot = %d\n", gameConf.defaultOT);
std::fprintf(fp, "enable_bot_mode = %d\n", gameConf.enable_bot_mode);
BufferIO::EncodeUTF8(gameConf.bot_deck_path, linebuf);
fprintf(fp, "bot_deck_path = %s\n", linebuf);
fprintf(fp, "quick_animation = %d\n", gameConf.quick_animation);
fprintf(fp, "auto_save_replay = %d\n", (chkAutoSaveReplay->isChecked() ? 1 : 0));
fprintf(fp, "draw_single_chain = %d\n", gameConf.draw_single_chain);
fprintf(fp, "hide_player_name = %d\n", gameConf.hide_player_name);
fprintf(fp, "prefer_expansion_script = %d\n", gameConf.prefer_expansion_script);
fprintf(fp, "ask_mset = %d\n", gameConf.ask_mset);
fprintf(fp, "window_maximized = %d\n", (gameConf.window_maximized ? 1 : 0));
fprintf(fp, "window_width = %d\n", gameConf.window_width);
fprintf(fp, "window_height = %d\n", gameConf.window_height);
fprintf(fp, "resize_popup_menu = %d\n", gameConf.resize_popup_menu ? 1 : 0);
std::fprintf(fp, "bot_deck_path = %s\n", linebuf);
std::fprintf(fp, "quick_animation = %d\n", gameConf.quick_animation);
std::fprintf(fp, "auto_save_replay = %d\n", (chkAutoSaveReplay->isChecked() ? 1 : 0));
std::fprintf(fp, "draw_single_chain = %d\n", gameConf.draw_single_chain);
std::fprintf(fp, "hide_player_name = %d\n", gameConf.hide_player_name);
std::fprintf(fp, "prefer_expansion_script = %d\n", gameConf.prefer_expansion_script);
std::fprintf(fp, "ask_mset = %d\n", gameConf.ask_mset);
std::fprintf(fp, "window_maximized = %d\n", (gameConf.window_maximized ? 1 : 0));
std::fprintf(fp, "window_width = %d\n", gameConf.window_width);
std::fprintf(fp, "window_height = %d\n", gameConf.window_height);
std::fprintf(fp, "resize_popup_menu = %d\n", gameConf.resize_popup_menu ? 1 : 0);
#ifdef YGOPRO_USE_AUDIO
fprintf(fp, "enable_sound = %d\n", (chkEnableSound->isChecked() ? 1 : 0));
fprintf(fp, "enable_music = %d\n", (chkEnableMusic->isChecked() ? 1 : 0));
fprintf(fp, "#Volume of sound and music, between 0 and 100\n");
std::fprintf(fp, "enable_sound = %d\n", (chkEnableSound->isChecked() ? 1 : 0));
std::fprintf(fp, "enable_music = %d\n", (chkEnableMusic->isChecked() ? 1 : 0));
std::fprintf(fp, "#Volume of sound and music, between 0 and 100\n");
int vol = gameConf.sound_volume * 100;
fprintf(fp, "sound_volume = %d\n", vol);
std::fprintf(fp, "sound_volume = %d\n", vol);
vol = gameConf.music_volume * 100;
fprintf(fp, "music_volume = %d\n", vol);
fprintf(fp, "music_mode = %d\n", (chkMusicMode->isChecked() ? 1 : 0));
std::fprintf(fp, "music_volume = %d\n", vol);
std::fprintf(fp, "music_mode = %d\n", (chkMusicMode->isChecked() ? 1 : 0));
#endif
fprintf(fp, "enable_pendulum_scale = %d\n", ((mainGame->chkEnablePScale->isChecked()) ? 1 : 0));
fprintf(fp, "skin_index = %d\n", gameConf.skin_index);
std::fprintf(fp, "enable_pendulum_scale = %d\n", ((mainGame->chkEnablePScale->isChecked()) ? 1 : 0));
std::fprintf(fp, "skin_index = %d\n", gameConf.skin_index);
BufferIO::EncodeUTF8(gameConf.locale, linebuf);
fprintf(fp, "locale = %s\n", linebuf);
fclose(fp);
std::fprintf(fp, "locale = %s\n", linebuf);
std::fclose(fp);
}
void Game::ShowCardInfo(int code, bool resize) {
if(showingcode == code && !resize)
......@@ -1998,19 +1998,19 @@ void Game::AddDebugMsg(const char* msg) {
}
if (enable_log & 0x2) {
char msgbuf[1040];
snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", msg);
std::snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", msg);
ErrorLog(msgbuf);
}
}
void Game::ErrorLog(const char* msg) {
FILE* fp = fopen("error.log", "at");
FILE* fp = std::fopen("error.log", "at");
if(!fp)
return;
time_t nowtime = std::time(nullptr);
char timebuf[40];
std::strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M:%S", std::localtime(&nowtime));
fprintf(fp, "[%s]%s\n", timebuf, msg);
fclose(fp);
std::fprintf(fp, "[%s]%s\n", timebuf, msg);
std::fclose(fp);
}
void Game::initUtils() {
//user files
......@@ -2494,7 +2494,7 @@ void Game::takeScreenshot() {
irr::video::IImage* const image = driver->createScreenShot();
if(image) {
irr::c8 filename[64];
snprintf(filename, 64, "screenshots/ygopro_%u.png", device->getTimer()->getRealTime());
std::snprintf(filename, 64, "screenshots/ygopro_%u.png", device->getTimer()->getRealTime());
if (!driver->writeImageToFile(image, filename))
device->getLogger()->log(L"Failed to take screenshot.", irr::ELL_WARNING);
image->drop();
......
......@@ -56,11 +56,11 @@ bool ImageManager::Initial() {
tFieldTransparent[1] = driver->getTexture("textures/field-transparent3.png");
char buff[100];
for (int i = 0; i < 14; i++) {
snprintf(buff, 100, "textures/pscale/rscale_%d.png", i);
std::snprintf(buff, 100, "textures/pscale/rscale_%d.png", i);
tRScale[i] = driver->getTexture(buff);
}
for (int i = 0; i < 14; i++) {
snprintf(buff, 100, "textures/pscale/lscale_%d.png", i);
std::snprintf(buff, 100, "textures/pscale/lscale_%d.png", i);
tLScale[i] = driver->getTexture(buff);
}
tClock = driver->getTexture("textures/clock.png");
......@@ -327,26 +327,26 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) {
char file[256];
snprintf(file, sizeof file, "expansions/pics/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.png"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.png"), code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.jpg"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.jpg"), code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.png", code);
std::snprintf(file, sizeof file, "pics/%d.png", code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr && !mainGame->gameConf.use_image_scale) {
......@@ -370,10 +370,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
}
irr::video::ITexture* texture;
char file[256];
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file);
}
if(srcimg == nullptr) {
......@@ -399,49 +399,49 @@ int ImageManager::LoadThumbThread() {
imageManager.tThumbLoadingCodes.pop();
imageManager.tThumbLoadingMutex.unlock();
char file[256];
snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.png", code);
irr::video::IImage* img = imageManager.driver->createImageFromFile(file);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/thumbnail/%d.png"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/thumbnail/%d.png"), code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/thumbnail/%d.jpg"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/thumbnail/%d.jpg"), code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/thumbnail/%d.png", code);
std::snprintf(file, sizeof file, "pics/thumbnail/%d.png", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr && mainGame->gameConf.use_image_scale) {
snprintf(file, sizeof file, "expansions/pics/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.png", code);
img = imageManager.driver->createImageFromFile(file);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.png"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.png"), code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.jpg"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.jpg"), code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.png", code);
std::snprintf(file, sizeof file, "pics/%d.png", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
}
......@@ -487,7 +487,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(lit != tThumbLoading.end()) {
if(lit->second != nullptr) {
char file[256];
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL
lit->second->drop();
tThumb[code] = texture;
......@@ -517,26 +517,26 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
auto tit = tFields.find(code);
if(tit == tFields.end()) {
char file[256];
snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.png"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.png"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.png", code);
std::snprintf(file, sizeof file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) {
tFields[code] = nullptr;
......@@ -561,26 +561,26 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code);
if(tit == tFields.end()) {
char file[256];
snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.png"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.png"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.png", code);
std::snprintf(file, sizeof file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) {
tFields[code] = nullptr;
......
......@@ -382,9 +382,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int flag = 0;
flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0);
char arg2[8];
snprintf(arg2, sizeof arg2, "%d", flag);
std::snprintf(arg2, sizeof arg2, "%d", flag);
char arg3[8];
snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport);
std::snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport);
execl("./bot", "bot", arg1, arg2, arg3, nullptr);
exit(0);
} else {
......@@ -571,7 +571,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
const wchar_t* name = mainGame->lstSinglePlayList->getListItem(sel);
wchar_t fname[256];
myswprintf(fname, L"./single/%ls", name);
FILE* fp = myfopen(fname, "rb");
FILE* fp = mywfopen(fname, "rb");
if(!fp) {
mainGame->stSinglePlayInfo->setText(L"");
break;
......@@ -580,7 +580,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t wlinebuf[1024];
std::wstring message = L"";
bool in_message = false;
while(fgets(linebuf, 1024, fp)) {
while(std::fgets(linebuf, 1024, fp)) {
if(!std::strncmp(linebuf, "--[[message", 11)) {
size_t len = std::strlen(linebuf);
char* msgend = std::strrchr(linebuf, ']');
......@@ -603,7 +603,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
message.append(wlinebuf);
}
}
fclose(fp);
std::fclose(fp);
mainGame->SetStaticText(mainGame->stSinglePlayInfo, 200, mainGame->guiFont, message.c_str());
break;
}
......
......@@ -94,7 +94,7 @@ public:
if(fh == INVALID_HANDLE_VALUE)
return;
do {
if(mywcsncasecmp(fdataw.cFileName, L".", 1) && mywcsncasecmp(fdataw.cFileName, L"..", 2))
if(std::wcscmp(fdataw.cFileName, L".") && std::wcscmp(fdataw.cFileName, L".."))
cb(fdataw.cFileName, (fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
......
......@@ -23,8 +23,8 @@ void Replay::BeginRecord() {
return;
#else
if(is_recording)
fclose(fp);
fp = fopen("./replay/_LastReplay.yrp", "wb");
std::fclose(fp);
fp = std::fopen("./replay/_LastReplay.yrp", "wb");
if(!fp)
return;
#endif
......@@ -39,8 +39,8 @@ void Replay::WriteHeader(ReplayHeader& header) {
DWORD size;
WriteFile(recording_fp, &header, sizeof(header), &size, nullptr);
#else
fwrite(&header, sizeof(header), 1, fp);
fflush(fp);
std::fwrite(&header, sizeof(header), 1, fp);
std::fflush(fp);
#endif
}
void Replay::WriteData(const void* data, size_t length, bool flush) {
......@@ -54,9 +54,9 @@ void Replay::WriteData(const void* data, size_t length, bool flush) {
DWORD size;
WriteFile(recording_fp, data, length, &size, nullptr);
#else
fwrite(data, length, 1, fp);
std::fwrite(data, length, 1, fp);
if(flush)
fflush(fp);
std::fflush(fp);
#endif
}
void Replay::WriteInt32(int32_t data, bool flush) {
......@@ -67,7 +67,7 @@ void Replay::Flush() {
return;
#ifdef _WIN32
#else
fflush(fp);
std::fflush(fp);
#endif
}
void Replay::EndRecord() {
......@@ -76,7 +76,7 @@ void Replay::EndRecord() {
#ifdef _WIN32
CloseHandle(recording_fp);
#else
fclose(fp);
std::fclose(fp);
#endif
pheader.datasize = replay_size;
pheader.flag |= REPLAY_COMPRESSED;
......@@ -94,19 +94,19 @@ void Replay::SaveReplay(const wchar_t* name) {
return;
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls.yrp", name);
FILE* rfp = myfopen(fname, "wb");
FILE* rfp = mywfopen(fname, "wb");
if(!rfp)
return;
fwrite(&pheader, sizeof pheader, 1, rfp);
fwrite(comp_data, comp_size, 1, rfp);
fclose(rfp);
std::fwrite(&pheader, sizeof pheader, 1, rfp);
std::fwrite(comp_data, comp_size, 1, rfp);
std::fclose(rfp);
}
bool Replay::OpenReplay(const wchar_t* name) {
FILE* rfp = myfopen(name, "rb");
FILE* rfp = mywfopen(name, "rb");
if(!rfp) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
rfp = myfopen(fname, "rb");
rfp = mywfopen(fname, "rb");
}
if(!rfp)
return false;
......@@ -116,13 +116,13 @@ bool Replay::OpenReplay(const wchar_t* name) {
is_replaying = false;
replay_size = 0;
comp_size = 0;
if(fread(&pheader, sizeof pheader, 1, rfp) < 1) {
fclose(rfp);
if(std::fread(&pheader, sizeof pheader, 1, rfp) < 1) {
std::fclose(rfp);
return false;
}
if(pheader.flag & REPLAY_COMPRESSED) {
comp_size = fread(comp_data, 1, MAX_COMP_SIZE, rfp);
fclose(rfp);
comp_size = std::fread(comp_data, 1, MAX_COMP_SIZE, rfp);
std::fclose(rfp);
if (pheader.datasize > MAX_REPLAY_SIZE)
return false;
replay_size = pheader.datasize;
......@@ -133,8 +133,8 @@ bool Replay::OpenReplay(const wchar_t* name) {
return false;
}
} else {
replay_size = fread(replay_data, 1, MAX_REPLAY_SIZE, rfp);
fclose(rfp);
replay_size = std::fread(replay_data, 1, MAX_REPLAY_SIZE, rfp);
std::fclose(rfp);
comp_size = 0;
}
is_replaying = true;
......@@ -143,12 +143,12 @@ bool Replay::OpenReplay(const wchar_t* name) {
bool Replay::CheckReplay(const wchar_t* name) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
FILE* rfp = myfopen(fname, "rb");
FILE* rfp = mywfopen(fname, "rb");
if(!rfp)
return false;
ReplayHeader rheader;
size_t count = fread(&rheader, sizeof rheader, 1, rfp);
fclose(rfp);
size_t count = std::fread(&rheader, sizeof rheader, 1, rfp);
std::fclose(rfp);
return count == 1 && rheader.id == 0x31707279 && rheader.version >= 0x12d0u && (rheader.version < 0x1353u || (rheader.flag & REPLAY_UNIFORM));
}
bool Replay::DeleteReplay(const wchar_t* name) {
......
......@@ -176,7 +176,7 @@ void SoundManager::PlaySoundEffect(int sound) {
break;
}
char soundPath[40];
snprintf(soundPath, 40, "./sound/%s.wav", soundName);
std::snprintf(soundPath, 40, "./sound/%s.wav", soundName);
#ifdef YGOPRO_USE_AUDIO
ma_engine_set_volume(&engineSound, mainGame->gameConf.sound_volume);
auto res = ma_engine_play_sound(&engineSound, soundPath, nullptr);
......
diff --git a/include/IOSOperator.h b/include/IOSOperator.h
index 2ab75a1..b574950 100644
--- a/include/IOSOperator.h
+++ b/include/IOSOperator.h
@@ -26,11 +26,11 @@ public:
}
//! Copies text to the clipboard
- virtual void copyToClipboard(const c8* text) const = 0;
+ virtual void copyToClipboard(const c16* text) const = 0;
//! Get text from the clipboard
/** \return Returns 0 if no string is in there. */
- virtual const c8* getTextFromClipboard() const = 0;
+ virtual const c16* getTextFromClipboard() const = 0;
//! Get the processor speed in megahertz
/** \param MHz The integer variable to store the speed in.
diff --git a/include/irrString.h b/include/irrString.h
index 43557cd..ffa06bc 100644
--- a/include/irrString.h
+++ b/include/irrString.h
@@ -1360,6 +1360,15 @@ typedef string<c8> stringc;
//! Typedef for wide character strings
typedef string<wchar_t> stringw;
+//! wrap of mbstowcs
+static inline wchar_t* toWideChar(const char* p)
+{
+ size_t lenOld = strlen(p);
+ wchar_t* ws = new wchar_t[lenOld + 1];
+ size_t lenNew = mbstowcs(ws, p, lenOld);
+ ws[lenNew] = 0;
+ return ws;
+}
} // end namespace core
} // end namespace irr
diff --git a/include/irrTypes.h b/include/irrTypes.h
index 403f890..940e859 100644
--- a/include/irrTypes.h
+++ b/include/irrTypes.h
@@ -48,6 +48,9 @@ typedef __int16 s16;
typedef signed short s16;
#endif
+//! 16 bit character variable.
+/** This is a typedef for wchar_t, it ensures portability of the engine. */
+typedef wchar_t c16;
//! 32 bit unsigned variable.
diff --git a/source/Irrlicht/CGUIEditBox.cpp b/source/Irrlicht/CGUIEditBox.cpp
index 395fb69..cc6b75f 100644
--- a/source/Irrlicht/CGUIEditBox.cpp
+++ b/source/Irrlicht/CGUIEditBox.cpp
@@ -287,7 +287,7 @@ bool CGUIEditBox::processKey(const SEvent& event)
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
- core::stringc s;
+ core::stringw s;
s = Text.subString(realmbgn, realmend - realmbgn).c_str();
Operator->copyToClipboard(s.c_str());
}
@@ -300,7 +300,7 @@ bool CGUIEditBox::processKey(const SEvent& event)
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
// copy
- core::stringc sc;
+ core::stringw sc;
sc = Text.subString(realmbgn, realmend - realmbgn).c_str();
Operator->copyToClipboard(sc.c_str());
@@ -330,16 +330,10 @@ bool CGUIEditBox::processKey(const SEvent& event)
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
// add new character
- const c8* p = Operator->getTextFromClipboard();
+ const c16* p = Operator->getTextFromClipboard();
if (p)
{
- // TODO: we should have such a function in core::string
- size_t lenOld = strlen(p);
- wchar_t *ws = new wchar_t[lenOld + 1];
- size_t len = mbstowcs(ws,p,lenOld);
- ws[len] = 0;
- irr::core::stringw widep(ws);
- delete[] ws;
+ irr::core::stringw widep(p);
if (MarkBegin == MarkEnd)
{
@@ -664,6 +658,16 @@ bool CGUIEditBox::processKey(const SEvent& event)
case KEY_ESCAPE:
case KEY_TAB:
case KEY_SHIFT:
+ case KEY_LSHIFT:
+ case KEY_RSHIFT:
+ case KEY_MENU:
+ case KEY_LMENU:
+ case KEY_RMENU:
+ case KEY_LWIN:
+ case KEY_RWIN:
+ case KEY_CAPITAL:
+ case KEY_NUMLOCK:
+ case KEY_SCROLL:
case KEY_F1:
case KEY_F2:
case KEY_F3:
diff --git a/source/Irrlicht/CGUIListBox.cpp b/source/Irrlicht/CGUIListBox.cpp
index 2c19a43..eb834a4 100644
--- a/source/Irrlicht/CGUIListBox.cpp
+++ b/source/Irrlicht/CGUIListBox.cpp
@@ -425,7 +425,7 @@ bool CGUIListBox::OnEvent(const SEvent& event)
}
case EMIE_MOUSE_MOVED:
- if (Selecting || MoveOverSelect)
+ if (MoveOverSelect)
{
if (isPointInside(p))
{
diff --git a/source/Irrlicht/CIrrDeviceLinux.cpp b/source/Irrlicht/CIrrDeviceLinux.cpp
index 39b1888..d359957 100644
--- a/source/Irrlicht/CIrrDeviceLinux.cpp
+++ b/source/Irrlicht/CIrrDeviceLinux.cpp
@@ -63,6 +63,7 @@ namespace
Atom X_ATOM_TARGETS;
Atom X_ATOM_UTF8_STRING;
Atom X_ATOM_TEXT;
+ Atom X_ATOM_XSEL_DATA;
};
namespace irr
@@ -1106,11 +1107,14 @@ bool CIrrDeviceLinux::run()
{
XEvent respond;
XSelectionRequestEvent *req = &(event.xselectionrequest);
- if ( req->target == XA_STRING)
+ if ( req->target == XA_STRING
+ || req->target == X_ATOM_TEXT
+ || req->target == X_ATOM_UTF8_STRING )
{
XChangeProperty (display,
req->requestor,
- req->property, req->target,
+ req->property,
+ req->target == X_ATOM_TEXT ? XA_STRING : req->target,
8, // format
PropModeReplace,
(unsigned char*) Clipboard.c_str(),
@@ -1124,11 +1128,14 @@ bool CIrrDeviceLinux::run()
data[0] = X_ATOM_TEXT;
data[1] = XA_STRING;
- XChangeProperty (display, req->requestor,
- req->property, req->target,
- 8, PropModeReplace,
- (unsigned char *) &data,
- sizeof (data));
+ XChangeProperty (display,
+ req->requestor,
+ req->property,
+ XA_ATOM,
+ 32, // format
+ PropModeReplace,
+ (unsigned char *) &X_ATOM_UTF8_STRING,
+ 1);
respond.xselection.property = req->property;
}
else
@@ -1875,34 +1882,36 @@ const c8* CIrrDeviceLinux::getTextFromClipboard() const
Clipboard = "";
if (ownerWindow != None )
{
- XConvertSelection (display, X_ATOM_CLIPBOARD, XA_STRING, XA_PRIMARY, ownerWindow, CurrentTime);
- XFlush (display);
-
- // check for data
- Atom type;
- int format;
- unsigned long numItems, bytesLeft, dummy;
- unsigned char *data;
- XGetWindowProperty (display, ownerWindow,
- XA_PRIMARY, // property name
- 0, // offset
- 0, // length (we only check for data, so 0)
+ XConvertSelection (display, X_ATOM_CLIPBOARD, X_ATOM_UTF8_STRING, X_ATOM_XSEL_DATA, window, CurrentTime);
+ XSync (display, 0);
+ XEvent event;
+ do nanosleep ((const struct timespec[]){{0, 1L}}, NULL);
+ while (!XCheckTypedEvent (display, SelectionNotify, &event));
+ if ( (event.xselection.selection == X_ATOM_CLIPBOARD) && event.xselection.property )
+ {
+ Atom type;
+ int format;
+ unsigned long size, dummy;
+ unsigned char *data;
+ int result = XGetWindowProperty (event.xselection.display,
+ event.xselection.requestor,
+ event.xselection.property,
+ 0L, // offset
+ (~0L), // length (max)
0, // Delete 0==false
AnyPropertyType, // AnyPropertyType or property identifier
&type, // return type
&format, // return format
- &numItems, // number items
- &bytesLeft, // remaining bytes for partial reads
+ &size, // number items
+ &dummy, // remaining bytes for partial reads
&data); // data
- if ( bytesLeft > 0 )
- {
- // there is some data to get
- int result = XGetWindowProperty (display, ownerWindow, XA_PRIMARY, 0,
- bytesLeft, 0, AnyPropertyType, &type, &format,
- &numItems, &dummy, &data);
- if (result == Success)
- Clipboard = (irr::c8*)data;
- XFree (data);
+ if ( result == Success
+ && (type == X_ATOM_UTF8_STRING || type == XA_STRING) ) // not implemented: INCR (partial reads)
+ {
+ Clipboard = strndup((char*)data, size);
+ XFree (data);
+ }
+ XDeleteProperty (event.xselection.display, event.xselection.requestor, event.xselection.property);
}
}
@@ -1966,6 +1975,7 @@ void CIrrDeviceLinux::initXAtoms()
X_ATOM_TARGETS = XInternAtom(display, "TARGETS", False);
X_ATOM_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
X_ATOM_TEXT = XInternAtom (display, "TEXT", False);
+ X_ATOM_XSEL_DATA = XInternAtom (display, "XSEL_DATA", False);
#endif
}
diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp
index 28290cb..76dfea1 100644
--- a/source/Irrlicht/CIrrDeviceWin32.cpp
+++ b/source/Irrlicht/CIrrDeviceWin32.cpp
@@ -20,6 +20,8 @@
#include "COSOperator.h"
#include "dimension2d.h"
#include "IGUISpriteBank.h"
+#include "IGUIEnvironment.h"
+#include "IGUIElement.h"
#include <winuser.h>
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
#ifdef _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_
@@ -749,6 +751,24 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
}
+ dev = getDeviceFromHWnd(hWnd);
+ if (dev)
+ {
+ irr::gui::IGUIElement* ele = dev->getGUIEnvironment()->getFocus();
+ if (!ele || (ele->getType() != irr::gui::EGUIET_EDIT_BOX) || !ele->isEnabled())
+ {
+ HIMC hIMC = ImmGetContext(hWnd);
+ if (hIMC)
+ {
+ ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
+ ImmReleaseContext(hWnd, hIMC);
+ }
+ ImmAssociateContextEx(hWnd, NULL, 0);
+ }
+ else
+ ImmAssociateContextEx(hWnd, NULL, IACE_DEFAULT);
+ }
+
switch (message)
{
case WM_PAINT:
@@ -773,7 +793,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
event.KeyInput.Key = (irr::EKEY_CODE)wParam;
event.KeyInput.PressedDown = (message==WM_KEYDOWN || message == WM_SYSKEYDOWN);
+#ifdef MAPVK_VSC_TO_VK_EX
+ const UINT MY_MAPVK_VSC_TO_VK_EX = MAPVK_VSC_TO_VK_EX;
+#else
const UINT MY_MAPVK_VSC_TO_VK_EX = 3; // MAPVK_VSC_TO_VK_EX should be in SDK according to MSDN, but isn't in mine.
+#endif
if ( event.KeyInput.Key == irr::KEY_SHIFT )
{
// this will fail on systems before windows NT/2000/XP, not sure _what_ will return there instead.
@@ -904,6 +928,53 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
KEYBOARD_INPUT_HKL = GetKeyboardLayout(0);
KEYBOARD_INPUT_CODEPAGE = LocaleIdToCodepage( LOWORD(KEYBOARD_INPUT_HKL) );
return 0;
+
+ case WM_IME_STARTCOMPOSITION:
+ {
+ dev = getDeviceFromHWnd(hWnd);
+ irr::gui::IGUIElement* ele = dev->getGUIEnvironment()->getFocus();
+ if (!ele)
+ break;
+ irr::core::position2di pos = ele->getAbsolutePosition().UpperLeftCorner;
+ COMPOSITIONFORM CompForm = { CFS_POINT, { pos.X, pos.Y + ele->getAbsolutePosition().getHeight() } };
+ HIMC hIMC = ImmGetContext(hWnd);
+ ImmSetCompositionWindow(hIMC, &CompForm);
+ ImmReleaseContext(hWnd, hIMC);
+ }
+ break;
+
+ case WM_IME_CHAR:
+ event.EventType = irr::EET_KEY_INPUT_EVENT;
+ event.KeyInput.PressedDown = true;
+#ifdef _UNICODE
+ event.KeyInput.Char = wParam;
+#else
+ BYTE ch[3];
+ if (wParam >> 8) {
+ ch[0] = wParam >> 8;
+ ch[1] = wParam & 0xff;
+ ch[2] = 0;
+ } else {
+ ch[0] = wParam;
+ ch[1] = 0;
+ }
+ WORD unicodeChar;
+ MultiByteToWideChar(
+ KEYBOARD_INPUT_CODEPAGE,
+ MB_PRECOMPOSED, // default
+ (LPCSTR)ch,
+ sizeof(wParam),
+ (WCHAR*)&unicodeChar,
+ 1);
+ event.KeyInput.Char = unicodeChar;
+#endif
+ event.KeyInput.Key = irr::KEY_ACCEPT;
+ event.KeyInput.Shift = 0;
+ event.KeyInput.Control = 0;
+ dev = getDeviceFromHWnd(hWnd);
+ if (dev)
+ dev->postEventFromUser(event);
+ return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
@@ -1797,8 +1868,8 @@ void CIrrDeviceWin32::handleSystemMessages()
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
- // No message translation because we don't use WM_CHAR and it would conflict with our
- // deadkey handling.
+ // conflict with deadkey handling.
+ TranslateMessage(&msg);
if (ExternalWindow && msg.hwnd == HWnd)
WndProc(HWnd, msg.message, msg.wParam, msg.lParam);
diff --git a/source/Irrlicht/COSOperator.cpp b/source/Irrlicht/COSOperator.cpp
index c5e4552..3b00628 100644
--- a/source/Irrlicht/COSOperator.cpp
+++ b/source/Irrlicht/COSOperator.cpp
@@ -9,6 +9,7 @@
#include <windows.h>
#endif
#else
+#include <locale.h>
#include <string.h>
#include <unistd.h>
#ifndef _IRR_SOLARIS_PLATFORM_
@@ -54,9 +55,10 @@ const core::stringc& COSOperator::getOperatingSystemVersion() const
//! copies text to the clipboard
-void COSOperator::copyToClipboard(const c8* text) const
+void COSOperator::copyToClipboard(const c16* text) const
{
- if (strlen(text)==0)
+ size_t len = wcslen(text);
+ if (len==0)
return;
// Windows version
@@ -68,15 +70,15 @@ void COSOperator::copyToClipboard(const c8* text) const
EmptyClipboard();
HGLOBAL clipbuffer;
- char * buffer;
+ wchar_t * buffer;
- clipbuffer = GlobalAlloc(GMEM_DDESHARE, strlen(text)+1);
- buffer = (char*)GlobalLock(clipbuffer);
+ clipbuffer = GlobalAlloc(GMEM_DDESHARE, sizeof(wchar_t) * (len + 1));
+ buffer = (wchar_t*)GlobalLock(clipbuffer);
- strcpy(buffer, text);
+ wcscpy(buffer, text);
GlobalUnlock(clipbuffer);
- SetClipboardData(CF_TEXT, clipbuffer);
+ SetClipboardData(CF_UNICODETEXT, clipbuffer);
CloseClipboard();
// MacOSX version
@@ -86,7 +88,18 @@ void COSOperator::copyToClipboard(const c8* text) const
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
if ( IrrDeviceLinux )
- IrrDeviceLinux->copyToClipboard(text);
+ {
+ size_t wlen = sizeof(wchar_t) * (len + 1);
+ char ctext[wlen];
+
+ char* oldLocale = setlocale(LC_CTYPE, NULL);
+ setlocale(LC_CTYPE, "");
+ size_t lenNew = wcstombs(ctext, text, wlen);
+ ctext[lenNew] = 0;
+ setlocale(LC_CTYPE, oldLocale);
+
+ IrrDeviceLinux->copyToClipboard(ctext);
+ }
#else
#endif
@@ -95,7 +108,7 @@ void COSOperator::copyToClipboard(const c8* text) const
//! gets text from the clipboard
//! \return Returns 0 if no string is in there.
-const c8* COSOperator::getTextFromClipboard() const
+const c16* COSOperator::getTextFromClipboard() const
{
#if defined(_IRR_XBOX_PLATFORM_)
return 0;
@@ -103,10 +116,10 @@ const c8* COSOperator::getTextFromClipboard() const
if (!OpenClipboard(NULL))
return 0;
- char * buffer = 0;
+ wchar_t * buffer = 0;
- HANDLE hData = GetClipboardData( CF_TEXT );
- buffer = (char*)GlobalLock( hData );
+ HANDLE hData = GetClipboardData( CF_UNICODETEXT );
+ buffer = (wchar_t*)GlobalLock( hData );
GlobalUnlock( hData );
CloseClipboard();
return buffer;
@@ -116,7 +129,16 @@ const c8* COSOperator::getTextFromClipboard() const
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
if ( IrrDeviceLinux )
- return IrrDeviceLinux->getTextFromClipboard();
+ {
+ const c8 * p = IrrDeviceLinux->getTextFromClipboard();
+
+ char* oldLocale = setlocale(LC_CTYPE, NULL);
+ setlocale(LC_CTYPE, "");
+ wchar_t* ws = core::toWideChar(p);
+ setlocale(LC_CTYPE, oldLocale);
+
+ return ws;
+ }
return 0;
#else
diff --git a/source/Irrlicht/COSOperator.h b/source/Irrlicht/COSOperator.h
index 819805f..a86cb6e 100644
--- a/source/Irrlicht/COSOperator.h
+++ b/source/Irrlicht/COSOperator.h
@@ -27,11 +27,11 @@ public:
virtual const core::stringc& getOperatingSystemVersion() const;
//! copies text to the clipboard
- virtual void copyToClipboard(const c8* text) const;
+ virtual void copyToClipboard(const c16* text) const;
//! gets text from the clipboard
//! \return Returns 0 if no string is in there.
- virtual const c8* getTextFromClipboard() const;
+ virtual const c16* getTextFromClipboard() const;
//! gets the processor speed in megahertz
//! \param Mhz:
diff --git a/source/Irrlicht/MacOSX/AppDelegate.h b/source/Irrlicht/MacOSX/AppDelegate.h
index ccb116d..29705f2 100644
--- a/source/Irrlicht/MacOSX/AppDelegate.h
+++ b/source/Irrlicht/MacOSX/AppDelegate.h
@@ -10,7 +10,7 @@
#import <Cocoa/Cocoa.h>
#import "CIrrDeviceMacOSX.h"
-@interface AppDelegate : NSObject
+@interface AppDelegate : NSTextView <NSApplicationDelegate>
{
BOOL _quit;
irr::CIrrDeviceMacOSX *_device;
diff --git a/source/Irrlicht/MacOSX/AppDelegate.mm b/source/Irrlicht/MacOSX/AppDelegate.mm
index 14a7f86..37f6a51 100644
--- a/source/Irrlicht/MacOSX/AppDelegate.mm
+++ b/source/Irrlicht/MacOSX/AppDelegate.mm
@@ -74,6 +74,35 @@
return (_quit);
}
+- (void)keyDown:(NSEvent *)event
+{
+ [self interpretKeyEvents:@[event]];
+}
+
+- (void)insertText:(id)string
+{
+ [self setString: @""];
+ if ([string isKindOfClass:[NSAttributedString class]])
+ {
+ _device->handleInputEvent([[string string] UTF8String]);
+ }
+ else
+ {
+ _device->handleInputEvent([string UTF8String]);
+ }
+}
+
+- (void)doCommandBySelector:(SEL)selector
+{
+ _device->processKeyEvent();
+}
+
+- (void)paste:(id)sender
+{
+ // TODO: pass the pasted string. Now we discard it otherwise it will be kept in the editbox.
+ [self setString: @""];
+}
+
@end
#endif // _IRR_COMPILE_WITH_OSX_DEVICE_
diff --git a/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h b/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h
index f629588..d2fefae 100644
--- a/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h
+++ b/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h
@@ -95,6 +95,8 @@ namespace irr
void setMouseLocation(int x, int y);
void setResize(int width, int height);
void setCursorVisible(bool visible);
+ void handleInputEvent(const char *str);
+ void processKeyEvent();
private:
diff --git a/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm b/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
index 60da342..8fd8f4a 100644
--- a/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
+++ b/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
@@ -592,6 +592,31 @@ void CIrrDeviceMacOSX::closeDevice()
CGLContext = NULL;
}
+void CIrrDeviceMacOSX::processKeyEvent()
+{
+ irr::SEvent ievent;
+ NSEvent *event = [[NSApplication sharedApplication] currentEvent];
+ postKeyEvent(event, ievent, true);
+}
+
+void CIrrDeviceMacOSX::handleInputEvent(const char *cStr)
+{
+ SEvent ievent;
+ irr::core::stringw widep(irr::core::toWideChar(cStr));
+
+ ievent.EventType = irr::EET_KEY_INPUT_EVENT;
+ ievent.KeyInput.Key = (irr::EKEY_CODE)0;
+ ievent.KeyInput.PressedDown = true;
+ ievent.KeyInput.Shift = false;
+ ievent.KeyInput.Control = false;
+
+ for (int i = 0; i < widep.size(); ++i)
+ {
+ ievent.KeyInput.Char = widep[i];
+ postEventFromUser(ievent);
+ }
+}
+
bool CIrrDeviceMacOSX::createWindow()
{
CGDisplayErr error;
@@ -721,14 +746,20 @@ bool CIrrDeviceMacOSX::createWindow()
[Window setDelegate:(id<NSWindowDelegate>)[NSApp delegate]];
if(CreationParams.DriverType == video::EDT_OPENGL)
+ {
+ [[Window contentView] setWantsBestResolutionOpenGLSurface:NO];
[OGLContext setView:[Window contentView]];
+ }
[Window setAcceptsMouseMovedEvents:TRUE];
[Window setIsVisible:TRUE];
[Window makeKeyAndOrderFront:nil];
}
else if(CreationParams.DriverType == video::EDT_OPENGL) //use another window for drawing
+ {
+ [(NSView*)CreationParams.WindowId setWantsBestResolutionOpenGLSurface:NO];
[OGLContext setView:(NSView*)CreationParams.WindowId];
+ }
if (CreationParams.DriverType == video::EDT_OPENGL)
CGLContext = (CGLContextObj) [OGLContext CGLContextObj];
@@ -881,6 +912,8 @@ bool CIrrDeviceMacOSX::createWindow()
newSwapInterval = (CreationParams.Vsync) ? 1 : 0;
CGLSetParameter(CGLContext,kCGLCPSwapInterval,&newSwapInterval);
}
+
+ [[Window contentView] addSubview:(AppDelegate*)[NSApp delegate]];
}
return (result);
@@ -971,6 +1004,41 @@ bool CIrrDeviceMacOSX::run()
os::Timer::tick();
storeMouseLocation();
+ auto focusElement = getGUIEnvironment()->getFocus();
+ bool editing = focusElement && focusElement->getType() == irr::gui::EGUIET_EDIT_BOX;
+ auto textView = (NSTextView*)[NSApp delegate];
+
+ if (!editing)
+ {
+ [textView setHidden:YES];
+ [Window makeFirstResponder:nil];
+ }
+ else
+ {
+ auto crect = focusElement->getAbsolutePosition();
+
+ // ensure font height enough to fill the rect, otherwize ime window will overlaps the edit box
+ [textView setFont:[NSFont userFontOfSize:crect.getHeight() - 5]];
+
+ // change origin from top left to bottom right
+ auto frameHeight = [[textView superview] frame].size.height;
+ NSRect rect = {
+ (frameHeight - crect.LowerRightCorner.Y > crect.getHeight()) ?
+ crect.UpperLeftCorner.X :
+ crect.UpperLeftCorner.X + crect.getWidth() / 2,
+ (frameHeight - crect.LowerRightCorner.Y > crect.getHeight()) ?
+ frameHeight - crect.LowerRightCorner.Y - crect.getHeight() - 1 :
+ frameHeight - crect.LowerRightCorner.Y,
+ crect.getWidth() / 2,
+ crect.getHeight(),
+ };
+ [textView setFrame:rect];
+ [textView setHidden:NO];
+
+ // start to receive input events
+ [Window makeFirstResponder:textView];
+ }
+
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
if (event != nil)
{
@@ -979,6 +1047,13 @@ bool CIrrDeviceMacOSX::run()
switch([(NSEvent *)event type])
{
case NSKeyDown:
+ if (editing)
+ {
+ // delegate to text edit control to handle text input
+ [NSApp sendEvent:event];
+ break;
+ }
+
postKeyEvent(event,ievent,true);
break;
@@ -1174,13 +1249,11 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed
std::map<int,int>::const_iterator iter;
unsigned int result,c,mkey,mchar;
const unsigned char *cStr;
- BOOL skipCommand;
str = [(NSEvent *)event characters];
if ((str != nil) && ([str length] > 0))
{
mkey = mchar = 0;
- skipCommand = false;
c = [str characterAtIndex:0];
mchar = c;
@@ -1199,19 +1272,11 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed
}
else
{
- cStr = (unsigned char *)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding];
+ cStr = (unsigned char *)[str UTF8String];
if (cStr != NULL && strlen((char*)cStr) > 0)
{
mchar = cStr[0];
mkey = toupper(mchar);
- if ([(NSEvent *)event modifierFlags] & NSCommandKeyMask)
- {
- if (mkey == 'C' || mkey == 'V' || mkey == 'X')
- {
- mchar = 0;
- skipCommand = true;
- }
- }
}
}
}
@@ -1220,14 +1285,9 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed
ievent.KeyInput.Key = (irr::EKEY_CODE)mkey;
ievent.KeyInput.PressedDown = pressed;
ievent.KeyInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask) != 0;
- ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0;
+ ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & (NSControlKeyMask | NSCommandKeyMask)) != 0;
ievent.KeyInput.Char = mchar;
- if (skipCommand)
- ievent.KeyInput.Control = true;
- else if ([(NSEvent *)event modifierFlags] & NSCommandKeyMask)
- [NSApp sendEvent:(NSEvent *)event];
-
postEventFromUser(ievent);
}
}
diff --git a/source/Irrlicht/MacOSX/MacOSX.xcodeproj/project.pbxproj b/source/Irrlicht/MacOSX/MacOSX.xcodeproj/project.pbxproj
index 65f4cec..d465792 100644
--- a/source/Irrlicht/MacOSX/MacOSX.xcodeproj/project.pbxproj
+++ b/source/Irrlicht/MacOSX/MacOSX.xcodeproj/project.pbxproj
@@ -6088,10 +6088,12 @@
1DEB922308733DC00010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = "$(NATIVE_ARCH_ACTUAL)";
+ ARCHS = "$(ARCHS_STANDARD)";
+ GCC_PREPROCESSOR_DEFINITIONS = GLES_SILENCE_DEPRECATION;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = NO;
HEADER_SEARCH_PATHS = ../../../include;
+ MACOSX_DEPLOYMENT_TARGET = 10.10;
OTHER_CFLAGS = (
"-DMACOSX",
"-D_DEBUG",
@@ -6104,16 +6106,18 @@
1DEB922408733DC00010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = "$(NATIVE_ARCH_ACTUAL)";
+ ARCHS = "$(ARCHS_STANDARD)";
GCC_DYNAMIC_NO_PIC = YES;
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_INLINES_ARE_PRIVATE_EXTERN = YES;
GCC_OPTIMIZATION_LEVEL = 3;
+ GCC_PREPROCESSOR_DEFINITIONS = GLES_SILENCE_DEPRECATION;
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = NO;
HEADER_SEARCH_PATHS = ../../../include;
INSTALL_MODE_FLAG = "a+rwx";
+ MACOSX_DEPLOYMENT_TARGET = 10.10;
OTHER_CFLAGS = "-DMACOSX";
PREBINDING = NO;
SDKROOT = "";
diff --git a/source/Irrlicht/MacOSX/OSXClipboard.h b/source/Irrlicht/MacOSX/OSXClipboard.h
index 68f598d..9d6832d 100644
--- a/source/Irrlicht/MacOSX/OSXClipboard.h
+++ b/source/Irrlicht/MacOSX/OSXClipboard.h
@@ -7,8 +7,8 @@
extern "C" {
#endif
- void OSXCopyToClipboard(const char *text);
- char* OSXCopyFromClipboard();
+ void OSXCopyToClipboard(const wchar_t *text);
+ wchar_t* OSXCopyFromClipboard();
#ifdef __cplusplus
}
diff --git a/source/Irrlicht/MacOSX/OSXClipboard.mm b/source/Irrlicht/MacOSX/OSXClipboard.mm
index d549911..1c9dc0f 100644
--- a/source/Irrlicht/MacOSX/OSXClipboard.mm
+++ b/source/Irrlicht/MacOSX/OSXClipboard.mm
@@ -3,34 +3,35 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
+#include "irrString.h"
#include "OSXClipboard.h"
#import <Cocoa/Cocoa.h>
-void OSXCopyToClipboard(const char *text)
+void OSXCopyToClipboard(const wchar_t *text)
{
NSString *str;
NSPasteboard *board;
- if ((text != NULL) && (strlen(text) > 0))
+ if ((text != NULL) && (wcslen(text) > 0))
{
- str = [NSString stringWithCString:text encoding:NSWindowsCP1252StringEncoding];
+ str = [[NSString alloc] initWithBytes:text length:wcslen(text)*sizeof(*text) encoding:NSUTF32LittleEndianStringEncoding];
board = [NSPasteboard generalPasteboard];
[board declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:NSApp];
[board setString:str forType:NSStringPboardType];
}
}
-char* OSXCopyFromClipboard()
+wchar_t* OSXCopyFromClipboard()
{
NSString* str;
NSPasteboard* board;
- char* result;
+ wchar_t* result;
result = NULL;
board = [NSPasteboard generalPasteboard];
str = [board stringForType:NSStringPboardType];
if (str != nil)
- result = (char*)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding];
+ result = (wchar_t*)[str cStringUsingEncoding:NSUTF32LittleEndianStringEncoding];
return (result);
}
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