-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented widget overrides by priority on the graph widget
- Loading branch information
Showing
8 changed files
with
238 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> | ||
* (C) 2020 Vladimir Sadovnikov <[email protected]> | ||
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/> | ||
* (C) 2023 Vladimir Sadovnikov <[email protected]> | ||
* | ||
* This file is part of lsp-tk-lib | ||
* Created on: 20 авг. 2020 г. | ||
|
@@ -58,9 +58,14 @@ namespace lsp | |
public: | ||
static const w_class_t metadata; | ||
|
||
private: | ||
Graph & operator = (const Graph &); | ||
Graph(const Graph &); | ||
protected: | ||
typedef struct w_alloc_t | ||
{ | ||
ws::rectangle_t sRect; | ||
ssize_t nGroup; | ||
ssize_t nPriority; | ||
GraphItem *pWidget; | ||
} w_alloc_t; | ||
|
||
protected: | ||
prop::WidgetList<GraphItem> vItems; // Overall list of graph items | ||
|
@@ -89,23 +94,31 @@ namespace lsp | |
static void on_add_item(void *obj, Property *prop, void *w); | ||
static void on_remove_item(void *obj, Property *prop, void *w); | ||
|
||
static ssize_t check_collision(const w_alloc_t *a, const w_alloc_t *b); | ||
static ssize_t compare_walloc(const w_alloc_t *a, const w_alloc_t *b); | ||
|
||
protected: | ||
virtual Widget *find_widget(ssize_t x, ssize_t y); | ||
virtual void size_request(ws::size_limit_t *r); | ||
virtual void property_changed(Property *prop); | ||
virtual void realize(const ws::rectangle_t *r); | ||
virtual void hide_widget(); | ||
virtual Widget *find_widget(ssize_t x, ssize_t y) override; | ||
virtual void size_request(ws::size_limit_t *r) override; | ||
virtual void property_changed(Property *prop) override; | ||
virtual void realize(const ws::rectangle_t *r) override; | ||
virtual void hide_widget() override; | ||
|
||
void sync_lists(); | ||
void drop_glass(); | ||
|
||
public: | ||
explicit Graph(Display *dpy); | ||
Graph(const Graph &) = delete; | ||
Graph(Graph &&) = delete; | ||
virtual ~Graph(); | ||
|
||
Graph & operator = (const Graph &) = delete; | ||
Graph & operator = (Graph &&) = delete; | ||
|
||
public: | ||
virtual status_t init(); | ||
virtual void destroy(); | ||
virtual status_t init() override; | ||
virtual void destroy() override; | ||
|
||
public: | ||
LSP_TK_PROPERTY(WidgetList<GraphItem>, items, &vItems); | ||
|
@@ -181,19 +194,19 @@ namespace lsp | |
status_t axis_to_xy(size_t index, ssize_t *x, ssize_t *y, float value); | ||
|
||
public: | ||
virtual status_t add(Widget *child); | ||
virtual status_t add(Widget *child) override; | ||
|
||
virtual status_t remove(Widget *child); | ||
virtual status_t remove(Widget *child) override; | ||
|
||
virtual status_t remove_all(); | ||
virtual status_t remove_all() override; | ||
|
||
virtual void render(ws::ISurface *s, const ws::rectangle_t *area, bool force); | ||
virtual void render(ws::ISurface *s, const ws::rectangle_t *area, bool force) override; | ||
|
||
virtual void draw(ws::ISurface *s); | ||
virtual void draw(ws::ISurface *s) override; | ||
}; | ||
|
||
} | ||
} | ||
} /* namespace tk */ | ||
} /* namespace lsp */ | ||
|
||
|
||
#endif /* LSP_PLUG_IN_TK_WIDGETS_GRAPH_GRAPH_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> | ||
* (C) 2020 Vladimir Sadovnikov <[email protected]> | ||
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/> | ||
* (C) 2023 Vladimir Sadovnikov <[email protected]> | ||
* | ||
* This file is part of lsp-tk-lib | ||
* Created on: 20 авг. 2020 г. | ||
|
@@ -37,6 +37,8 @@ namespace lsp | |
{ | ||
LSP_TK_STYLE_DEF_BEGIN(GraphItem, Widget) | ||
prop::Boolean sSmooth; | ||
prop::Integer sPriorityGroup; // Priority group | ||
prop::Integer sPriority; // Priority inside of a group | ||
LSP_TK_STYLE_DEF_END | ||
} | ||
|
||
|
@@ -45,26 +47,31 @@ namespace lsp | |
public: | ||
static const w_class_t metadata; | ||
|
||
private: | ||
GraphItem & operator = (const GraphItem &); | ||
GraphItem(const GraphItem &); | ||
|
||
protected: | ||
prop::Boolean sSmooth; | ||
prop::Integer sPriorityGroup; // Priority group | ||
prop::Integer sPriority; // Priority inside of a group | ||
|
||
protected: | ||
virtual void property_changed(Property *prop); | ||
virtual void property_changed(Property *prop) override; | ||
|
||
public: | ||
explicit GraphItem(Display *dpy); | ||
virtual ~GraphItem(); | ||
GraphItem(const GraphItem &) = delete; | ||
GraphItem(GraphItem &&) = delete; | ||
virtual ~GraphItem() override; | ||
|
||
GraphItem & operator = (const GraphItem &) = delete; | ||
GraphItem & operator = (GraphItem &&) = delete; | ||
|
||
public: | ||
virtual status_t init(); | ||
virtual void destroy(); | ||
virtual status_t init() override; | ||
virtual void destroy() override; | ||
|
||
public: | ||
LSP_TK_PROPERTY(Boolean, smooth, &sSmooth); | ||
LSP_TK_PROPERTY(Integer, priority_group, &sPriorityGroup); | ||
LSP_TK_PROPERTY(Integer, priority, &sPriority); | ||
|
||
public: | ||
/** | ||
|
@@ -73,18 +80,27 @@ namespace lsp | |
*/ | ||
Graph *graph(); | ||
|
||
virtual void query_draw(size_t flags = REDRAW_SURFACE); | ||
virtual void query_draw(size_t flags = REDRAW_SURFACE) override; | ||
|
||
/** | ||
* Check whether mouse pointer is inside of the graph item | ||
* @param x horizontal position of mouse pointer | ||
* @param y vertical position of mouse pointer | ||
* @return true if item is inside of the graph | ||
*/ | ||
virtual bool inside(ssize_t x, ssize_t y); | ||
virtual bool inside(ssize_t x, ssize_t y) override; | ||
|
||
public: | ||
/** | ||
* Estimate the bounding box for prioritized drawing | ||
* @param s surface for drawing | ||
* @param r rectangle to store the bound box | ||
* @return false if widget does not provide bound box | ||
*/ | ||
virtual bool bound_box(ws::ISurface *s, ws::rectangle_t *r); | ||
}; | ||
|
||
} | ||
} | ||
} /* namespace tk */ | ||
} /* namespace lsp */ | ||
|
||
#endif /* LSP_PLUG_IN_TK_WIDGETS_GRAPH_GRAPHITEM_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> | ||
* (C) 2020 Vladimir Sadovnikov <[email protected]> | ||
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/> | ||
* (C) 2023 Vladimir Sadovnikov <[email protected]> | ||
* | ||
* This file is part of lsp-tk-lib | ||
* Created on: 20 авг. 2020 г. | ||
|
@@ -53,10 +53,6 @@ namespace lsp | |
public: | ||
static const w_class_t metadata; | ||
|
||
private: | ||
GraphText & operator = (const GraphText &); | ||
GraphText(const GraphText &); | ||
|
||
private: | ||
prop::String sText; | ||
prop::Font sFont; | ||
|
@@ -71,13 +67,18 @@ namespace lsp | |
prop::Integer sOrigin; | ||
|
||
protected: | ||
virtual void property_changed(Property *prop); | ||
virtual void property_changed(Property *prop) override; | ||
|
||
public: | ||
explicit GraphText(Display *dpy); | ||
virtual ~GraphText(); | ||
GraphText(const GraphText &) = delete; | ||
GraphText(GraphText &&) = delete; | ||
virtual ~GraphText() override; | ||
|
||
virtual status_t init(); | ||
GraphText & operator = (const GraphText &) = delete; | ||
GraphText & operator = (GraphText &&) = delete; | ||
|
||
virtual status_t init() override; | ||
|
||
public: | ||
LSP_TK_PROPERTY(String, text, &sText) | ||
|
@@ -93,10 +94,12 @@ namespace lsp | |
LSP_TK_PROPERTY(Integer, origin, &sOrigin) | ||
|
||
public: | ||
virtual void render(ws::ISurface *s, const ws::rectangle_t *area, bool force); | ||
virtual void render(ws::ISurface *s, const ws::rectangle_t *area, bool force) override; | ||
|
||
virtual bool bound_box(ws::ISurface *s, ws::rectangle_t *r) override; | ||
}; | ||
} | ||
} | ||
} /* namespace tk */ | ||
} /* namespace lsp */ | ||
|
||
|
||
#endif /* LSP_PLUG_IN_TK_WIDGETS_GRAPH_GRAPHTEXT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> | ||
* (C) 2020 Vladimir Sadovnikov <[email protected]> | ||
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/> | ||
* (C) 2023 Vladimir Sadovnikov <[email protected]> | ||
* | ||
* This file is part of lsp-tk-lib | ||
* Created on: 20 авг. 2020 г. | ||
|
@@ -23,6 +23,7 @@ | |
#include <lsp-plug.in/tk/helpers/draw.h> | ||
#include <lsp-plug.in/stdlib/math.h> | ||
#include <lsp-plug.in/common/debug.h> | ||
#include <lsp-plug.in/lltl/ptrset.h> | ||
#include <private/tk/style/BuiltinStyle.h> | ||
|
||
namespace lsp | ||
|
@@ -315,6 +316,24 @@ namespace lsp | |
s->clip_end(); | ||
} | ||
|
||
ssize_t Graph::check_collision(const w_alloc_t *a, const w_alloc_t *b) | ||
{ | ||
if ((a->nGroup != b->nGroup) || (a->nPriority == b->nPriority)) | ||
return 0; | ||
if (!Size::overlap(&a->sRect, &b->sRect)) | ||
return 0; | ||
|
||
return b->nPriority - a->nPriority; | ||
} | ||
|
||
ssize_t Graph::compare_walloc(const w_alloc_t *a, const w_alloc_t *b) | ||
{ | ||
ssize_t diff = a->nGroup - b->nGroup; | ||
if (diff == 0) | ||
diff = a->nPriority - b->nPriority; | ||
return diff; | ||
} | ||
|
||
void Graph::draw(ws::ISurface *s) | ||
{ | ||
// Clear canvas | ||
|
@@ -326,12 +345,63 @@ namespace lsp | |
// Sync internal lists of axes and origins | ||
sync_lists(); | ||
|
||
// Compute list of discarded widgets | ||
lltl::ptrset<GraphItem> discarded; | ||
{ | ||
lltl::darray<w_alloc_t> grouped; | ||
|
||
// Fill all grouped widgets | ||
for (size_t i=0, n=vItems.size(); i<n; ++i) | ||
{ | ||
GraphItem *gi = vItems.get(i); | ||
if ((gi == NULL) || (!gi->visibility()->get())) | ||
continue; | ||
|
||
// Fill the widget allocation | ||
w_alloc_t wa; | ||
wa.nGroup = gi->priority_group()->get(); | ||
if (wa.nGroup < 0) | ||
continue; | ||
if (!gi->bound_box(s, &wa.sRect)) | ||
continue; | ||
|
||
wa.nPriority = gi->priority()->get(); | ||
wa.pWidget = gi; | ||
|
||
grouped.add(&wa); | ||
} | ||
grouped.qsort(compare_walloc); | ||
|
||
// Scan for conflicting widgets and discard some widgets according to priority | ||
for (size_t i=0, n=grouped.size(); i<n; ++i) | ||
{ | ||
w_alloc_t *wa = grouped.uget(i); | ||
if (wa == NULL) | ||
continue; | ||
|
||
for (size_t j=0; j<i; ++j) | ||
{ | ||
w_alloc_t *wb = grouped.uget(j); | ||
if (wb == NULL) | ||
continue; | ||
|
||
if (check_collision(wb, wa) > 0) | ||
{ | ||
discarded.put(wa->pWidget); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Draw all objects | ||
for (size_t i=0, n=vItems.size(); i<n; ++i) | ||
{ | ||
GraphItem *gi = vItems.get(i); | ||
if ((gi == NULL) || (!gi->visibility()->get())) | ||
continue; | ||
if (discarded.contains(gi)) | ||
continue; | ||
|
||
gi->render(s, &sICanvas, true); | ||
gi->commit_redraw(); | ||
|
Oops, something went wrong.