Начинающий
- Статус
- Оффлайн
- Регистрация
- 29 Дек 2021
- Сообщения
- 8
- Реакции
- 0
Сделал кейбинд, вроде все работает но mouse4,mouse5 не работают (кейбинд переписал тоже не помогло)
Сурс - aristois
Сурс - aristois
C++:
bool ImGui::Hotkey(const char* label, int* k, const ImVec2& size_arg)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
ImGuiContext& g = *GImGui;
ImGuiIO& io = g.IO;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID(label);
const ImVec2 label_size = CalcTextSize(label, NULL, true);
ImVec2 size = CalcItemSize(ImVec2(50, size_arg.y), CalcItemWidth(), label_size.y + style.FramePadding.y * 2.0f);
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f));
ItemSize(total_bb, style.FramePadding.y);
if (!ItemAdd(total_bb, &id))
return false;
const bool focus_requested = ImGui::FocusableItemRegister(window, g.ActiveId == id);
const bool hovered = ImGui::IsHovered(frame_bb, id);
if (hovered) {
SetHoveredID(id);
g.MouseCursor = ImGuiMouseCursor_TextInput;
}
const bool user_clicked = hovered && io.MouseClicked[0];
if (focus_requested || user_clicked) {
if (g.ActiveId != id) {
// Start edition
memset(io.MouseDown, 0, sizeof(io.MouseDown));
memset(io.KeysDown, 0, sizeof(io.KeysDown));
*k = 0;
}
SetActiveID(id, window);
FocusWindow(window);
}
else if (io.MouseClicked[0]) {
// Release focus when we click outside
if (g.ActiveId == id)
ClearActiveID();
}
bool value_changed = false;
int key = *k;
if (g.ActiveId == id) {
for (auto i = 0; i < 5; i++) {
if (io.MouseDown[i]) {
switch (i) {
case 0:
key = VK_LBUTTON;
break;
case 1:
key = VK_RBUTTON;
break;
case 2:
key = VK_MBUTTON;
break;
case 3:
key = VK_XBUTTON1;
break;
case 4:
key = VK_XBUTTON2;
break;
}
value_changed = true;
ClearActiveID();
}
}
if (!value_changed) {
for (auto i = VK_BACK; i <= VK_RMENU; i++) {
if (io.KeysDown[i]) {
key = i;
value_changed = true;
ClearActiveID();
}
}
}
if (IsKeyPressedMap(ImGuiKey_Escape)) {
*k = 0;
ClearActiveID();
}
else {
*k = key;
}
}
// Render
// Select which buffer we are going to display. When ImGuiInputTextFlags_NoLiveEdit is set 'buf' might still be the old value. We set buf to NULL to prevent accidental usage from now on.
char buf_display[64] = "None";
RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
if (*k != 0 && g.ActiveId != id) {
strcpy(buf_display, KeyNames[*k]);
}
else if (g.ActiveId == id) {
strcpy(buf_display, "Press");
}
const ImRect clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + size.x, frame_bb.Min.y + size.y); // Not using frame_bb.Max because we have adjusted size
ImVec2 render_pos = frame_bb.Min + style.FramePadding;
RenderTextClipped(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding, buf_display, NULL, NULL);
//draw_window->DrawList->AddText(g.Font, g.FontSize, render_pos, GetColorU32(ImGuiCol_Text), buf_display, NULL, 0.0f, &clip_rect);
if (label_size.x > 0)
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
return value_changed;
}
Последнее редактирование: