commit 2a4bfd271c421c9bfc5ea7a764e5715b1ba8b4fd
parent c1f3a7878834571ce3f9a6d302a364df442860d6
Author: William Casarin <jb55@jb55.com>
Date: Thu, 16 Aug 2018 20:09:24 -0700
better focusing
Diffstat:
M | ln.c | | | 17 | ++++++++++------- |
M | ln.h | | | 4 | ++-- |
M | render.c | | | 44 | ++++++++++++++++++++++++++++++++++---------- |
M | update.c | | | 43 | +++++++++++++++++++++++++++++++++++++------ |
4 files changed, 83 insertions(+), 25 deletions(-)
diff --git a/ln.c b/ln.c
@@ -124,21 +124,24 @@ void filter_network(const char *nodeid, struct node *filter_node, struct ln *ln)
node = &ln->nodes[i];
if (filter_node == node || (nodeid && streq(nodeid, node->id)))
- node->filtered = 1;
+ node->visible = 1;
else
- node->filtered = 0;
+ node->visible = 0;
}
for (i = 0; i < ln->channel_count; i++) {
chan = &ln->channels[i];
- if (i % 2 == 0)
- chan->filtered = 1;
+ // this should filter out duplicates?
+ if ((chan->flags & 1) == 0)
+ chan->visible = 0;
+ else
+ chan->visible = 1;
- if (chan->nodes[0]->filtered)
+ if (chan->nodes[0]->visible)
chan->nodes[1]->mark_filtered = 1;
- if (chan->nodes[1]->filtered)
+ if (chan->nodes[1]->visible)
chan->nodes[0]->mark_filtered = 1;
}
@@ -146,7 +149,7 @@ void filter_network(const char *nodeid, struct node *filter_node, struct ln *ln)
node = &ln->nodes[i];
if (node->mark_filtered) {
- node->filtered = 1;
+ node->visible = 1;
node->mark_filtered = 0;
}
}
diff --git a/ln.h b/ln.h
@@ -23,7 +23,7 @@ struct node {
char alias[MAX_ALIAS_SIZE+1];
char id[PUBKEY_SIZE+1];
- int filtered, mark_filtered;
+ int visible, mark_filtered, adj_drag_target;
union color color;
@@ -98,7 +98,7 @@ struct channel {
u64 satoshis;
// app specific stuff
- int filtered;
+ int visible;
int draw_last;
};
diff --git a/render.c b/render.c
@@ -29,16 +29,15 @@ void saturate(union color *c, double change)
c->b = P+((c->b)-P)*change;
}
-
void draw_channel(NVGcontext *vg, struct ln *ln, struct channel *channel)
{
- if (channel->filtered == 1)
+ if (!channel->visible)
return;
const struct node *n1 = channel->nodes[0];
const struct node *n2 = channel->nodes[1];
- if (!(n1->filtered && n2->filtered))
+ if (!n1->visible || !n2->visible)
return;
const float stroke = max(1.0, channel->satoshis * 0.000001f);
@@ -170,7 +169,7 @@ void draw_grid(NVGcontext *vg, struct ln *ln) {
void draw_node(NVGcontext *vg, struct ln *ln, struct node *node)
{
- if (!node->filtered)
+ if (!node->visible)
return;
nvgFontSize(vg, 18.0f);
@@ -216,6 +215,33 @@ void draw_node(NVGcontext *vg, struct ln *ln, struct node *node)
const int dark_theme = ln->display_flags & DISP_DARK;
//TODO: use brightness instead of clear color for white theme
+ nvgBeginPath(vg);
+ nvgCircle(vg, 0, 0, r);
+ /* nvgPathWinding(vg, NVG_HOLE); */
+
+
+ if (node->adj_drag_target || node == ln->last_drag_target) {
+ node_color.a = 1.0;
+ node_color_inv.a = 1.0;
+ blend.a = 1.0;
+ clear_adj.a = 1.0;
+ }
+ else {
+ if (ln->drag_target) {
+ saturate((union color*)&node_color, 0.01);
+ node_color.a = 0.1;
+ node_color_inv.a = 0.1;
+ blend.a = 0.1;
+ clear_adj.a = 0.1;
+ }
+ else {
+ node_color.a = 0.9;
+ node_color_inv.a = 0.9;
+ blend.a = 0.9;
+ clear_adj.a = 0.9;
+ }
+ }
+
if (!dark_theme)
bg = nvgRadialGradient(vg, -light, -light, 0, r+2.0,
ln->clear_color.nvg_color,
@@ -223,10 +249,6 @@ void draw_node(NVGcontext *vg, struct ln *ln, struct node *node)
else
bg = nvgRadialGradient(vg, -light, -light, 0, r+2.0, node_color, blend);
- nvgBeginPath(vg);
- nvgCircle(vg, 0, 0, r);
- /* nvgPathWinding(vg, NVG_HOLE); */
-
if (ln->display_flags & DISP_STROKE_NODES) {
nvgStrokeWidth(vg, 3.0f);
nvgStrokeColor(vg, dark_theme ? clear_adj : ln->clear_color.nvg_color);
@@ -236,11 +258,13 @@ void draw_node(NVGcontext *vg, struct ln *ln, struct node *node)
nvgFillPaint(vg, bg);
nvgFill(vg);
- if (ln->display_flags & DISP_ALIASES) {
+ int is_adj = !ln->drag_target || ((ln->drag_target && node->adj_drag_target) || node == ln->drag_target);
+
+ if (is_adj && ln->display_flags & DISP_ALIASES) {
nvgBeginPath(vg);
nvgRoundedRect(vg, -bounds[2] / 2.0 - pad, bounds[3] - pad, bounds[2] + pad * 2.0, bounds[3] + pad * 2.0, 5.0);
- nvgFillColor(vg, nvgRGBAf(node_color.r, node_color.g, node_color.b, 0.9));
+ nvgFillColor(vg, nvgRGBAf(node_color.r, node_color.g, node_color.b, node_color.a));
nvgFill(vg);
/* nvgTextMetrics(vg, NULL, NULL, &lineh); */
diff --git a/update.c b/update.c
@@ -9,7 +9,7 @@ struct node *hit_node(struct ln *ln) {
for (u32 i = 0; i < ln->node_count; ++i)
{
struct node *n = &ln->nodes[i];
- if (!n->filtered)
+ if (!n->visible)
continue;
const double dx = fabs(n->x - ln->mx);
@@ -83,7 +83,7 @@ static void force_graph(struct ln *ln, double dt) {
struct node *n1 = channel->nodes[0];
struct node *n2 = channel->nodes[1];
- if (!n1->filtered || !n2->filtered)
+ if (!n1->visible || !n2->visible)
continue;
repel_nodes(n1, n2, dt);
@@ -127,7 +127,7 @@ static void physics(struct ln *ln, double dt)
for (u32 i = 0; i < ln->node_count; i++) {
struct node *node = &ln->nodes[i];
- if (!node->filtered)
+ if (!node->visible)
continue;
/* repel_nearby(node, dt); */
@@ -150,7 +150,17 @@ static void physics(struct ln *ln, double dt)
}
-static void print_channel_info(struct channel chan)
+static void print_channel_info(struct channel *chan)
+{
+ printf("%u:%u:%hu %s -> %s (%f bits)\n",
+ chan->short_channel_id.blocknum,
+ chan->short_channel_id.txnum,
+ chan->short_channel_id.outnum,
+ chan->nodes[0]->alias,
+ chan->nodes[1]->alias,
+ chan->satoshis / 100.0
+ );
+}
static void handle_click(struct ln *ln)
@@ -166,15 +176,36 @@ static void handle_click(struct ln *ln)
return;
// print some info about channels
+ printf("\nchannels\n--------\n");
+
+ for (u32 i = 0; i < ln->channel_count; i++) {
+ chan = &ln->channels[i];
+ chan->nodes[0]->adj_drag_target = 0;
+ chan->nodes[1]->adj_drag_target = 0;
+ }
+
for (u32 i = 0; i < ln->channel_count; i++) {
chan = &ln->channels[i];
- if (chan->filtered)
+ if (!chan->visible)
continue;
+ if (chan->nodes[0]->visible && chan->nodes[0] == ln->drag_target)
+ chan->nodes[1]->adj_drag_target |= 1;
+ else
+ chan->nodes[0]->adj_drag_target ^= 0;
+
+ if (chan->nodes[1]->visible && chan->nodes[1] == ln->drag_target)
+ chan->nodes[0]->adj_drag_target = 1;
+ else
+ chan->nodes[1]->adj_drag_target ^= 0;
+
if (nodeid_eq(chan->nodes[0]->id, hit->id) ||
- nodeid_eq(chan->nodes[1]->id, hit->id))
+ nodeid_eq(chan->nodes[1]->id, hit->id)) {
+ if (!chan->nodes[0]->visible || !chan->nodes[1]->visible)
+ continue;
print_channel_info(chan);
+ }
}
}