Port 2V0 UI Python bindings and app module link surface

This commit is contained in:
shen
2026-09-22 19:57:35 -07:00
parent a0ad587f78
commit b221a9eaf5
74 changed files with 18320 additions and 9 deletions
@@ -0,0 +1,295 @@
#include "StdAfx.h"
#include "../common/PortPythonPointer.h" // PORT: preserve Win32 pointer handles on 64-bit hosts
bool PyTuple_GetImageInstance(PyObject* poArgs, int pos, CGraphicImageInstance** ppRetImageInstance)
{
return PyTuple_GetPointer(poArgs, pos, ppRetImageInstance) && *ppRetImageInstance;
}
bool PyTuple_GetExpandedImageInstance(PyObject* poArgs, int pos, CGraphicExpandedImageInstance ** ppRetImageInstance)
{
CGraphicImageInstance* image;
if (!PyTuple_GetPointer(poArgs, pos, &image) || !image)
return false;
if (!image->IsType(CGraphicExpandedImageInstance::Type()))
return false;
*ppRetImageInstance = static_cast<CGraphicExpandedImageInstance*>(image);
return true;
}
PyObject* grpImageGenerate(PyObject * poSelf, PyObject* poArgs)
{
char * szFileName;
if (!PyTuple_GetString(poArgs, 0, &szFileName))
return Py_BadArgument();
if (!*szFileName)
return Py_BuildValue("i", 0);
CResource * pResource = CResourceManager::Instance().GetResourcePointer(szFileName);
if (!pResource->IsType(CGraphicImage::Type()))
return Py_BuildException("Resource is not an image (filename: %s)", szFileName);
CGraphicImageInstance * pImageInstance = CGraphicImageInstance::New();
pImageInstance->SetImagePointer(static_cast<CGraphicImage*>(pResource));
if (pImageInstance->IsEmpty())
return Py_BuildException("Cannot load image (filename: %s)", szFileName);
return Py_BuildPointer(pImageInstance);
}
PyObject* grpImageGenerateExpanded(PyObject* poSelf, PyObject* poArgs)
{
char * szFileName;
if (!PyTuple_GetString(poArgs, 0, &szFileName))
return Py_BadArgument();
if (strlen(szFileName) <= 0)
return Py_BuildValue("i", 0);
CResource* pResource = CResourceManager::Instance().GetResourcePointer(szFileName);
if (!pResource->IsType(CGraphicImage::Type()))
return Py_BuildException("Resource is not an image (filename: %s)", szFileName);
CGraphicExpandedImageInstance * pImageInstance = CGraphicExpandedImageInstance::New();
pImageInstance->SetImagePointer(static_cast<CGraphicImage*>(pResource));
if (pImageInstance->IsEmpty())
return Py_BuildException("Cannot load image (filename: %s)", szFileName);
return Py_BuildPointer(pImageInstance);
}
PyObject* grpImageGenerateFromHandle(PyObject * poSelf, PyObject* poArgs)
{
CGraphicImage* image;
if (!PyTuple_GetPointer(poArgs, 0, &image))
return Py_BadArgument();
CGraphicImageInstance * pImageInstance = CGraphicImageInstance::New();
pImageInstance->SetImagePointer(image);
return Py_BuildPointer(pImageInstance);
}
PyObject* grpImageDelete(PyObject* poSelf, PyObject* poArgs)
{
CGraphicImageInstance * pImageInstance;
if (!PyTuple_GetImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
if (!pImageInstance)
return Py_BuildNone();
CGraphicImageInstance::Delete(pImageInstance);
return Py_BuildNone();
}
PyObject* grpImageDeleteExpanded(PyObject* poSelf, PyObject* poArgs)
{
CGraphicExpandedImageInstance * pExpandedImageInstance;
if (!PyTuple_GetExpandedImageInstance(poArgs, 0, &pExpandedImageInstance))
return Py_BadArgument();
CGraphicExpandedImageInstance::Delete(pExpandedImageInstance);
return Py_BuildNone();
}
PyObject* grpImageSetFileName(PyObject* poSelf, PyObject* poArgs)
{
CGraphicImageInstance * pImageInstance;
if (!PyTuple_GetImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
char * szFileName;
if (!PyTuple_GetString(poArgs, 1, &szFileName))
return Py_BadArgument();
CResource * pResource = CResourceManager::Instance().GetResourcePointer(szFileName);
if (!pResource->IsType(CGraphicImage::Type()))
return Py_BuildException("Resource is not an image (filename: %s)", szFileName);
pImageInstance->SetImagePointer(static_cast<CGraphicImage*>(pResource));
return Py_BuildNone();
}
PyObject* grpImageRender(PyObject* poSelf, PyObject* poArgs)
{
CGraphicImageInstance* pImageInstance;
if (!PyTuple_GetImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
pImageInstance->Render();
return Py_BuildNone();
}
PyObject * grpSetImagePosition(PyObject * poSelf, PyObject * poArgs)
{
CGraphicImageInstance* pImageInstance;
if (!PyTuple_GetImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
float x;
if (!PyTuple_GetFloat(poArgs, 1, &x))
return Py_BadArgument();
float y;
if (!PyTuple_GetFloat(poArgs, 2, &y))
return Py_BadArgument();
pImageInstance->SetPosition(x, y);
return Py_BuildNone();
}
PyObject * grpSetImageOrigin(PyObject * poSelf, PyObject * poArgs)
{
CGraphicExpandedImageInstance * pImageInstance;
if (!PyTuple_GetExpandedImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
float x;
if (!PyTuple_GetFloat(poArgs, 1, &x))
return Py_BadArgument();
float y;
if (!PyTuple_GetFloat(poArgs, 2, &y))
return Py_BadArgument();
pImageInstance->SetOrigin(x, y);
return Py_BuildNone();
}
PyObject * grpSetImageRotation(PyObject * poSelf, PyObject * poArgs)
{
CGraphicExpandedImageInstance * pImageInstance;
if (!PyTuple_GetExpandedImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
float Degree;
if (!PyTuple_GetFloat(poArgs, 1, &Degree))
return Py_BadArgument();
pImageInstance->SetRotation(Degree);
return Py_BuildNone();
}
PyObject * grpSetImageScale(PyObject * poSelf, PyObject * poArgs)
{
CGraphicExpandedImageInstance * pImageInstance;
if (!PyTuple_GetExpandedImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
float x;
if (!PyTuple_GetFloat(poArgs, 1, &x))
return Py_BadArgument();
float y;
if (!PyTuple_GetFloat(poArgs, 2, &y))
return Py_BadArgument();
pImageInstance->SetScale(x, y);
return Py_BuildNone();
}
PyObject * grpSetRenderingRect(PyObject * poSelf, PyObject * poArgs)
{
CGraphicExpandedImageInstance * pImageInstance;
if (!PyTuple_GetExpandedImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
float fLeft;
if (!PyTuple_GetFloat(poArgs, 1, &fLeft))
return Py_BadArgument();
float fTop;
if (!PyTuple_GetFloat(poArgs, 2, &fTop))
return Py_BadArgument();
float fRight;
if (!PyTuple_GetFloat(poArgs, 3, &fRight))
return Py_BadArgument();
float fBottom;
if (!PyTuple_GetFloat(poArgs, 4, &fBottom))
return Py_BadArgument();
pImageInstance->SetRenderingRect(fLeft, fTop, fRight, fBottom);
return Py_BuildNone();
}
PyObject * grpSetImageDiffuseColor(PyObject * poSelf, PyObject * poArgs)
{
CGraphicImageInstance* pImageInstance;
if (!PyTuple_GetImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
float r;
if (!PyTuple_GetFloat(poArgs, 1, &r))
return Py_BadArgument();
float g;
if (!PyTuple_GetFloat(poArgs, 2, &g))
return Py_BadArgument();
float b;
if (!PyTuple_GetFloat(poArgs, 3, &b))
return Py_BadArgument();
float a;
if (!PyTuple_GetFloat(poArgs, 4, &a))
return Py_BadArgument();
pImageInstance->SetDiffuseColor(r, g, b, a);
return Py_BuildNone();
}
PyObject * grpGetWidth(PyObject * poSelf, PyObject * poArgs)
{
CGraphicImageInstance * pImageInstance;
if (!PyTuple_GetImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
if (pImageInstance->IsEmpty())
return Py_BuildException("Image is empty");
return Py_BuildValue("i", pImageInstance->GetWidth());
}
PyObject * grpGetHeight(PyObject * poSelf, PyObject * poArgs)
{
CGraphicImageInstance * pImageInstance;
if (!PyTuple_GetImageInstance(poArgs, 0, &pImageInstance))
return Py_BadArgument();
if (pImageInstance->IsEmpty())
return Py_BuildException("Image is empty");
return Py_BuildValue("i", pImageInstance->GetHeight());
}
void initgrpImage()
{
static PyMethodDef s_methods[] =
{
{ "Render", grpImageRender, METH_VARARGS },
{ "SetPosition", grpSetImagePosition, METH_VARARGS },
{ "Generate", grpImageGenerate, METH_VARARGS },
{ "GenerateExpanded", grpImageGenerateExpanded, METH_VARARGS },
{ "GenerateFromHandle", grpImageGenerateFromHandle, METH_VARARGS },
{ "Delete", grpImageDelete, METH_VARARGS },
{ "DeleteExpanded", grpImageDeleteExpanded, METH_VARARGS },
{ "SetFileName", grpImageSetFileName, METH_VARARGS },
{ "SetOrigin", grpSetImageOrigin, METH_VARARGS },
{ "SetRotation", grpSetImageRotation, METH_VARARGS },
{ "SetScale", grpSetImageScale, METH_VARARGS },
{ "SetRenderingRect", grpSetRenderingRect, METH_VARARGS },
{ "SetDiffuseColor", grpSetImageDiffuseColor, METH_VARARGS },
{ "GetWidth", grpGetWidth, METH_VARARGS },
{ "GetHeight", grpGetHeight, METH_VARARGS },
{ NULL, NULL, NULL },
};
Py_InitModule("grpImage", s_methods);
}
@@ -0,0 +1,999 @@
#include "StdAfx.h"
#include "../common/PortPythonPointer.h" // PORT: preserve Win32 pointer handles on 64-bit hosts
#include "../EterLib/Camera.h"
#include "../EterLib/TextBar.h"
#include <shlobj.h>
PyObject* grpCreateTextBar(PyObject* poSelf, PyObject* poArgs)
{
int iWidth;
if (!PyTuple_GetInteger(poArgs, 0, &iWidth))
return Py_BuildException();
int iHeight;
if (!PyTuple_GetInteger(poArgs, 1, &iHeight))
return Py_BuildException();
CTextBar * pTextBar = new CTextBar(12, false);
if (!pTextBar->Create(NULL, iWidth, iHeight))
{
delete pTextBar;
return Py_BuildValue("i", NULL);
}
return Py_BuildPointer(pTextBar);
}
PyObject* grpCreateBigTextBar(PyObject* poSelf, PyObject* poArgs)
{
int iWidth;
if (!PyTuple_GetInteger(poArgs, 0, &iWidth))
return Py_BuildException();
int iHeight;
if (!PyTuple_GetInteger(poArgs, 1, &iHeight))
return Py_BuildException();
int iFontSize;
if (!PyTuple_GetInteger(poArgs, 2, &iFontSize))
return Py_BuildException();
CTextBar * pTextBar = new CTextBar(iFontSize, true);
if (!pTextBar->Create(NULL, iWidth, iHeight))
{
delete pTextBar;
return Py_BuildValue("i", NULL);
}
return Py_BuildPointer(pTextBar);
}
PyObject* grpDestroyTextBar(PyObject* poSelf, PyObject* poArgs)
{
CTextBar* pTextBar;
if (!PyTuple_GetPointer(poArgs, 0, &pTextBar))
return Py_BuildException();
delete pTextBar;
return Py_BuildNone();
}
PyObject* grpRenderTextBar(PyObject* poSelf, PyObject* poArgs)
{
CTextBar* pTextBar;
if (!PyTuple_GetPointer(poArgs, 0, &pTextBar))
return Py_BuildException();
int ix;
if (!PyTuple_GetInteger(poArgs, 1, &ix))
return Py_BuildException();
int iy;
if (!PyTuple_GetInteger(poArgs, 2, &iy))
return Py_BuildException();
if (pTextBar)
pTextBar->Render(ix, iy);
return Py_BuildNone();
}
PyObject* grpTextBarSetTextColor(PyObject* poSelf, PyObject* poArgs)
{
CTextBar* pTextBar;
if (!PyTuple_GetPointer(poArgs, 0, &pTextBar))
return Py_BuildException();
int r;
if (!PyTuple_GetInteger(poArgs, 1, &r))
return Py_BuildException();
int g;
if (!PyTuple_GetInteger(poArgs, 2, &g))
return Py_BuildException();
int b;
if (!PyTuple_GetInteger(poArgs, 3, &b))
return Py_BuildException();
if (pTextBar)
pTextBar->SetTextColor(r, g, b);
return Py_BuildNone();
}
PyObject* grpTextBarGetTextExtent(PyObject* poSelf, PyObject* poArgs)
{
CTextBar* pTextBar;
if (!PyTuple_GetPointer(poArgs, 0, &pTextBar))
return Py_BuildException();
char * szText;
if (!PyTuple_GetString(poArgs, 1, &szText))
return Py_BuildException();
SIZE size = {0, 0};
if (pTextBar)
pTextBar->GetTextExtent(szText, &size);
return Py_BuildValue("ii", size.cx, size.cy);
}
PyObject* grpTextBarTextOut(PyObject* poSelf, PyObject* poArgs)
{
CTextBar* pTextBar;
if (!PyTuple_GetPointer(poArgs, 0, &pTextBar))
return Py_BuildException();
int ix;
if (!PyTuple_GetInteger(poArgs, 1, &ix))
return Py_BuildException();
int iy;
if (!PyTuple_GetInteger(poArgs, 2, &iy))
return Py_BuildException();
char * szText;
if (!PyTuple_GetString(poArgs, 3, &szText))
return Py_BuildException();
if (pTextBar)
pTextBar->TextOut(ix, iy, szText);
return Py_BuildNone();
}
PyObject* grpClearTextBar(PyObject* poSelf, PyObject* poArgs)
{
CTextBar* pTextBar;
if (!PyTuple_GetPointer(poArgs, 0, &pTextBar))
return Py_BuildException();
if (pTextBar)
pTextBar->ClearBar();
return Py_BuildNone();
}
PyObject* grpSetTextBarClipRect(PyObject* poSelf, PyObject* poArgs)
{
CTextBar* pTextBar;
if (!PyTuple_GetPointer(poArgs, 0, &pTextBar))
return Py_BuildException();
int isx;
if (!PyTuple_GetInteger(poArgs, 1, &isx))
return Py_BuildException();
int isy;
if (!PyTuple_GetInteger(poArgs, 2, &isy))
return Py_BuildException();
int iex;
if (!PyTuple_GetInteger(poArgs, 3, &iex))
return Py_BuildException();
int iey;
if (!PyTuple_GetInteger(poArgs, 4, &iey))
return Py_BuildException();
if (pTextBar)
{
RECT rect;
rect.left = isx;
rect.top = isy;
rect.right = iex;
rect.bottom = iey;
pTextBar->SetClipRect(rect);
}
return Py_BuildNone();
}
PyObject* grpCulling(PyObject* poSelf, PyObject* poArgs)
{
CCullingManager::Instance().Process();
return Py_BuildNone();
}
PyObject* grpInitScreenEffect(PyObject* poSelf, PyObject* poArgs)
{
CPythonGraphic::Instance().InitScreenEffect();
return Py_BuildNone();
}
PyObject* grpClearDepthBuffer(PyObject* poSelf, PyObject* poArgs)
{
CPythonGraphic::Instance().ClearDepthBuffer();
return Py_BuildNone();
}
PyObject* grpPushState(PyObject* poSelf, PyObject* poArgs)
{
CPythonGraphic::Instance().PushState();
return Py_BuildNone();
}
PyObject* grpPopState(PyObject* poSelf, PyObject* poArgs)
{
CPythonGraphic::Instance().PopState();
return Py_BuildNone();
}
PyObject* grpPushMatrix(PyObject* poSelf, PyObject* poArgs)
{
CPythonGraphic::Instance().PushMatrix();
return Py_BuildNone();
}
PyObject* grpPopMatrix(PyObject* poSelf, PyObject* poArgs)
{
CPythonGraphic::Instance().PopMatrix();
return Py_BuildNone();
}
PyObject* grpTranslate(PyObject* poSelf, PyObject* poArgs)
{
float x;
if (!PyTuple_GetFloat(poArgs, 0, &x))
return Py_BuildException("grp.Translate:Wrong X");
float y;
if (!PyTuple_GetFloat(poArgs, 1, &y))
return Py_BuildException("grp.Translate:Wrong Y");
float z;
if (!PyTuple_GetFloat(poArgs, 2, &z))
return Py_BuildException("grp.Translate:Wrong Z");
CPythonGraphic::Instance().Translate(x, y, z);
return Py_BuildNone();
}
PyObject* grpRotate(PyObject* poSelf, PyObject* poArgs)
{
float Degree;
if (!PyTuple_GetFloat(poArgs, 0, &Degree))
return Py_BuildException();
float x;
if (!PyTuple_GetFloat(poArgs, 1, &x))
return Py_BuildException();
float y;
if (!PyTuple_GetFloat(poArgs, 2, &y))
return Py_BuildException();
float z;
if (!PyTuple_GetFloat(poArgs, 3, &z))
return Py_BuildException();
CPythonGraphic::Instance().Rotate(Degree, x, y, z);
return Py_BuildNone();
}
PyObject * grpSetColorRenderState(PyObject* poSelf, PyObject* poArgs)
{
return Py_BuildNone();
}
PyObject* grpSetAroundCamera(PyObject* poSelf, PyObject* poArgs)
{
float distance;
if (!PyTuple_GetFloat(poArgs, 0, &distance))
return Py_BuildException();
float pitch;
if (!PyTuple_GetFloat(poArgs, 1, &pitch))
return Py_BuildException();
float roll;
if (!PyTuple_GetFloat(poArgs, 2, &roll))
return Py_BuildException();
float lookAtZ;
if (!PyTuple_GetFloat(poArgs, 3, &lookAtZ))
return Py_BuildException();
CPythonGraphic::Instance().SetAroundCamera(distance, pitch, roll, lookAtZ);
return Py_BuildNone();
}
PyObject* grpSetPositionCamera(PyObject* poSelf, PyObject* poArgs)
{
float fx;
if (!PyTuple_GetFloat(poArgs, 0, &fx))
return Py_BuildException();
float fy;
if (!PyTuple_GetFloat(poArgs, 1, &fy))
return Py_BuildException();
float fz;
if (!PyTuple_GetFloat(poArgs, 2, &fz))
return Py_BuildException();
float distance;
if (!PyTuple_GetFloat(poArgs, 3, &distance))
return Py_BuildException();
float pitch;
if (!PyTuple_GetFloat(poArgs, 4, &pitch))
return Py_BuildException();
float roll;
if (!PyTuple_GetFloat(poArgs, 5, &roll))
return Py_BuildException();
CPythonGraphic::Instance().SetPositionCamera(fx, fy, fz, distance, pitch, roll);
return Py_BuildNone();
}
PyObject* grpSetEyeCamera(PyObject* poSelf, PyObject* poArgs)
{
float xEye;
if (!PyTuple_GetFloat(poArgs, 0, &xEye))
return Py_BuildException();
float yEye;
if (!PyTuple_GetFloat(poArgs, 1, &yEye))
return Py_BuildException();
float zEye;
if (!PyTuple_GetFloat(poArgs, 2, &zEye))
return Py_BuildException();
float xCenter;
if (!PyTuple_GetFloat(poArgs, 3, &xCenter))
return Py_BuildException();
float yCenter;
if (!PyTuple_GetFloat(poArgs, 4, &yCenter))
return Py_BuildException();
float zCenter;
if (!PyTuple_GetFloat(poArgs, 5, &zCenter))
return Py_BuildException();
float xUp;
if (!PyTuple_GetFloat(poArgs, 6, &xUp))
return Py_BuildException();
float yUp;
if (!PyTuple_GetFloat(poArgs, 7, &yUp))
return Py_BuildException();
float zUp;
if (!PyTuple_GetFloat(poArgs, 8, &zUp))
return Py_BuildException();
CPythonGraphic::Instance().SetEyeCamera(xEye, yEye, zEye, xCenter, yCenter, zCenter, xUp, yUp, zUp);
return Py_BuildNone();
}
PyObject* grpSetPerspective(PyObject* poSelf, PyObject* poArgs)
{
float fov;
if (!PyTuple_GetFloat(poArgs, 0, &fov))
return Py_BuildException();
float aspect;
if (!PyTuple_GetFloat(poArgs, 1, &aspect))
return Py_BuildException();
float zNear;
if (!PyTuple_GetFloat(poArgs, 2, &zNear))
return Py_BuildException();
float zFar;
if (!PyTuple_GetFloat(poArgs, 3, &zFar))
return Py_BuildException();
CPythonGraphic::Instance().SetPerspective(fov, aspect, zNear, zFar);
return Py_BuildNone();
}
PyObject* grpSetOrtho2D(PyObject* poSelf, PyObject* poArgs)
{
float width;
if (!PyTuple_GetFloat(poArgs, 0, &width))
return Py_BuildException();
float height;
if (!PyTuple_GetFloat(poArgs, 1, &height))
return Py_BuildException();
float length;
if (!PyTuple_GetFloat(poArgs, 2, &length))
return Py_BuildException();
CPythonGraphic::Instance().SetOrtho2D(width, height, length);
return Py_BuildNone();
}
PyObject* grpSetOrtho3D(PyObject* poSelf, PyObject* poArgs)
{
float width;
if (!PyTuple_GetFloat(poArgs, 0, &width))
return Py_BuildException();
float height;
if (!PyTuple_GetFloat(poArgs, 1, &height))
return Py_BuildException();
float zmin;
if (!PyTuple_GetFloat(poArgs, 2, &zmin))
return Py_BuildException();
float zmax;
if (!PyTuple_GetFloat(poArgs, 3, &zmax))
return Py_BuildException();
CPythonGraphic::Instance().SetOrtho3D(width, height, zmin, zmax);
return Py_BuildNone();
}
PyObject* grpGenerateColor(PyObject* poSelf, PyObject* poArgs)
{
float r;
if (!PyTuple_GetFloat(poArgs, 0, &r))
return Py_BuildException();
float g;
if (!PyTuple_GetFloat(poArgs, 1, &g))
return Py_BuildException();
float b;
if (!PyTuple_GetFloat(poArgs, 2, &b))
return Py_BuildException();
float a;
if (!PyTuple_GetFloat(poArgs, 3, &a))
return Py_BuildException();
return Py_BuildValue("l", CPythonGraphic::Instance().GenerateColor(r, g, b, a));
}
PyObject* grpSetColor(PyObject* poSelf, PyObject* poArgs)
{
int color;
if (!PyTuple_GetInteger(poArgs, 0, &color))
return Py_BuildException();
CPythonGraphic::Instance().SetDiffuseColor(DWORD(color));
return Py_BuildNone();
}
PyObject* grpSetAlpha(PyObject* poSelf, PyObject* poArgs)
{
float Alpha;
if (!PyTuple_GetFloat(poArgs, 0, &Alpha))
return Py_BuildException();
//CPythonGraphic::Instance().SetAlpha(Alpha);
return Py_BuildNone();
}
PyObject* grpGetCursorPosition3d(PyObject * poSelf, PyObject * poArgs)
{
float x, y, z;
CPythonGraphic::Instance().GetCursorPosition(&x, &y, &z);
return Py_BuildValue("(fff)", x, y, z);
}
PyObject* grpSetCursorPosition(PyObject * poSelf, PyObject * poArgs)
{
int ix;
if (!PyTuple_GetInteger(poArgs, 0, &ix))
return Py_BuildException();
int iy;
if (!PyTuple_GetInteger(poArgs, 1, &iy))
return Py_BuildException();
CPythonGraphic::Instance().SetCursorPosition(ix, iy);
return Py_BuildNone();
}
PyObject* grpRenderLine(PyObject* poSelf, PyObject* poArgs)
{
int x;
if (!PyTuple_GetInteger(poArgs, 0, &x))
return Py_BuildException();
int y;
if (!PyTuple_GetInteger(poArgs, 1, &y))
return Py_BuildException();
int width;
if (!PyTuple_GetInteger(poArgs, 2, &width))
return Py_BuildException();
int height;
if (!PyTuple_GetInteger(poArgs, 3, &height))
return Py_BuildException();
CPythonGraphic::Instance().RenderLine2d((float) x, (float) y, (float) x+width, (float) y+height);
return Py_BuildNone();
}
PyObject* grpRenderRoundBox(PyObject* poSelf, PyObject* poArgs)
{
int x;
if (!PyTuple_GetInteger(poArgs, 0, &x))
return Py_BuildException();
int y;
if (!PyTuple_GetInteger(poArgs, 1, &y))
return Py_BuildException();
int width;
if (!PyTuple_GetInteger(poArgs, 2, &width))
return Py_BuildException();
int height;
if (!PyTuple_GetInteger(poArgs, 3, &height))
return Py_BuildException();
float fx = float(x);
float fy = float(y);
float fWidth = float(width);
float fHeight = float(height);
CPythonGraphic::Instance().RenderLine2d(fx+2.0f, fy, fx+2.0f + (fWidth-3.0f), fy);
CPythonGraphic::Instance().RenderLine2d(fx+2.0f, fy+fHeight, fx+2.0f + (fWidth-3.0f), fy+fHeight);
CPythonGraphic::Instance().RenderLine2d(fx, fy+2.0f, fx, fy+2.0f + fHeight-4.0f);
CPythonGraphic::Instance().RenderLine2d(fx+fWidth, fy+1.0f, fx+fWidth, fy+1.0f + fHeight-3.0f);
CPythonGraphic::Instance().RenderLine2d(fx, fy+2.0f, fx+2.0f, fy);
CPythonGraphic::Instance().RenderLine2d(fx, fy+fHeight-2.0f, fx+2.0f, fy+fHeight);
CPythonGraphic::Instance().RenderLine2d(fx+fWidth-2.0f, fy, fx+fWidth, fy+2.0f);
CPythonGraphic::Instance().RenderLine2d(fx+fWidth-2.0f, fy+fHeight, fx+fWidth, fy+fHeight-2.0f);
return Py_BuildNone();
}
PyObject* grpRenderBox(PyObject* poSelf, PyObject* poArgs)
{
int x;
if (!PyTuple_GetInteger(poArgs, 0, &x))
return Py_BuildException();
int y;
if (!PyTuple_GetInteger(poArgs, 1, &y))
return Py_BuildException();
int width;
if (!PyTuple_GetInteger(poArgs, 2, &width))
return Py_BuildException();
int height;
if (!PyTuple_GetInteger(poArgs, 3, &height))
return Py_BuildException();
CPythonGraphic::Instance().RenderBox2d((float) x, (float) y, (float) x+width, (float) y+height);
return Py_BuildNone();
}
PyObject* grpRenderBar(PyObject* poSelf, PyObject* poArgs)
{
int x;
if (!PyTuple_GetInteger(poArgs, 0, &x))
return Py_BuildException();
int y;
if (!PyTuple_GetInteger(poArgs, 1, &y))
return Py_BuildException();
int width;
if (!PyTuple_GetInteger(poArgs, 2, &width))
return Py_BuildException();
int height;
if (!PyTuple_GetInteger(poArgs, 3, &height))
return Py_BuildException();
CPythonGraphic::Instance().RenderBar2d((float) x, (float) y, (float) x+width, (float) y+height);
return Py_BuildNone();
}
PyObject* grpRenderCube(PyObject* poSelf, PyObject* poArgs)
{
float sx;
if (!PyTuple_GetFloat(poArgs, 0, &sx))
return Py_BuildException();
float sy;
if (!PyTuple_GetFloat(poArgs, 1, &sy))
return Py_BuildException();
float sz;
if (!PyTuple_GetFloat(poArgs, 2, &sz))
return Py_BuildException();
float ex;
if (!PyTuple_GetFloat(poArgs, 3, &ex))
return Py_BuildException();
float ey;
if (!PyTuple_GetFloat(poArgs, 4, &ey))
return Py_BuildException();
float ez;
if (!PyTuple_GetFloat(poArgs, 5, &ez))
return Py_BuildException();
CPythonGraphic::Instance().RenderCube(sx, sy, sz, ex, ey, ez);
return Py_BuildNone();
}
PyObject* grpRenderBar3d(PyObject* poSelf, PyObject* poArgs)
{
int sx;
if (!PyTuple_GetInteger(poArgs, 0, &sx))
return Py_BuildException();
int sy;
if (!PyTuple_GetInteger(poArgs, 1, &sy))
return Py_BuildException();
int sz;
if (!PyTuple_GetInteger(poArgs, 2, &sz))
return Py_BuildException();
int ex;
if (!PyTuple_GetInteger(poArgs, 3, &ex))
return Py_BuildException();
int ey;
if (!PyTuple_GetInteger(poArgs, 4, &ey))
return Py_BuildException();
int ez;
if (!PyTuple_GetInteger(poArgs, 5, &ez))
return Py_BuildException();
CPythonGraphic::Instance().RenderBar3d(sx, sy, sz, ex, ey, ez);
return Py_BuildNone();
}
PyObject * grpRenderGradationBar(PyObject* poSelf, PyObject* poArgs)
{
int x;
if (!PyTuple_GetInteger(poArgs, 0, &x))
return Py_BadArgument();
int y;
if (!PyTuple_GetInteger(poArgs, 1, &y))
return Py_BadArgument();
int width;
if (!PyTuple_GetInteger(poArgs, 2, &width))
return Py_BadArgument();
int height;
if (!PyTuple_GetInteger(poArgs, 3, &height))
return Py_BadArgument();
int iStartColor;
if (!PyTuple_GetInteger(poArgs, 4, &iStartColor))
return Py_BadArgument();
int iEndColor;
if (!PyTuple_GetInteger(poArgs, 5, &iEndColor))
return Py_BadArgument();
CPythonGraphic::Instance().RenderGradationBar2d((float)x, (float)y, (float)x+width, (float)y+height, iStartColor, iEndColor);
return Py_BuildNone();
}
PyObject* grpRenderDownButton(PyObject* poSelf, PyObject* poArgs)
{
int x;
if (!PyTuple_GetInteger(poArgs, 0, &x))
return Py_BuildException();
int y;
if (!PyTuple_GetInteger(poArgs, 1, &y))
return Py_BuildException();
int width;
if (!PyTuple_GetInteger(poArgs, 2, &width))
return Py_BuildException();
int height;
if (!PyTuple_GetInteger(poArgs, 3, &height))
return Py_BuildException();
CPythonGraphic::Instance().RenderDownButton((float) x, (float) y, (float) x+width, (float) y+height);
return Py_BuildNone();
}
PyObject* grpRenderUpButton(PyObject* poSelf, PyObject* poArgs)
{
int x;
if (!PyTuple_GetInteger(poArgs, 0, &x))
return Py_BuildException();
int y;
if (!PyTuple_GetInteger(poArgs, 1, &y))
return Py_BuildException();
int width;
if (!PyTuple_GetInteger(poArgs, 2, &width))
return Py_BuildException();
int height;
if (!PyTuple_GetInteger(poArgs, 3, &height))
return Py_BuildException();
CPythonGraphic::Instance().RenderUpButton((float) x, (float) y, (float) x+width, (float) y+height);
return Py_BuildNone();
}
PyObject* grpRenderBox3d(PyObject* poSelf, PyObject* poArgs)
{
float sx;
if (!PyTuple_GetFloat(poArgs, 0, &sx))
return Py_BuildException();
float sy;
if (!PyTuple_GetFloat(poArgs, 1, &sy))
return Py_BuildException();
float sz;
if (!PyTuple_GetFloat(poArgs, 2, &sz))
return Py_BuildException();
float ex;
if (!PyTuple_GetFloat(poArgs, 3, &ex))
return Py_BuildException();
float ey;
if (!PyTuple_GetFloat(poArgs, 4, &ey))
return Py_BuildException();
float ez;
if (!PyTuple_GetFloat(poArgs, 5, &ez))
return Py_BuildException();
CPythonGraphic::Instance().RenderBox3d((float) sx, (float) sy, (float) sz, (float) ex, (float) ey, (float) ez);
return Py_BuildNone();
}
PyObject * grpSetClearColor(PyObject * poSelf, PyObject * poArgs)
{
float fr;
if (!PyTuple_GetFloat(poArgs, 0, &fr))
return Py_BuildException();
float fg;
if (!PyTuple_GetFloat(poArgs, 1, &fg))
return Py_BuildException();
float fb;
if (!PyTuple_GetFloat(poArgs, 2, &fb))
return Py_BuildException();
CPythonGraphic::Instance().SetClearColor(fr, fg, fb, 1.0f);
return Py_BuildNone();
}
PyObject * grpSetDiffuseColor(PyObject * poSelf, PyObject * poArgs)
{
float r;
if (!PyTuple_GetFloat(poArgs, 0, &r))
return Py_BuildException();
float g;
if (!PyTuple_GetFloat(poArgs, 1, &g))
return Py_BuildException();
float b;
if (!PyTuple_GetFloat(poArgs, 2, &b))
return Py_BuildException();
float a;
if (!PyTuple_GetFloat(poArgs, 3, &a))
return Py_BuildException();
CPythonGraphic::Instance().SetDiffuseColor(r, g, b, a);
return Py_BuildNone();
}
PyObject * grpIdentity(PyObject * poSelf, PyObject * poArgs)
{
CPythonGraphic::Instance().Identity();
return Py_BuildNone();
}
PyObject * grpGetAvailableMemory(PyObject * poSelf, PyObject * poArgs)
{
int iValue = CPythonGraphic::Instance().GetAvailableMemory();
return Py_BuildValue("i", iValue);
}
// SCREENSHOT_CWDSAVE
PyObject * grpSaveScreenShotToPath(PyObject * poSelf, PyObject * poArgs)
{
char * szBasePath;
if (!PyTuple_GetString(poArgs, 0, &szBasePath))
return Py_BuildException();
struct tm * tmNow;
time_t ct;
ct = time(0);
tmNow = localtime(&ct);
char szPath[MAX_PATH + 256];
snprintf(szPath, sizeof(szPath), "%s%02d%02d_%02d%02d%02d.jpg",
szBasePath,
tmNow->tm_mon + 1,
tmNow->tm_mday,
tmNow->tm_hour,
tmNow->tm_min,
tmNow->tm_sec);
BOOL bResult = CPythonGraphic::Instance().SaveScreenShot(szPath);
return Py_BuildValue("(is)", bResult, szPath);
}
// END_OF_SCREENSHOT_CWDSAVE
PyObject * grpSaveScreenShot(PyObject * poSelf, PyObject * poArgs)
{
struct tm * tmNow;
time_t ct;
ct = time(0);
tmNow = localtime(&ct);
char szPath[MAX_PATH + 256];
SHGetSpecialFolderPath(NULL, szPath, CSIDL_PERSONAL, TRUE);
//GetTempPath();
strcat(szPath, "\\METIN2\\");
if (-1 == _access(szPath, 0))
if (!CreateDirectory(szPath, NULL))
{
TraceError("Failed to create directory [%s]\n", szPath);
return Py_BuildValue("(is)", FALSE, "");
}
sprintf(szPath + strlen(szPath), "%02d%02d_%02d%02d%02d.jpg",
tmNow->tm_mon + 1,
tmNow->tm_mday,
tmNow->tm_hour,
tmNow->tm_min,
tmNow->tm_sec);
BOOL bResult = CPythonGraphic::Instance().SaveScreenShot(szPath);
return Py_BuildValue("(is)", bResult, szPath);
}
PyObject * grpSetGamma(PyObject * poSelf, PyObject * poArgs)
{
float gamma;
if (!PyTuple_GetFloat(poArgs, 0, &gamma))
return Py_BuildException();
CPythonGraphic::Instance().SetGamma(gamma);
return Py_BuildNone();
}
PyObject * grpSetInterfaceRenderState(PyObject * poSelf, PyObject * poArgs)
{
CPythonGraphic::Instance().SetInterfaceRenderState();
return Py_BuildNone();
}
PyObject * grpSetGameRenderState(PyObject * poSelf, PyObject * poArgs)
{
CPythonGraphic::Instance().SetGameRenderState();
return Py_BuildNone();
}
PyObject * grpSetViewport(PyObject * poSelf, PyObject * poArgs)
{
float fx;
if (!PyTuple_GetFloat(poArgs, 0, &fx))
return Py_BuildException();
float fy;
if (!PyTuple_GetFloat(poArgs, 1, &fy))
return Py_BuildException();
float fWidth;
if (!PyTuple_GetFloat(poArgs, 2, &fWidth))
return Py_BuildException();
float fHeight;
if (!PyTuple_GetFloat(poArgs, 3, &fHeight))
return Py_BuildException();
UINT uWidth;
UINT uHeight;
CPythonGraphic::Instance().GetBackBufferSize(&uWidth, &uHeight);
CPythonGraphic::Instance().SetViewport(fx*uWidth, fy*uHeight, fWidth*uWidth, fHeight*uHeight);
return Py_BuildNone();
}
PyObject * grpRestoreViewport(PyObject * poSelf, PyObject * poArgs)
{
CPythonGraphic::Instance().RestoreViewport();
return Py_BuildNone();
}
PyObject * grpSetOmniLight(PyObject * poSelf, PyObject * poArgs)
{
CPythonGraphic::Instance().SetOmniLight();
return Py_BuildNone();
}
PyObject * grpGetCameraPosition(PyObject * poSelf, PyObject * poArgs)
{
D3DXVECTOR3 v3Eye = CCameraManager::Instance().GetCurrentCamera()->GetEye();
return Py_BuildValue("fff", v3Eye.x, v3Eye.y, v3Eye.z);
}
PyObject * grpGetTargetPosition(PyObject * poSelf, PyObject * poArgs)
{
D3DXVECTOR3 v3Target = CCameraManager::Instance().GetCurrentCamera()->GetTarget();
return Py_BuildValue("fff", v3Target.x, v3Target.y, v3Target.z);
}
void initgrp()
{
static PyMethodDef s_methods[] =
{
{ "InitScreenEffect", grpInitScreenEffect, METH_VARARGS },
{ "Culling", grpCulling, METH_VARARGS },
{ "ClearDepthBuffer", grpClearDepthBuffer, METH_VARARGS },
{ "Identity", grpIdentity, METH_VARARGS },
{ "GenerateColor", grpGenerateColor, METH_VARARGS },
{ "PopState", grpPopState, METH_VARARGS },
{ "PushState", grpPushState, METH_VARARGS },
{ "PushMatrix", grpPushMatrix, METH_VARARGS },
{ "PopMatrix", grpPopMatrix, METH_VARARGS },
{ "Translate", grpTranslate, METH_VARARGS },
{ "Rotate", grpRotate, METH_VARARGS },
{ "SetColorRenderState", grpSetColorRenderState, METH_VARARGS },
{ "SetAroundCamera", grpSetAroundCamera, METH_VARARGS },
{ "SetPositionCamera", grpSetPositionCamera, METH_VARARGS },
{ "SetEyeCamera", grpSetEyeCamera, METH_VARARGS },
{ "SetPerspective", grpSetPerspective, METH_VARARGS },
{ "SetOrtho2d", grpSetOrtho2D, METH_VARARGS },
{ "SetOrtho3d", grpSetOrtho3D, METH_VARARGS },
{ "SetColor", grpSetColor, METH_VARARGS },
{ "SetAlpha", grpSetAlpha, METH_VARARGS },
{ "SetDiffuseColor", grpSetDiffuseColor, METH_VARARGS },
{ "SetClearColor", grpSetClearColor, METH_VARARGS },
{ "GetCursorPosition3d", grpGetCursorPosition3d, METH_VARARGS },
{ "SetCursorPosition", grpSetCursorPosition, METH_VARARGS },
{ "RenderLine", grpRenderLine, METH_VARARGS },
{ "RenderBox", grpRenderBox, METH_VARARGS },
{ "RenderRoundBox", grpRenderRoundBox, METH_VARARGS },
{ "RenderBox3d", grpRenderBox3d, METH_VARARGS },
{ "RenderBar", grpRenderBar, METH_VARARGS },
{ "RenderBar3d", grpRenderBar3d, METH_VARARGS },
{ "RenderGradationBar", grpRenderGradationBar, METH_VARARGS },
{ "RenderCube", grpRenderCube, METH_VARARGS },
{ "RenderDownButton", grpRenderDownButton, METH_VARARGS },
{ "RenderUpButton", grpRenderUpButton, METH_VARARGS },
{ "GetAvailableMemory", grpGetAvailableMemory, METH_VARARGS },
{ "SaveScreenShot", grpSaveScreenShot, METH_VARARGS },
{ "SaveScreenShotToPath", grpSaveScreenShotToPath, METH_VARARGS },
{ "SetGamma", grpSetGamma, METH_VARARGS },
{ "SetInterfaceRenderState", grpSetInterfaceRenderState, METH_VARARGS },
{ "SetGameRenderState", grpSetGameRenderState, METH_VARARGS },
{ "SetViewport", grpSetViewport, METH_VARARGS },
{ "RestoreViewport", grpRestoreViewport, METH_VARARGS },
{ "SetOmniLight", grpSetOmniLight, METH_VARARGS },
{ "GetCameraPosition", grpGetCameraPosition, METH_VARARGS },
{ "GetTargetPosition", grpGetTargetPosition, METH_VARARGS },
{ "CreateTextBar", grpCreateTextBar, METH_VARARGS },
{ "CreateBigTextBar", grpCreateBigTextBar, METH_VARARGS },
{ "DestroyTextBar", grpDestroyTextBar, METH_VARARGS },
{ "RenderTextBar", grpRenderTextBar, METH_VARARGS },
{ "TextBarTextOut", grpTextBarTextOut, METH_VARARGS },
{ "TextBarSetTextColor", grpTextBarSetTextColor, METH_VARARGS },
{ "TextBarGetTextExtent", grpTextBarGetTextExtent, METH_VARARGS },
{ "ClearTextBar", grpClearTextBar, METH_VARARGS },
{ "SetTextBarClipRect", grpSetTextBarClipRect, METH_VARARGS },
{ NULL, NULL, NULL },
};
Py_InitModule("grp", s_methods);
}
@@ -0,0 +1,418 @@
#include "StdAfx.h"
#include "../common/PortPythonPointer.h" // PORT: preserve Win32 pointer handles on 64-bit hosts
bool PyTuple_GetTextInstance(PyObject* poArgs, int pos, CGraphicTextInstance** ppTextInstance)
{
return PyTuple_GetPointer(poArgs, pos, ppTextInstance) && *ppTextInstance;
}
PyObject* grpTextGenerate(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance * pTextInstance = CGraphicTextInstance::New();
return Py_BuildPointer(pTextInstance);
}
PyObject* grpTextDestroy(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
CGraphicTextInstance::Delete(pTextInstance);
return Py_BuildNone();
}
PyObject* grpTextGetSize(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
int width, height;
pTextInstance->GetTextSize(&width, &height);
return Py_BuildValue("(i, i)", width, height);
}
PyObject* grpTextSetPosition(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
int ix;
if (!PyTuple_GetInteger(poArgs, 1, &ix))
return Py_BuildException();
int iy;
if (!PyTuple_GetInteger(poArgs, 2, &iy))
return Py_BuildException();
pTextInstance->SetPosition((float) ix, (float) iy);
return Py_BuildNone();
}
PyObject* grpTextSetText(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
char* szText;
if (!PyTuple_GetString(poArgs, 1, &szText))
return Py_BuildException();
pTextInstance->SetValue(szText);
return Py_BuildNone();
}
PyObject* grpTextSetSecret(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
bool bValue;
if (!PyTuple_GetBoolean(poArgs, 1, &bValue))
return Py_BuildException();
pTextInstance->SetSecret(bValue);
return Py_BuildNone();
}
PyObject* grpTextOutline(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
bool bValue;
if (!PyTuple_GetBoolean(poArgs, 1, &bValue))
return Py_BuildException();
pTextInstance->SetOutline(bValue);
return Py_BuildNone();
}
PyObject* grpTextGetText(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
return Py_BuildValue("s", pTextInstance->GetValueStringReference().c_str());
}
PyObject* grpTextSetFontName(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
char* szFontName;
if (!PyTuple_GetString(poArgs, 1, &szFontName))
return Py_BuildException();
std::string stFontName = szFontName;
stFontName += ".fnt";
CResource* pResource = CResourceManager::Instance().GetResourcePointer(stFontName.c_str());
pTextInstance->SetTextPointer(static_cast<CGraphicText*>(pResource));
return Py_BuildNone();
}
PyObject* grpTextSetFontColor(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
if (2 == PyTuple_Size(poArgs))
{
int iColor;
if (!PyTuple_GetInteger(poArgs, 1, &iColor))
return Py_BuildException();
pTextInstance->SetColor(DWORD(iColor));
}
else if (4 == PyTuple_Size(poArgs))
{
float fRed;
if (!PyTuple_GetFloat(poArgs, 1, &fRed))
return Py_BuildException();
float fGreen;
if (!PyTuple_GetFloat(poArgs, 2, &fGreen))
return Py_BuildException();
float fBlue;
if (!PyTuple_GetFloat(poArgs, 3, &fBlue))
return Py_BuildException();
pTextInstance->SetColor(fRed, fGreen, fBlue);
}
else
{
return Py_BuildException();
}
return Py_BuildNone();
}
PyObject* grpTextSetOutLineColor(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
float fRed;
if (!PyTuple_GetFloat(poArgs, 1, &fRed))
return Py_BuildException();
float fGreen;
if (!PyTuple_GetFloat(poArgs, 2, &fGreen))
return Py_BuildException();
float fBlue;
if (!PyTuple_GetFloat(poArgs, 3, &fBlue))
return Py_BuildException();
float fAlpha;
if (!PyTuple_GetFloat(poArgs, 4, &fAlpha))
return Py_BuildException();
pTextInstance->SetOutLineColor(fRed, fGreen, fBlue, fAlpha);
return Py_BuildNone();
}
PyObject* grpTextRender(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
pTextInstance->Render();
return Py_BuildNone();
}
PyObject* grpTextUpdate(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
pTextInstance->Update();
return Py_BuildNone();
}
PyObject* grpTextShowCursor(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
pTextInstance->ShowCursor();
return Py_BuildNone();
}
PyObject* grpTextHideCursor(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
pTextInstance->HideCursor();
return Py_BuildNone();
}
PyObject* grpSetHorizontalAlign(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
int iAlign;
if (!PyTuple_GetInteger(poArgs, 1, &iAlign))
return Py_BuildException();
pTextInstance->SetHorizonalAlign(iAlign);
return Py_BuildNone();
}
PyObject* grpSetVerticalAlign(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
int iAlign;
if (!PyTuple_GetInteger(poArgs, 1, &iAlign))
return Py_BuildException();
pTextInstance->SetVerticalAlign(iAlign);
return Py_BuildNone();
}
PyObject* grpSetMax(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance* pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
int iValue;
if (!PyTuple_GetInteger(poArgs, 1, &iValue))
return Py_BuildException();
pTextInstance->SetMax(iValue);
return Py_BuildNone();
}
PyObject* grpGetSplitingTextLineCount(PyObject* poSelf, PyObject* poArgs)
{
char * szText;
if (!PyTuple_GetString(poArgs, 0, &szText))
return Py_BuildException();
int iLineLimitation;
if (!PyTuple_GetInteger(poArgs, 1, &iLineLimitation))
return Py_BuildException();
int iPosition = 0;
int iLineCount = 0;
for (DWORD i = 0; i < strlen(szText);)
{
if ('|' == szText[i])
{
i += 1;
// 자동 줄 바꿈되고 바로 | 가 있을 경우
if (iPosition>0)
++iLineCount;
iPosition = 0;
continue;
}
if (szText[i] & 0x80)
{
i += 2;
iPosition += 2;
}
else
{
i += 1;
iPosition += 1;
}
if (iPosition >= iLineLimitation)
{
++iLineCount;
iPosition = 0;
}
}
if (iPosition > 0)
++iLineCount;
return Py_BuildValue("i", iLineCount);
}
PyObject* grpGetSplitingTextLine(PyObject* poSelf, PyObject* poArgs)
{
char * szText;
if (!PyTuple_GetString(poArgs, 0, &szText))
return Py_BuildException();
int iLineLimitation;
if (!PyTuple_GetInteger(poArgs, 1, &iLineLimitation))
return Py_BuildException();
int iGettingLine;
if (!PyTuple_GetInteger(poArgs, 2, &iGettingLine))
return Py_BuildException();
std::string strLine = "";
int iPosition = 0;
int iLineCount = 0;
// 1차 : 조금 더 깔끔하게 안될까 -_-a
// 2차 : 오.. 좀 나아졌다 +_+
for (DWORD i = 0; i < strlen(szText);)
{
if ('|' == szText[i])
{
i += 1;
// 자동 줄 바꿈되고 바로 | 가 있을 경우
if (iPosition>0)
++iLineCount;
iPosition = 0;
continue;
}
if (szText[i] & 0x80)
{
if (iLineCount == iGettingLine)
strLine.append(szText+i, 2);
i += 2;
iPosition += 2;
}
else
{
if (iLineCount == iGettingLine)
strLine += szText[i];
i += 1;
iPosition += 1;
}
if (iPosition >= iLineLimitation)
{
++iLineCount;
iPosition = 0;
}
}
return Py_BuildValue("s", strLine.c_str());
}
PyObject* grpTextPixelPositionToCharacterPosition(PyObject* poSelf, PyObject* poArgs)
{
CGraphicTextInstance * pTextInstance;
if (!PyTuple_GetTextInstance(poArgs, 0, &pTextInstance))
return Py_BuildException();
int iPixelPosition;
if (!PyTuple_GetInteger(poArgs, 1, &iPixelPosition))
return Py_BuildException();
int iCharacterPosition = pTextInstance->PixelPositionToCharacterPosition(iPixelPosition);
return Py_BuildValue("i", iCharacterPosition);
}
void initgrpText()
{
static PyMethodDef s_methods[] =
{
{ "Update", grpTextUpdate, METH_VARARGS },
{ "Render", grpTextRender, METH_VARARGS },
{ "Generate", grpTextGenerate, METH_VARARGS },
{ "Destroy", grpTextDestroy, METH_VARARGS },
{ "SetFontName", grpTextSetFontName, METH_VARARGS },
{ "SetFontColor", grpTextSetFontColor, METH_VARARGS },
{ "SetOutLineColor", grpTextSetOutLineColor, METH_VARARGS },
{ "SetSecret", grpTextSetSecret, METH_VARARGS },
{ "SetOutline", grpTextOutline, METH_VARARGS },
{ "SetText", grpTextSetText, METH_VARARGS },
{ "GetText", grpTextGetText, METH_VARARGS },
{ "GetSize", grpTextGetSize, METH_VARARGS },
{ "SetPosition", grpTextSetPosition, METH_VARARGS },
{ "ShowCursor", grpTextShowCursor, METH_VARARGS },
{ "HideCursor", grpTextHideCursor, METH_VARARGS },
{ "SetHorizontalAlign", grpSetHorizontalAlign, METH_VARARGS },
{ "SetVerticalAlign", grpSetVerticalAlign, METH_VARARGS },
{ "SetMax", grpSetMax, METH_VARARGS },
{ "GetSplitingTextLineCount", grpGetSplitingTextLineCount, METH_VARARGS },
{ "GetSplitingTextLine", grpGetSplitingTextLine, METH_VARARGS },
{ "PixelPositionToCharacterPosition", grpTextPixelPositionToCharacterPosition, METH_VARARGS },
{ NULL, NULL, NULL },
};
Py_InitModule("grpText", s_methods);
}
@@ -0,0 +1,157 @@
#include "StdAfx.h"
#include "../common/PortPythonPointer.h" // PORT: preserve Win32 pointer handles on 64-bit hosts
bool PyTuple_GetThingInstance(PyObject* poArgs, int pos, CGraphicThingInstance** ppRetThingInstance)
{
return PyTuple_GetPointer(poArgs, pos, ppRetThingInstance) && *ppRetThingInstance;
}
PyObject* grpThingGenerate(PyObject* poSelf, PyObject* poArgs)
{
char * szFileName;
if (!PyTuple_GetString(poArgs, 0, &szFileName))
return Py_BuildException();
if (strlen(szFileName) <= 0)
return Py_BuildValue("i", 0);
CResource* pResource = CResourceManager::Instance().GetResourcePointer(szFileName);
if (!pResource->IsType(CGraphicThing::Type()))
return Py_BuildException();
CGraphicThingInstance * pThingInstance = CGraphicThingInstance::New();
pThingInstance->ReserveModelThing(1);
pThingInstance->ReserveModelInstance(1);
pThingInstance->RegisterModelThing(0, static_cast<CGraphicThing*>(pResource));
pThingInstance->SetModelInstance(0, 0, 0);
return Py_BuildPointer(pThingInstance);
}
PyObject* grpThingDelete(PyObject* poSelf, PyObject* poArgs)
{
CGraphicThingInstance * pThingInstance;
if (!PyTuple_GetThingInstance(poArgs, 0, &pThingInstance))
return Py_BuildException();
CGraphicThingInstance::Delete(pThingInstance);
return Py_BuildNone();
}
PyObject* grpThingSetFileName(PyObject* poSelf, PyObject* poArgs)
{
CGraphicThingInstance * pThingInstance;
if (!PyTuple_GetThingInstance(poArgs, 0, &pThingInstance))
return Py_BuildException();
char* szFileName;
if (!PyTuple_GetString(poArgs, 1, &szFileName))
return Py_BuildException();
CResource* pResource = CResourceManager::Instance().GetResourcePointer(szFileName);
if (!pResource->IsType(CGraphicThing::Type()))
return Py_BuildException();
pThingInstance->Clear();
pThingInstance->ReserveModelThing(1);
pThingInstance->ReserveModelInstance(1);
pThingInstance->RegisterModelThing(0, static_cast<CGraphicThing*>(pResource));
pThingInstance->SetModelInstance(0, 0, 0);
return Py_BuildNone();
}
PyObject* grpThingRender(PyObject* poSelf, PyObject* poArgs)
{
CGraphicThingInstance* pThingInstance;
if (!PyTuple_GetThingInstance(poArgs, 0, &pThingInstance))
return Py_BuildException();
pThingInstance->Render();
return Py_BuildNone();
}
PyObject* grpThingUpdate(PyObject* poSelf, PyObject* poArgs)
{
CGraphicThingInstance* pThingInstance;
if (!PyTuple_GetThingInstance(poArgs, 0, &pThingInstance))
return Py_BuildException();
pThingInstance->Update();
pThingInstance->Deform();
return Py_BuildNone();
}
PyObject * grpSetThingPosition(PyObject * poSelf, PyObject * poArgs)
{
CGraphicThingInstance* pThingInstance;
if (!PyTuple_GetThingInstance(poArgs, 0, &pThingInstance))
return Py_BuildException();
float x;
if (!PyTuple_GetFloat(poArgs, 1, &x))
return Py_BuildException();
float y;
if (!PyTuple_GetFloat(poArgs, 2, &y))
return Py_BuildException();
float z;
if (!PyTuple_GetFloat(poArgs, 3, &z))
return Py_BuildException();
pThingInstance->SetPosition(x, y, z);
return Py_BuildNone();
}
PyObject * grpSetThingRotation(PyObject * poSelf, PyObject * poArgs)
{
CGraphicThingInstance* pThingInstance;
if (!PyTuple_GetThingInstance(poArgs, 0, &pThingInstance))
return Py_BuildException();
float fDegree;
if (!PyTuple_GetFloat(poArgs, 1, &fDegree))
return Py_BuildException();
pThingInstance->SetRotation(fDegree);
return Py_BuildNone();
}
PyObject * grpSetThingScale(PyObject * poSelf, PyObject * poArgs)
{
CGraphicThingInstance* pThingInstance;
if (!PyTuple_GetThingInstance(poArgs, 0, &pThingInstance))
return Py_BuildException();
float x;
if (!PyTuple_GetFloat(poArgs, 1, &x))
return Py_BuildException();
float y;
if (!PyTuple_GetFloat(poArgs, 2, &y))
return Py_BuildException();
float z;
if (!PyTuple_GetFloat(poArgs, 3, &z))
return Py_BuildException();
pThingInstance->SetScale(x, y, z);
return Py_BuildNone();
}
void initgrpThing()
{
static PyMethodDef s_methods[] =
{
{ "Update", grpThingUpdate, METH_VARARGS },
{ "Render", grpThingRender, METH_VARARGS },
{ "SetPosition", grpSetThingPosition, METH_VARARGS },
{ "Generate", grpThingGenerate, METH_VARARGS },
{ "Delete", grpThingDelete, METH_VARARGS },
{ "SetFileName", grpThingSetFileName, METH_VARARGS },
{ "SetRotation", grpSetThingRotation, METH_VARARGS },
{ "SetScale", grpSetThingScale, METH_VARARGS },
{ NULL, NULL, NULL },
};
Py_InitModule("grpThing", s_methods);
}
File diff suppressed because it is too large Load Diff