Stop using WindowSize and actually make use of event window size, provide default
This commit is contained in:
@@ -110,6 +110,11 @@ Vec2 operator/=(Vec2 &a, float b) { a = a / b; return a; }
|
||||
|
||||
// clang-format on
|
||||
|
||||
Rect2 Rect0Size(float x, float y) {
|
||||
Rect2 rect = {0, 0, x, y};
|
||||
return rect;
|
||||
}
|
||||
|
||||
Rect2 Rect2FromSize(Vec2 pos, Vec2 size) {
|
||||
Rect2 result = {};
|
||||
result.min = pos;
|
||||
|
||||
@@ -73,6 +73,11 @@ Vec2I operator/=(Vec2I &a, Int b) { a = a / b; return a; }
|
||||
|
||||
// clang-format on
|
||||
|
||||
Rect2I RectI0Size(Int x, Int y) {
|
||||
Rect2I rect = {0, 0, x, y};
|
||||
return rect;
|
||||
}
|
||||
|
||||
Rect2I Rect2IFromSize(Vec2I pos, Vec2I size) {
|
||||
Rect2I result = {};
|
||||
result.min = pos;
|
||||
|
||||
@@ -29,46 +29,36 @@ int64_t TotalVertexCount;
|
||||
unsigned VBO, VAO;
|
||||
Shader Shader2D;
|
||||
Arena RenderArena;
|
||||
Vec2 WindowSize;
|
||||
Rect2 CurrentScissor;
|
||||
|
||||
Font MainFont;
|
||||
Int FontLineSpacing;
|
||||
Int FontCharSpacing;
|
||||
|
||||
Rect2 GetScreenRectF() {
|
||||
Rect2 result = {0, 0, WindowSize.x, WindowSize.y};
|
||||
return result;
|
||||
}
|
||||
|
||||
Rect2I GetScreenRectI() {
|
||||
Rect2I result = {0, 0, (Int)WindowSize.x, (Int)WindowSize.y};
|
||||
return result;
|
||||
}
|
||||
void BeginFrameRender() {
|
||||
void BeginFrameRender(float wx, float wy) {
|
||||
Clear(&RenderArena);
|
||||
TotalVertexCount = 0;
|
||||
Vertices.first = NULL;
|
||||
Vertices.last = NULL;
|
||||
CurrentScissor = GetScreenRectF();
|
||||
CurrentScissor = Rect0Size(wx, wy);
|
||||
}
|
||||
|
||||
void EndFrameRender(Color color) {
|
||||
void EndFrameRender(float wx, float wy, Color color) {
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glViewport(0, 0, (GLsizei)WindowSize.x, (GLsizei)WindowSize.y);
|
||||
glScissor(0, 0, (GLsizei)WindowSize.x, (GLsizei)WindowSize.y);
|
||||
glViewport(0, 0, (GLsizei)wx, (GLsizei)wy);
|
||||
glScissor(0, 0, (GLsizei)wx, (GLsizei)wy);
|
||||
glClearColor(color.r, color.g, color.b, color.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
// Default draw using the font texture
|
||||
glBindProgramPipeline(Shader2D.pipeline);
|
||||
float xinverse = 1.f / (WindowSize.x / 2.f);
|
||||
float yinverse = 1.f / (WindowSize.y / 2.f);
|
||||
float xinverse = 1.f / (wx / 2.f);
|
||||
float yinverse = 1.f / (wy / 2.f);
|
||||
glProgramUniform2f(Shader2D.vshader, 0, xinverse, yinverse);
|
||||
for (VertexNode2D *it = Vertices.first; it; it = it->next) {
|
||||
Rect2 rect = it->scissor;
|
||||
@@ -76,7 +66,7 @@ void EndFrameRender(Color color) {
|
||||
GLint y = (GLint)rect.min.y;
|
||||
GLsizei w = (GLsizei)(rect.max.x - x);
|
||||
GLsizei h = (GLsizei)(rect.max.y - y);
|
||||
glScissor(x, (GLint)WindowSize.y - (GLint)rect.max.y, w, h);
|
||||
glScissor(x, (GLint)wy - (GLint)rect.max.y, w, h);
|
||||
glNamedBufferSubData(VBO, 0, it->count * sizeof(Vertex2D), it->vertices);
|
||||
glBindVertexArray(VAO);
|
||||
GLint s_texture = 0; // texture unit that sampler2D will use in GLSL code
|
||||
|
||||
@@ -155,8 +155,7 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
|
||||
}
|
||||
|
||||
void Update(Event event) {
|
||||
WindowSize = {(float)event.xwindow, (float)event.ywindow};
|
||||
LayoutWindows();
|
||||
LayoutWindows(event.xwindow, event.ywindow);
|
||||
|
||||
Scratch scratch;
|
||||
Array<Int> order = GetWindowZOrder(scratch);
|
||||
@@ -330,6 +329,14 @@ int main(int argc, char **argv)
|
||||
For(frame_events) {
|
||||
Serialize(&ser, &it);
|
||||
if (it.kind == EVENT_QUIT) goto end_of_editor_loop;
|
||||
|
||||
if (it.xwindow == 0 || it.ywindow == 0) {
|
||||
int xwindow, ywindow;
|
||||
SDL_GetWindowSize(SDLWindow, &xwindow, &ywindow);
|
||||
it.xwindow = xwindow;
|
||||
it.ywindow = ywindow;
|
||||
}
|
||||
|
||||
Update(it);
|
||||
}
|
||||
|
||||
@@ -349,15 +356,16 @@ int main(int argc, char **argv)
|
||||
SDL_SetWindowTitle(SDLWindow, string.data);
|
||||
}
|
||||
|
||||
LayoutWindows(); // This is here to render changes in title bar size without a frame of delay
|
||||
BeginFrameRender();
|
||||
Event *event = GetLast(frame_events);
|
||||
LayoutWindows(event->xwindow, event->ywindow); // This is here to render changes in title bar size without a frame of delay
|
||||
BeginFrameRender(event->xwindow, event->ywindow);
|
||||
Array<Int> order = GetWindowZOrder(scratch);
|
||||
For(IterateInReverse(&order)) {
|
||||
Window *window = Windows[it].o;
|
||||
if (!window->visible) continue;
|
||||
DrawWindow(window, *GetLast(frame_events));
|
||||
}
|
||||
EndFrameRender(ColorBackground);
|
||||
EndFrameRender(event->xwindow, event->ywindow, ColorBackground);
|
||||
SDL_GL_SwapWindow(SDLWindow);
|
||||
}
|
||||
end_of_editor_loop:;
|
||||
|
||||
@@ -166,9 +166,9 @@ void InitWindows() {
|
||||
ActiveWindow = {0};
|
||||
}
|
||||
|
||||
void LayoutWindows() {
|
||||
void LayoutWindows(int16_t wx, int16_t wy) {
|
||||
float ScrollBarSize = (10.f * DPIScale);
|
||||
Rect2I screen_rect = GetScreenRectI();
|
||||
Rect2I screen_rect = RectI0Size(wx, wy);
|
||||
float line_numbers_size = (float)FontCharSpacing * 10;
|
||||
float sizex = (float)GetSize(screen_rect).x;
|
||||
|
||||
@@ -203,7 +203,7 @@ void LayoutWindows() {
|
||||
|
||||
{
|
||||
Window *window = GetWindow(DebugWindowID);
|
||||
Rect2 screen_rect = GetScreenRectF();
|
||||
Rect2 screen_rect = Rect0Size(wx, wy);
|
||||
Vec2 size = GetSize(screen_rect);
|
||||
|
||||
Rect2 a = CutLeft(&screen_rect, 0.3f * size.x);
|
||||
|
||||
@@ -106,9 +106,10 @@ void DrawUnderline(Window *window, View *view, Buffer *buffer, Range range, Colo
|
||||
}
|
||||
|
||||
void DrawWindow(Window *window, Event &event) {
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
SetScissor(GetScreenRectF());
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
Rect2 screen_rect = Rect0Size(event.xwindow, event.ywindow);
|
||||
SetScissor(screen_rect);
|
||||
|
||||
bool is_active = window->id == ActiveWindow || window->title_bar_window == ActiveWindow;
|
||||
|
||||
@@ -266,7 +267,7 @@ void DrawWindow(Window *window, Event &event) {
|
||||
}
|
||||
|
||||
if (!is_active) {
|
||||
SetScissor(GetScreenRectF());
|
||||
SetScissor(screen_rect);
|
||||
DrawRect(window->total_rect, ColorInactiveWindow);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user