Compare commits

...

2 Commits

Author SHA1 Message Date
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
6 changed files with 46 additions and 5 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

@ -58,6 +58,23 @@ int main(int argc, char** argv) {
//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);
ImGui_ImplSDLRenderer3_Init(renderer.get());

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,
@ -17,6 +17,13 @@ uint64_t SDLRendererTextureUploader::uploadRGBA(const uint8_t* data, uint32_t wi
);
assert(surf); // TODO: add error reporting
// TODO: this touches global state, reset?
if (filter == NEAREST) {
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
} else if (filter == LINEAR) {
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
}
SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, surf);
assert(tex); // TODO: add error reporting

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

@ -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);