Compare commits

...

5 Commits

Author SHA1 Message Date
7fe6df5889 update deps (fix uppercase hex and others) 2024-01-27 12:27:55 +01:00
2647c85323 add imgui stylign window + change how texture filters are applied 2024-01-21 20:20:32 +01:00
93140231c6 theme according to system 2024-01-21 14:28:56 +01:00
e76e56e025 larger font hack + linear texture filter for images 2024-01-21 13:58:22 +01:00
b1062e701e make primary selection pasting work
it is also bugged, as SDL misses large parts of selection sources (terminals etc) but browers work
2024-01-20 18:06:58 +01:00
12 changed files with 68 additions and 11 deletions

View File

@ -17,6 +17,7 @@
#include "./media_meta_info_loader.hpp"
#include "./sdl_clipboard_utils.hpp"
#include "SDL_clipboard.h"
#include <cctype>
#include <cstdint>
@ -492,6 +493,18 @@ void ChatGui4::render(float time_delta) {
_text_input_buffer.clear();
evil_enter_looses_focus_hack = true;
}
// welcome to linux
if (ImGui::IsMouseClicked(ImGuiMouseButton_Middle)) {
if (!ImGui::IsItemFocused()) {
ImGui::SetKeyboardFocusHere(-1);
}
char* primary_text = SDL_GetPrimarySelectionText();
if (primary_text != nullptr) {
ImGui::GetIO().AddInputCharactersUTF8(primary_text);
SDL_free(primary_text);
}
}
}
ImGui::EndChild();
ImGui::SameLine();

View File

@ -55,8 +55,29 @@ int main(int argc, char** argv) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
//ImGui::StyleColorsDark();
setThemeGreen();
if (SDL_GetSystemTheme() == SDL_SYSTEM_THEME_LIGHT) {
ImGui::StyleColorsLight();
} else {
//ImGui::StyleColorsDark();
setThemeGreen();
}
{
ImGui::GetIO().Fonts->ClearFonts();
ImFontConfig fontcfg;
// upsampling to int looks almost ok
const float font_size_scale = 1.3f;
const float font_oversample = 4.f;
// default font is pixel perfect at 13
fontcfg.SizePixels = 13.f * font_size_scale;
fontcfg.RasterizerDensity = font_oversample/font_size_scale;
// normally density would be set to dpi scale of the display
ImGui::GetIO().Fonts->AddFontDefault(&fontcfg);
ImGui::GetIO().Fonts->Build();
}
ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get());
auto imgui_sdl_scope = std::async(std::launch::deferred, &ImGui_ImplSDL3_Shutdown);

View File

@ -191,6 +191,12 @@ Screen* MainScreen::render(float time_delta, bool&) {
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Settings")) {
if (ImGui::MenuItem("ImGui Style Editor")) {
_show_tool_style_editor = true;
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
@ -198,6 +204,12 @@ Screen* MainScreen::render(float time_delta, bool&) {
ImGui::End();
}
if (_show_tool_style_editor) {
if (ImGui::Begin("Dear ImGui Style Editor", &_show_tool_style_editor)) {
ImGui::ShowStyleEditor();
}
ImGui::End();
}
if constexpr (false) {
ImGui::ShowDemoWindow();

View File

@ -64,6 +64,8 @@ struct MainScreen final : public Screen {
ToxUIUtils tuiu;
ToxDHTCapHisto tdch;
bool _show_tool_style_editor {false};
bool _window_hidden {false};
bool _window_hidden_ts {0};
float _time_since_event {0.f};

View File

@ -7,7 +7,7 @@ SDLRendererTextureUploader::SDLRendererTextureUploader(SDL_Renderer* renderer_)
{
}
uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height) {
uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter) {
// TODO: test if pitch is 4 or 4*width
SDL_Surface* surf = SDL_CreateSurfaceFrom(
(void*)data,
@ -20,6 +20,12 @@ uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t wi
SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, surf);
assert(tex); // TODO: add error reporting
if (filter == NEAREST) {
SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_NEAREST);
} else if (filter == LINEAR) {
SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_LINEAR);
}
SDL_DestroySurface(surf);
return reinterpret_cast<uint64_t>(tex);

View File

@ -10,7 +10,7 @@ struct SDLRendererTextureUploader : public TextureUploaderI {
SDLRendererTextureUploader(SDL_Renderer* renderer_);
~SDLRendererTextureUploader(void) = default;
uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height) override;
uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter) override;
void destroy(uint64_t tex_id) override;
};

View File

@ -116,7 +116,6 @@ void SettingsWindow::render(void) {
}
ImGui::EndMenuBar();
}
}
ImGui::End();
}

View File

@ -5,10 +5,14 @@
struct TextureUploaderI {
static constexpr const char* version {"1"};
enum Filter {
NEAREST,
LINEAR,
};
virtual ~TextureUploaderI(void) {}
//virtual uint64_t uploadRGBA(const uint8_t* data, uint64_t data_size) = 0;
virtual uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height) = 0;
virtual uint64_t uploadRGBA(const uint8_t* data, uint32_t width, uint32_t height, Filter filter = LINEAR) = 0;
virtual void destroy(uint64_t tex_id) = 0;
};

View File

@ -203,7 +203,7 @@ std::optional<TextureEntry> ToxAvatarLoader::load(TextureUploaderI& tu, Contact3
new_entry.timestamp_last_rendered = Message::getTimeMS();
new_entry.current_texture = 0;
const auto n_t = tu.uploadRGBA(pixels.data(), 5, 5);
const auto n_t = tu.uploadRGBA(pixels.data(), 5, 5, TextureUploaderI::NEAREST);
new_entry.textures.push_back(n_t);
new_entry.frame_duration.push_back(250);