Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
-----

- d3dx9 -> d3d9 にデグレードして d3dx を使わない生々しい実装に切り替えられた。
- 最小化状態での描画回避による高効率化が図られた。

- SDLウィンドウコンテキストを外部から提供される形にしてこのソースからは除外した。
- コーディングルールを`type *value` から `type* value` に変更した。
- フレームバッファーのサイズ計算で零除算が発生する可能性があったので排除した。

- `ImTextureID` についてインソースコメントドキュメントに追加。
- ImGui のウィンドウコンテキストを使わずに `ImDrawList API` で ImGui を使う方法をインソースコメントドキュメントに追記。
- コーディングルールを`type *value` から `type* value` に変更した。
- インソースコメントドキュメントを若干わかりやすく修正した。
- 2016-03-21 (1.48の途中) から 2016-05-12 (1.49の途中) までにあった APIの 破壊的変更についてインソースコメントドキュメントに追記。
    - `GetWindowFont` -> `GetFont` 但し、旧APIはリダイレクトを定義しているが廃止予定
    - `GetWindowFontSize` -> `GetFontSize` 但し、旧APIはリダイレクトを定義しているが廃止予定
    - ImGuiCol_TooltipBg -> ImGuiCol_PopupBg ポップアップとメニューはこのAPIを事前に必要とするようになった ocornut#337
    - style.WindowFillAlphaDefault 削除 style.Colors[ImGuiCol_WindowBg] を使えばいい。  ocornut#337
    - `ImDrawList::PushClipRect(ImVec4 rect)` -> `ImDraw::PushClipRect(Imvec2 min,ImVec2 max,bool intersect_with_current_clip_rect=false)`
    - `CollapsingHeader(const char* label, const char* str_id = NULL, bool display_frame = true, bool default_open = false)` 廃止 -> `default_open` が `true` の `CollapsingHeader(label, ImGuiTreeNodeFlags_DefaultOpen)` を使えばいい。
    - `SetNextTreeNodeOpened()` -> `SetNextTreeNodeOpen()` 但し旧APIからのリダイレクトは定義していない。
    - `GetInternalState()`, `GetInternalStateSize()`, `SetInternalState()` は意味がわからないから `CreateContext()`, `DestroyContext()`, `GetCurrentContext()`, `SetCurrentContext()` にした。
    - タイトルバーがウィンドウ背景に重ねて描画されないように変更した。
- MSVC++ で `snprintf` の代わりに `_snprintf` をCPPで使ってたのをやめた。
- GCC で `-Wformat` `-Wdouble-promotion` `-Wconversion` で警告を出すようにした。
- OSX  でキーバインディングのデフォルトをそれっい感じになるようにした。
- `IM_INT_MIN` `IM_INT_MAX` CPP を廃止して IM_F32_TO_INT8_UNBOUND` と `IM_F32_TO_INT8_SAT` CPP にかえた。
- `void ImStrncpy(char* dst, const char* src, int count)` API を追加した。
- `bool ImGuiStorage::GetBool(ImU32 key, bool default_val) const` API を追加した。
- `bool* ImGuiStorage::GetBoolRef(ImGuiID key, bool default_val)` API を追加した。
- `void ImGuiStorage::SetBool(ImU32 key, bool val)` API を追加した。
- `ImGuiListClipper` 系のAPI を追加した。
- 実装詳細の CamelCase コーディングルールの徹底を図った。
- 実装詳細の不要なブロックスコープを廃止しコーディングルールの徹底を図った。
- 実装詳細のリファクタリングにより動作効率の向上と論理構造の見直しによる可読性の向上などを図った。
- `unsigned long long int` -> `int64_t` など処理系の実装依存による想定外の型挙動が起こらないよう修正した。
- `void ImGui::RenderBullet(ImVec2 pos)` API 追加。
- `bool ImGui::IsItemClicked(int mouse_button)` API 追加。
- `static void ApplySizeFullWithConstraint(ImGuiWindow* window, ImVec2 new_size)` API 追加。
- `void ImGui::SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeConstraintCallback custom_callback, void* custom_callback_user_data)` API 追加。
- `void ImGui::Bullet()` API 追加。
- `void ImGui::TreePushRawID(ImGuiID id)` API 追加。

-----
  • Loading branch information
usagi committed Jul 4, 2016
2 parents a20857d + 5525c23 commit 914c6d2
Show file tree
Hide file tree
Showing 79 changed files with 6,850 additions and 2,934 deletions.
21 changes: 15 additions & 6 deletions examples/README.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Those are standalone ready-to-build applications to demonstrate ImGui.
Binaries of some of those demos are available at http://www.miracleworld.net/imgui/binaries
Binaries of some of those demos: http://www.miracleworld.net/imgui/binaries

Third party languages and frameworks bindings: https://github.com/ocornut/imgui/wiki/Links
(languages: C, .net, rust, D, Python, Lua..)
(frameworks: DX12, Vulkan, Cinder, OpenGLES, openFrameworks, Cocos2d-x, SFML, Flexium, NanoRT, Irrlicht..)
(extras: RemoteImGui, ImWindow, imgui_wm..)

TL;DR;
- Newcomers, read 'PROGRAMMER GUIDE' in imgui.cpp for notes on how to setup ImGui in your codebase.
Expand Down Expand Up @@ -58,20 +63,24 @@ directx11_example/
DirectX11 example, Windows only.
This is quite long and tedious, because: DirectX11.

ios_example/
iOS example.
Using Synergy to access keyboard/mouse data from server computer.
apple_example/
OSX & iOS example.
On iOS, Using Synergy to access keyboard/mouse data from server computer.
Synergy keyboard integration is rather hacky.

sdl_opengl_example/
SDL2 + OpenGL example.

sdl_opengl_example/
sdl_opengl3_example/
SDL2 + OpenGL3 example.

allegro5_example/
Allegro 5 example.

marmalade_example/
Marmalade example using IwGx


vulkan_example/
Vulkan example.
This is quite long and tedious, because: Vulkan.

39 changes: 21 additions & 18 deletions examples/allegro5_example/imgui_impl_a5.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// ImGui Allegro 5 bindings
// In this binding, ImTextureID is used to store a 'ALLEGRO_BITMAP*' texture identifier. Read the FAQ about ImTextureID in imgui.cpp.

// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
Expand Down Expand Up @@ -38,14 +40,14 @@ void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data)
al_get_blender(&op, &src, &dst);
al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);

for (int n = 0; n < draw_data->CmdListsCount; n++)
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];

// FIXME-OPT: Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 floats
static ImVector<ImDrawVertAllegro> vertices;
vertices.resize(cmd_list->VtxBuffer.size());
for (int i = 0; i < cmd_list->VtxBuffer.size(); ++i)
for (int i = 0; i < cmd_list->VtxBuffer.size(); ++i)
{
const ImDrawVert &dv = cmd_list->VtxBuffer[i];
ImDrawVertAllegro v;
Expand All @@ -60,18 +62,18 @@ void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data)
// You can also use '#define ImDrawIdx unsigned int' in imconfig.h and request ImGui to output 32-bit indices
static ImVector<int> indices;
indices.resize(cmd_list->IdxBuffer.size());
for (int i = 0; i < cmd_list->IdxBuffer.size(); ++i)
for (int i = 0; i < cmd_list->IdxBuffer.size(); ++i)
indices[i] = (int)cmd_list->IdxBuffer.Data[i];

int idx_offset = 0;
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
if (pcmd->UserCallback)
if (pcmd->UserCallback)
{
pcmd->UserCallback(cmd_list, pcmd);
}
else
else
{
ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->TextureId;
al_set_clipping_rectangle(pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z-pcmd->ClipRect.x, pcmd->ClipRect.w-pcmd->ClipRect.y);
Expand Down Expand Up @@ -102,11 +104,11 @@ bool Imgui_ImplA5_CreateDeviceObjects()
ALLEGRO_BITMAP* img = al_create_bitmap(width, height);
al_set_new_bitmap_flags(flags);
al_set_new_bitmap_format(fmt);
if (!img)
if (!img)
return false;

ALLEGRO_LOCKED_REGION *locked_img = al_lock_bitmap(img, al_get_bitmap_format(img), ALLEGRO_LOCK_WRITEONLY);
if (!locked_img)
if (!locked_img)
{
al_destroy_bitmap(img);
return false;
Expand All @@ -117,7 +119,7 @@ bool Imgui_ImplA5_CreateDeviceObjects()
// Convert software texture to hardware texture.
ALLEGRO_BITMAP* cloned_img = al_clone_bitmap(img);
al_destroy_bitmap(img);
if (!cloned_img)
if (!cloned_img)
return false;

// Store our identifier
Expand All @@ -135,7 +137,7 @@ bool Imgui_ImplA5_CreateDeviceObjects()

void ImGui_ImplA5_InvalidateDeviceObjects()
{
if (g_Texture)
if (g_Texture)
{
al_destroy_bitmap(g_Texture);
ImGui::GetIO().Fonts->TexID = NULL;
Expand All @@ -151,11 +153,11 @@ void ImGui_ImplA5_InvalidateDeviceObjects()
bool ImGui_ImplA5_Init(ALLEGRO_DISPLAY* display)
{
g_Display = display;
// Create custom vertex declaration.

// Create custom vertex declaration.
// Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 floats.
// We still use a custom declaration to use 'ALLEGRO_PRIM_TEX_COORD' instead of 'ALLEGRO_PRIM_TEX_COORD_PIXEL' else we can't do a reliable conversion.
ALLEGRO_VERTEX_ELEMENT elems[] =
ALLEGRO_VERTEX_ELEMENT elems[] =
{
{ ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, OFFSETOF(ImDrawVertAllegro, pos) },
{ ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, OFFSETOF(ImDrawVertAllegro, uv) },
Expand Down Expand Up @@ -204,13 +206,13 @@ bool ImGui_ImplA5_ProcessEvent(ALLEGRO_EVENT *ev)
{
ImGuiIO &io = ImGui::GetIO();

switch (ev->type)
switch (ev->type)
{
case ALLEGRO_EVENT_MOUSE_AXES:
io.MouseWheel += ev->mouse.dz;
return true;
case ALLEGRO_EVENT_KEY_CHAR:
if (ev->keyboard.display == g_Display)
if (ev->keyboard.display == g_Display)
if (ev->keyboard.unichar > 0 && ev->keyboard.unichar < 0x10000)
io.AddInputCharacter((unsigned short)ev->keyboard.unichar);
return true;
Expand All @@ -226,7 +228,7 @@ bool ImGui_ImplA5_ProcessEvent(ALLEGRO_EVENT *ev)

void ImGui_ImplA5_NewFrame()
{
if (!g_Texture)
if (!g_Texture)
Imgui_ImplA5_CreateDeviceObjects();

ImGuiIO &io = ImGui::GetIO();
Expand All @@ -248,14 +250,15 @@ void ImGui_ImplA5_NewFrame()
io.KeyCtrl = al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALLEGRO_KEY_RCTRL);
io.KeyShift = al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT);
io.KeyAlt = al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR);
io.KeySuper = al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALLEGRO_KEY_RWIN);

ALLEGRO_MOUSE_STATE mouse;
if (keys.display == g_Display)
if (keys.display == g_Display)
{
al_get_mouse_state(&mouse);
io.MousePos = ImVec2((float)mouse.x, (float)mouse.y);
}
else
else
{
io.MousePos = ImVec2(-1, -1);
}
Expand Down
2 changes: 2 additions & 0 deletions examples/allegro5_example/imgui_impl_a5.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// ImGui Allegro 5 bindings
// In this binding, ImTextureID is used to store a 'ALLEGRO_BITMAP*' texture identifier. Read the FAQ about ImTextureID in imgui.cpp.

// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
Expand Down
8 changes: 4 additions & 4 deletions examples/allegro5_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

int main(int, char**)
{
// Setup Allegro
// Setup Allegro
al_init();
al_install_keyboard();
al_install_mouse();
Expand Down Expand Up @@ -41,7 +41,7 @@ int main(int, char**)

// Main loop
bool running = true;
while (running)
while (running)
{
ALLEGRO_EVENT ev;
while (al_get_next_event(queue, &ev))
Expand Down Expand Up @@ -70,7 +70,7 @@ int main(int, char**)
}

// 2. Show another simple window, this time using an explicit Begin/End pair
if (show_another_window)
if (show_another_window)
{
ImGui::SetNextWindowSize(ImVec2(200, 100), ImGuiSetCond_FirstUseEver);
ImGui::Begin("Another Window", &show_another_window);
Expand All @@ -79,7 +79,7 @@ int main(int, char**)
}

// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
if (show_test_window)
if (show_test_window)
{
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
ImGui::ShowTestWindow(&show_test_window);
Expand Down
File renamed without changes.
28 changes: 18 additions & 10 deletions examples/ios_example/README.md → examples/apple_example/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# iOS example
# iOS / OSX example

## Introduction

This example is the default XCode "OpenGL" example code, modified to support ImGui and [Synergy](http://synergy-project.org/).
This example is the default XCode "OpenGL" example code, modified to support ImGui and [Synergy](http://synergy-project.org/) to share mouse/keyboard on an iOS device.

It is a rather complex example because of all of the faff required to get an XCode/iOS application running. Refer to the regular OpenGL examples if you want to learn about integrating ImGui.
It is a rather complex and messy example because of all of the faff required to get an XCode/iOS application running. Refer to the regular OpenGL examples if you want to learn about integrating ImGui. **The opengl3_example/ should also work on OS X and is much simpler.** This is an integration for iOS with Synergy.

Synergy (remote keyboard/mouse) is not required, but it's pretty hard to use ImGui without it. Synergy includes a "uSynergy" library that allows embedding a synergy client, this is what is used here. ImGui supports "TouchPadding", and this is enabled when Synergy is not active.

## How to Use
## How to Use on iOS

0. In Synergy, go to Preferences, and uncheck "Use SSL encryption"
0. Run the example app.
0. Tap the "servername" button in the corner
0. Enter the name or the IP of your synergy host
0. If you had previously connected to a server, you may need to kill and re-start the app.
* In Synergy, go to Preferences, and uncheck "Use SSL encryption"
* Run the example app.
* Tap the "servername" button in the corner
* Enter the name or the IP of your synergy host
* If you had previously connected to a server, you may need to kill and re-start the app.

## How to Build on OSX

* Make sure you have install `brew`, if not, please refer to [Homebrew Website](http://brew.sh)
* Run the command: `brew install glfw3`
* Double click `imguiex.xcodeproj` and select `imguiex-osx` scheme
* Click `Run` button

## Notes and TODOs

Expand All @@ -25,7 +32,8 @@ Things that would be nice but I didn't get around to doing:
* Graceful disconnect/reconnect from uSynergy.
* Copy/Paste not well-supported

## C++ on iOS
## C++ on iOS / OSX

ImGui is a c++ library. If you want to include it directly, rename your Obj-C file to have the ".mm" extension.

Alternatively, you can wrap your debug code in a C interface, this is what I am demonstrating here with the "debug_hud.h" interface. Either approach works, use whatever you prefer.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
"idiom" : "ipad",
"filename" : "icon_imgui_76@2x~ipad.png",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions examples/apple_example/imguiex-ios/imgui_impl_ios.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ImGui iOS+OpenGL+Synergy binding
// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp.
// Providing a standalone iOS application with Synergy integration makes this sample more verbose than others. It also hasn't been tested as much.
// Refer to other examples to get an easier understanding of how to integrate ImGui into your existing application.

// by Joel Davis (joeld42@gmail.com)

#pragma once

#include <Foundation/Foundation.h>
#include <UIKit/UIKit.h>

@interface ImGuiHelper : NSObject

- (id) initWithView: (UIView *)view;

- (void)connectServer: (NSString*)serverName;

- (void)render;
- (void)newFrame;

@end
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// imgui_impl_ios.cpp
// imguiex
// ImGui iOS+OpenGL+Synergy binding
// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp.
// Providing a standalone iOS application with Synergy integration makes this sample more verbose than others. It also hasn't been tested as much.
// Refer to other examples to get an easier understanding of how to integrate ImGui into your existing application.

#import <OpenGLES/ES3/gl.h>
#import <OpenGLES/ES3/glext.h>
Expand Down Expand Up @@ -262,10 +263,10 @@ void ImGui_KeyboardCallback(uSynergyCookie cookie, uint16_t key,
// printf("Synergy: keyboard callback: 0x%02X (%s)", scanCode, down?"true":"false");
ImGuiIO& io = ImGui::GetIO();
io.KeysDown[key] = down;
io.KeyShift = modifiers & USYNERGY_MODIFIER_SHIFT;
io.KeyCtrl = modifiers & USYNERGY_MODIFIER_CTRL;
io.KeyAlt = modifiers & USYNERGY_MODIFIER_ALT;

io.KeyShift = (modifiers & USYNERGY_MODIFIER_SHIFT);
io.KeyCtrl = (modifiers & USYNERGY_MODIFIER_CTRL);
io.KeyAlt = (modifiers & USYNERGY_MODIFIER_ALT);
io.KeySuper = (modifiers & USYNERGY_MODIFIER_WIN);

// Add this as keyboard input
if ((down) && (key) && (scanCode<256) && !(modifiers & USYNERGY_MODIFIER_CTRL))
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions examples/apple_example/imguiex-osx/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// imguiex-osx
//
// Created by James Chen on 4/5/16.
// Copyright © 2016 Joel Davis. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>


@end

26 changes: 26 additions & 0 deletions examples/apple_example/imguiex-osx/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// AppDelegate.m
// imguiex-osx
//
// Created by James Chen on 4/5/16.
// Copyright © 2016 Joel Davis. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}

@end
Loading

0 comments on commit 914c6d2

Please sign in to comment.