diff --git a/src/label.c b/src/label.c index 3a284c2986cd52bf60e43d41ee519b2d4bb05c43..c31ef6fc39b960d2b2309760910288e2a69b4933 100644 --- a/src/label.c +++ b/src/label.c @@ -391,11 +391,14 @@ void addlabelat(short x, short y, char *s) l->y = y; l->w = m_strwidth(logfont_lfont, s) / log_scale0; chpageplace(gg.pages[gg.curpage - 1], x, y, x + l->w, y + 2); + + /* now render the label */ remcursor(); clipon(); m_color((long)gg.color.labeltext); m_drawstr(x * gg.scale - gg.xoff, y * gg.scale - gg.yoff + 2, logfont_lfont, s); clipoff(); + gg.nearlabel = l; } @@ -411,9 +414,11 @@ void addlabel(log_lrec **l, char *s) do { fixxy(&x, &y); + + // check the position of other label to see if some will colide conflict = false; l1 = gg.pages[gg.curpage - 1]->lbase; - while (l1 != NULL) + while (l1 != NULL && !conflict) { if (l1->y * gg.scale - gg.yoff == y && labs(l1->x * gg.scale - gg.xoff - x) < 20) @@ -421,6 +426,7 @@ void addlabel(log_lrec **l, char *s) l1 = l1->next; } + // if some colide, then place it not exactly at same place if (conflict) { y -= gg.scale * 2; @@ -431,10 +437,16 @@ void addlabel(log_lrec **l, char *s) } } } while (conflict); + + // prepare coordinates x = (x + gg.xoff) / gg.scale; y = (y + gg.yoff) / gg.scale; + + //fix if needed if (x * gg.scale < gg.xoff) x++; + + // create label addlabelat(x, y, s); *l = gg.nearlabel; } @@ -453,10 +465,12 @@ void editlabel(log_lrec *l) char name[log_lablen + 1]; char STR1[256]; + // prepare rendering m_graphics_on(); clearalpha(); remcursor(); touching = (l != NULL && l == gg.nearlabel); + // in case that we are editing a non existing label if (l == NULL) addlabel(&l, ""); x1 = l->x * gg.scale - gg.xoff;