Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

if ((GetAsyncKeyState(virtualKeyCode) & 0x8000) != 0) { } virtualKeyCode = 33 but aint…

  1. User

    if ((GetAsyncKeyState(virtualKeyCode) & 0x8000) != 0) { } virtualKeyCode = 33 but aint working

  2. Assistant

    As an AI language model, I cannot fully understand the context of your code. However, I can suggest some general tips:

    1. Make sure you have defined the value of virtualKeyCode correctly and it matches the correct key code of the key you want to detect.

    2. Check if you have included the header file <Windows.h> which is required for GetAsyncKeyState() function.

    3. Try using a different key code to test if the function is working properly.

    4. Check if there is any other part of the code that might be interfering with the function.

    5. If all else fails, try using a different method to detect key presses such as using the Win32 API function GetMessage() or using a third-party library like SDL or GLFW.

  3. User

    if ((GetAsyncKeyState(33) & 0x8000) != 0) { }

  4. Assistant

    This code is checking if the virtual key code 33 (which corresponds to the exclamation mark key) is currently being held down by the user. The function GetAsyncKeyState returns the state of the specified virtual key (in this case, the exclamation mark key) by checking its status in the current input queue.

    If the key is currently being held down, the function returns a value of 0x8000, indicating that the key is in a pressed state. The code then checks if this value is not equal to 0 by using the != operator and if it is not, then the code inside the curly brackets is executed.

    Note that this code alone does not perform any specific action or function, it is just checking the state of the exclamation mark key. You would typically use this code as part of a larger program that responds to user input.

  5. User

    template bool loadFromJson(const nlohmann::json& j, const std::string& key, T& value) { if (j.find(key) != j.end() && !j[key].is_null()) { value = j[key].get(); return true; } return false; }

    template<> bool loadFromJson(const nlohmann::json& j, const std::string& key, ImColor& value) { if (j.find(key) != j.end() && !j[key].is_null()) { std::vector colorToSaveLoad = j[key].get<std::vector>(); value = ImColor(colorToSaveLoad[0], colorToSaveLoad[1], colorToSaveLoad[2]); return true; } return false; }

    give me example for ULONG64 type

  6. Assistant

    Here is an example of how you can use the loadFromJson template function to load a ULONG64 value from a JSON file:

    // Example JSON data
    nlohmann::json jsonData = R"({
        "my_ulong64_value": 18446744073709551615
    })"_json;
    
    // Declare a variable to store the loaded value
    ULONG64 myValue = 0;
    
    // Call the loadFromJson function, passing in the JSON data, the key to look up, and a reference to the variable to store the value in
    loadFromJson(jsonData, "my_ulong64_value", myValue);
    
    // The value of myValue should now be 18446744073709551615 if the JSON data contained a valid value for the "my_ulong64_value" key
    

    Note that you will need to include the appropriate headers for the nlohmann::json and ULONG64 types, depending on the implementation you are using. Additionally, you will need to make sure that the JSON data you are loading contains a valid value for the specified key in order for the function to successfully load the value into the variable.

  7. User

    done = false;

    while (!done) { ... // }

    how to return to the start of the while cycle

  8. Assistant

    To return to the start of the while loop, you can use the continue statement. The continue statement is used to immediately stop the current iteration of a loop and move on to the next iteration of the loop.

    Here is an example of how you can use the continue statement to return to the start of a while loop:

    bool done = false;
    
    while (!done) {
        // do something
    
        if (some_condition_is_met) {
            // return to the start of the loop
            continue;
        }
    
        // do something else
    }
    

    In this example, the code inside the while loop will continue executing until some_condition_is_met evaluates to true. At that point, the continue statement is executed, which causes the program to immediately return to the start of the while loop and re-evaluate the condition. If the condition is still false, the loop will continue normally. If the condition is true, the code inside the if statement will be executed, and so on.

  9. User

    if (&globalItems == nullptr || &globalItems == nullptr) continue;

    why intellisense marking this for me as "redunant code" ?

  10. Assistant

    Intellisense is marking the code as redundant because the two conditions in the if statement are identical and will always return the same result. This means that the second condition is unnecessary and can be removed without affecting the behavior of the code.

    Here's an explanation of why the two conditions are equivalent:

    1. &globalItems == nullptr This condition checks if the address of the globalItems variable is equal to nullptr, which means that globalItems is a null pointer.

    2. &globalItems == nullptr This condition is identical to the first condition and will always evaluate to the same result.

    Therefore, the second condition is redundant and can be removed without changing the behavior of the code. You can simplify the if statement to:

    if (&globalItems == nullptr)
        continue;
    

    Or, if globalItems is a pointer, you can simplify it further to:

    if (globalItems == nullptr)
        continue;
    

    Note that this assumes that globalItems is a pointer. If it is not a pointer, your original code may be correct.

  11. User

    i need a box with text and gray bacground behind text, written on imgui

  12. Assistant

    You can create a box with text and a gray background in ImGui using the ImGui::GetWindowDrawList() function to draw a rectangle and ImGui::GetWindowPos() and ImGui::GetWindowSize() functions to get the position and size of the current window. Here's an example:

    // Set up the background color
    ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
    
    // Get the position and size of the current window
    ImVec2 pos = ImGui::GetWindowPos();
    ImVec2 size = ImGui::GetWindowSize();
    
    // Draw the background rectangle
    ImGui::GetWindowDrawList()->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), ImGui::GetColorU32(ImGuiCol_Header));
    
    // Draw the text inside the box
    ImGui::SetCursorPos(ImVec2(pos.x + 10.0f, pos.y + 10.0f)); // adjust the position as needed
    ImGui::Text("Hello, World!");
    
    // Reset the background color
    ImGui::PopStyleColor();
    

    This code will draw a gray rectangle behind the text "Hello, World!" in the current ImGui window. You can adjust the position and size of the rectangle and the text as needed to suit your requirements.

  13. User

    im adding lot of text in draw order, and i will need to add background box which size will be calculated, based on amount of lines already added in draw order. but box should be behind those text. what i should change in your snippet to achieve that

  14. Assistant

    To draw the box behind the text, you can first calculate the size of the text using ImGui::CalcTextSize() function, then use that size to set the size of the box. Here is an example code snippet that shows how you can achieve this:

    // Set up the background color
    ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
    
    // Get the position of the next line of text in the window
    ImVec2 textPos = ImGui::GetCursorScreenPos();
    
    // Compute the size of the text
    ImVec2 textSize = ImGui::CalcTextSize("Hello, World!");
    
    // Get the current cursor position to know where the next text line starts
    ImVec2 curPos = ImGui::GetCursorPos();
    
    // Calculate the size of the bounding box
    auto boxSize = ImVec2(textSize.x + 20, textSize.y + 20);
    
    // Move the text position a little to the right and down, so that it fits in the box
    textPos.x += 10;
    textPos.y += 10;
    
    // Draw the background rectangle
    ImGui::GetWindowDrawList()->AddRectFilled(textPos - ImVec2(10, 10), textPos + boxSize, ImGui::GetColorU32(ImGuiCol_Header));
    
    // Draw the text inside the box
    ImGui::SetCursorScreenPos(textPos);
    ImGui::Text("Hello, World!");
    
    // Restore the cursor position
    ImGui::SetCursorPos(curPos);
    
    // Reset the background color
    ImGui::PopStyleColor();
    

    In this code, we compute the size of the text using the ImGui::CalcTextSize() function and then use textSize to set the size of the bounding box. We also move the text position a little to the right and down so that it fits inside the box. Finally, we draw the background box first and then the text on top of it.

    Note that you may need to adjust the size and position of the box and text to suit your specific needs.

  15. User

    but i already called drawlist->addText in order, and only after that i can call draw box.

  16. Assistant

    If you have already called DrawList->AddText() to draw your text in order, you can use DrawList->GetCursorScreenPos() to get the position of the last text line, then use that position to compute the size of your background box. Here is an example code snippet that illustrates this:

    // Compute the size of the text by getting the position of the last line of text and adding the height of the text
    ImVec2 lastLinePos = ImGui::GetWindowDrawList()->GetCursorScreenPos();
    ImVec2 textSize = ImGui::CalcTextSize("Hello, World!");
    ImVec2 boxSize = ImVec2(textSize.x + 20, textSize.y + 20);
    
    // Move the position of the box up by the height of the text, so it sits behind the text
    ImVec2 boxPos = lastLinePos - ImVec2(0, textSize.y);
    
    // Draw the background box behind the text
    ImGui::GetWindowDrawList()->AddRectFilled(boxPos - ImVec2(10, 10), boxPos + boxSize, ImColor(0.5f, 0.5f, 0.5f, 1.0f));
    
    // Draw the text on top of the background box
    ImGui::GetWindowDrawList()->AddText(ImVec2(boxPos.x + 10, boxPos.y + 10), ImColor(1.0f, 1.0f, 1.0f), "Hello, World!");
    

    In this snippet, we first use DrawList->GetCursorScreenPos() to get the position of the last line of text. We then compute the size of the text as before and use it to compute the size of the background box. The position of the box is set to be above the last line of text, so it will appear behind the text. Finally, we draw the background box and the text as before.

    Note that this assumes that all your text has the same font size. If your text has different font sizes, you may need to calculate the height of each line separately and adjust the position of the background box accordingly.

  17. User

    will rectFilled behind text, or it will be in front of it?

  18. Assistant

    The AddRectFilled() function will draw a rectangle (or filled box) behind your text. If you call AddRectFilled() before calling AddText(), the rectangle will be drawn first and the text will be drawn on top of it.

    Here's an example to illustrate this:

    // Draw the background box first
    ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(10, 10), ImVec2(200, 50), ImColor(0.5f, 0.5f, 0.5f, 1.0f));
    
    // Draw the text on top of the background box
    ImGui::GetWindowDrawList()->AddText(ImVec2(30, 30), ImColor(1.0f, 1.0f, 1.0f), "Hello, World!");
    

    In this example, the AddRectFilled() function is called first, and it draws a gray background box from (10, 10) to (200, 50). The AddText() function is then called, and it draws the text "Hello, World!" in white on top of the background box.

    If you want the background box to appear behind the text, you should call AddRectFilled() before AddText(). If you want the text to appear behind the background box, you should call AddText() before AddRectFilled().

  19. User

    i need background be behind text, but i can put calls only in that order: drawlist->addtext; drawlist->addrectfilled

  20. Assistant

    In that case, you can still achieve the desired result by drawing the text with a transparent background color using AddText() and then drawing the opaque background box behind it with AddRectFilled().

    Here's an example code snippet to illustrate this:

    // Draw the text first with a transparent background
    ImGui::GetWindowDrawList()->AddText(ImVec2(30, 30), ImColor(1.0f, 1.0f, 1.0f, 0.0f), "Hello, World!");
    
    // Compute the size of the text by using CalcTextSize() function
    ImVec2 textSize = ImGui::CalcTextSize("Hello, World!");
    
    // Compute the position of the background box, which will be slightly larger than the text and positioned behind it
    ImVec2 textPos = ImGui::GetCursorScreenPos();
    ImVec2 bgBoxPos = textPos - ImVec2(5, 5);
    ImVec2 bgBoxSize = textSize + ImVec2(10, 10);
    
    // Draw the opaque background box behind the text
    ImGui::GetWindowDrawList()->AddRectFilled(bgBoxPos, bgBoxPos + bgBoxSize, ImColor(0.5f, 0.5f, 0.5f, 1.0f));
    

    In this example, we first draw the text with a transparent background color. We then use CalcTextSize() to compute the size of the text, and we use the bottom-left position of the text as the position of the background box. Finally, we draw the opaque background box behind the text.

    Note that you may need to adjust the position and size of the background box as needed to suit your specific requirements.

  21. User

    ImDrawList can i calculate how much objects being put into imdrawlist

  22. Assistant

    Yes, you can calculate the number of objects that have been added to an ImDrawList object by calling the vtx_buffer and idx_buffer member functions of the ImDrawList object.

    Here's an example of how to calculate the number of vertices and indices in an ImDrawList object:

    // Get a pointer to the ImDrawList object for the current window
    ImDrawList* drawList = ImGui::GetWindowDrawList();
    
    // Get the number of vertices and indices in the buffer
    int numVertices = drawList->vtx_buffer.size();
    int numIndices = drawList->idx_buffer.size();
    
    // Output the number of vertices and indices to the console for debugging purposes
    printf("Number of vertices in draw list: %d\n", numVertices);
    printf("Number of indices in draw list: %d\n", numIndices);
    

    In this code, we get a pointer to the ImDrawList object for the current window using ImGui::GetWindowDrawList(). We then use the vtx_buffer and idx_buffer member functions to get the size of the vertex and index buffers, respectively. Finally, we output the number of vertices and indices to the console using printf().

    Note that this code only gives you the total number of vertices and indices in the ImDrawList object. It doesn't tell you how many specific types of objects, such as rectangles or lines, have been added to the object. If you need that information, you'll need to manually count the number of each type of object that you add to the ImDrawList.

  23. User

    what is vertices and indices in your explanation

  24. Assistant

    In my explanation earlier, "vertices" and "indices" refer to the components of the graphics primitives that are rendered by the ImDrawList object.

    In graphics programming, a vertex is a point in three-dimensional space that is represented by a set of attributes, such as position, color, and texture coordinates. A vertex represents a single point in space, and it is used to create more complex shapes and objects.

    In ImDrawList objects, which are used in ImGui to render graphical elements, a vertex is represented by a structure called ImDrawVert. This structure contains attributes such as position, UV coordinates, and color information for each vertex.

    An "index" in graphics programming refers to an integer value that is used to reference a vertex in a vertex buffer. In ImDrawList objects, an index represents the position of a vertex in the vertex buffer, and it is used to specify the order in which the vertices should be rendered to create shapes and objects.

    In summary, the vertices and indices in an ImDrawList object represent the building blocks of the graphical elements that are rendered on the screen. The vertices contain the position, color, and texture coordinates for each point in the object, while the indices specify the order in which the vertices should be rendered to create the object.

  25. User

    well, i put only similar objects into drawlist and wanna receive back amount of items putten there

  26. Assistant

    If you have put only similar objects into the ImDrawList object, you can calculate the number of objects that have been added by dividing the total number of vertices or indices by the number of vertices or indices per object.

    For example, let's say you have added a total of 100 vertices to the ImDrawList

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.