gpt4 book ai didi

c - 如何在C中创建像PowerShell这样的多行文本框

转载 作者:行者123 更新时间:2023-12-02 23:39:03 27 4
gpt4 key购买 nike

在PowerShell中,您可以在多行GUI(如文本框)中定义类或函数。但是这些内容实际上发生在控制台窗口中。它使您可以完全控制多行文本编辑。我只想在C / C++的控制台中创建这种文本框。 Win32 API是否具有过程/功能?任何代码?或任何图书馆?任何提示或线索将不胜感激。

谢谢。

最佳答案

您可以将以下内容与包装一起使用:

pragma once
#include "SDL.h"
#include "SDL_ttf.h"
#include "SDLUtils.h"
#include <string>
#include <vector>

class Textbox
{
public:
Textbox(int w, int h, int xPos, int yPos);
~Textbox(void);
void draw();
void edit(string s);
private:
TTF_Font *font;
int width;
int height;
Point pos;
SDL_Surface *textSurface;
SDL_Color textColor;
std::string str;
int maxCharsPerLine;
int currentLine;
std::vector<std::string> lines;
};

CPP
#include "Textbox.h"
#include <iostream>

using namespace std;

Textbox::Textbox(int w, int h, int xPos, int yPos)
{
TTF_Init();
font = TTF_OpenFont("DOTMATRI.ttf", 20);
textColor.r = 255;
textColor.g = 0;
textColor.b = 0;

width = w;
height = h;

pos.x = xPos;
pos.y = yPos;

int x, y;
TTF_SizeText(font,"a",&x,&y);
cout << "width: " << x << endl;
cout << "height: " << y << endl;

maxCharsPerLine = width / x;

str = "";
lines.push_back(str);
currentLine = 0;
}

Textbox::~Textbox(void)
{
SDL_FreeSurface(textSurface);
TTF_CloseFont(font);
TTF_Quit();
}

void Textbox::draw()
{
SDL_Rect rect;
rect.x = pos.x;
rect.y = pos.y;
rect.w = width;
rect.h = height;

SDL_FillRect(SDL_GetVideoSurface(), &rect, SDL_MapRGB(SDL_GetVideoSurface()->format, 100, 100, 0));


for(int i = 0; i < lines.size(); i++)
{
textSurface = TTF_RenderText_Solid(font, lines[i].c_str(), textColor);
applySurface(pos.x, pos.y, textSurface, SDL_GetVideoSurface());
pos.y += 21;
}

pos.y = 200;
}

void Textbox::edit(string s)

引用链接: Creating TextBox

关于c - 如何在C中创建像PowerShell这样的多行文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47223990/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com