Skip to content

Commit

Permalink
Merge branch 'master' of github.com:RMichelsen/Nvy
Browse files Browse the repository at this point in the history
  • Loading branch information
RMichelsen committed Sep 3, 2024
2 parents fa6dad5 + aae760b commit cfcea51
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
9 changes: 6 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ void ProcessMPackMessage(Context *context, mpack_tree_t *tree) {
}
}

void SendResizeIfNecessary(Context *context, int rows, int cols) {
if (!context->renderer->grid_initialized) return;
bool SendResizeIfNecessary(Context *context, int rows, int cols) {
if (!context->renderer->grid_initialized) return false;

if (rows != context->renderer->grid_rows || cols != context->renderer->grid_cols) {
NvimSendResize(context->nvim, rows, cols);
return true;
}
return false;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
Expand Down Expand Up @@ -587,7 +589,8 @@ int WINAPI wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance, _
previous_height = context.saved_window_height;
auto [rows, cols] = RendererPixelsToGridSize(context.renderer, context.saved_window_width, context.saved_window_height);
RendererResize(context.renderer, context.saved_window_width, context.saved_window_height);
SendResizeIfNecessary(&context, rows, cols);
if (!SendResizeIfNecessary(&context, rows, cols))
RendererFlush(context.renderer);
}
}

Expand Down
36 changes: 24 additions & 12 deletions src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ void DrawCursor(Renderer *renderer) {
}
}

void UpdateGridSize(Renderer *renderer, mpack_node_t grid_resize) {
bool UpdateGridSize(Renderer *renderer, mpack_node_t grid_resize) {
mpack_node_t grid_resize_params = mpack_node_array_at(grid_resize, 1);
int grid_cols = MPackIntFromArray(grid_resize_params, 1);
int grid_rows = MPackIntFromArray(grid_resize_params, 2);
Expand All @@ -815,7 +815,10 @@ void UpdateGridSize(Renderer *renderer, mpack_node_t grid_resize) {
renderer->wchar_buffer = static_cast<wchar_t *>(malloc(static_cast<size_t>(grid_cols * 2) * sizeof(wchar_t)));

renderer->grid_initialized = true;
return true;
}

return false;
}

void UpdateCursorPos(Renderer *renderer, mpack_node_t cursor_goto) {
Expand Down Expand Up @@ -1107,6 +1110,20 @@ void FinishDraw(Renderer *renderer) {
}
}

void RendererFlush(Renderer* renderer) {
StartDraw(renderer);
if (renderer->draws_invalidated) {
renderer->draws_invalidated = false;
DrawAllGridLines(renderer);
}

if (!renderer->ui_busy) {
DrawCursor(renderer);
}
DrawBorderRectangles(renderer);
FinishDraw(renderer);
}

void RendererRedraw(Renderer *renderer, mpack_node_t params, bool start_maximized) {
StartDraw(renderer);

Expand All @@ -1119,7 +1136,11 @@ void RendererRedraw(Renderer *renderer, mpack_node_t params, bool start_maximize
SetGuiOptions(renderer, redraw_command_arr);
}
if (MPackMatchString(redraw_command_name, "grid_resize")) {
UpdateGridSize(renderer, redraw_command_arr);
if (UpdateGridSize(renderer, redraw_command_arr))
{
PixelSize size = RendererGridToPixelSize(renderer, renderer->grid_rows, renderer->grid_cols);
SetWindowPos(renderer->hwnd, HWND_TOP, 0, 0, size.width, size.height, SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
}
if (MPackMatchString(redraw_command_name, "grid_clear")) {
ClearGrid(renderer);
Expand Down Expand Up @@ -1174,16 +1195,7 @@ void RendererRedraw(Renderer *renderer, mpack_node_t params, bool start_maximize
renderer->has_drawn = true;
ShowWindow(renderer->hwnd, start_maximized ? SW_MAXIMIZE : SW_SHOWDEFAULT); }

if (renderer->draws_invalidated) {
renderer->draws_invalidated = false;
DrawAllGridLines(renderer);
}

if(!renderer->ui_busy) {
DrawCursor(renderer);
}
DrawBorderRectangles(renderer);
FinishDraw(renderer);
RendererFlush(renderer);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void RendererResize(Renderer *renderer, uint32_t width, uint32_t height);
bool RendererUpdateGuiFont(Renderer *renderer, const char *guifont, size_t strlen);
bool RendererUpdateFont(Renderer *renderer, float font_size, const char *font_string = "", int strlen = 0);
void RendererRedraw(Renderer *renderer, mpack_node_t params, bool start_maximized);
void RendererFlush(Renderer* renderer);

PixelSize RendererGridToPixelSize(Renderer *renderer, int rows, int cols);
GridSize RendererPixelsToGridSize(Renderer *renderer, int width, int height);
Expand Down

0 comments on commit cfcea51

Please sign in to comment.