Skip to content
Extraits de code Groupes Projets
Valider 86412d5c rédigé par Etienne BRATEAU's avatar Etienne BRATEAU
Parcourir les fichiers

label: add some comments and improve a while loop

parent 4f50b399
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -391,11 +391,14 @@ void addlabelat(short x, short y, char *s) ...@@ -391,11 +391,14 @@ void addlabelat(short x, short y, char *s)
l->y = y; l->y = y;
l->w = m_strwidth(logfont_lfont, s) / log_scale0; l->w = m_strwidth(logfont_lfont, s) / log_scale0;
chpageplace(gg.pages[gg.curpage - 1], x, y, x + l->w, y + 2); chpageplace(gg.pages[gg.curpage - 1], x, y, x + l->w, y + 2);
/* now render the label */
remcursor(); remcursor();
clipon(); clipon();
m_color((long)gg.color.labeltext); m_color((long)gg.color.labeltext);
m_drawstr(x * gg.scale - gg.xoff, y * gg.scale - gg.yoff + 2, logfont_lfont, s); m_drawstr(x * gg.scale - gg.xoff, y * gg.scale - gg.yoff + 2, logfont_lfont, s);
clipoff(); clipoff();
gg.nearlabel = l; gg.nearlabel = l;
} }
...@@ -411,9 +414,11 @@ void addlabel(log_lrec **l, char *s) ...@@ -411,9 +414,11 @@ void addlabel(log_lrec **l, char *s)
do do
{ {
fixxy(&x, &y); fixxy(&x, &y);
// check the position of other label to see if some will colide
conflict = false; conflict = false;
l1 = gg.pages[gg.curpage - 1]->lbase; l1 = gg.pages[gg.curpage - 1]->lbase;
while (l1 != NULL) while (l1 != NULL && !conflict)
{ {
if (l1->y * gg.scale - gg.yoff == y && if (l1->y * gg.scale - gg.yoff == y &&
labs(l1->x * gg.scale - gg.xoff - x) < 20) labs(l1->x * gg.scale - gg.xoff - x) < 20)
...@@ -421,6 +426,7 @@ void addlabel(log_lrec **l, char *s) ...@@ -421,6 +426,7 @@ void addlabel(log_lrec **l, char *s)
l1 = l1->next; l1 = l1->next;
} }
// if some colide, then place it not exactly at same place
if (conflict) if (conflict)
{ {
y -= gg.scale * 2; y -= gg.scale * 2;
...@@ -431,10 +437,16 @@ void addlabel(log_lrec **l, char *s) ...@@ -431,10 +437,16 @@ void addlabel(log_lrec **l, char *s)
} }
} }
} while (conflict); } while (conflict);
// prepare coordinates
x = (x + gg.xoff) / gg.scale; x = (x + gg.xoff) / gg.scale;
y = (y + gg.yoff) / gg.scale; y = (y + gg.yoff) / gg.scale;
//fix if needed
if (x * gg.scale < gg.xoff) if (x * gg.scale < gg.xoff)
x++; x++;
// create label
addlabelat(x, y, s); addlabelat(x, y, s);
*l = gg.nearlabel; *l = gg.nearlabel;
} }
...@@ -453,10 +465,12 @@ void editlabel(log_lrec *l) ...@@ -453,10 +465,12 @@ void editlabel(log_lrec *l)
char name[log_lablen + 1]; char name[log_lablen + 1];
char STR1[256]; char STR1[256];
// prepare rendering
m_graphics_on(); m_graphics_on();
clearalpha(); clearalpha();
remcursor(); remcursor();
touching = (l != NULL && l == gg.nearlabel); touching = (l != NULL && l == gg.nearlabel);
// in case that we are editing a non existing label
if (l == NULL) if (l == NULL)
addlabel(&l, ""); addlabel(&l, "");
x1 = l->x * gg.scale - gg.xoff; x1 = l->x * gg.scale - gg.xoff;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter