Merge pull request #194 from halx99/ImGuiEXT

Add Extension ImGui
This commit is contained in:
HALX99 2020-09-04 04:24:01 -07:00 committed by GitHub
commit e3e3352440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 48547 additions and 686 deletions

View File

@ -1,19 +1,12 @@
language: cpp
matrix:
include:
# linux
#- os: linux
# dist: xenial
# env:
# - BUILD_TARGET=linux
# - GEN_BINDING_AND_COCOSFILE=true
# sudo: required
# language: cpp
# mac_cmake
# - os: osx
# env: BUILD_TARGET=mac_cmake
# language: cpp
# osx_image: xcode10.3
# sudo: required
- os: osx
env: BUILD_TARGET=mac_cmake
language: cpp
osx_image: xcode11
sudo: required
# iOS_cmake
- os: osx
env: BUILD_TARGET=ios_cmake

View File

@ -2,40 +2,11 @@
NS_CC_MATH_BEGIN
/**
* Constructor instantiates a new Mat3 object. The initial
* values for the matrix is that of the identity matrix.
*
*
*/
Mat3::Mat3() {
Mat3::Mat3()
{
loadIdentity();
}
/**
* constructs a matrix with the given values.
*
* @param m[0]
* 0x0 in the matrix.
* @param m[1]
* 0x1 in the matrix.
* @param m[2]
* 0x2 in the matrix.
* @param m[3]
* 1x0 in the matrix.
* @param m[4]
* 1x1 in the matrix.
* @param m[5]
* 1x2 in the matrix.
* @param m[6]
* 2x0 in the matrix.
* @param m[7]
* 2x1 in the matrix.
* @param m[8]
* 2x2 in the matrix.
*/
Mat3::Mat3(float m[9]) {
this->m[0] = m[0];
@ -45,22 +16,10 @@ Mat3::Mat3(float m[9]) {
this->m[4] = m[4];
this->m[5] = m[5];
this->m[6] = m[6];
this->m[8] = m[7];
this->m[9] = m[8];
this->m[7] = m[7];
this->m[8] = m[8];
}
/**
* get retrieves a value from the matrix at the given position.
* If the position is invalid a JmeException is thrown.
*
*
* @param i
* the row index.012
* @param j
* the colum index.012
* @return the value at (i, j).
*/
float Mat3::get(int i, int j) {
switch (i) {
case 0:
@ -96,19 +55,6 @@ float Mat3::get(int i, int j) {
// throw new JmeException("Invalid indices into matrix.");
}
/**
* getColumn returns one of three columns specified by the
* parameter. This column is returned as a cocos2d::Vec3 object.
*
*
* @param i
* the column to retrieve. Must be between 0 and 2.
* @param store
* the vector object to store the result in. if null, a new one
* is created.
* @return the column specified by the index.
*/
cocos2d::Vec3 Mat3::getColumn(int i) {
cocos2d::Vec3 store;
switch (i) {
@ -134,19 +80,6 @@ cocos2d::Vec3 Mat3::getColumn(int i) {
return store;
}
/**
* getRow returns one of three rows as specified by the
* parameter. This row is returned as a cocos2d::Vec3 object.
*
*
* @param i
* the row to retrieve. Must be between 0 and 2.
* @param store
* the vector object to store the result in. if null, a new one
* is created.
* @return the row specified by the index.
*/
cocos2d::Vec3 Mat3::getRow(int i) {
cocos2d::Vec3 store;
switch (i) {
@ -175,18 +108,6 @@ std::string Mat3::toString() {
return "";
}
/**
*
* setColumn sets a particular column of this matrix to that
* represented by the provided vector.
*
*
* @param i
* the column to set.
* @param column
* the data to set.
*/
void Mat3::setColumn(int i, const cocos2d::Vec3& column) {
switch (i) {
@ -211,18 +132,6 @@ void Mat3::setColumn(int i, const cocos2d::Vec3& column) {
}
}
/**
*
* setRow sets a particular row of this matrix to that
* represented by the provided vector.
*
*
* @param i
* the row to set.
* @param row
* the data to set.
*/
void Mat3::setRow(int i, const cocos2d::Vec3& row) {
switch (i) {
case 0:
@ -246,20 +155,6 @@ void Mat3::setRow(int i, const cocos2d::Vec3& row) {
}
}
/**
* set places a given value into the matrix at the given
* position. If the position is invalid a JmeException is
* thrown.
*
*
* @param i
* the row index.
* @param j
* the colum index.
* @param value
* the value for (i, j).
*/
void Mat3::set(int i, int j, float value) {
switch (i) {
case 0:
@ -304,18 +199,6 @@ void Mat3::set(int i, int j, float value) {
//throw new JmeException("Invalid indices into matrix.");
}
/**
*
* set sets the values of the matrix to those supplied by the
* 3x3 two dimenion array.
*
*
* @param matrix
* the new values of the matrix.
* @throws JmeException
* if the array is not of size 9.
*/
void Mat3::set(float matrix[3][3]) {
//if (matrix.length != 3 || matrix[0].length != 3) {
// throw new JmeException("Array must be of size 9.");
@ -332,18 +215,6 @@ void Mat3::set(float matrix[3][3]) {
m[8] = matrix[2][2];
}
/**
* Recreate Matrix using the provided axis.
*
*
* @param uAxis
* cocos2d::Vec3
* @param vAxis
* cocos2d::Vec3
* @param wAxis
* cocos2d::Vec3
*/
void Mat3::set(const cocos2d::Vec3& uAxis, const cocos2d::Vec3& vAxis, const cocos2d::Vec3& wAxis) {
m[0] = uAxis.x;
m[3] = uAxis.y;
@ -358,16 +229,6 @@ void Mat3::set(const cocos2d::Vec3& uAxis, const cocos2d::Vec3& vAxis, const coc
m[8] = wAxis.z;
}
/**
* set sets the values of this matrix from an array of values;
*
*
* @param matrix
* the matrix to set the value to.
* @param rowMajor
* whether the incoming data is in row or column major order.
*/
void Mat3::set(float matrix[9], bool rowMajor) {
//if (matrix.length != 9)
// throw new JmeException("Array must be of size 9.");
@ -396,80 +257,6 @@ void Mat3::set(float matrix[9], bool rowMajor) {
}
}
/**
* fromAngleNormalAxis sets this matrix4f to the values
* specified by an angle and a normalized axis of rotation.
* axisangle3D旋转矩阵
*
* @param angle
* the angle to rotate (in radians).
* @param axis
* the axis of rotation (already normalized).
*/
/**
* Creates a matrix describing a rotation around the z-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
/**
* Creates a matrix describing a rotation around the y-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
/**
* Creates a matrix describing a rotation around the x-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
/**
* Creates a matrix describing a rotation around the z-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
/**
* Creates a matrix describing a rotation around the y-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
/**
* Creates a matrix describing a rotation around the x-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
/**
*
*
* @return true if this matrix is identity
*/
/**
* loadIdentity sets this matrix to the identity matrix. Where
* all values are zero except those along the diagonal which are one.
*
*
*/
void Mat3::loadIdentity() {
m[1] = m[2] = m[3] = m[5] = m[6] = m[7] = 0;
m[0] = m[4] = m[8] = 1;
@ -559,13 +346,6 @@ void Mat3::createRotation(const cocos2d::Vec3& axis, float fSin, float fCos) {
m[8] = fZ2 * fOneMinusCos + fCos;
}
/**
* Creates a matrix describing a rotation around the x-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
void Mat3::createRotationX(float s, float c)
{
m[4] = c;
@ -574,13 +354,6 @@ void Mat3::createRotationX(float s, float c)
m[8] = c;
}
/**
* Creates a matrix describing a rotation around the y-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
void Mat3::createRotationY(float s, float c)
{
m[0] = c;
@ -589,13 +362,6 @@ void Mat3::createRotationY(float s, float c)
m[8] = c;
}
/**
* Creates a matrix describing a rotation around the z-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
void Mat3::createRotationZ(float s, float c)
{
m[0] = c;
@ -633,16 +399,6 @@ Mat3& Mat3::mult(const Mat3& mat, Mat3& product) const
return product;
}
/**
* Multiplies this 3x3 matrix by the 1x3 Vector vec and stores the result in
* product.
* product中
*
* @param vec
* The cocos2d::Vec3 to multiply.
* @return The given product vector.
*/
cocos2d::Vec3 Mat3::mult(const cocos2d::Vec3& vec) const {
cocos2d::Vec3 product;
@ -658,16 +414,6 @@ cocos2d::Vec3 Mat3::mult(const cocos2d::Vec3& vec) const {
return product;
}
/**
* multLocal multiplies this matrix internally by a given float
* scale factor.
*
*
* @param scale
* the value to scale by.
* @return this Mat3
*/
Mat3& Mat3::multLocal(float scale) {
m[0] *= scale;
m[1] *= scale;
@ -681,14 +427,6 @@ Mat3& Mat3::multLocal(float scale) {
return *this;
}
/**
* add adds the values of a parameter matrix to this matrix.
*
*
* @param mat
* the matrix to add to this.
*/
Mat3& Mat3::addLocal(const Mat3& mat) {
m[0] += mat.m[0];
m[1] += mat.m[1];
@ -702,13 +440,6 @@ Mat3& Mat3::addLocal(const Mat3& mat) {
return *this;
}
/**
* Transposes this matrix in place. Returns this matrix for chaining
*
*
* @return This matrix after transpose
*/
Mat3& Mat3::transposeLocal() {
float tmp[9];
get(tmp, false);
@ -716,13 +447,6 @@ Mat3& Mat3::transposeLocal() {
return *this;
}
/**
* Inverts this matrix and stores it in the given store.
*
*
* @return The store
*/
Mat3 Mat3::invertNew(void) {
Mat3 store;
float det = determinant();
@ -743,13 +467,6 @@ Mat3 Mat3::invertNew(void) {
return store;
}
/**
* Inverts this matrix locally.
*
*
* @return this
*/
Mat3& Mat3::invertLocal() {
float det = determinant();
if (std::abs(det) <= FLT_EPSILON)
@ -779,16 +496,6 @@ Mat3& Mat3::invertLocal() {
return *this;
}
/**
* Places the adjoint of this matrix in store (creates store if null.)
*
*
* @param store
* The matrix to store the result in. If null, a new matrix is
* created.
* @return store
*/
Mat3 Mat3::adjoint() {
Mat3 store;
@ -805,13 +512,6 @@ Mat3 Mat3::adjoint() {
return store;
}
/**
* determinant generates the determinate of this matrix.
*
*
* @return the determinate
*/
float Mat3::determinant() {
float fCo00 = m[4] * m[8] - m[5] * m[7];
float fCo10 = m[5] * m[6] - m[3] * m[8];
@ -820,56 +520,20 @@ float Mat3::determinant() {
return fDet;
}
/**
* Sets all of the values in this matrix to zero.
* 0
*
* @return this matrix
*/
Mat3& Mat3::zero() {
m[0] = m[1] = m[2] = m[3] = m[4] = m[5] = m[6] = m[7] = m[8] = 0.0f;
return *this;
}
/**
* transposeNew returns a transposed version of this matrix.
*
*
* @return The new Mat3 object.
*/
Mat3 Mat3::transposeNew() {
float temp[9] = { m[0], m[3], m[6], m[1], m[4], m[7], m[2], m[5], m[8] };
return Mat3(temp);
}
/**
* are these two matrices the same? they are is they both have the same mXX
* values.
*
* @param o
* the object to compare for equality
* @return true if they are equal
*/
bool Mat3::equals(const Mat3& o) const {
return memcmp(&o, this, sizeof(o)) == 0;
}
/**
* A function for creating a rotation matrix that rotates a vector called
* "start" into another vector called "end".
* start旋转到end
*
* @param start
* normalized non-zero starting vector
* @param end
* normalized non-zero ending vector
* @see "Tomas M?ller, John Hughes /"Efficiently Building a Matrix to Rotate
* / One Vector to Another/" Journal of Graphics Tools, 4(4):1-4, 1999"
*/
void Mat3::fromStartEndVectors(cocos2d::Vec3 start, cocos2d::Vec3 end) {
cocos2d::Vec3 v;
float e, h, f;
@ -954,15 +618,6 @@ void Mat3::fromStartEndVectors(cocos2d::Vec3 start, cocos2d::Vec3 end) {
}
}
/**
* scale scales the operation performed by this matrix on a
* per-component basis.
*
*
* @param scale
* The scale applied to each of the X, Y and Z output values.
*/
void Mat3::scale(const cocos2d::Vec3& scale) {
m[0] *= scale.x;
m[3] *= scale.x;

View File

@ -7,7 +7,7 @@
* @autohr HALX99 2016
* @author Mark Powell
* @author Joshua Slack
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
@ -33,7 +33,6 @@ public:
/**
* Constructor instantiates a new Mat3 object. The initial
* values for the matrix is that of the identity matrix.
*
*
*/
Mat3();
@ -61,16 +60,15 @@ public:
* 2x2 in the matrix.
*/
Mat3(float m[9]);
/**
* get retrieves a value from the matrix at the given position.
* If the position is invalid a JmeException is thrown.
*
*
* @param i
* the row index.012
* the row index.(0,1,2)
* @param j
* the colum index.012
* the colum index(0,1,2)
* @return the value at (i, j).
*/
float get(int i, int j);
@ -78,7 +76,6 @@ public:
/**
* get(float[]) returns the matrix in row-major or column-major
* order.
* data数组中
*
* @param data
* The array to return the data into. This array can be 9 or 16
@ -147,7 +144,6 @@ public:
/**
* getColumn returns one of three columns specified by the
* parameter. This column is returned as a cocos2d::Vec3 object.
*
*
* @param i
* the column to retrieve. Must be between 0 and 2.
@ -162,7 +158,6 @@ public:
/**
* getRow returns one of three rows as specified by the
* parameter. This row is returned as a cocos2d::Vec3 object.
*
*
* @param i
* the row to retrieve. Must be between 0 and 2.
@ -180,7 +175,6 @@ public:
*
* setColumn sets a particular column of this matrix to that
* represented by the provided vector.
*
*
* @param i
* the column to set.
@ -193,7 +187,6 @@ public:
*
* setRow sets a particular row of this matrix to that
* represented by the provided vector.
*
*
* @param i
* the row to set.
@ -206,7 +199,6 @@ public:
* set places a given value into the matrix at the given
* position. If the position is invalid a JmeException is
* thrown.
*
*
* @param i
* the row index.
@ -221,7 +213,6 @@ public:
*
* set sets the values of the matrix to those supplied by the
* 3x3 two dimenion array.
*
*
* @param matrix
* the new values of the matrix.
@ -232,7 +223,6 @@ public:
/**
* Recreate Matrix using the provided axis.
*
*
* @param uAxis
* cocos2d::Vec3
@ -246,7 +236,6 @@ public:
/**
* set sets the values of this matrix from an array of values
* assuming that the data is rowMajor order;
*
*
* @param matrix
* the matrix to set the value to.
@ -257,7 +246,6 @@ public:
/**
* set sets the values of this matrix from an array of values;
*
*
* @param matrix
* the matrix to set the value to.
@ -271,7 +259,6 @@ public:
* set defines the values of the matrix based on a supplied
* Quaternion. It should be noted that all previous values will
* be overridden.
*
*
* @param quaternion
* the quaternion to create a rotational matrix from.
@ -283,13 +270,11 @@ public:
/**
* loadIdentity sets this matrix to the identity matrix. Where
* all values are zero except those along the diagonal which are one.
*
*
*/
void loadIdentity();
/**
*
*
* @return true if this matrix is identity
*/
@ -318,13 +303,13 @@ public:
* @param dst A matrix to store the result in.
*/
void rotateZ(float angle);
/**
* Creates a matrix describing a rotation around the x-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
/**
* Creates a matrix describing a rotation around the x-axis.
*
* @param angle The angle of rotation (in radians).
* @param dst A matrix to store the result in.
*/
void rotateX(float s, float c);
/**
@ -361,7 +346,6 @@ public:
/**
* fromAngleNormalAxis sets this matrix4f to the values
* specified by an angle and a normalized axis of rotation.
* axisangle3D旋转矩阵
*
* @param angle
* the angle to rotate (in radians).
@ -369,7 +353,7 @@ public:
* the axis of rotation (already normalized).
*/
void createRotation(const cocos2d::Vec3& axis, float fSin, float fCos);
/**
* Creates a matrix describing a rotation around the x-axis.
*
@ -393,7 +377,7 @@ public:
* @param dst A matrix to store the result in.
*/
void createRotationZ(float s, float c);
/**
* Creates a scale matrix.
*
@ -428,12 +412,11 @@ public:
* @param zTranslation The translation on the z-axis.
* @param dst A matrix to store the result in.
*/
void createTranslation(float xTranslation, float yTranslation, float zTranslation);
void createTranslation(float xTranslation, float yTranslation, float zTranslation);
/**
* mult multiplies this matrix by a given matrix. The result
* matrix is returned as a new object.
* product中
*
* @param mat
* the matrix to multiply this matrix by.
@ -442,22 +425,21 @@ public:
* created. It is safe for mat and product to be the same object.
* @return a Mat3 object containing the result of this operation
*/
Mat3& mult(const Mat3& mat) {
Mat3& mult(const Mat3& mat) {
return mult(mat, *this);
}
Mat3& mult(const Mat3& mat, Mat3& product) const;
Mat3& mult(const Mat3& mat, Mat3& product) const;
/**
* Multiplies this 3x3 matrix by the 1x3 Vector vec and stores the result in
* product.
* product中
*
* @param vec
* The cocos2d::Vec3 to multiply.
* @return The given product vector.
*/
cocos2d::Vec3 mult(const cocos2d::Vec3& vec) const;
cocos2d::Vec3 mult(const cocos2d::Vec3& vec) const;
Mat3& premultAlpha(float alpha) {
return multLocal(alpha);
@ -466,7 +448,6 @@ public:
/**
* multLocal multiplies this matrix internally by a given float
* scale factor.
*
*
* @param scale
* the value to scale by.
@ -476,7 +457,6 @@ public:
/**
* add adds the values of a parameter matrix to this matrix.
*
*
* @param mat
* the matrix to add to this.
@ -488,28 +468,25 @@ public:
* matrix is saved in the current matrix. If the given matrix is null,
* nothing happens. The current matrix is returned. This is equivalent to
* this*=mat
*
*
* @param mat
* the matrix to multiply this matrix by.
* @return This matrix, after the multiplication
*/
/*void multLocal() {
/*void multLocal() {
return mult(mat, this);
}*/
return mult(mat, this);
}*/
/**
* Transposes this matrix in place. Returns this matrix for chaining
*
*
* @return This matrix after transpose
*/
/**
* Transposes this matrix in place. Returns this matrix for chaining
*
* @return This matrix after transpose
*/
Mat3& transposeLocal();
/**
* Inverts this matrix and stores it in the given store.
*
*
* @return The store
*/
@ -517,7 +494,6 @@ public:
/**
* Inverts this matrix locally.
*
*
* @return this
*/
@ -526,7 +502,6 @@ public:
/**
* Places the adjoint of this matrix in store (creates store if null.)
*
*
* @param store
* The matrix to store the result in. If null, a new matrix is
@ -537,7 +512,6 @@ public:
/**
* determinant generates the determinate of this matrix.
*
*
* @return the determinate
*/
@ -545,7 +519,6 @@ public:
/**
* Sets all of the values in this matrix to zero.
* 0
*
* @return this matrix
*/
@ -553,7 +526,6 @@ public:
/**
* transposeNew returns a transposed version of this matrix.
*
*
* @return The new Mat3 object.
*/
@ -572,7 +544,6 @@ public:
/**
* A function for creating a rotation matrix that rotates a vector called
* "start" into another vector called "end".
* start旋转到end
*
* @param start
* normalized non-zero starting vector
@ -586,7 +557,6 @@ public:
/**
* scale scales the operation performed by this matrix on a
* per-component basis.
*
*
* @param scale
* The scale applied to each of the X, Y and Z output values.

View File

@ -47,6 +47,90 @@ THE SOFTWARE.
NS_CC_BEGIN
class GLFWEventHandler
{
public:
static void onGLFWError(int errorID, const char* errorDesc)
{
if (_view)
_view->onGLFWError(errorID, errorDesc);
}
static void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
{
if (_view)
_view->onGLFWMouseCallBack(window, button, action, modify);
}
static void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
{
if (_view)
_view->onGLFWMouseMoveCallBack(window, x, y);
}
static void onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
{
if (_view)
_view->onGLFWMouseScrollCallback(window, x, y);
}
static void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (_view)
_view->onGLFWKeyCallback(window, key, scancode, action, mods);
}
static void onGLFWCharCallback(GLFWwindow* window, unsigned int character)
{
if (_view)
_view->onGLFWCharCallback(window, character);
}
static void onGLFWWindowPosCallback(GLFWwindow* windows, int x, int y)
{
if (_view)
_view->onGLFWWindowPosCallback(windows, x, y);
}
// Notes: Unused on windows or macos Metal renderer backend
// static void onGLFWframebufferSize(GLFWwindow* window, int w, int h)
// {
// if (_view)
// _view->onGLFWframebufferSize(window, w, h);
// }
static void onGLFWWindowSizeCallback(GLFWwindow *window, int width, int height)
{
if (_view)
_view->onGLFWWindowSizeCallback(window, width, height);
}
static void setGLViewImpl(GLViewImpl* view)
{
_view = view;
}
static void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified)
{
if (_view)
{
_view->onGLFWWindowIconifyCallback(window, iconified);
}
}
static void onGLFWWindowFocusCallback(GLFWwindow* window, int focused)
{
if (_view)
{
_view->onGLFWWindowFocusCallback(window, focused);
}
}
private:
static GLViewImpl* _view;
};
GLViewImpl* GLFWEventHandler::_view = nullptr;
const std::string GLViewImpl::EVENT_WINDOW_RESIZED = "glview_window_resized";
const std::string GLViewImpl::EVENT_WINDOW_FOCUSED = "glview_window_focused";
const std::string GLViewImpl::EVENT_WINDOW_UNFOCUSED = "glview_window_unfocused";
@ -192,91 +276,6 @@ static keyCodeItem g_keyCodeStructArray[] = {
};
//////////////////////////////////////////////////////////////////////////
// GLFW Event forward handler
//////////////////////////////////////////////////////////////////////////
class GLFWEventHandler
{
public:
static void onGLFWError(int errorID, const char* errorDesc)
{
if (_view)
_view->onGLFWError(errorID, errorDesc);
}
static void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
{
if (_view)
_view->onGLFWMouseCallBack(window, button, action, modify);
}
static void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
{
if (_view)
_view->onGLFWMouseMoveCallBack(window, x, y);
}
static void onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
{
if (_view)
_view->onGLFWMouseScrollCallback(window, x, y);
}
static void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (_view)
_view->onGLFWKeyCallback(window, key, scancode, action, mods);
}
static void onGLFWCharCallback(GLFWwindow* window, unsigned int character)
{
if (_view)
_view->onGLFWCharCallback(window, character);
}
static void onGLFWWindowPosCallback(GLFWwindow* windows, int x, int y)
{
if (_view)
_view->onGLFWWindowPosCallback(windows, x, y);
}
static void onGLFWFrameBufferSizeCallback(GLFWwindow* window, int w, int h)
{
if (_view)
_view->onGLFWFramebufferSizeCallback(window, w, h);
}
static void onGLFWWindowSizeCallback(GLFWwindow* window, int width, int height)
{
if (_view)
_view->onGLFWWindowSizeCallback(window, width, height);
}
static void setGLViewImpl(GLViewImpl* view)
{
_view = view;
}
static void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified)
{
if (_view)
{
_view->onGLFWWindowIconifyCallback(window, iconified);
}
}
static void onGLFWWindowFocusCallback(GLFWwindow* window, int focused)
{
if (_view)
{
_view->onGLFWWindowFocusCallback(window, focused);
}
}
private:
static GLViewImpl* _view;
};
GLViewImpl* GLFWEventHandler::_view = nullptr;
// implement GLViewImpl
//////////////////////////////////////////////////////////////////////////
@ -441,7 +440,6 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
glfwSetCharCallback(_mainWindow, GLFWEventHandler::onGLFWCharCallback);
glfwSetKeyCallback(_mainWindow, GLFWEventHandler::onGLFWKeyCallback);
glfwSetWindowPosCallback(_mainWindow, GLFWEventHandler::onGLFWWindowPosCallback);
glfwSetFramebufferSizeCallback(_mainWindow, GLFWEventHandler::onGLFWFrameBufferSizeCallback);
glfwSetWindowSizeCallback(_mainWindow, GLFWEventHandler::onGLFWWindowSizeCallback);
glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback);
glfwSetWindowFocusCallback(_mainWindow, GLFWEventHandler::onGLFWWindowFocusCallback);
@ -805,7 +803,6 @@ void GLViewImpl::setScissorInPoints(float x , float y , float w , float h)
auto height1 = (unsigned int)(h * _scaleY * _retinaFactor * _frameZoomFactor);
auto renderer = Director::getInstance()->getRenderer();
renderer->setScissorRect(x1, y1, width1, height1);
}
Rect GLViewImpl::getScissorRect() const
@ -993,37 +990,6 @@ void GLViewImpl::onGLFWWindowPosCallback(GLFWwindow* /*window*/, int /*x*/, int
Director::getInstance()->setViewport();
}
void GLViewImpl::onGLFWFramebufferSizeCallback(GLFWwindow* window, int w, int h)
{ // win32 glfw same with onGLFWWindowSizeCallback
#if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32
float frameSizeW = _screenSize.width;
float frameSizeH = _screenSize.height;
float factorX = frameSizeW / w * _retinaFactor * _frameZoomFactor;
float factorY = frameSizeH / h * _retinaFactor * _frameZoomFactor;
if (std::abs(factorX - 0.5f) < FLT_EPSILON && std::abs(factorY - 0.5f) < FLT_EPSILON)
{
_isInRetinaMonitor = true;
if (_isRetinaEnabled)
{
_retinaFactor = 1;
}
else
{
_retinaFactor = 2;
}
glfwSetWindowSize(window, static_cast<int>(frameSizeW * 0.5f * _retinaFactor * _frameZoomFactor) , static_cast<int>(frameSizeH * 0.5f * _retinaFactor * _frameZoomFactor));
}
else if (std::abs(factorX - 2.0f) < FLT_EPSILON && std::abs(factorY - 2.0f) < FLT_EPSILON)
{
_isInRetinaMonitor = false;
_retinaFactor = 1;
glfwSetWindowSize(window, static_cast<int>(frameSizeW * _retinaFactor * _frameZoomFactor), static_cast<int>(frameSizeH * _retinaFactor * _frameZoomFactor));
}
#endif
}
void GLViewImpl::onGLFWWindowSizeCallback(GLFWwindow* /*window*/, int w, int h)
{
if (w && h && _resolutionPolicy != ResolutionPolicy::UNKNOWN)
@ -1045,6 +1011,7 @@ void GLViewImpl::onGLFWWindowSizeCallback(GLFWwindow* /*window*/, int w, int h)
}
}
void GLViewImpl::onGLFWWindowIconifyCallback(GLFWwindow* /*window*/, int iconified)
{
if (iconified == GL_TRUE)

View File

@ -57,6 +57,7 @@ NS_CC_BEGIN
class GLFWEventHandler;
class CC_DLL GLViewImpl : public GLView
{
friend class GLFWEventHandler;
public:
static GLViewImpl* create(const std::string& viewName);
static GLViewImpl* create(const std::string& viewName, bool resizable);
@ -169,7 +170,6 @@ protected:
void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
void onGLFWCharCallback(GLFWwindow* window, unsigned int character);
void onGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
void onGLFWFramebufferSizeCallback(GLFWwindow* window, int w, int h);
void onGLFWWindowSizeCallback(GLFWwindow *window, int width, int height);
void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified);
void onGLFWWindowFocusCallback(GLFWwindow* window, int focused);
@ -189,8 +189,6 @@ protected:
float _mouseX;
float _mouseY;
friend class GLFWEventHandler;
public:
// View will trigger an event when window is resized, gains or loses focus
static const std::string EVENT_WINDOW_RESIZED;

View File

@ -52,9 +52,10 @@ THE SOFTWARE.
NS_CC_BEGIN
class GLFWEventHandler;
class CC_DLL GLViewImpl : public GLView
{
friend class GLFWEventHandler;
public:
static GLViewImpl* create(const std::string& viewName);
static GLViewImpl* create(const std::string& viewName, bool resizable);
@ -80,10 +81,27 @@ public:
GLFWwindow* getWindow() const { return _mainWindow; }
bool isFullscreen() const;
/* Sets primary monitor full screen with default w*h(refresh rate) */
void setFullscreen();
/* Sets primary monitor full screen with w*h(refresh rate) */
void setFullscreen(int w, int h, int refreshRate);
/* Sets monitor full screen with default w*h(refresh rate) */
void setFullscreen(int monitorIndex);
void setFullscreen(const GLFWvidmode &videoMode, GLFWmonitor *monitor);
/// <summary>
/// Sets monitor full screen with w*h(refresh rate)
/// </summary>
/// <param name="monitorIndex">the 0 based index of monitor</param>
/// <param name="w">the width of hardware resolution in full screen, -1 use default value</param>
/// <param name="h">the height of hardware resolution in full screen, -1 use default value</param>
/// <param name="refreshRate">the display refresh rate, usually 60, -1 use default value</param>
void setFullscreen(int monitorIndex, int w, int h, int refreshRate);
/* for internal use */
void setFullscreen(GLFWmonitor *monitor, int w, int h, int refreshRate);
void setWindowed(int width, int height);
int getMonitorCount() const;
Size getMonitorSize() const;
@ -128,8 +146,8 @@ protected:
bool initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor, bool resizable);
bool initWithFullScreen(const std::string& viewName);
bool initWithFullscreen(const std::string& viewname, const GLFWvidmode &videoMode, GLFWmonitor *monitor);
bool initGlew();
/* update frame layout when enter/exit full screen mode */
void updateWindowSize();
void updateFrameSize();
@ -141,13 +159,11 @@ protected:
void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
void onGLFWCharCallback(GLFWwindow* window, unsigned int character);
void onGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
void onGLFWframebuffersize(GLFWwindow* window, int w, int h);
void onGLFWWindowSizeFunCallback(GLFWwindow *window, int width, int height);
void onGLFWWindowSizeCallback(GLFWwindow *window, int width, int height);
void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified);
void onGLFWWindowFocusCallback(GLFWwindow* window, int focused);
bool _captured;
bool _supportTouch;
bool _isInRetinaMonitor;
bool _isRetinaEnabled;
int _retinaFactor; // Should be 1 or 2
@ -162,8 +178,6 @@ protected:
float _mouseX;
float _mouseY;
friend class GLFWEventHandler;
public:
// View will trigger an event when window is resized, gains or loses focus
static const std::string EVENT_WINDOW_RESIZED;
@ -174,87 +188,4 @@ private:
CC_DISALLOW_COPY_AND_ASSIGN(GLViewImpl);
};
class CC_DLL GLFWEventHandler
{
public:
static void onGLFWError(int errorID, const char* errorDesc)
{
if (_view)
_view->onGLFWError(errorID, errorDesc);
}
static void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
{
if (_view)
_view->onGLFWMouseCallBack(window, button, action, modify);
}
static void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
{
if (_view)
_view->onGLFWMouseMoveCallBack(window, x, y);
}
static void onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
{
if (_view)
_view->onGLFWMouseScrollCallback(window, x, y);
}
static void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (_view)
_view->onGLFWKeyCallback(window, key, scancode, action, mods);
}
static void onGLFWCharCallback(GLFWwindow* window, unsigned int character)
{
if (_view)
_view->onGLFWCharCallback(window, character);
}
static void onGLFWWindowPosCallback(GLFWwindow* windows, int x, int y)
{
if (_view)
_view->onGLFWWindowPosCallback(windows, x, y);
}
static void onGLFWframebuffersize(GLFWwindow* window, int w, int h)
{
if (_view)
_view->onGLFWframebuffersize(window, w, h);
}
static void onGLFWWindowSizeFunCallback(GLFWwindow *window, int width, int height)
{
if (_view)
_view->onGLFWWindowSizeFunCallback(window, width, height);
}
static void setGLViewImpl(GLViewImpl* view)
{
_view = view;
}
static void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified)
{
if (_view)
{
_view->onGLFWWindowIconifyCallback(window, iconified);
}
}
static void onGLFWWindowFocusCallback(GLFWwindow* window, int focused)
{
if (_view)
{
_view->onGLFWWindowFocusCallback(window, focused);
}
}
private:
static GLViewImpl* _view;
};
NS_CC_END // end of namespace cocos2d

View File

@ -48,6 +48,88 @@ THE SOFTWARE.
NS_CC_BEGIN
class GLFWEventHandler
{
public:
static void onGLFWError(int errorID, const char* errorDesc)
{
if (_view)
_view->onGLFWError(errorID, errorDesc);
}
static void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
{
if (_view)
_view->onGLFWMouseCallBack(window, button, action, modify);
}
static void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
{
if (_view)
_view->onGLFWMouseMoveCallBack(window, x, y);
}
static void onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
{
if (_view)
_view->onGLFWMouseScrollCallback(window, x, y);
}
static void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (_view)
_view->onGLFWKeyCallback(window, key, scancode, action, mods);
}
static void onGLFWCharCallback(GLFWwindow* window, unsigned int character)
{
if (_view)
_view->onGLFWCharCallback(window, character);
}
static void onGLFWWindowPosCallback(GLFWwindow* windows, int x, int y)
{
if (_view)
_view->onGLFWWindowPosCallback(windows, x, y);
}
// Notes: Unused on windows or macos Metal renderer backend
// static void onGLFWframebufferSize(GLFWwindow* window, int w, int h)
// {
// if (_view)
// _view->onGLFWframebufferSize(window, w, h);
// }
static void onGLFWWindowSizeCallback(GLFWwindow *window, int width, int height)
{
if (_view)
_view->onGLFWWindowSizeCallback(window, width, height);
}
static void setGLViewImpl(GLViewImpl* view)
{
_view = view;
}
static void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified)
{
if (_view)
{
_view->onGLFWWindowIconifyCallback(window, iconified);
}
}
static void onGLFWWindowFocusCallback(GLFWwindow* window, int focused)
{
if (_view)
{
_view->onGLFWWindowFocusCallback(window, focused);
}
}
private:
static GLViewImpl* _view;
};
GLViewImpl* GLFWEventHandler::_view = nullptr;
const std::string GLViewImpl::EVENT_WINDOW_RESIZED = "glview_window_resized";
@ -201,7 +283,6 @@ static keyCodeItem g_keyCodeStructArray[] = {
GLViewImpl::GLViewImpl(bool initglfw)
: _captured(false)
, _supportTouch(false)
, _isInRetinaMonitor(false)
, _isRetinaEnabled(false)
, _retinaFactor(1)
@ -372,7 +453,7 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
glfwSetCharCallback(_mainWindow, GLFWEventHandler::onGLFWCharCallback);
glfwSetKeyCallback(_mainWindow, GLFWEventHandler::onGLFWKeyCallback);
glfwSetWindowPosCallback(_mainWindow, GLFWEventHandler::onGLFWWindowPosCallback);
glfwSetWindowSizeCallback(_mainWindow, GLFWEventHandler::onGLFWWindowSizeFunCallback);
glfwSetWindowSizeCallback(_mainWindow, GLFWEventHandler::onGLFWWindowSizeCallback);
glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback);
glfwSetWindowFocusCallback(_mainWindow, GLFWEventHandler::onGLFWWindowFocusCallback);
@ -389,7 +470,7 @@ bool GLViewImpl::initWithFullScreen(const std::string& viewName)
return false;
const GLFWvidmode* videoMode = glfwGetVideoMode(_monitor);
return initWithRect(viewName, Rect(0, 0, videoMode->width, videoMode->height), 1.0f, false);
return initWithRect(viewName, Rect(0, 0, (float)videoMode->width, (float)videoMode->height), 1.0f, false);
}
bool GLViewImpl::initWithFullscreen(const std::string &viewname, const GLFWvidmode &videoMode, GLFWmonitor *monitor)
@ -405,7 +486,7 @@ bool GLViewImpl::initWithFullscreen(const std::string &viewname, const GLFWvidmo
glfwWindowHint(GLFW_BLUE_BITS, videoMode.blueBits);
glfwWindowHint(GLFW_GREEN_BITS, videoMode.greenBits);
return initWithRect(viewname, Rect(0, 0, videoMode.width, videoMode.height), 1.0f, false);
return initWithRect(viewname, Rect(0, 0, (float)videoMode.width, (float)videoMode.height), 1.0f, false);
}
bool GLViewImpl::isOpenGLReady()
@ -495,7 +576,7 @@ void GLViewImpl::setIcon(const std::vector<std::string>& filelist) const {
GLFWwindow* window = this->getWindow();
glfwSetWindowIcon(window, iconsCount, images);
CC_SAFE_DELETE(images);
CC_SAFE_DELETE_ARRAY(images);
for (auto& icon: icons) {
CC_SAFE_DELETE(icon);
}
@ -540,56 +621,84 @@ bool GLViewImpl::isFullscreen() const {
return (_monitor != nullptr);
}
void GLViewImpl::setFullscreen() {
if (this->isFullscreen()) {
return;
}
_monitor = glfwGetPrimaryMonitor();
if (nullptr == _monitor) {
return;
}
const GLFWvidmode* videoMode = glfwGetVideoMode(_monitor);
this->setFullscreen(*videoMode, _monitor);
void GLViewImpl::setFullscreen()
{
setFullscreen(-1, -1, -1);
}
void GLViewImpl::setFullscreen(int monitorIndex) {
// set fullscreen on specific monitor
void GLViewImpl::setFullscreen(int w, int h, int refreshRate) {
auto monitor = glfwGetPrimaryMonitor();
if (nullptr == monitor || monitor == _monitor) {
return;
}
this->setFullscreen(monitor, w, h, refreshRate);
}
void GLViewImpl::setFullscreen(int monitorIndex)
{
setFullscreen(monitorIndex, -1, -1, -1);
}
void GLViewImpl::setFullscreen(int monitorIndex, int w, int h, int refreshRate) {
int count = 0;
GLFWmonitor** monitors = glfwGetMonitors(&count);
if (monitorIndex < 0 || monitorIndex >= count) {
return;
}
GLFWmonitor* monitor = monitors[monitorIndex];
if (nullptr == monitor) {
if (nullptr == monitor || _monitor == monitor) {
return;
}
const GLFWvidmode* videoMode = glfwGetVideoMode(monitor);
this->setFullscreen(*videoMode, monitor);
this->setFullscreen(monitor, w, h, refreshRate);
}
void GLViewImpl::setFullscreen(const GLFWvidmode &videoMode, GLFWmonitor *monitor) {
void GLViewImpl::setFullscreen(GLFWmonitor *monitor, int w, int h, int refreshRate) {
_monitor = monitor;
glfwSetWindowMonitor(_mainWindow, _monitor, 0, 0, videoMode.width, videoMode.height, videoMode.refreshRate);
const GLFWvidmode* videoMode = glfwGetVideoMode(_monitor);
if (w == -1)
w = videoMode->width;
if (h == -1)
h = videoMode->height;
if (refreshRate == -1)
refreshRate = videoMode->refreshRate;
glfwSetWindowMonitor(_mainWindow, _monitor, 0, 0, w, h, refreshRate);
updateWindowSize();
}
void GLViewImpl::setWindowed(int width, int height) {
if (!this->isFullscreen()) {
this->setFrameSize(width, height);
this->setFrameSize((float)width, (float)height);
} else {
const GLFWvidmode* videoMode = glfwGetVideoMode(_monitor);
int xpos = 0, ypos = 0;
glfwGetMonitorPos(_monitor, &xpos, &ypos);
xpos += (videoMode->width - width) * 0.5;
ypos += (videoMode->height - height) * 0.5;
xpos += (int)((videoMode->width - width) * 0.5f);
ypos += (int)((videoMode->height - height) * 0.5f);
_monitor = nullptr;
glfwSetWindowMonitor(_mainWindow, nullptr, xpos, ypos, width, height, GLFW_DONT_CARE);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
// on mac window will sometimes lose title when windowed
glfwSetWindowTitle(_mainWindow, _viewName.c_str());
#endif
updateWindowSize();
}
}
void GLViewImpl::updateWindowSize()
{
int w = 0, h = 0;
glfwGetFramebufferSize(_mainWindow, &w, &h);
int frameWidth = w / _frameZoomFactor;
int frameHeight = h / _frameZoomFactor;
setFrameSize(frameWidth, frameHeight);
updateDesignResolutionSize();
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_RESIZED, nullptr);
}
int GLViewImpl::getMonitorCount() const {
int count = 0;
glfwGetMonitors(&count);
@ -607,7 +716,7 @@ Size GLViewImpl::getMonitorSize() const {
}
if (nullptr != monitor) {
const GLFWvidmode* videoMode = glfwGetVideoMode(monitor);
Size size = Size(videoMode->width, videoMode->height);
Size size = Size((float)videoMode->width, (float)videoMode->height);
return size;
}
return Size::ZERO;
@ -623,26 +732,27 @@ void GLViewImpl::updateFrameSize()
int frameBufferW = 0, frameBufferH = 0;
glfwGetFramebufferSize(_mainWindow, &frameBufferW, &frameBufferH);
if (frameBufferW == 2 * w && frameBufferH == 2 * h)
{
if (_isRetinaEnabled)
{
_retinaFactor = 1;
}
else
{
_retinaFactor = 2;
}
glfwSetWindowSize(_mainWindow, _screenSize.width/2 * _retinaFactor * _frameZoomFactor, _screenSize.height/2 * _retinaFactor * _frameZoomFactor);
_isInRetinaMonitor = true;
}
else
if (frameBufferW == 2 * w && frameBufferH == 2 * h)
{
if (_isRetinaEnabled)
{
_retinaFactor = 1;
}
else
{
_retinaFactor = 2;
}
glfwSetWindowSize(_mainWindow, _screenSize.width/2 * _retinaFactor * _frameZoomFactor, _screenSize.height/2 * _retinaFactor * _frameZoomFactor);
_isInRetinaMonitor = true;
}
else
{
if (_isInRetinaMonitor)
{
_retinaFactor = 1;
}
glfwSetWindowSize(_mainWindow, _screenSize.width * _retinaFactor * _frameZoomFactor, _screenSize.height *_retinaFactor * _frameZoomFactor);
glfwSetWindowSize(_mainWindow, (int)(_screenSize.width * _retinaFactor * _frameZoomFactor), (int)(_screenSize.height *_retinaFactor * _frameZoomFactor));
_isInRetinaMonitor = false;
}
@ -658,10 +768,10 @@ void GLViewImpl::setFrameSize(float width, float height)
void GLViewImpl::setViewPortInPoints(float x , float y , float w , float h)
{
Viewport vp;
vp.x = x * _scaleX * _retinaFactor * _frameZoomFactor + _viewPortRect.origin.x * _retinaFactor *_frameZoomFactor;
vp.y = y * _scaleY * _retinaFactor *_frameZoomFactor + _viewPortRect.origin.y * _retinaFactor *_frameZoomFactor;
vp.w = w * _scaleX *_retinaFactor * _frameZoomFactor;
vp.h = h * _scaleY * _retinaFactor * _frameZoomFactor;
vp.x = (int)(x * _scaleX * _retinaFactor * _frameZoomFactor + _viewPortRect.origin.x * _retinaFactor * _frameZoomFactor);
vp.y = (int)(y * _scaleY * _retinaFactor * _frameZoomFactor + _viewPortRect.origin.y * _retinaFactor * _frameZoomFactor);
vp.w = (unsigned int)(w * _scaleX * _retinaFactor * _frameZoomFactor);
vp.h = (unsigned int)(h * _scaleY * _retinaFactor * _frameZoomFactor);
Camera::setDefaultViewport(vp);
}
@ -802,12 +912,10 @@ void GLViewImpl::onGLFWMouseScrollCallback(GLFWwindow* /*window*/, double x, dou
void GLViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*scancode*/, int action, int /*mods*/)
{
if (GLFW_REPEAT != action)
{
EventKeyboard event(g_keyCodeMap[key], GLFW_PRESS == action);
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->dispatchEvent(&event);
}
// x-studio spec, for repeat press key support.
EventKeyboard event(g_keyCodeMap[key], action);
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->dispatchEvent(&event);
if (GLFW_RELEASE != action)
{
@ -862,7 +970,7 @@ void GLViewImpl::onGLFWWindowPosCallback(GLFWwindow* /*window*/, int /*x*/, int
Director::getInstance()->setViewport();
}
void GLViewImpl::onGLFWWindowSizeFunCallback(GLFWwindow* /*window*/, int width, int height)
void GLViewImpl::onGLFWWindowSizeCallback(GLFWwindow* /*window*/, int width, int height)
{
if (width && height && _resolutionPolicy != ResolutionPolicy::UNKNOWN)
{

View File

@ -15,6 +15,8 @@ option(BUILD_EXTENSION_COCOSTUDIO "Build extension cocostudio" ON)
option(BUILD_EXTENSION_FAIRYGUI "Build extension FairyGUI" ON)
option(BUILD_EXTENSION_IMGUI "Build extension ImGui" OFF)
function(setup_cocos_extension_config target_name)
if(ANDROID)
target_link_libraries(${target_name} INTERFACE cocos2d)
@ -71,4 +73,8 @@ if(BUILD_EXTENSION_FAIRYGUI)
add_subdirectory(fairygui)
endif()
if(BUILD_EXTENSION_IMGUI)
add_subdirectory(ImGui)
endif()
message(STATUS "CC_EXTENSION_LIBS:${CC_EXTENSION_LIBS}")

View File

@ -0,0 +1,379 @@
#include "CCImGuiEXT.h"
#include "imgui_impl_cocos2dx.h"
NS_CC_EXT_BEGIN
static ImGuiEXT* _instance = nullptr;
std::function<void(ImGuiEXT*)> ImGuiEXT::_onInit;
void ImGuiEXT::init()
{
ImGui_ImplCocos2dx_Init(true);
}
ImGuiEXT* ImGuiEXT::getInstance()
{
if(_instance == nullptr)
{
_instance = new ImGuiEXT();
_instance->init();
if (_onInit)
_onInit(_instance);
}
return _instance;
}
void ImGuiEXT::destroyInstance()
{
if (_instance)
{
delete _instance;
ImGui_ImplCocos2dx_Shutdown();
_instance = nullptr;
}
}
void ImGuiEXT::setOnInit(const std::function<void(ImGuiEXT*)>& callBack)
{
_onInit = callBack;
}
void ImGuiEXT::onDraw()
{
// clear things from last frame
usedCCRefIdMap.clear();
usedCCRef.clear();
// drawing commands
auto iter = _callPiplines.begin();
for (; iter != _callPiplines.end(); ++iter)
{
iter->second();
}
// commands will be processed after update
}
void ImGuiEXT::addCallback(const std::function<void()>& callBack, const std::string& name)
{
_callPiplines[name] = callBack;
}
void ImGuiEXT::removeCallback(const std::string& name)
{
const auto iter = _callPiplines.find(name);
if (iter != _callPiplines.end())
_callPiplines.erase(iter);
}
static std::tuple<ImVec2, ImVec2> getTextureUV(Sprite* sp)
{
ImVec2 uv0, uv1;
if (!sp || !sp->getTexture())
return { uv0,uv1 };
const auto rect = sp->getTextureRect();
const auto tex = sp->getTexture();
const float atlasWidth = (float)tex->getPixelsWide();
const float atlasHeight = (float)tex->getPixelsHigh();
uv0.x = rect.origin.x / atlasWidth;
uv0.y = rect.origin.y / atlasHeight;
uv1.x = (rect.origin.x + rect.size.width) / atlasWidth;
uv1.y = (rect.origin.y + rect.size.height) / atlasHeight;
return { uv0,uv1 };
}
void ImGuiEXT::image(Texture2D* tex, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1,
const ImVec4& tint_col, const ImVec4& border_col)
{
if (!tex)
return;
auto size_ = size;
if (size_.x <= 0.f) size_.x = tex->getPixelsWide();
if (size_.y <= 0.f) size_.y = tex->getPixelsHigh();
ImGui::PushID(getCCRefId(tex));
ImGui::Image((ImTextureID)tex, size_, uv0, uv1, tint_col, border_col);
ImGui::PopID();
}
void ImGuiEXT::image(Sprite* sprite, const ImVec2& size, const ImVec4& tint_col, const ImVec4& border_col)
{
if (!sprite || !sprite->getTexture())
return;
auto size_ = size;
const auto rect = sprite->getTextureRect();
if (size_.x <= 0.f) size_.x = rect.size.width;
if (size_.y <= 0.f) size_.y = rect.size.height;
ImVec2 uv0, uv1;
std::tie(uv0, uv1) = getTextureUV(sprite);
ImGui::PushID(getCCRefId(sprite));
ImGui::Image((ImTextureID)sprite->getTexture(), size_, uv0, uv1, tint_col, border_col);
ImGui::PopID();
}
bool ImGuiEXT::imageButton(Texture2D* tex, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1,
int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col)
{
if (!tex)
return false;
auto size_ = size;
if (size_.x <= 0.f) size_.x = tex->getPixelsWide();
if (size_.y <= 0.f) size_.y = tex->getPixelsHigh();
ImGui::PushID(getCCRefId(tex));
const auto ret = ImGui::ImageButton((ImTextureID)tex,
size_, uv0, uv1, frame_padding, bg_col, tint_col);
ImGui::PopID();
return ret;
}
bool ImGuiEXT::imageButton(Sprite* sprite, const ImVec2& size, int frame_padding, const ImVec4& bg_col,
const ImVec4& tint_col)
{
if (!sprite || !sprite->getTexture())
return false;
auto size_ = size;
const auto rect = sprite->getTextureRect();
if (size_.x <= 0.f) size_.x = rect.size.width;
if (size_.y <= 0.f) size_.y = rect.size.height;
ImVec2 uv0, uv1;
std::tie(uv0, uv1) = getTextureUV(sprite);
ImGui::PushID(getCCRefId(sprite));
const auto ret = ImGui::ImageButton((ImTextureID)sprite->getTexture(),
size_, uv0, uv1, frame_padding, bg_col, tint_col);
ImGui::PopID();
return ret;
}
void ImGuiEXT::node(Node* node, const ImVec4& tint_col, const ImVec4& border_col)
{
if (!node)
return;
const auto size = node->getContentSize();
const auto pos = ImGui::GetCursorScreenPos();
Mat4 tr;
tr.m[5] = -1;
tr.m[12] = pos.x;
tr.m[13] = pos.y + size.height;
if (border_col.w > 0.f)
{
tr.m[12] += 1;
tr.m[13] += 1;
}
node->setNodeToParentTransform(tr);
ImGui::PushID(getCCRefId(node));
ImGui::Image((ImTextureID)node,
ImVec2(size.width, size.height), ImVec2(0, 0), ImVec2(1, 1), tint_col, border_col);
ImGui::PopID();
}
bool ImGuiEXT::nodeButton(Node* node, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col)
{
if (!node)
return false;
const auto size = node->getContentSize();
const auto pos = ImGui::GetCursorScreenPos();
Mat4 tr;
tr.m[5] = -1;
tr.m[12] = pos.x;
tr.m[13] = pos.y + size.height;
if (frame_padding >= 0)
{
tr.m[12] += (float)frame_padding;
tr.m[13] += (float)frame_padding;
}
else
{
tr.m[12] += ImGui::GetStyle().FramePadding.x;
tr.m[13] += ImGui::GetStyle().FramePadding.y;
}
node->setNodeToParentTransform(tr);
ImGui::PushID(getCCRefId(node));
const auto ret = ImGui::ImageButton((ImTextureID)node,
ImVec2(size.width, size.height), ImVec2(0, 0), ImVec2(1, 1), frame_padding, bg_col, tint_col);
ImGui::PopID();
return ret;
}
std::tuple<ImTextureID, int> ImGuiEXT::useTexture(Texture2D* texture)
{
if (!texture)
return { nullptr,0 };
return { (ImTextureID)texture,getCCRefId(texture) };
}
std::tuple<ImTextureID, ImVec2, ImVec2, int> ImGuiEXT::useSprite(Sprite* sprite)
{
if (!sprite || !sprite->getTexture())
return { nullptr,{},{},0 };
ImVec2 uv0, uv1;
std::tie(uv0, uv1) = getTextureUV(sprite);
return { (ImTextureID)sprite->getTexture(),uv0,uv1,getCCRefId(sprite) };
}
std::tuple<ImTextureID, ImVec2, ImVec2, int> ImGuiEXT::useNode(Node* node, const ImVec2& pos)
{
if (!node)
return { nullptr,{},{},0 };
const auto size = node->getContentSize();
Mat4 tr;
tr.m[5] = -1;
tr.m[12] = pos.x;
tr.m[13] = pos.y + size.height;
node->setNodeToParentTransform(tr);
return { (ImTextureID)node,pos,ImVec2(pos.x + size.width,pos.y + size.height),getCCRefId(node) };
}
void ImGuiEXT::setNodeColor(Node* node, const ImVec4& col)
{
if (node)
{
node->setColor({ uint8_t(col.x * 255),uint8_t(col.y * 255),uint8_t(col.z * 255) });
node->setOpacity(uint8_t(col.w * 255));
}
}
void ImGuiEXT::setNodeColor(Node* node, ImGuiCol col)
{
if (node && 0 <= col && col < ImGuiCol_COUNT)
setNodeColor(node, ImGui::GetStyleColorVec4(col));
}
void ImGuiEXT::setLabelColor(Label* label, const ImVec4& col)
{
if (label)
{
label->setTextColor(
{ uint8_t(col.x * 255),uint8_t(col.y * 255),uint8_t(col.z * 255),uint8_t(col.w * 255) });
}
}
void ImGuiEXT::setLabelColor(Label* label, bool disabled)
{
if (label)
setLabelColor(label, ImGui::GetStyleColorVec4(disabled ? ImGuiCol_TextDisabled : ImGuiCol_Text));
}
void ImGuiEXT::setLabelColor(Label* label, ImGuiCol col)
{
if (label && 0 <= col && col < ImGuiCol_COUNT)
setLabelColor(label, ImGui::GetStyleColorVec4(col));
}
ImWchar* ImGuiEXT::addGlyphRanges(const std::string& key, const std::vector<ImWchar>& ranges)
{
auto it = glyphRanges.find(key);
// the pointer must be persistant, do not replace
if (it != glyphRanges.end())
return it->second.data();
glyphRanges[key] = ranges;
if (ranges.empty())
glyphRanges[key].push_back(0);
return glyphRanges[key].data();
}
void ImGuiEXT::mergeFontGlyphs(ImFont* dst, ImFont* src, ImWchar start, ImWchar end)
{
if (!dst || !src || start > end)
return;
for (auto i = start; i <= end; ++i)
{
const auto g = src->FindGlyphNoFallback(i);
if (g)
{
// TODO
// dst->AddGlyph(g->Codepoint, g->X0, g->Y0, g->X1, g->Y1, g->U0, g->V0, g->U1, g->V1, g->AdvanceX);
}
}
dst->BuildLookupTable();
}
int ImGuiEXT::getCCRefId(Ref* p)
{
int id = 0;
const auto it = usedCCRefIdMap.find(p);
if (it == usedCCRefIdMap.end())
{
usedCCRefIdMap[p] = 0;
usedCCRef.pushBack(p);
}
else
id = ++it->second;
// BKDR hash
constexpr unsigned int seed = 131;
unsigned int hash = 0;
for (auto i = 0u; i < sizeof(void*); ++i)
hash = hash * seed + ((const char*)&p)[i];
for (auto i = 0u; i < sizeof(int); ++i)
hash = hash * seed + ((const char*)&id)[i];
return (int)hash;
}
#if defined(HAVE_IMGUI_MARKDOWN)
#include "imgui_markdown/imgui_markdown.h"
static ImGuiEXT::MdLinkCallback ImGuiMarkdownLinkCallback = nullptr;
static ImGuiEXT::MdImageCallback ImGuiMarkdownImageCallback = nullptr;
static ImGui::MarkdownImageData ImGuiMarkdownInvalidImageData = { false, false, nullptr, {0.f, 0.f} };
void MarkdownLinkCallback(ImGui::MarkdownLinkCallbackData data)
{
if (ImGuiMarkdownLinkCallback)
{
ImGuiMarkdownLinkCallback(
{ data.text, (size_t)data.textLength }, { data.link, (size_t)data.linkLength }, data.isImage);
}
}
ImGui::MarkdownImageData MarkdownImageCallback(ImGui::MarkdownLinkCallbackData data)
{
if (!data.isImage || !ImGuiMarkdownImageCallback)
return ImGuiMarkdownInvalidImageData;
Sprite* sp; ImVec2 size; ImVec4 tint_col; ImVec4 border_col;
std::tie(sp, size, tint_col, border_col) = ImGuiMarkdownImageCallback(
{ data.text, (size_t)data.textLength },
{ data.link, (size_t)data.linkLength });
if(!sp || !sp->getTexture())
return ImGuiMarkdownInvalidImageData;
auto size_ = size;
const auto rect = sp->getTextureRect();
if (size_.x <= 0.f) size_.x = rect.size.width;
if (size_.y <= 0.f) size_.y = rect.size.height;
ImVec2 uv0, uv1;
std::tie(uv0, uv1) = getTextureUV(sp);
ImGuiEXT::getInstance()->getCCRefId(sp);
return { true, true, (ImTextureID)sp->getTexture(), size_,uv0, uv1, tint_col, border_col };
}
static std::string ImGuiMarkdownLinkIcon;
static ImGui::MarkdownConfig ImGuiMarkdownConfig = {
MarkdownLinkCallback, MarkdownImageCallback, "" };
void ImGuiEXT::setMarkdownLinkCallback(const MdLinkCallback& f)
{
ImGuiMarkdownLinkCallback = f;
}
void ImGuiEXT::setMarkdownImageCallback(const MdImageCallback& f)
{
ImGuiMarkdownImageCallback = f;
}
void ImGuiEXT::setMarkdownFont(int index, ImFont* font, bool seperator, float scale)
{
if (index < 0 || index >= ImGui::MarkdownConfig::NUMHEADINGS)
return;
ImGuiMarkdownConfig.headingFormats[index] = { font,seperator };
ImGuiMarkdownConfig.headingScales[index] = scale;
}
void ImGuiEXT::setMarkdownLinkIcon(const std::string& icon)
{
ImGuiMarkdownLinkIcon = icon;
ImGuiMarkdownConfig.linkIcon = ImGuiMarkdownLinkIcon.c_str();
}
void ImGuiEXT::markdown(const std::string& content)
{
ImGui::Markdown(content.c_str(), content.size(), ImGuiMarkdownConfig);
}
#endif
NS_CC_EXT_END

View File

@ -0,0 +1,105 @@
#pragma once
#include "cocos2d.h"
#include "ExtensionMacros.h"
#include "imgui/imgui.h"
#include <tuple>
// #define HAVE_IMGUI_MARKDOWN 1
NS_CC_EXT_BEGIN
class ImGuiLayer;
class ImGuiEXT
{
friend class ImGuiLayer;
void init();
public:
static ImGuiEXT* getInstance();
static void destroyInstance();
static void setOnInit(const std::function<void(ImGuiEXT*)>& callBack);
void addCallback(const std::function<void()>& callBack, const std::string& name);
void removeCallback(const std::string& name);
// imgui helper
void image(
Texture2D* tex,
const ImVec2& size,
const ImVec2& uv0 = ImVec2(0, 0),
const ImVec2& uv1 = ImVec2(1, 1),
const ImVec4& tint_col = ImVec4(1, 1, 1, 1),
const ImVec4& border_col = ImVec4(0, 0, 0, 0));
void image(
Sprite* sprite,
const ImVec2& size,
const ImVec4& tint_col = ImVec4(1, 1, 1, 1),
const ImVec4& border_col = ImVec4(0, 0, 0, 0));
bool imageButton(
Texture2D* tex,
const ImVec2& size,
const ImVec2& uv0 = ImVec2(0, 0),
const ImVec2& uv1 = ImVec2(1, 1),
int frame_padding = -1,
const ImVec4& bg_col = ImVec4(0, 0, 0, 0),
const ImVec4& tint_col = ImVec4(1, 1, 1, 1));
bool imageButton(
Sprite* sprite,
const ImVec2& size,
int frame_padding = -1,
const ImVec4& bg_col = ImVec4(0, 0, 0, 0),
const ImVec4& tint_col = ImVec4(1, 1, 1, 1));
void node(
Node* node,
const ImVec4& tint_col = ImVec4(1, 1, 1, 1),
const ImVec4& border_col = ImVec4(0, 0, 0, 0));
bool nodeButton(
Node* node,
int frame_padding = -1,
const ImVec4& bg_col = ImVec4(0, 0, 0, 0),
const ImVec4& tint_col = ImVec4(1, 1, 1, 1));
std::tuple<ImTextureID, int> useTexture(Texture2D* texture);
std::tuple<ImTextureID, ImVec2, ImVec2, int> useSprite(Sprite* sprite);
std::tuple<ImTextureID, ImVec2, ImVec2, int> useNode(Node* node, const ImVec2& pos);
static void setNodeColor(Node* node, const ImVec4& col);
static void setNodeColor(Node* node, ImGuiCol col);
static void setLabelColor(Label* label, const ImVec4& col);
static void setLabelColor(Label* label, bool disabled = false);
static void setLabelColor(Label* label, ImGuiCol col);
ImWchar* addGlyphRanges(const std::string& key, const std::vector<ImWchar>& ranges);
static void mergeFontGlyphs(ImFont* dst, ImFont* src, ImWchar start, ImWchar end);
int getCCRefId(Ref* p);
#if defined(HAVE_IMGUI_MARKDOWN)
// markdown
using MdLinkCallback = std::function<void(const std::string&, const std::string&, bool)>;
using MdImageCallback = std::function<std::tuple<Sprite*, ImVec2, ImVec4, ImVec4>(const std::string&, const std::string&)>;
void setMarkdownLinkCallback(const MdLinkCallback& f);
void setMarkdownImageCallback(const MdImageCallback& f);
void setMarkdownFont(int index, ImFont* font, bool seperator, float scale = 1.f);
void setMarkdownLinkIcon(const std::string& icon);
void markdown(const std::string& content);
#endif
private:
// perform draw ImGui stubs
void onDraw();
private:
static std::function<void(ImGuiEXT*)> _onInit;
std::unordered_map<std::string, std::function<void()>> _callPiplines;
std::unordered_map<Ref*, int> usedCCRefIdMap;
// cocos objects should be retained until next frame
Vector<Ref*> usedCCRef;
std::unordered_map<std::string, std::vector<ImWchar>> glyphRanges;
};
NS_CC_EXT_END

View File

@ -0,0 +1,65 @@
#include "CCImGuiLayer.h"
#include "imgui/imgui.h"
#include "imgui_impl_cocos2dx.h"
#include "CCImGuiEXT.h"
NS_CC_EXT_BEGIN
bool ImGuiLayer::init()
{
if (!Layer::init() || !ImGuiEXT::getInstance())
return false;
#ifdef CC_PLATFORM_PC
// note: when at the first click to focus the window, this will not take effect
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [this](Touch* touch, Event*) -> bool {
if (!_visible)
return false;
return ImGui::IsAnyWindowHovered();
};
getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
// add by halx99
auto stopAnyMouse = [=](EventMouse* event) {
if (ImGui::IsAnyWindowHovered()) {
event->stopPropagation();
cocos2d::log("!!!EventMouse should stop by ImGuiLayer");
}
};
auto mouseListener = EventListenerMouse::create();
mouseListener->onMouseDown = mouseListener->onMouseUp = stopAnyMouse;
getEventDispatcher()->addEventListenerWithSceneGraphPriority(mouseListener, this);
#endif
// add an empty sprite to avoid render problem
const auto sp = Sprite::create();
sp->setGlobalZOrder(1);
sp->setOpacity(0);
addChild(sp, 1);
return true;
}
void ImGuiLayer::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
Layer::visit(renderer, parentTransform, parentFlags);
if(_visible) frame();
}
void ImGuiLayer::frame()
{
// create frame
ImGui_ImplCocos2dx_NewFrame();
// draw all gui
ImGuiEXT::getInstance()->onDraw();
// render
ImGui::Render();
ImGui_ImplCocos2dx_RenderDrawData(ImGui::GetDrawData());
ImGui_ImplCocos2dx_RenderPlatform();
}
NS_CC_EXT_END

View File

@ -0,0 +1,18 @@
#pragma once
#include "cocos2d.h"
#include "ExtensionMacros.h"
NS_CC_EXT_BEGIN
class ImGuiLayer : public Layer
{
CC_CONSTRUCTOR_ACCESS:
virtual bool init() override;
protected:
virtual void visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags) override;
void frame();
};
NS_CC_EXT_END

View File

@ -0,0 +1,74 @@
set(target_name ImGui)
#~ if(WINDOWS)
#~ include_directories(${COCOS2DX_ROOT_PATH}/external/win32-specific/gles/include/OGLES)
#~ endif()
include_directories(imgui)
set(HEADER
CCImGuiEXT.h
CCImGuiLayer.h
# CCImGuiColorTextEdit.h
imgui_impl_cocos2dx.h
imgui/imconfig.h
imgui/imgui.h
imgui/imgui_internal.h
imgui/imstb_rectpack.h
imgui/imstb_textedit.h
imgui/imstb_truetype.h
imgui/misc/cpp/imgui_stdlib.h
#~ imgui_markdown/imgui_markdown.h
#~ ImGuiColorTextEdit/TextEditor.h
#~ implot/implot.h
)
set(SOURCE
CCImGuiEXT.cpp
CCImGuiLayer.cpp
# CCImGuiColorTextEdit.cpp
imgui_impl_cocos2dx.cpp
imgui/imgui.cpp
imgui/imgui_demo.cpp
imgui/imgui_draw.cpp
imgui/imgui_widgets.cpp
imgui/misc/cpp/imgui_stdlib.cpp
#~ ImGuiColorTextEdit/TextEditor.cpp
#~ implot/implot.cpp
#~ implot/implot_demo.cpp
)
#~ if(BUILD_LUA_LIBS)
#~ include_directories(
#~ lua-bindings
#~ ${COCOS2DX_ROOT_PATH}/external/lua/luajit/include
#~ ${COCOS2DX_ROOT_PATH}/external/lua/tolua
#~ )
#~ list(APPEND HEADER
#~ lua-bindings/imgui_lua.hpp
#~ lua-bindings/lua_conversion.hpp
#~ lua-bindings/lua_imgui_auto.hpp
#~ lua-bindings/lua_imguiDrawList_auto.hpp
#~ lua-bindings/lua_imguiFont_auto.hpp
#~ lua-bindings/lua_imguiIO_auto.hpp
#~ lua-bindings/lua_imguiStyle_auto.hpp
#~ lua-bindings/lua_imguiViewport_auto.hpp
#~ lua-bindings/lua_ImGuiColorTextEdit_auto.hpp
#~ lua-bindings/lua_implot_auto.hpp
#~ )
#~ list(APPEND SOURCE
#~ lua-bindings/imgui_lua.cpp
#~ lua-bindings/lua_imguiDrawList_auto.cpp
#~ lua-bindings/lua_imguiFont_auto.cpp
#~ lua-bindings/lua_imguiIO_auto.cpp
#~ lua-bindings/lua_imguiStyle_auto.cpp
#~ lua-bindings/lua_imguiViewport_auto.cpp
#~ lua-bindings/lua_imgui_auto.cpp
#~ lua-bindings/lua_ImGuiColorTextEdit_auto.cpp
#~ lua-bindings/lua_implot_auto.cpp
#~ )
#~ endif()
add_library(${target_name} STATIC
${HEADER}
${SOURCE})
setup_cocos_extension_config(${target_name})

21
extensions/ImGui/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Xrysnow
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,8 @@
# egnx-imgui-ext
Sync from https://github.com/Xrysnow/cocos2d-x-imgui and do a little changes
## How to use
Same with https://github.com/Xrysnow/cocos2d-x-imgui but do a little changes:
* ```CCIMGUI``` --> ```cocos2d::extension::ImGuiEXT```
* ```ImGuiLayer``` --> ```cocos2d::extension::ImGuiLayer```
* And no lua bindings currently

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014-2020 Omar Cornut
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,108 @@
//-----------------------------------------------------------------------------
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
//-----------------------------------------------------------------------------
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/branch with your modifications to imconfig.h)
// B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h"
// If you do so you need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include
// the imgui*.cpp files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
//-----------------------------------------------------------------------------
#pragma once
//---- Define assertion handler. Defaults to calling assert().
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
// Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//---- Disable all of Dear ImGui or don't implement standard windows.
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended.
//#define IMGUI_DISABLE_METRICS_WINDOW // Disable debug/metrics window: ShowMetricsWindow() will be empty.
//---- Don't implement some functions to reduce linkage requirements.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc.
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow.
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
//---- Include imgui_user.h at the end of imgui.h as a convenience
//#define IMGUI_INCLUDE_IMGUI_USER_H
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
//#define IMGUI_USE_BGRA_PACKED_COLOR
//---- Use 32-bit for ImWchar (default is 16-bit) to support full unicode code points.
//#define IMGUI_USE_WCHAR32
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
// By default the embedded implementations are declared static and not available outside of imgui cpp files.
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
//---- Unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined, use the much faster STB sprintf library implementation of vsnprintf instead of the one from the default C library.
// Note that stb_sprintf.h is meant to be provided by the user and available in the include path at compile time. Also, the compatibility checks of the arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf.
// #define IMGUI_USE_STB_SPRINTF
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
/*
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
operator MyVec2() const { return MyVec2(x,y); }
#define IM_VEC4_CLASS_EXTRA \
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
// Your renderer back-end will need to support it (most example renderer back-ends support both 16/32-bit indices).
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
//#define ImDrawIdx unsigned int
//---- Override ImDrawCallback signature (will need to modify renderer back-ends accordingly)
//struct ImDrawList;
//struct ImDrawCmd;
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
//#define ImDrawCallback MyImDrawCallback
//---- Debug Tools: Macro to break in Debugger
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
//#define IM_DEBUG_BREAK IM_ASSERT(0)
//#define IM_DEBUG_BREAK __debugbreak()
//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
// This adds a small runtime cost which is why it is not enabled by default.
//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
//---- Debug Tools: Enable slower asserts
//#define IMGUI_DEBUG_PARANOID
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
/*
namespace ImGui
{
void MyFunction(const char* name, const MyMatrix44& v);
}
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,639 @@
// [DEAR IMGUI]
// This is a slightly modified version of stb_rect_pack.h 1.00.
// Those changes would need to be pushed into nothings/stb:
// - Added STBRP__CDECL
// Grep for [DEAR IMGUI] to find the changes.
// stb_rect_pack.h - v1.00 - public domain - rectangle packing
// Sean Barrett 2014
//
// Useful for e.g. packing rectangular textures into an atlas.
// Does not do rotation.
//
// Not necessarily the awesomest packing method, but better than
// the totally naive one in stb_truetype (which is primarily what
// this is meant to replace).
//
// Has only had a few tests run, may have issues.
//
// More docs to come.
//
// No memory allocations; uses qsort() and assert() from stdlib.
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
//
// This library currently uses the Skyline Bottom-Left algorithm.
//
// Please note: better rectangle packers are welcome! Please
// implement them to the same API, but with a different init
// function.
//
// Credits
//
// Library
// Sean Barrett
// Minor features
// Martins Mozeiko
// github:IntellectualKitty
//
// Bugfixes / warning fixes
// Jeremy Jaussaud
// Fabian Giesen
//
// Version history:
//
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
// 0.99 (2019-02-07) warning fixes
// 0.11 (2017-03-03) return packing success/fail result
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
// 0.09 (2016-08-27) fix compiler warnings
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
// 0.05: added STBRP_ASSERT to allow replacing assert
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
// 0.01: initial release
//
// LICENSE
//
// See end of file for license information.
//////////////////////////////////////////////////////////////////////////////
//
// INCLUDE SECTION
//
#ifndef STB_INCLUDE_STB_RECT_PACK_H
#define STB_INCLUDE_STB_RECT_PACK_H
#define STB_RECT_PACK_VERSION 1
#ifdef STBRP_STATIC
#define STBRP_DEF static
#else
#define STBRP_DEF extern
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct stbrp_context stbrp_context;
typedef struct stbrp_node stbrp_node;
typedef struct stbrp_rect stbrp_rect;
#ifdef STBRP_LARGE_RECTS
typedef int stbrp_coord;
#else
typedef unsigned short stbrp_coord;
#endif
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
// Assign packed locations to rectangles. The rectangles are of type
// 'stbrp_rect' defined below, stored in the array 'rects', and there
// are 'num_rects' many of them.
//
// Rectangles which are successfully packed have the 'was_packed' flag
// set to a non-zero value and 'x' and 'y' store the minimum location
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
// if you imagine y increasing downwards). Rectangles which do not fit
// have the 'was_packed' flag set to 0.
//
// You should not try to access the 'rects' array from another thread
// while this function is running, as the function temporarily reorders
// the array while it executes.
//
// To pack into another rectangle, you need to call stbrp_init_target
// again. To continue packing into the same rectangle, you can call
// this function again. Calling this multiple times with multiple rect
// arrays will probably produce worse packing results than calling it
// a single time with the full rectangle array, but the option is
// available.
//
// The function returns 1 if all of the rectangles were successfully
// packed and 0 otherwise.
struct stbrp_rect
{
// reserved for your use:
int id;
// input:
stbrp_coord w, h;
// output:
stbrp_coord x, y;
int was_packed; // non-zero if valid packing
}; // 16 bytes, nominally
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
// Initialize a rectangle packer to:
// pack a rectangle that is 'width' by 'height' in dimensions
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
//
// You must call this function every time you start packing into a new target.
//
// There is no "shutdown" function. The 'nodes' memory must stay valid for
// the following stbrp_pack_rects() call (or calls), but can be freed after
// the call (or calls) finish.
//
// Note: to guarantee best results, either:
// 1. make sure 'num_nodes' >= 'width'
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
//
// If you don't do either of the above things, widths will be quantized to multiples
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
//
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
// may run out of temporary storage and be unable to pack some rectangles.
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
// Optionally call this function after init but before doing any packing to
// change the handling of the out-of-temp-memory scenario, described above.
// If you call init again, this will be reset to the default (false).
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
// Optionally select which packing heuristic the library should use. Different
// heuristics will produce better/worse results for different data sets.
// If you call init again, this will be reset to the default.
enum
{
STBRP_HEURISTIC_Skyline_default=0,
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
STBRP_HEURISTIC_Skyline_BF_sortHeight
};
//////////////////////////////////////////////////////////////////////////////
//
// the details of the following structures don't matter to you, but they must
// be visible so you can handle the memory allocations for them
struct stbrp_node
{
stbrp_coord x,y;
stbrp_node *next;
};
struct stbrp_context
{
int width;
int height;
int align;
int init_mode;
int heuristic;
int num_nodes;
stbrp_node *active_head;
stbrp_node *free_head;
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
};
#ifdef __cplusplus
}
#endif
#endif
//////////////////////////////////////////////////////////////////////////////
//
// IMPLEMENTATION SECTION
//
#ifdef STB_RECT_PACK_IMPLEMENTATION
#ifndef STBRP_SORT
#include <stdlib.h>
#define STBRP_SORT qsort
#endif
#ifndef STBRP_ASSERT
#include <assert.h>
#define STBRP_ASSERT assert
#endif
// [DEAR IMGUI] Added STBRP__CDECL
#ifdef _MSC_VER
#define STBRP__NOTUSED(v) (void)(v)
#define STBRP__CDECL __cdecl
#else
#define STBRP__NOTUSED(v) (void)sizeof(v)
#define STBRP__CDECL
#endif
enum
{
STBRP__INIT_skyline = 1
};
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
{
switch (context->init_mode) {
case STBRP__INIT_skyline:
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
context->heuristic = heuristic;
break;
default:
STBRP_ASSERT(0);
}
}
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
{
if (allow_out_of_mem)
// if it's ok to run out of memory, then don't bother aligning them;
// this gives better packing, but may fail due to OOM (even though
// the rectangles easily fit). @TODO a smarter approach would be to only
// quantize once we've hit OOM, then we could get rid of this parameter.
context->align = 1;
else {
// if it's not ok to run out of memory, then quantize the widths
// so that num_nodes is always enough nodes.
//
// I.e. num_nodes * align >= width
// align >= width / num_nodes
// align = ceil(width/num_nodes)
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
}
}
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
{
int i;
#ifndef STBRP_LARGE_RECTS
STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
#endif
for (i=0; i < num_nodes-1; ++i)
nodes[i].next = &nodes[i+1];
nodes[i].next = NULL;
context->init_mode = STBRP__INIT_skyline;
context->heuristic = STBRP_HEURISTIC_Skyline_default;
context->free_head = &nodes[0];
context->active_head = &context->extra[0];
context->width = width;
context->height = height;
context->num_nodes = num_nodes;
stbrp_setup_allow_out_of_mem(context, 0);
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
context->extra[0].x = 0;
context->extra[0].y = 0;
context->extra[0].next = &context->extra[1];
context->extra[1].x = (stbrp_coord) width;
#ifdef STBRP_LARGE_RECTS
context->extra[1].y = (1<<30);
#else
context->extra[1].y = 65535;
#endif
context->extra[1].next = NULL;
}
// find minimum y position if it starts at x1
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
{
stbrp_node *node = first;
int x1 = x0 + width;
int min_y, visited_width, waste_area;
STBRP__NOTUSED(c);
STBRP_ASSERT(first->x <= x0);
#if 0
// skip in case we're past the node
while (node->next->x <= x0)
++node;
#else
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
#endif
STBRP_ASSERT(node->x <= x0);
min_y = 0;
waste_area = 0;
visited_width = 0;
while (node->x < x1) {
if (node->y > min_y) {
// raise min_y higher.
// we've accounted for all waste up to min_y,
// but we'll now add more waste for everything we've visted
waste_area += visited_width * (node->y - min_y);
min_y = node->y;
// the first time through, visited_width might be reduced
if (node->x < x0)
visited_width += node->next->x - x0;
else
visited_width += node->next->x - node->x;
} else {
// add waste area
int under_width = node->next->x - node->x;
if (under_width + visited_width > width)
under_width = width - visited_width;
waste_area += under_width * (min_y - node->y);
visited_width += under_width;
}
node = node->next;
}
*pwaste = waste_area;
return min_y;
}
typedef struct
{
int x,y;
stbrp_node **prev_link;
} stbrp__findresult;
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
{
int best_waste = (1<<30), best_x, best_y = (1 << 30);
stbrp__findresult fr;
stbrp_node **prev, *node, *tail, **best = NULL;
// align to multiple of c->align
width = (width + c->align - 1);
width -= width % c->align;
STBRP_ASSERT(width % c->align == 0);
// if it can't possibly fit, bail immediately
if (width > c->width || height > c->height) {
fr.prev_link = NULL;
fr.x = fr.y = 0;
return fr;
}
node = c->active_head;
prev = &c->active_head;
while (node->x + width <= c->width) {
int y,waste;
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
// bottom left
if (y < best_y) {
best_y = y;
best = prev;
}
} else {
// best-fit
if (y + height <= c->height) {
// can only use it if it first vertically
if (y < best_y || (y == best_y && waste < best_waste)) {
best_y = y;
best_waste = waste;
best = prev;
}
}
}
prev = &node->next;
node = node->next;
}
best_x = (best == NULL) ? 0 : (*best)->x;
// if doing best-fit (BF), we also have to try aligning right edge to each node position
//
// e.g, if fitting
//
// ____________________
// |____________________|
//
// into
//
// | |
// | ____________|
// |____________|
//
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
//
// This makes BF take about 2x the time
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
tail = c->active_head;
node = c->active_head;
prev = &c->active_head;
// find first node that's admissible
while (tail->x < width)
tail = tail->next;
while (tail) {
int xpos = tail->x - width;
int y,waste;
STBRP_ASSERT(xpos >= 0);
// find the left position that matches this
while (node->next->x <= xpos) {
prev = &node->next;
node = node->next;
}
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
if (y + height <= c->height) {
if (y <= best_y) {
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
best_x = xpos;
STBRP_ASSERT(y <= best_y);
best_y = y;
best_waste = waste;
best = prev;
}
}
}
tail = tail->next;
}
}
fr.prev_link = best;
fr.x = best_x;
fr.y = best_y;
return fr;
}
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
{
// find best position according to heuristic
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
stbrp_node *node, *cur;
// bail if:
// 1. it failed
// 2. the best node doesn't fit (we don't always check this)
// 3. we're out of memory
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
res.prev_link = NULL;
return res;
}
// on success, create new node
node = context->free_head;
node->x = (stbrp_coord) res.x;
node->y = (stbrp_coord) (res.y + height);
context->free_head = node->next;
// insert the new node into the right starting point, and
// let 'cur' point to the remaining nodes needing to be
// stiched back in
cur = *res.prev_link;
if (cur->x < res.x) {
// preserve the existing one, so start testing with the next one
stbrp_node *next = cur->next;
cur->next = node;
cur = next;
} else {
*res.prev_link = node;
}
// from here, traverse cur and free the nodes, until we get to one
// that shouldn't be freed
while (cur->next && cur->next->x <= res.x + width) {
stbrp_node *next = cur->next;
// move the current node to the free list
cur->next = context->free_head;
context->free_head = cur;
cur = next;
}
// stitch the list back in
node->next = cur;
if (cur->x < res.x + width)
cur->x = (stbrp_coord) (res.x + width);
#ifdef _DEBUG
cur = context->active_head;
while (cur->x < context->width) {
STBRP_ASSERT(cur->x < cur->next->x);
cur = cur->next;
}
STBRP_ASSERT(cur->next == NULL);
{
int count=0;
cur = context->active_head;
while (cur) {
cur = cur->next;
++count;
}
cur = context->free_head;
while (cur) {
cur = cur->next;
++count;
}
STBRP_ASSERT(count == context->num_nodes+2);
}
#endif
return res;
}
// [DEAR IMGUI] Added STBRP__CDECL
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
{
const stbrp_rect *p = (const stbrp_rect *) a;
const stbrp_rect *q = (const stbrp_rect *) b;
if (p->h > q->h)
return -1;
if (p->h < q->h)
return 1;
return (p->w > q->w) ? -1 : (p->w < q->w);
}
// [DEAR IMGUI] Added STBRP__CDECL
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
{
const stbrp_rect *p = (const stbrp_rect *) a;
const stbrp_rect *q = (const stbrp_rect *) b;
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
}
#ifdef STBRP_LARGE_RECTS
#define STBRP__MAXVAL 0xffffffff
#else
#define STBRP__MAXVAL 0xffff
#endif
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
{
int i, all_rects_packed = 1;
// we use the 'was_packed' field internally to allow sorting/unsorting
for (i=0; i < num_rects; ++i) {
rects[i].was_packed = i;
}
// sort according to heuristic
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
for (i=0; i < num_rects; ++i) {
if (rects[i].w == 0 || rects[i].h == 0) {
rects[i].x = rects[i].y = 0; // empty rect needs no space
} else {
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
if (fr.prev_link) {
rects[i].x = (stbrp_coord) fr.x;
rects[i].y = (stbrp_coord) fr.y;
} else {
rects[i].x = rects[i].y = STBRP__MAXVAL;
}
}
}
// unsort
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
// set was_packed flags and all_rects_packed status
for (i=0; i < num_rects; ++i) {
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
if (!rects[i].was_packed)
all_rects_packed = 0;
}
// return the all_rects_packed status
return all_rects_packed;
}
#endif
/*
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Sean Barrett
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
imgui_stdlib.h + imgui_stdlib.cpp
InputText() wrappers for C++ standard library (STL) type: std::string.
This is also an example of how you may wrap your own similar types.
imgui_scoped.h
[Experimental, not currently in main repository]
Additional header file with some RAII-style wrappers for common Dear ImGui functions.
Try by merging: https://github.com/ocornut/imgui/pull/2197
Discuss at: https://github.com/ocornut/imgui/issues/2096

View File

@ -0,0 +1,76 @@
// dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.)
// This is also an example of how you may wrap your own similar types.
// Compatibility:
// - std::string support is only guaranteed to work from C++11.
// If you try to use it pre-C++11, please share your findings (w/ info about compiler/architecture)
// Changelog:
// - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string
#include "imgui.h"
#include "imgui_stdlib.h"
struct InputTextCallback_UserData
{
std::string* Str;
ImGuiInputTextCallback ChainCallback;
void* ChainCallbackUserData;
};
static int InputTextCallback(ImGuiInputTextCallbackData* data)
{
InputTextCallback_UserData* user_data = (InputTextCallback_UserData*)data->UserData;
if (data->EventFlag == ImGuiInputTextFlags_CallbackResize)
{
// Resize string callback
// If for some reason we refuse the new length (BufTextLen) and/or capacity (BufSize) we need to set them back to what we want.
std::string* str = user_data->Str;
IM_ASSERT(data->Buf == str->c_str());
str->resize(data->BufTextLen);
data->Buf = (char*)str->c_str();
}
else if (user_data->ChainCallback)
{
// Forward to user callback, if any
data->UserData = user_data->ChainCallbackUserData;
return user_data->ChainCallback(data);
}
return 0;
}
bool ImGui::InputText(const char* label, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
{
IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
flags |= ImGuiInputTextFlags_CallbackResize;
InputTextCallback_UserData cb_user_data;
cb_user_data.Str = str;
cb_user_data.ChainCallback = callback;
cb_user_data.ChainCallbackUserData = user_data;
return InputText(label, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data);
}
bool ImGui::InputTextMultiline(const char* label, std::string* str, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
{
IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
flags |= ImGuiInputTextFlags_CallbackResize;
InputTextCallback_UserData cb_user_data;
cb_user_data.Str = str;
cb_user_data.ChainCallback = callback;
cb_user_data.ChainCallbackUserData = user_data;
return InputTextMultiline(label, (char*)str->c_str(), str->capacity() + 1, size, flags, InputTextCallback, &cb_user_data);
}
bool ImGui::InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
{
IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
flags |= ImGuiInputTextFlags_CallbackResize;
InputTextCallback_UserData cb_user_data;
cb_user_data.Str = str;
cb_user_data.ChainCallback = callback;
cb_user_data.ChainCallbackUserData = user_data;
return InputTextWithHint(label, hint, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data);
}

View File

@ -0,0 +1,22 @@
// dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.)
// This is also an example of how you may wrap your own similar types.
// Compatibility:
// - std::string support is only guaranteed to work from C++11.
// If you try to use it pre-C++11, please share your findings (w/ info about compiler/architecture)
// Changelog:
// - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string
#pragma once
#include <string>
namespace ImGui
{
// ImGui::InputText() with std::string
// Because text input needs dynamic resizing, we need to setup a callback to grow the capacity
IMGUI_API bool InputText(const char* label, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
IMGUI_API bool InputTextMultiline(const char* label, std::string* str, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
IMGUI_API bool InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
#pragma once
#include "imgui/imgui.h"
IMGUI_IMPL_API bool ImGui_ImplCocos2dx_Init(bool install_callbacks);
IMGUI_IMPL_API void ImGui_ImplCocos2dx_Shutdown();
IMGUI_IMPL_API void ImGui_ImplCocos2dx_NewFrame();
IMGUI_IMPL_API void ImGui_ImplCocos2dx_RenderDrawData(ImDrawData* draw_data);
IMGUI_IMPL_API void ImGui_ImplCocos2dx_RenderPlatform();
// Called by Init/NewFrame/Shutdown
IMGUI_IMPL_API bool ImGui_ImplCocos2dx_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplCocos2dx_DestroyDeviceObjects();
IMGUI_IMPL_API bool ImGui_ImplCocos2dx_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplCocos2dx_DestroyFontsTexture();

View File

@ -108,7 +108,7 @@ If ($env:build_type -eq "android_cpp_tests") {
# if ($lastexitcode -ne 0) {throw} # mkdir return no-zero
Push-Location $env:APPVEYOR_BUILD_FOLDER\win32-build
& cmake -A Win32 -DCMAKE_BUILD_TYPE=Release ..
& cmake -A Win32 -DCMAKE_BUILD_TYPE=Release .. -DBUILD_EXTENSION_IMGUI=ON
if ($lastexitcode -ne 0) {throw}
& cmake --build . --config Release --target cpp-tests

View File

@ -49,9 +49,8 @@ function build_mac_cmake()
# cd $COCOS2DX_ROOT/cocos_new_test
cd $COCOS2DX_ROOT
mkdir -p build
cd build
cmake .. -GXcode
cmake --build . --config Release -- -quiet
cmake -S . -B build -GXcode -DBUILD_EXTENSION_IMGUI=ON
cmake --build build --config Release -- -quiet
#xcodebuild -project Cocos2d-x.xcodeproj -alltargets -jobs $NUM_OF_CORES build | xcpretty
##the following commands must not be removed
#xcodebuild -project Cocos2d-x.xcodeproj -alltargets -jobs $NUM_OF_CORES build