Code Monkey home page Code Monkey logo

imguix's Introduction

cocos2d-x-3.8.1 with imgui

  1. https://github.com/cocos2d/cocos2d-x
  2. https://github.com/ocornut/imgui

screen

how to integrate imguix

  • all you need are Classes/imgui folder

  • create GLView:

    // include headers
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    #include "CCIMGUIGLViewImpl.h"
    #include "CCImGuiLayer.h"
    #endif
    
    // create glview
    director->setOpenGLView(IMGUIGLViewImpl::createWithRect("imguix", Rect(0, 0, width,   height)));
    
    // add imgui layer on the top
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
        // ImGui is always on the top
        Director::getInstance()->getScheduler()->schedule([](float)
        {
           if (!Director::getInstance()->getRunningScene()->getChildByName("ImGUILayer"))
           {
               Director::getInstance()->getRunningScene()->addChild(ImGuiLayer::create(), INT_MAX,   "ImGUILayer");
           }
        }, this, 0, false, "checkImGUI");
    #endif
    

how to use

// add ui
CCIMGUI::getInstance()->addImGUI([=](){
    {
        ImGui::Text("Hello, world!");
    }
}, "demoid");

// remove ui
CCIMGUI::getInstance()->removeImGUI("demoid");

// create button with file name, auto pushID / popID with texture id
CCIMGUI::getInstance()->imageButton("filename.png");

// create button with SpriteFrameName, auto pushID / popID with texture id
CCIMGUI:: getInstance()->imageButton("#framename");

// chinese font
// http://www.slackware.com/~alien/slackbuilds/wqy-zenhei-font-ttf/build/wqy-zenhei-0.4.23-1.tar.gz
ImGuiIO &io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("res/wqy-zenhei.ttf", 18.0f, 0, io.Fonts->GetGlyphRangesChinese());

lua binding

  1. ImGui::ImageButton -> imgui.imageButton
-- text
imgui.text("Hello, World!")
    
-- text button
imgui.button("text button")
    
-- new window
if imgui.begin("Toolbar") then
end

-- input text
buf = "input"
ret, buf = imgui.inputText("input", buf, 256)

-- slider
float = 3
ret, float = imgui.sliderFloat("float", float, 0, 8)

-- image button

-- create with image file name
if imgui.imageButton("res/1.png") then print("image button click 1") end
-- or create with sprite frame name
if imgui.imageButton("#CoinSpin01.png") then print("CoinSpin01 1") end

more example in main.lua

imguix's People

Contributors

jrdeng avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.