From 3b354f16caa988332445423ac433e99ec95afcf4 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Tue, 16 Sep 2014 14:13:27 +0200 Subject: [PATCH] Added pattern if loop and bookmarks overlap Part of #96 work --- ogl_editor/emgui/include/emgui/Emgui.h | 1 + ogl_editor/emgui/src/Emgui.c | 85 +++++++++++++++++++++--- ogl_editor/emgui/src/Emgui.h | 2 + ogl_editor/emgui/src/Emgui_internal.h | 1 + ogl_editor/emgui/src/GFXBackend.h | 1 + ogl_editor/emgui/src/GFXBackends/OpenGLBackend.c | 54 ++++++++++++++- ogl_editor/src/TrackView.c | 12 +++- 7 files changed, 146 insertions(+), 10 deletions(-) diff --git a/ogl_editor/emgui/include/emgui/Emgui.h b/ogl_editor/emgui/include/emgui/Emgui.h index 9ae98c5..4a93509 100644 --- a/ogl_editor/emgui/include/emgui/Emgui.h +++ b/ogl_editor/emgui/include/emgui/Emgui.h @@ -135,6 +135,7 @@ void Emgui_drawTextFlipped(const char* text, int x, int y, uint32_t color); void Emgui_staticImage(const char* filename); void Emgui_fill(uint32_t color, int x, int y, int w, int h); +void Emgui_fillStipple(uint32_t color, int x, int y, int w, int h); void Emgui_fillGrad(uint32_t color0, uint32_t color1, int x, int y, int w, int h); void Emgui_drawBorder(uint32_t color0, uint32_t color1, int x, int y, int w, int h); void Emgui_drawDots(uint32_t color, int* coords, int count); diff --git a/ogl_editor/emgui/src/Emgui.c b/ogl_editor/emgui/src/Emgui.c index d7184cb..e3bdbb2 100644 --- a/ogl_editor/emgui/src/Emgui.c +++ b/ogl_editor/emgui/src/Emgui.c @@ -236,6 +236,58 @@ void createDefaultFont() /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void createStipplePattern() +{ + static unsigned char pattern[32*34]; + static unsigned char tempData[32 * 34] = { 0 }; + int x, y, i, startX = 8, width = 16, t = 0; + + for (y = 0; y < 32; ++y) + { + unsigned char* line = &tempData[y * 32]; + + for (i = 0; i < width; ++i) + line[startX + i] = 0x1; + + /* + for (int i = 0; i < width; ++i) + { + int p = startX + i; + + if (p <= -1) + p = 32 + p; + + line[p] = 0x1; + } + startX--; + */ + + } + + // pack data to bits + + for (x = 0; x < (32 * 32) / 8; ++x) + { + unsigned char p = 0; + + p = tempData[t + 0] << 0; + p |= tempData[t + 1] << 1; + p |= tempData[t + 2] << 2; + p |= tempData[t + 3] << 3; + p |= tempData[t + 4] << 4; + p |= tempData[t + 5] << 5; + p |= tempData[t + 6] << 6; + p |= tempData[t + 7] << 7; + + pattern[x] = p; + t += 8; + } + + EMGFXBackend_setStippleMask(pattern); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + int Emgui_loadFontBitmap(const char* buffer, int size, enum EmguiMemoryLocation location, int rangeStart, int rangeEnd, EmguiFontLayout* layout) @@ -318,6 +370,7 @@ bool Emgui_create() const uint32_t size = 1024 * 1024; LinearAllocator_create(&s_allocator, malloc(size), size); createDefaultFont(); + createStipplePattern(); g_emguiGuiState.kbdItem = -1; return true; } @@ -397,14 +450,7 @@ static bool Emgui_regionHitSlider(const EmguiControlInfo* control) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void Emgui_fill(uint32_t color, int x, int y, int w, int h) -{ - Emgui_fillGrad(color, color, x, y, w, h); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -void Emgui_fillGrad(uint32_t color0, uint32_t color1, int x, int y, int w, int h) +static void fillGrad(uint32_t color0, uint32_t color1, int x, int y, int w, int h, int stipple) { const int active_layer = s_activeLayer; struct DrawFillCommand* command = LinearAllocator_allocZero(&s_allocator, struct DrawFillCommand); @@ -415,6 +461,7 @@ void Emgui_fillGrad(uint32_t color0, uint32_t color1, int x, int y, int w, int h command->height = h; command->color0 = color0; command->color1 = color1; + command->stipple = stipple; if (!s_renderData.layers[active_layer].fillCommands) { @@ -426,6 +473,28 @@ void Emgui_fillGrad(uint32_t color0, uint32_t color1, int x, int y, int w, int h s_renderData.layers[active_layer].fillCommandsTail->next = command; s_renderData.layers[active_layer].fillCommandsTail = command; } + +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void Emgui_fill(uint32_t color, int x, int y, int w, int h) +{ + Emgui_fillGrad(color, color, x, y, w, h); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void Emgui_fillStipple(uint32_t color, int x, int y, int w, int h) +{ + fillGrad(color, color, x, y, w, h, 1); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void Emgui_fillGrad(uint32_t color0, uint32_t color1, int x, int y, int w, int h) +{ + fillGrad(color0, color1, x, y, w, h, 0); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/ogl_editor/emgui/src/Emgui.h b/ogl_editor/emgui/src/Emgui.h index 1e5e8c0..c84baab 100644 --- a/ogl_editor/emgui/src/Emgui.h +++ b/ogl_editor/emgui/src/Emgui.h @@ -104,6 +104,7 @@ void Emgui_beginHorizontalPanel(); void Emgui_setLayer(int layer); void Emgui_setScissor(int x, int y, int w, int h); +void Emgui_setStipple(int enabled); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Font functions @@ -133,6 +134,7 @@ void Emgui_drawTextFlipped(const char* text, int x, int y, uint32_t color); void Emgui_staticImage(const char* filename); void Emgui_fill(uint32_t color, int x, int y, int w, int h); +void Emgui_fillStipple(uint32_t color, int x, int y, int w, int h); void Emgui_fillGrad(uint32_t color0, uint32_t color1, int x, int y, int w, int h); void Emgui_drawBorder(uint32_t color0, uint32_t color1, int x, int y, int w, int h); void Emgui_drawDots(uint32_t color, int* coords, int count); diff --git a/ogl_editor/emgui/src/Emgui_internal.h b/ogl_editor/emgui/src/Emgui_internal.h index a7cd8c7..65728c9 100644 --- a/ogl_editor/emgui/src/Emgui_internal.h +++ b/ogl_editor/emgui/src/Emgui_internal.h @@ -74,6 +74,7 @@ struct DrawFillCommand int y; int width; int height; + int stipple; }; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/ogl_editor/emgui/src/GFXBackend.h b/ogl_editor/emgui/src/GFXBackend.h index 13e4df4..08d6a65 100644 --- a/ogl_editor/emgui/src/GFXBackend.h +++ b/ogl_editor/emgui/src/GFXBackend.h @@ -10,6 +10,7 @@ void EMGFXBackend_render(); uint64_t EMGFXBackend_createFontTexture(void* imageBuffer, int w, int h); uint64_t EMGFXBackend_createTexture(void* imageBuffer, int w, int h, int comp); +void EMGFXBackend_setStippleMask(unsigned char* mask); #endif diff --git a/ogl_editor/emgui/src/GFXBackends/OpenGLBackend.c b/ogl_editor/emgui/src/GFXBackends/OpenGLBackend.c index 99f5c62..afdeb0d 100644 --- a/ogl_editor/emgui/src/GFXBackends/OpenGLBackend.c +++ b/ogl_editor/emgui/src/GFXBackends/OpenGLBackend.c @@ -271,7 +271,6 @@ static void drawText(struct DrawTextCommand* commands, int fontId) static void drawFill(struct DrawFillCommand* command) { glEnable(GL_BLEND); - glBegin(GL_QUADS); while (command) @@ -281,6 +280,12 @@ static void drawFill(struct DrawFillCommand* command) const float w = (float)command->width; const float h = (float)command->height; + if (command->stipple) + { + command = command->next; + continue; + } + setColor(command->color0); glVertex2f(x, y); glVertex2f(x + w, y); @@ -293,6 +298,44 @@ static void drawFill(struct DrawFillCommand* command) glEnd(); + glDisable(GL_POLYGON_STIPPLE); + glDisable(GL_BLEND); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +static void drawFillStipple(struct DrawFillCommand* command) +{ + glEnable(GL_POLYGON_STIPPLE); + glEnable(GL_BLEND); + glBegin(GL_QUADS); + + while (command) + { + const float x = (float)command->x; + const float y = (float)command->y; + const float w = (float)command->width; + const float h = (float)command->height; + + if (!command->stipple) + { + command = command->next; + continue; + } + + setColor(command->color0); + glVertex2f(x, y); + glVertex2f(x + w, y); + setColor(command->color1); + glVertex2f(x + w, y + h); + glVertex2f(x, y + h); + + command = command->next; + } + + glEnd(); + + glDisable(GL_POLYGON_STIPPLE); glDisable(GL_BLEND); } @@ -369,6 +412,7 @@ void EMGFXBackend_render() } drawFill(layer->fillCommands); + drawFillStipple(layer->fillCommands); for (i = 0; i < EMGUI_MAX_FONTS; ++i) { @@ -388,4 +432,12 @@ void EMGFXBackend_render() swapBuffers(); } +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void EMGFXBackend_setStippleMask(unsigned char* mask) +{ + glPolygonStipple(mask); +} + + diff --git a/ogl_editor/src/TrackView.c b/ogl_editor/src/TrackView.c index e20406f..62fdd65 100644 --- a/ogl_editor/src/TrackView.c +++ b/ogl_editor/src/TrackView.c @@ -447,11 +447,21 @@ static int renderChannel(struct TrackInfo* info, int startX, Track* trackData, b if (y != 0) { + bool overlapping = false; + if (TrackData_hasBookmark(info->trackData, y)) + { + overlapping = true; Emgui_fill(bookmark_color, startX, y_offset - font_size_half, size, 8); + } if (TrackData_hasLoopmark(info->trackData, y)) - Emgui_fill(loopmark_color , startX, y_offset - font_size_half, size, 8); + { + if (!overlapping) + Emgui_fill(loopmark_color , startX, y_offset - font_size_half, size, 8); + else + Emgui_fillStipple(loopmark_color , startX, y_offset - font_size_half, size, 8); + } } y_offset += font_size;