本文整理汇总了C++中ImVec2函数的典型用法代码示例。如果您正苦于以下问题:C++ ImVec2函数的具体用法?C++ ImVec2怎么用?C++ ImVec2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImVec2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ImGui_ImplSdl_NewFrame
void ImGui_ImplSdl_NewFrame(SDL_Window *window)
{
if (!g_FontTexture)
ImGui_ImplSdl_CreateDeviceObjects();
ImGuiIO& io = ImGui::GetIO();
// Setup display size (every frame to accommodate for window resizing)
int w, h;
SDL_GetWindowSize(window, &w, &h);
io.DisplaySize = ImVec2((float)w, (float)h);
// Setup time step
Uint32 time = SDL_GetTicks();
double current_time = time / 1000.0;
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
g_Time = current_time;
// Setup inputs
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
int mx, my;
Uint32 mouseMask = SDL_GetMouseState(&mx, &my);
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS)
io.MousePos = ImVec2((float)mx, (float)my); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
else
io.MousePos = ImVec2(-1,-1);
io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
io.MouseDown[1] = g_MousePressed[1] || (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
io.MouseDown[2] = g_MousePressed[2] || (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;
io.MouseWheel = g_MouseWheel;
g_MouseWheel = 0.0f;
// Hide OS mouse cursor if ImGui is drawing it
SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1);
// Start the frame
ImGui::NewFrame();
}
示例2: GetCurrentWindow
bool ImGui::Image(cocos2d::Texture2D* texture, const cocos2d::Rect cropSize, const ImVec2& displaySize, int borderSize)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
const ImVec4& tint_col = ImVec4(1, 1, 1, 1);
const ImVec4& border_col = ImVec4(0.95f, 0.12f, 0.04f, 1);
GLuint textureID = texture->getName();
ImRect bb(window->DC.CursorPos, window->DC.CursorPos + displaySize);
if (border_col.w > 0.0f)
bb.Max += ImVec2(2, 2);
ItemSize(bb);
if (!ItemAdd(bb, NULL))
return false;
ImGui::PushID((void *)textureID);
const ImGuiID id = window->GetID("#image");
ImGui::PopID();
bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held);
float focus_x = cropSize.origin.x;
float focus_y = cropSize.origin.y;
ImVec2 uv0 = ImVec2((focus_x) / texture->getContentSize().width, (focus_y) / texture->getContentSize().height);
ImVec2 uv1 = ImVec2((focus_x + cropSize.size.width) / texture->getContentSize().width, (focus_y + cropSize.size.height) / texture->getContentSize().height);
if (border_col.w > 0.0f)
{
window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(border_col));
window->DrawList->AddImage((ImTextureID)textureID, bb.Min + ImVec2(borderSize, borderSize), bb.Max - ImVec2(borderSize, borderSize), uv0, uv1, GetColorU32(tint_col));
}
else
{
window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(border_col));
window->DrawList->AddImage((ImTextureID)textureID, bb.Min + ImVec2(borderSize, borderSize), bb.Max - ImVec2(borderSize, borderSize), uv0, uv1, GetColorU32(tint_col));
}
return pressed;
}
示例3: RenderInMenu
void CEditorLights::RenderInMenu()
{
ImGui::SetNextWindowSize(ImVec2(512, 512), ImGuiSetCond_FirstUseEver);
if (m_activated_editor) {
ImGui::Begin("LightsEditor", &m_activated_editor);
RenderGeneral();
RenderNewLight();
RenderAllLights();
RenderMultiEdit();
ImGui::End();
}
}
示例4: onToolbar
void AssetBrowser::onToolbar()
{
auto pos = ImGui::GetCursorScreenPos();
if (ImGui::BeginToolbar("asset_browser_toolbar", pos, ImVec2(0, 24)))
{
if (m_history_index > 0) m_back_action->toolbarButton();
if (m_history_index < m_history.size() - 1) m_forward_action->toolbarButton();
m_auto_reload_action->toolbarButton();
m_refresh_action->toolbarButton();
}
ImGui::EndToolbar();
}
示例5: beginFrame
void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId)
{
m_viewId = _viewId;
ImGuiIO& io = ImGui::GetIO();
if (_inputChar < 0x7f)
{
io.AddInputCharacter(_inputChar); // ASCII or GTFO! :(
}
io.DisplaySize = ImVec2( (float)_width, (float)_height);
const int64_t now = bx::getHPCounter();
const int64_t frameTime = now - m_last;
m_last = now;
const double freq = double(bx::getHPFrequency() );
io.DeltaTime = float(frameTime/freq);
io.MousePos = ImVec2( (float)_mx, (float)_my);
io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT);
io.MouseDown[1] = 0 != (_button & IMGUI_MBUT_RIGHT);
io.MouseDown[2] = 0 != (_button & IMGUI_MBUT_MIDDLE);
io.MouseWheel = (float)(_scroll - m_lastScroll);
m_lastScroll = _scroll;
#if defined(SCI_NAMESPACE)
uint8_t modifiers = inputGetModifiersState();
io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) );
io.KeyCtrl = 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) );
io.KeyAlt = 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt ) );
for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii)
{
io.KeysDown[ii] = inputGetKeyState(entry::Key::Enum(ii) );
}
#endif // defined(SCI_NAMESPACE)
ImGui::NewFrame();
ImGuizmo::BeginFrame();
ImGui::PushStyleVar(ImGuiStyleVar_ViewId, (float)_viewId);
}
示例6: ImGui_ImplSDL2_UpdateMousePosAndButtons
static void ImGui_ImplSDL2_UpdateMousePosAndButtons()
{
ImGuiIO& io = ImGui::GetIO();
// Set OS mouse position if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
if (io.WantSetMousePos)
SDL_WarpMouseInWindow(g_Window, (int)io.MousePos.x, (int)io.MousePos.y);
else
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
int mx, my;
Uint32 mouse_buttons = SDL_GetMouseState(&mx, &my);
io.MouseDown[0] = g_MousePressed[0] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
io.MouseDown[1] = g_MousePressed[1] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
io.MouseDown[2] = g_MousePressed[2] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS)
SDL_Window* focused_window = SDL_GetKeyboardFocus();
if (g_Window == focused_window)
{
// SDL_GetMouseState() gives mouse position seemingly based on the last window entered/focused(?)
// The creation of a new windows at runtime and SDL_CaptureMouse both seems to severely mess up with that, so we retrieve that position globally.
int wx, wy;
SDL_GetWindowPosition(focused_window, &wx, &wy);
SDL_GetGlobalMouseState(&mx, &my);
mx -= wx;
my -= wy;
io.MousePos = ImVec2((float)mx, (float)my);
}
// SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger the OS window resize cursor.
// The function is only supported from SDL 2.0.4 (released Jan 2016)
bool any_mouse_button_down = ImGui::IsAnyMouseDown();
SDL_CaptureMouse(any_mouse_button_down ? SDL_TRUE : SDL_FALSE);
#else
if (SDL_GetWindowFlags(g_Window) & SDL_WINDOW_INPUT_FOCUS)
io.MousePos = ImVec2((float)mx, (float)my);
#endif
}
示例7: ImVec2
void NotificationOSDLayer::Draw(RenderWindowOSD* OSD, ImGuiDX9* GUI)
{
if (Tick() == false)
return;
ImGui::SetNextWindowPos(ImVec2(10, *TESRenderWindow::ScreenHeight - 150));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
if (!ImGui::Begin("Notification Overlay", nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoInputs))
{
ImGui::End();
ImGui::PopStyleVar(4);
return;
}
const Notification& Current = GetNextNotification();
float RemainingTime = Current.GetRemainingTicks() / (float)Current.Duration;
ImGui::Text(" %s ", Current.Message.c_str());
ImGui::Dummy(ImVec2(10, 15));
ImGui::ProgressBar(RemainingTime, ImVec2(-1, 1));
ImGui::End();
ImGui::PopStyleVar(4);
}
示例8: ImGui_ImplAllegro5_Init
bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display)
{
g_Display = display;
// Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
io.BackendPlatformName = io.BackendRendererName = "imgui_impl_allegro5";
// 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_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, IM_OFFSETOF(ImDrawVertAllegro, pos) },
{ ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, IM_OFFSETOF(ImDrawVertAllegro, uv) },
{ ALLEGRO_PRIM_COLOR_ATTR, 0, IM_OFFSETOF(ImDrawVertAllegro, col) },
{ 0, 0, 0 }
};
g_VertexDecl = al_create_vertex_decl(elems, sizeof(ImDrawVertAllegro));
io.KeyMap[ImGuiKey_Tab] = ALLEGRO_KEY_TAB;
io.KeyMap[ImGuiKey_LeftArrow] = ALLEGRO_KEY_LEFT;
io.KeyMap[ImGuiKey_RightArrow] = ALLEGRO_KEY_RIGHT;
io.KeyMap[ImGuiKey_UpArrow] = ALLEGRO_KEY_UP;
io.KeyMap[ImGuiKey_DownArrow] = ALLEGRO_KEY_DOWN;
io.KeyMap[ImGuiKey_PageUp] = ALLEGRO_KEY_PGUP;
io.KeyMap[ImGuiKey_PageDown] = ALLEGRO_KEY_PGDN;
io.KeyMap[ImGuiKey_Home] = ALLEGRO_KEY_HOME;
io.KeyMap[ImGuiKey_End] = ALLEGRO_KEY_END;
io.KeyMap[ImGuiKey_Insert] = ALLEGRO_KEY_INSERT;
io.KeyMap[ImGuiKey_Delete] = ALLEGRO_KEY_DELETE;
io.KeyMap[ImGuiKey_Backspace] = ALLEGRO_KEY_BACKSPACE;
io.KeyMap[ImGuiKey_Space] = ALLEGRO_KEY_SPACE;
io.KeyMap[ImGuiKey_Enter] = ALLEGRO_KEY_ENTER;
io.KeyMap[ImGuiKey_Escape] = ALLEGRO_KEY_ESCAPE;
io.KeyMap[ImGuiKey_A] = ALLEGRO_KEY_A;
io.KeyMap[ImGuiKey_C] = ALLEGRO_KEY_C;
io.KeyMap[ImGuiKey_V] = ALLEGRO_KEY_V;
io.KeyMap[ImGuiKey_X] = ALLEGRO_KEY_X;
io.KeyMap[ImGuiKey_Y] = ALLEGRO_KEY_Y;
io.KeyMap[ImGuiKey_Z] = ALLEGRO_KEY_Z;
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
#if ALLEGRO_HAS_CLIPBOARD
io.SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText;
io.GetClipboardTextFn = ImGui_ImplAllegro5_GetClipboardText;
io.ClipboardUserData = NULL;
#endif
return true;
}
示例9: aEvent
void GUISelectAdapterWindow::draw(const sf::Vector2u& windowSize) {
if (!this->isEnabled) return;
int winFlags = ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_AlwaysAutoResize;
// temp bool for state etc
ImGui::Begin("Select Network Adapter Device", &this->isEnabled, winFlags);
ImGui::Text("Select Network Adapter Device");
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
std::vector<AdapterDevice>& adapters = *state.adapters;
for (unsigned i = 0; i < adapters.size(); i++) {
ImGui::RadioButton(
adapters[i].name.c_str(),
state.selectedAdapter,
i );
ImGui::Text(adapters[i].description.c_str());
ImGui::Spacing();
}
ImGui::Separator();
ImGui::Spacing();
ImGui::Spacing();
ImGui::SameLine(ImGui::GetWindowContentRegionMax().x - 55);
if (ImGui::Button("Select")) {
Event aEvent(this, EventType::AdapterChosen, *state.selectedAdapter);
adapterChosenDispatcher.fire(aEvent);
}
// center the window
ImVec2 thisSize = ImGui::GetWindowSize();
ImGui::SetWindowPos(ImVec2(windowSize.x / 2 - thisSize.x / 2,
windowSize.y / 2 - thisSize.y / 2));
ImGui::End();
}
示例10: ImColor
void RoR::DrawImGuiSpinner(float& counter, const ImVec2 size, const float spacing, const float step_sec)
{
// Hardcoded to 4 segments, counter is reset after full round (4 steps)
// --------------------------------------------------------------------
const ImU32 COLORS[] = { ImColor(255,255,255,255), ImColor(210,210,210,255), ImColor(120,120,120,255), ImColor(60,60,60,255) };
// Update counter, determine coloring
counter += ImGui::GetIO().DeltaTime;
int color_start = 0; // Index to GUI_SPINNER_COLORS array for the top middle segment (segment 0)
while (counter > (step_sec*4.f))
{
counter -= (step_sec*4.f);
}
if (counter > (step_sec*3.f))
{
color_start = 3;
}
else if (counter > (step_sec*2.f))
{
color_start = 2;
}
else if (counter > (step_sec))
{
color_start = 1;
}
// Draw segments
ImDrawList* draw_list = ImGui::GetWindowDrawList();
const ImVec2 pos = ImGui::GetCursorScreenPos();
const float left = pos.x;
const float top = pos.y;
const float right = pos.x + size.x;
const float bottom = pos.y + size.y;
const float mid_x = pos.x + (size.x / 2.f);
const float mid_y = pos.y + (size.y / 2.f);
// NOTE: Enter vertices in clockwise order, otherwise anti-aliasing doesn't work and polygon is rasterized larger! -- Observed under OpenGL2 / OGRE 1.9
// Top triangle, vertices: mid, left, right
draw_list->AddTriangleFilled(ImVec2(mid_x, mid_y-spacing), ImVec2(left + spacing, top), ImVec2(right - spacing, top), COLORS[color_start]);
// Right triangle, vertices: mid, top, bottom
draw_list->AddTriangleFilled(ImVec2(mid_x+spacing, mid_y), ImVec2(right, top + spacing), ImVec2(right, bottom - spacing), COLORS[(color_start+3)%4]);
// Bottom triangle, vertices: mid, right, left
draw_list->AddTriangleFilled(ImVec2(mid_x, mid_y+spacing), ImVec2(right - spacing, bottom), ImVec2(left + spacing, bottom), COLORS[(color_start+2)%4]);
// Left triangle, vertices: mid, bottom, top
draw_list->AddTriangleFilled(ImVec2(mid_x-spacing, mid_y), ImVec2(left, bottom - spacing), ImVec2(left, top + spacing), COLORS[(color_start+1)%4]);
}
示例11: ImGui_ImplGLUT_MouseFunc
void ImGui_ImplGLUT_MouseFunc(int glut_button, int state, int x, int y)
{
ImGuiIO& io = ImGui::GetIO();
io.MousePos = ImVec2((float)x, (float)y);
int button = -1;
if (glut_button == GLUT_LEFT_BUTTON) button = 0;
if (glut_button == GLUT_RIGHT_BUTTON) button = 1;
if (glut_button == GLUT_MIDDLE_BUTTON) button = 2;
if (button != -1 && state == GLUT_DOWN)
io.MouseDown[button] = true;
if (button != -1 && state == GLUT_UP)
io.MouseDown[button] = false;
}
示例12: ImGui_ImplSDL2_NewFrame
void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
{
ImGuiIO& io = ImGui::GetIO();
IM_ASSERT(io.Fonts->IsBuilt()); // Font atlas needs to be built, call renderer _NewFrame() function e.g. ImGui_ImplOpenGL3_NewFrame()
// Setup display size (every frame to accommodate for window resizing)
int w, h;
int display_w, display_h;
SDL_GetWindowSize(window, &w, &h);
SDL_GL_GetDrawableSize(window, &display_w, &display_h);
io.DisplaySize = ImVec2((float)w, (float)h);
io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0);
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
static Uint64 frequency = SDL_GetPerformanceFrequency();
Uint64 current_time = SDL_GetPerformanceCounter();
io.DeltaTime = g_Time > 0 ? (float)((double)(current_time - g_Time) / frequency) : (float)(1.0f / 60.0f);
g_Time = current_time;
ImGui_ImplSDL2_UpdateMousePosAndButtons();
ImGui_ImplSDL2_UpdateMouseCursor();
}
示例13: ImGui_ImplNyan_NewFrame
void ImGui_ImplNyan_NewFrame(void)
{
unsigned int winx, winy;
int mx, my;
ImGuiIO &io = ImGui::GetIO();
wchar_t *inputstr;
winx = nvGetStatusi(NV_STATUS_WINX);
winy = nvGetStatusi(NV_STATUS_WINY);
mx = nvGetStatusi(NV_STATUS_WINMX);
my = nvGetStatusi(NV_STATUS_WINMY);
inputstr = nvGetStatusw(NV_STATUS_WINTEXTINPUTBUF);
io.DisplaySize = ImVec2((float)winx, (float)winy);
io.DeltaTime = (float)nGetspf();
io.MousePos = ImVec2((float)mx, (float)my);
io.MouseDown[0] = (nvGetStatusi(NV_STATUS_WINMBL)==1)?true:false;
io.MouseDown[1] = (nvGetStatusi(NV_STATUS_WINMBR)==1)?true:false;
io.MouseDown[2] = (nvGetStatusi(NV_STATUS_WINMBM)==1)?true:false;
for(int i = 0; i < 256; i++)
io.KeysDown[i] = (nvGetKey(i) == 1)?true:false;
io.KeyCtrl = io.KeysDown[NK_CONTROL];
io.KeyShift = io.KeysDown[NK_SHIFT];
io.KeyAlt = io.KeysDown[NK_ALT];
io.KeySuper = io.KeysDown[NK_LWIN] || io.KeysDown[NK_RWIN];
while(*inputstr) {
if(*inputstr > 0 && *inputstr < 0x10000)
io.AddInputCharacter(*inputstr);
inputstr++;
}
ImGui::NewFrame();
}
示例14: dc_debug
extern "C" void dc_debug(void)
{
static DebugMemoryState memory_ctx_sat;
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f), ImGuiSetCond_FirstUseEver);
ImGui::Begin("Dreamcast", NULL, ImGuiWindowFlags_NoMove);
if(ImGui::CollapsingHeader("Memory", NULL, true, true)) {
static DebugMemoryState memory_state;
debug_memory("DC RAM", &memory_state, dc_ram, sizeof(dc_ram));
}
ImGui::End();
}
示例15: ImVec2
void game_system::on_resize_viewport(const uint2& size)
{
if (size.x == 0 || size.y == 0) {
viewport_is_visible_ = false;
return;
}
ImGui::GetIO().DisplaySize = ImVec2(float(size.x), float(size.y));
viewport_is_visible_ = true;
frame_.projection_matrix = math::perspective_matrix_directx(game_system::projection_fov,
aspect_ratio(size), game_system::projection_near, game_system::projection_far);
render_system_.resize_viewport(size);
}