diff --git a/include/label.h b/include/label.h index 892e7cc9473fb8e9ae30aee8973909347e773b7e..5c322dbad11e27937d8d83a090a3d1755c7c1fef 100644 --- a/include/label.h +++ b/include/label.h @@ -25,4 +25,10 @@ void unlinklabel(log_lrec *l); void displabel(log_lrec **l); +void addlabelat(short x, short y, char *s); + +void addlabel(log_lrec **l, char *s); + +void editlabel(log_lrec *l); + #endif diff --git a/include/log.h b/include/log.h index 330eb6ffc642c0c4a91cde76b6258f3530fb1540..a99bdaa5cd5cf8220610f0d586ce09c7c2cb16c5 100644 --- a/include/log.h +++ b/include/log.h @@ -30,6 +30,8 @@ void doimmedcnffunction(); void doimmedfunction(); void docnffunction(); void trykbd(); +char inkey2(); +int pollkbd2(); void confirmsimtype(log_nrec *n); void scancn(cnrec *cn, struct LOC_checkcombine *LINK); void addblobs(blobrec **blbase, short x1, short y1, short x2, short y2); @@ -46,7 +48,6 @@ short readlibrary(char *n); void histdelsignals(); void histaddsignal(log_hnrec **hn, short sig, short y); void addboxat(short x1, short y1, short x2, short y2); -void addlabelat(short x, short y, char *s); void settofrom(log_grec **g, char *name); void solderat(short x, short y); void frysolder(short x, short y); diff --git a/src/label.c b/src/label.c index 3df1b34ee7928384a74a1ef65d7a919963ef670f..5452f2b638856c36e38f741af590dd2b23cdaaa2 100644 --- a/src/label.c +++ b/src/label.c @@ -1,14 +1,17 @@ +#include "label.h" #include <string.h> #include <utils/p2c.h> #include <utils/strings.h> #include <graphics/newkbd.h> +#include <graphics/newci.h> #include "settings.h" #include "logglobals.h" #include "logfont.h" #include "utils.h" #include "page.h" -#include "label.h" +#include "screen.h" +#include "log.h" /** @@ -375,3 +378,245 @@ void displabel(log_lrec **l) Free(*l); l = NULL; } + +void addlabelat(short x, short y, char *s) +{ + log_lrec *l; + + newlabel(&l); + strcpy(l->name, s); + l->x = x; + 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); + 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; +} + + +void addlabel(log_lrec **l, char *s) +{ + int conflict; + log_lrec *l1; + short x, y; + + x = 0; + y = baseline - 15; + do + { + fixxy(&x, &y); + conflict = false; + l1 = gg.pages[gg.curpage - 1]->lbase; + while (l1 != NULL) + { + if (l1->y * gg.scale - gg.yoff == y && + labs(l1->x * gg.scale - gg.xoff - x) < 20) + conflict = true; + l1 = l1->next; + } + + if (conflict) + { + y -= gg.scale * 2; + if (y < 10) + { + y = baseline - 15; + x += gg.scale * 20; + } + } + } while (conflict); + x = (x + gg.xoff) / gg.scale; + y = (y + gg.yoff) / gg.scale; + if (x * gg.scale < gg.xoff) + x++; + addlabelat(x, y, s); + *l = gg.nearlabel; +} + + +#define blinkrate 25 + + +/// Edit or create a label. +void editlabel(log_lrec *l) +{ + short i, x1, y1; + long j; + uchar ch; + int savecaps, redraw, touching; + char name[log_lablen + 1]; + char STR1[256]; + + m_graphics_on(); + clearalpha(); + remcursor(); + savecaps = nk_setcapslock(labelcaps); + touching = (l != NULL && l == gg.nearlabel); + if (l == NULL) + addlabel(&l, ""); + x1 = l->x * gg.scale - gg.xoff; + y1 = l->y * gg.scale - gg.yoff + 2; + i = 1; + strcpy(name, l->name); + if (touching) + { + while (i <= strlen(name) && + gg.t.x - x1 > m_strwidth(logfont_lfont, + (sprintf(STR1, "%.*s", i, name), STR1))) + { + i++; + } + } + + do + { + do + { + remcursor(); + clipon(); + m_colormode((long)m_xor); + m_color((long)gg.color.labeltext); + sprintf(STR1, "%.*s", i - 1, name); + m_move(x1 + m_strwidth(logfont_lfont, STR1) - 1, y1 + 8L); + if (i > strlen(name)) + { + m_drawrel(6L, 0L); + } + else + { + sprintf(STR1, "%.1s", name + i - 1); + m_drawrel(m_strwidth(logfont_lfont, STR1), 0L); + } + m_colormode((long)m_normal); + clipoff(); + j = timers_sysclock() + blinkrate; + if (!pollkbd2()) + { + do + { + pass(); + pen(); + } while (!(pollkbd2() || gg.t.dn || timers_sysclock() > j)); + } + remcursor(); + clipon(); + m_colormode((long)m_xor); + m_color((long)gg.color.labeltext); + sprintf(STR1, "%.*s", i - 1, name); + m_move(x1 + m_strwidth(logfont_lfont, STR1) - 1, y1 + 8L); + if (i > strlen(name)) + { + m_drawrel(6L, 0L); + } + else + { + sprintf(STR1, "%.1s", name + i - 1); + m_drawrel(m_strwidth(logfont_lfont, STR1), 0L); + } + m_colormode((long)m_normal); + clipoff(); + j = timers_sysclock() + blinkrate; + if (!(pollkbd2() || gg.t.dn)) + { + do + { + pass(); + pen(); + } while (!(pollkbd2() || gg.t.dn || timers_sysclock() > j)); + } + } while (!(pollkbd2() || gg.t.dn)); + + if (!gg.t.dn) + { + ch = inkey2(); + if (ch >= 32 || ((1L << ch) & 0x10002108L) == 0) + { + remcursor(); + m_color((long)gg.color.backgr); + m_drawstr((long)x1, (long)y1, logfont_lfont, name); + redraw = true; + } + else + { + redraw = false; + } + + if (ch >= ' ' && ch != 250 && ch != 251 && strlen(name) < log_lablen) + { + if (i <= strlen(name)) + { + sprintf(STR1, " %s", name + i - 1); + strcpy(name + i - 1, STR1); + } + else + { + strcat(name, " "); + } + name[i - 1] = ch; + i++; + } + else if (ch == '\007' && i > 1) + { + i--; + strcpy_overlap(name + i - 1, name + i); + } + else if (ch == '\030' && i <= strlen(name)) + { + strcpy_overlap(name + i - 1, name + i); + } + else if (ch == '\b' && i > 1) + { + i--; + } + else if (ch == '\034' && i <= strlen(name)) + { + i++; + } + else if (ch == '\031') + { + i = 1; + } + else if (ch == '\032') + { + i = strlen(name) + 1; + } + else if (ch == '\n' && strlen(name) < log_lablen) + { + sprintf(STR1, " %s", name + i - 1); + strcpy(name + i - 1, STR1); + } + else if (ch == '\037' && i <= strlen(name) && strlen(name) > 1) + { + strcpy_overlap(name + i - 1, name + i); + } + if (redraw) + { + remcursor(); + m_color((long)gg.color.labeltext); + m_drawstr((long)x1, (long)y1, logfont_lfont, name); + } + } + } while (!((ch < 32 && ((1L << ch) & 0x2008) != 0) || gg.t.dn)); + + if (*name == '\0') + { + displabel(&l); + } + else if (strcmp(name, l->name)) + { + strcpy(l->name, name); + l->w = m_strwidth(logfont_lfont, l->name) / log_scale0; + stamp(&gg.labelstamp); + chpageplace(gg.pages[gg.curpage - 1], l->x, l->y, l->x + l->w, l->y + 2); + } + labelcaps = nk_setcapslock(savecaps); + gg.t.depressed = false; + refreshsoon(); +} + +#undef blinkrate + diff --git a/src/log.c b/src/log.c index 677165b9feaa984e904eb0a8fce56cdb5c41e039..64a62ca0ef7a5966ce6cf0cfa04f0d3d91ae1f9d 100644 --- a/src/log.c +++ b/src/log.c @@ -742,7 +742,7 @@ static void show_events() /// Return TRUE if a key has been pressed (via keyboard or menu boxes). -static int pollkbd2() +int pollkbd2() { return (nk_keybufsize() != 0 || pushedbackkey != '\0'); } @@ -961,7 +961,7 @@ static char testkey2() /// Return a keystroke. Key is removed from the buffer. -static char inkey2() +char inkey2() { char ch; @@ -8804,249 +8804,6 @@ static void findboxmarker(log_krec *k, short num, short *x1, short *y1, short *x k->y2 = k->vector[i - 1].UU.U99.y2; } - -void addlabelat(short x, short y, char *s) -{ - log_lrec *l; - - newlabel(&l); - strcpy(l->name, s); - l->x = x; - 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); - 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; -} - - -static void addlabel(log_lrec **l, char *s) -{ - int conflict; - log_lrec *l1; - short x, y; - - x = 0; - y = baseline - 15; - do - { - fixxy(&x, &y); - conflict = false; - l1 = gg.pages[gg.curpage - 1]->lbase; - while (l1 != NULL) - { - if (l1->y * gg.scale - gg.yoff == y && - labs(l1->x * gg.scale - gg.xoff - x) < 20) - conflict = true; - l1 = l1->next; - } - - if (conflict) - { - y -= gg.scale * 2; - if (y < 10) - { - y = baseline - 15; - x += gg.scale * 20; - } - } - } while (conflict); - x = (x + gg.xoff) / gg.scale; - y = (y + gg.yoff) / gg.scale; - if (x * gg.scale < gg.xoff) - x++; - addlabelat(x, y, s); - *l = gg.nearlabel; -} - - -#define blinkrate 25 - - -/// Edit or create a label. -static void editlabel(log_lrec *l) -{ - short i, x1, y1; - long j; - uchar ch; - int savecaps, redraw, touching; - char name[log_lablen + 1]; - char STR1[256]; - - m_graphics_on(); - clearalpha(); - remcursor(); - savecaps = nk_setcapslock(labelcaps); - touching = (l != NULL && l == gg.nearlabel); - if (l == NULL) - addlabel(&l, ""); - x1 = l->x * gg.scale - gg.xoff; - y1 = l->y * gg.scale - gg.yoff + 2; - i = 1; - strcpy(name, l->name); - if (touching) - { - while (i <= strlen(name) && - gg.t.x - x1 > m_strwidth(logfont_lfont, - (sprintf(STR1, "%.*s", i, name), STR1))) - { - i++; - } - } - - do - { - do - { - remcursor(); - clipon(); - m_colormode((long)m_xor); - m_color((long)gg.color.labeltext); - sprintf(STR1, "%.*s", i - 1, name); - m_move(x1 + m_strwidth(logfont_lfont, STR1) - 1, y1 + 8L); - if (i > strlen(name)) - { - m_drawrel(6L, 0L); - } - else - { - sprintf(STR1, "%.1s", name + i - 1); - m_drawrel(m_strwidth(logfont_lfont, STR1), 0L); - } - m_colormode((long)m_normal); - clipoff(); - j = timers_sysclock() + blinkrate; - if (!pollkbd2()) - { - do - { - pass(); - pen(); - } while (!(pollkbd2() || gg.t.dn || timers_sysclock() > j)); - } - remcursor(); - clipon(); - m_colormode((long)m_xor); - m_color((long)gg.color.labeltext); - sprintf(STR1, "%.*s", i - 1, name); - m_move(x1 + m_strwidth(logfont_lfont, STR1) - 1, y1 + 8L); - if (i > strlen(name)) - { - m_drawrel(6L, 0L); - } - else - { - sprintf(STR1, "%.1s", name + i - 1); - m_drawrel(m_strwidth(logfont_lfont, STR1), 0L); - } - m_colormode((long)m_normal); - clipoff(); - j = timers_sysclock() + blinkrate; - if (!(pollkbd2() || gg.t.dn)) - { - do - { - pass(); - pen(); - } while (!(pollkbd2() || gg.t.dn || timers_sysclock() > j)); - } - } while (!(pollkbd2() || gg.t.dn)); - - if (!gg.t.dn) - { - ch = inkey2(); - if (ch >= 32 || ((1L << ch) & 0x10002108L) == 0) - { - remcursor(); - m_color((long)gg.color.backgr); - m_drawstr((long)x1, (long)y1, logfont_lfont, name); - redraw = true; - } - else - { - redraw = false; - } - - if (ch >= ' ' && ch != 250 && ch != 251 && strlen(name) < log_lablen) - { - if (i <= strlen(name)) - { - sprintf(STR1, " %s", name + i - 1); - strcpy(name + i - 1, STR1); - } - else - { - strcat(name, " "); - } - name[i - 1] = ch; - i++; - } - else if (ch == '\007' && i > 1) - { - i--; - strcpy_overlap(name + i - 1, name + i); - } - else if (ch == '\030' && i <= strlen(name)) - { - strcpy_overlap(name + i - 1, name + i); - } - else if (ch == '\b' && i > 1) - { - i--; - } - else if (ch == '\034' && i <= strlen(name)) - { - i++; - } - else if (ch == '\031') - { - i = 1; - } - else if (ch == '\032') - { - i = strlen(name) + 1; - } - else if (ch == '\n' && strlen(name) < log_lablen) - { - sprintf(STR1, " %s", name + i - 1); - strcpy(name + i - 1, STR1); - } - else if (ch == '\037' && i <= strlen(name) && strlen(name) > 1) - { - strcpy_overlap(name + i - 1, name + i); - } - if (redraw) - { - remcursor(); - m_color((long)gg.color.labeltext); - m_drawstr((long)x1, (long)y1, logfont_lfont, name); - } - } - } while (!((ch < 32 && ((1L << ch) & 0x2008) != 0) || gg.t.dn)); - - if (*name == '\0') - { - displabel(&l); - } - else if (strcmp(name, l->name)) - { - strcpy(l->name, name); - l->w = m_strwidth(logfont_lfont, l->name) / log_scale0; - stamp(&gg.labelstamp); - chpageplace(gg.pages[gg.curpage - 1], l->x, l->y, l->x + l->w, l->y + 2); - } - labelcaps = nk_setcapslock(savecaps); - gg.t.depressed = false; - refreshsoon(); -} - -#undef blinkrate - - /// Create a new dashed box. void addboxat(short x1, short y1, short x2, short y2) {