Using new RichTextBox instead of CollabTextBox in program. Fixes still needed to work properly

This commit is contained in:
Yousef Khadadeh 2025-10-20 17:30:36 +03:00
parent ec68dd9b71
commit 4db5838a64
18 changed files with 157 additions and 1441 deletions

View file

@ -1,5 +1,4 @@
#include "MainProgram.hpp"
#include "CollabTextBox/CollabTextBoxCursor.hpp"
#include "DrawingProgram/DrawingProgramToolBase.hpp"
#include "cereal/archives/portable_binary.hpp"
#include "cereal/details/helpers.hpp"
@ -37,12 +36,6 @@
#include <Helpers/Logger.hpp>
#include <Helpers/Networking/NetLibrary.hpp>
#include "RichTextBox/RichTextBox.hpp"
std::shared_ptr<RichTextBox> textBox;
std::shared_ptr<RichTextBox::Cursor> textBoxCursor;
RichTextBox::PaintOpts paintOpts;
MainProgram::MainProgram():
toolbar(*this)
{
@ -68,87 +61,67 @@ MainProgram::MainProgram():
*logFile << "[CHAT] " << text << std::endl;
std::cout << "[CHAT] " << text << std::endl;
});
textBox = std::make_shared<RichTextBox>();
textBoxCursor = std::make_shared<RichTextBox::Cursor>();
textBox->set_font_collection(fonts.collection);
textBox->insert({0, 0}, R"(Hello world)");
paintOpts.cursor = RichTextBox::Cursor{};
paintOpts.cursorColor = {1.0f, 0.0f, 0.0f};
}
void MainProgram::update() {
input.text.set_rich_text_box_input(textBox, textBoxCursor);
textBox->process_mouse_left_button(*textBoxCursor, input.mouse.pos - Vector2f{10.0f, 10.0f}, input.mouse.leftClicks, input.mouse.leftDown, input.key(InputManager::KEY_GENERIC_LSHIFT).held);
textBox->set_width(window.size.x() - 20.0f);
while(std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastFrameTime).count() < 1.0 / fpsLimit);
lastFrameTime = std::chrono::steady_clock::now();
//while(std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastFrameTime).count() < 1.0 / fpsLimit);
//lastFrameTime = std::chrono::steady_clock::now();
std::erase_if(input.droppedItems, [&](auto& droppedItem) {
if(droppedItem.isFile && std::filesystem::is_regular_file(droppedItem.droppedData)) {
std::filesystem::path droppedFilePath(droppedItem.droppedData);
if(droppedFilePath.has_extension() && droppedFilePath.extension().string() == std::string("." + World::FILE_EXTENSION)) {
new_tab({
.conType = World::CONNECTIONTYPE_LOCAL,
.fileSource = droppedFilePath.string()
}, true);
return true;
}
}
return false;
});
//if(input.key(InputManager::KEY_DRAW_TOOL_BRUSH).repeat)
// paintOpts.cursor.value().pos = textBox.move(paintOpts.cursor.value().pos, RichTextBox::Movement::kRight);
//else if(input.key(InputManager::KEY_DRAW_TOOL_ERASER).repeat)
// paintOpts.cursor.value().pos = textBox.move(paintOpts.cursor.value().pos, RichTextBox::Movement::kLeft);
//else if(input.key(InputManager::KEY_DRAW_TOOL_TEXTBOX).repeat)
// paintOpts.cursor.value().pos = textBox.move(paintOpts.cursor.value().pos, RichTextBox::Movement::kUp);
//else if(input.key(InputManager::KEY_DRAW_TOOL_ELLIPSE).repeat)
// paintOpts.cursor.value().pos = textBox.move(paintOpts.cursor.value().pos, RichTextBox::Movement::kDown);
if(setTabToClose) {
worlds.erase(worlds.begin() + setTabToClose.value());
setTabToClose.reset();
}
//std::erase_if(input.droppedItems, [&](auto& droppedItem) {
// if(droppedItem.isFile && std::filesystem::is_regular_file(droppedItem.droppedData)) {
// std::filesystem::path droppedFilePath(droppedItem.droppedData);
// if(droppedFilePath.has_extension() && droppedFilePath.extension().string() == std::string("." + World::FILE_EXTENSION)) {
// new_tab({
// .conType = World::CONNECTIONTYPE_LOCAL,
// .fileSource = droppedFilePath.string()
// }, true);
// return true;
// }
// }
// return false;
//});
if(worldIndex >= worlds.size())
worldIndex = worlds.size() - 1;
if(worlds.size() == 0)
new_tab({
.conType = World::CONNECTIONTYPE_LOCAL
}, true);
//if(setTabToClose) {
// worlds.erase(worlds.begin() + setTabToClose.value());
// setTabToClose.reset();
//}
std::shared_ptr<World> oldWorld = world;
world = worlds[worldIndex];
//if(worldIndex >= worlds.size())
// worldIndex = worlds.size() - 1;
//if(worlds.size() == 0)
// new_tab({
// .conType = World::CONNECTIONTYPE_LOCAL
// }, true);
deltaTime.update_time_since();
deltaTime.update_time_point();
//std::shared_ptr<World> oldWorld = world;
//world = worlds[worldIndex];
toolbar.initialize_io_before_update();
//deltaTime.update_time_since();
//deltaTime.update_time_point();
for(auto& w : worlds) {
if(w == world)
w->focus_update();
else
w->unfocus_update();
}
//toolbar.initialize_io_before_update();
toolbar.update(); // GUI should be setup after the world data has been fully updated for this frame, so that the GUI reflects the current state of the world data
//for(auto& w : worlds) {
// if(w == world)
// w->focus_update();
// else
// w->unfocus_update();
//}
if(input.key(InputManager::KEY_NOGUI).pressed)
drawGui = !drawGui;
//toolbar.update(); // GUI should be setup after the world data has been fully updated for this frame, so that the GUI reflects the current state of the world data
if(input.key(InputManager::KEY_FULLSCREEN).pressed)
input.toggleFullscreen = true;
//if(input.key(InputManager::KEY_NOGUI).pressed)
// drawGui = !drawGui;
NetLibrary::update();
//if(input.key(InputManager::KEY_FULLSCREEN).pressed)
// input.toggleFullscreen = true;
//NetLibrary::update();
//if(tabSetToOpen) {
// tabSetToOpen = false;
// new_tab_open();
//}
if(tabSetToOpen) {
tabSetToOpen = false;
new_tab_open();
}
return;
}
@ -257,16 +230,9 @@ void MainProgram::load_config() {
}
void MainProgram::draw(SkCanvas* canvas) {
//canvas->clear(transparentBackground ? SkColor4f{0.0f, 0.0f, 0.0f, 0.0f} : world->canvasTheme.backColor);
//world->draw(canvas);
//toolbar.draw(canvas);
canvas->clear(SkColor4f{0.0f, 0.0f, 0.0f, 1.0f});
canvas->save();
canvas->translate(10.0f, 10.0f);
paintOpts.cursor = *textBoxCursor;
textBox->paint(canvas, paintOpts);
canvas->restore();
canvas->clear(transparentBackground ? SkColor4f{0.0f, 0.0f, 0.0f, 0.0f} : world->canvasTheme.backColor);
world->draw(canvas);
toolbar.draw(canvas);
}
bool MainProgram::network_being_used() {