郁金香灬老师 游戏安全  驱动 逆向调试 C/C++编程  脚本 UE4/UE5

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
课程大纲和价格
官方联系方式2024在线课大纲QQ咨询
查看: 3523|回复: 0

008-imGui窗口中的文本框InputText

[复制链接]

132

主题

29

回帖

34万

积分

管理员

积分
343636
QQ
发表于 2023-3-28 15:47:32 | 显示全部楼层 |阅读模式
008-imGui窗口中的文本框InputText




郁金香灬外挂技术
        
        https://www.yjxsoft.com/
        
        本教程视频1920*1080分辩率下观看最佳
        VS2017+win10 64位 环境
        郁金香老师:扣扣 150330575
        欢迎大家参加 郁金香灬技术 游戏安全与外挂的研究学习。
        
        兴趣是我们最好的老师
        成长需要过程与循序渐进         
        兴趣+坚持+时间+优秀的课教程会帮助你快速成功
   
  

学习目标:
    多行文本框InputTextMultiline
        多行文本框大小设置
        
   // ~ FontSize
       IMGUI_API float         GetTextLineHeight();
           

    IMGUI_API bool
        InputText(
        const char* label, //UI名字,不会被显示 相当于人的身份证 以区别不同的UI对象
        char* buf, // 显示内容缓冲区 保存文本的变化
        size_t buf_size,  //显示内容缓冲区大小
        //以下可用默认值
        ImGuiInputTextFlags flags = 0,
        ImGuiInputTextCallback callback = NULL,
        void* user_data = NULL);
        
    IMGUI_API bool
        InputTextMultiline(
        const char* label, //UI名字,不会被显示 相当于人的身份证 以区别不同的UI对象
        char* buf,
        size_t buf_size,
        //以下可用默认值
        const ImVec2& size = ImVec2(0, 0),  //UI宽度 高度
        ImGuiInputTextFlags flags = 0,  //显示标志位
        ImGuiInputTextCallback callback = NULL,  //回调函数
        void* user_data = NULL); //用户数组
   
   // Callback function for ImGui::InputText()   
   typedef int     (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData* data);   
   // int callback(ImGuiInputTextCallbackData* data);   

// ImGuiInputTextFlags
   enum ImGuiInputTextFlags_
{
    ImGuiInputTextFlags_None                = 0,
    ImGuiInputTextFlags_CharsDecimal        = 1 << 0,   // Allow 0123456789.+-*/
    ImGuiInputTextFlags_CharsHexadecimal    = 1 << 1,   // Allow 0123456789ABCDEFabcdef
    ImGuiInputTextFlags_CharsUppercase      = 1 << 2,   // Turn a..z into A..Z
    ImGuiInputTextFlags_CharsNoBlank        = 1 << 3,   // Filter out spaces, tabs
    ImGuiInputTextFlags_AutoSelectAll       = 1 << 4,   // Select entire text when first taking mouse focus
    ImGuiInputTextFlags_EnterReturnsTrue    = 1 << 5,   // Return 'true' when Enter is pressed (as opposed to every time the value was modified). Consider looking at the IsItemDeactivatedAfterEdit() function.
    ImGuiInputTextFlags_CallbackCompletion  = 1 << 6,   // Callback on pressing TAB (for completion handling)
    ImGuiInputTextFlags_CallbackHistory     = 1 << 7,   // Callback on pressing Up/Down arrows (for history handling)
    ImGuiInputTextFlags_CallbackAlways      = 1 << 8,   // Callback on each iteration. User code may query cursor position, modify text buffer.
    ImGuiInputTextFlags_CallbackCharFilter  = 1 << 9,   // Callback on character inputs to replace or discard them. Modify 'EventChar' to replace or discard, or return 1 in callback to discard.
    ImGuiInputTextFlags_AllowTabInput       = 1 << 10,  // Pressing TAB input a '        ' character into the text field
    ImGuiInputTextFlags_CtrlEnterForNewLine = 1 << 11,  // In multi-line mode, unfocus with Enter, add new line with Ctrl+Enter (default is opposite: unfocus with Ctrl+Enter, add line with Enter).
    ImGuiInputTextFlags_NoHorizontalScroll  = 1 << 12,  // Disable following the cursor horizontally
    ImGuiInputTextFlags_AlwaysOverwrite     = 1 << 13,  // Overwrite mode 覆盖模式
    ImGuiInputTextFlags_ReadOnly            = 1 << 14,  // Read-only mode 只读模式
    ImGuiInputTextFlags_Password            = 1 << 15,  // Password mode, display all characters as '*'
    ImGuiInputTextFlags_NoUndoRedo          = 1 << 16,  // Disable undo/redo. Note that input text owns the text data while active, if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID().
    ImGuiInputTextFlags_CharsScientific     = 1 << 17,  // Allow 0123456789.+-*/eE (Scientific notation input)
    ImGuiInputTextFlags_CallbackResize      = 1 << 18,  // Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. Notify when the string wants to be resized (for string types which hold a cache of their Size). You will be provided a new BufSize in the callback and NEED to honor it. (see misc/cpp/imgui_stdlib.h for an example of using this)
    ImGuiInputTextFlags_CallbackEdit        = 1 << 19,  // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active)
    ImGuiInputTextFlags_EscapeClearsAll     = 1 << 20,  // Escape key clears content if not empty, and deactivate otherwise (contrast to default behavior of Escape to revert)

    // Obsolete names
    //ImGuiInputTextFlags_AlwaysInsertMode  = ImGuiInputTextFlags_AlwaysOverwrite   // [renamed in 1.82] name was not matching behavior
};

     ImGui::Begin();
      {
          char lineText[256] = "11111111";
          int flag = ImGuiInputTextFlags_CallbackCharFilter;// | ImGuiInputTextFlags_CallbackEdit;
          ImGui::InputText("InputText1", lineText, IM_ARRAYSIZE(lineText), flag, testEditCallback);
      }
      ImGui::End();
         

  static int testEditCallback(ImGuiInputTextCallbackData* data)
  {
      
      printf("data->EventChar=%d buf=%s EventKey=%d EventFlag=%d",
          data->EventChar,
          data->Buf,
          data->EventKey,
          data->EventFlag
          );

      if (data->EventChar >='a'&& data->EventChar <= 'c')
      {
          return 1; //过滤 屏蔽掉输入
      }
      else
      {
          return 0;
      }
     
      
  }
  

static int MyCallback(ImGuiInputTextCallbackData* data)
                {
                    if (data->EventFlag == ImGuiInputTextFlags_CallbackCompletion)
                    {
                        data->InsertChars(data->CursorPos, "..");
                    }
                    else if (data->EventFlag == ImGuiInputTextFlags_CallbackHistory)
                    {
                        if (data->EventKey == ImGuiKey_UpArrow)
                        {
                            data->DeleteChars(0, data->BufTextLen);
                            data->InsertChars(0, "Pressed Up!");
                            data->SelectAll();
                        }
                        else if (data->EventKey == ImGuiKey_DownArrow)
                        {
                            data->DeleteChars(0, data->BufTextLen);
                            data->InsertChars(0, "Pressed Down!");
                            data->SelectAll();
                        }
                    }
                    else if (data->EventFlag == ImGuiInputTextFlags_CallbackEdit)
                    {
                        // Toggle casing of first character
                        char c = data->Buf[0];
                        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) data->Buf[0] ^= 32;
                        data->BufDirty = true;

                        // Increment a counter
                        int* p_int = (int*)data->UserData;
                        *p_int = *p_int + 1;
                    }
                    return 0;
                }
            };
                        
                        
                        ImGuidInputTextFlags_无=0,
ImGuidInputTextFlags_CharsDecimal=1<<0,//允许0123456789+-*/
ImGuiInputTextFlags_Chars十六进制=1<<1,//允许0123456789ABCDEFabcdef
ImGuiInputTextFlags_CharsUppercase=1<<2,//将a..z转换为a..z
ImGuidInputTextFlags_CharsNoBlank=1<<3,//筛选出空格、制表符
ImGuidInputTextFlags_AutoSelectAll=1<<4,//第一次获取鼠标焦点时选择整个文本
ImGuiInputTextFlags_EnterReturnsTrue=1<<5,//按下Enter键时返回“true”(与每次修改值时相反)。请考虑查看IsItemDeactivatedAfterEdit()函数。
ImGuidInputTextFlags_CallbackCompletion=1<6,//按TAB键时回调(用于完成处理)
ImGuidInputTextFlags_CallbackHistory=1<<7,//按下上/下箭头时回调(用于历史处理)
ImGuiInputTextFlags_CallbackAlways=1<<8,//每次迭代的回调。用户代码可以查询光标位置,修改文本缓冲区。
ImGuiInputTextFlags_CallbackCharFilter=1<9,//对字符输入进行回调以替换或丢弃它们。修改“EventChar”以替换或丢弃,或在回调中返回1以丢弃。
ImGuidInputTextFlags_AllowTabInput=1<<10,//按TAB键在文本字段中输入一个“        ”字符
ImGuiInputTextFlags_CtrlEnterForNewLine=1<<11,//在多行模式中,使用Enter取消焦点,使用Ctrl+Enter添加新行(默认情况相反:使用Ctrl+Enter取消焦点、使用Enter添加行)。
ImGuidInputTextFlags_NoHorizontalScroll=1<<12,//禁用水平跟随光标
ImGuidInputTextFlags_AlwaysOverwrite=1<<13,//覆盖模式
ImGuidInputTextFlags_ReadOnly=1<<14,//只读模式
ImGuiInputTextFlags_Password=1<<15,//密码模式,将所有字符显示为“*”
ImGuidInputTextFlags_NoUndoRedo=1<<16,//禁用撤消/重做。请注意,输入文本在活动时拥有文本数据,如果您想提供自己的undo/redo堆栈,则需要调用ClearActiveID()。
ImGuidInputTextFlags_CharsScientific=1<<17,//允许0123456789.+-*/eE(科学记数法输入)
ImGuiInputTextFlags_CallbackResize=1<<18,//缓冲区容量更改请求时的回调(超过“buf_size”参数值),允许字符串增长。当字符串需要调整大小时通知(对于保存其大小的缓存的字符串类型)。回调中会为您提供一个新的BufSize,并且需要遵守它。(有关使用它的示例,请参阅misc/cpp/imgui_stdlib.h)
ImGuiInputTextFlags_CallbackEdit=1<<19,//在任何编辑时回调(请注意,InputText()在编辑时已经返回true,回调主要用于在焦点处于活动状态时操作底层缓冲区)
ImGuiInputTextFlags_EscapeClearsAll=1<<20,//如果Escape键不为空,则清除内容,否则将停用(与Escape的默认行为相反)



游客,如果您要查看本帖隐藏内容请回复




  void CDX11::CreateMyFrame()
  {
      //创建一个窗口帧
      ImGui::Begin(u8"111中文");
      //{
      //    //设置窗口位置
      //    ImVec2 pos = { 100,100 };
      //    ImGui::SetWindowPos(pos);
      //    ImVec2 nSize = { 300,200 };
      //    ImGui::SetWindowSize(nSize);
      //}      
      文本输入框测试();
      ImGui::End();
         
         





游戏安全课程 学员办理咨询联系QQ150330575 手机 139 9636 2600  免费课程 在 www.bilibili.com 搜 郁金香灬老师
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ咨询

QQ|Archiver|手机版|小黑屋|郁金香游戏技术

GMT+8, 2024-5-17 22:03 , Processed in 0.091278 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表