diff options
Diffstat (limited to 'ldmicro')
-rw-r--r-- | ldmicro/draw.cpp | 211 | ||||
-rw-r--r-- | ldmicro/draw_outputdev.cpp | 191 | ||||
-rw-r--r-- | ldmicro/includes/ldmicro.h | 16 | ||||
-rw-r--r-- | ldmicro/ldmicro.cpp | 242 | ||||
-rw-r--r-- | ldmicro/lib/freezeLD/freezeLD.cpp | 16 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxLD.h | 10 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp | 49 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.h | 24 | ||||
-rw-r--r-- | ldmicro/maincontrols.cpp | 143 | ||||
-rw-r--r-- | ldmicro/schematic.cpp | 456 |
10 files changed, 768 insertions, 590 deletions
diff --git a/ldmicro/draw.cpp b/ldmicro/draw.cpp index ad8259d..7c58154 100644 --- a/ldmicro/draw.cpp +++ b/ldmicro/draw.cpp @@ -250,54 +250,54 @@ int ProgCountWidestRow(void) // Draw a vertical wire one leaf element unit high up from (cx, cy), where cx // and cy are in charcter units. //----------------------------------------------------------------------------- -static void VerticalWire(int cx, int cy) +static void VerticalWire(HCRDC Hcr, int cx, int cy) { int j; for(j = 1; j < POS_HEIGHT; j++) { - DrawChars(cx, cy + (POS_HEIGHT/2 - j), "|"); + DrawChars(Hcr, cx, cy + (POS_HEIGHT/2 - j), "|"); } - DrawChars(cx, cy + (POS_HEIGHT/2), "+"); - DrawChars(cx, cy + (POS_HEIGHT/2 - POS_HEIGHT), "+"); + DrawChars(Hcr, cx, cy + (POS_HEIGHT/2), "+"); + DrawChars(Hcr, cx, cy + (POS_HEIGHT/2 - POS_HEIGHT), "+"); } //----------------------------------------------------------------------------- // Convenience functions for making the text colors pretty, for DrawElement. //----------------------------------------------------------------------------- -static void NormText(void) +static void NormText(HCRDC Hcr) { - SetTextColor(Hdc, InSimulationMode ? HighlightColours.simOff : + SetTextColor(Hcr, InSimulationMode ? HighlightColours.simOff : HighlightColours.def); - SelectObject(Hdc, FixedWidthFont); + SelectObject(Hcr, FixedWidthFont); } -static void EmphText(void) +static void EmphText(HCRDC Hcr) { - SetTextColor(Hdc, InSimulationMode ? HighlightColours.simOn : + SetTextColor(Hcr, InSimulationMode ? HighlightColours.simOn : HighlightColours.selected); - SelectObject(Hdc, FixedWidthFontBold); + SelectObject(Hcr, FixedWidthFontBold); } -static void NameText(void) +static void NameText(HCRDC Hcr) { if(!InSimulationMode && !ThisHighlighted) { - SetTextColor(Hdc, HighlightColours.name); + SetTextColor(Hcr, HighlightColours.name); } } -static void BodyText(void) +static void BodyText(HCRDC Hcr) { if(!InSimulationMode && !ThisHighlighted) { - SetTextColor(Hdc, HighlightColours.def); + SetTextColor(Hcr, HighlightColours.def); } } -static void PoweredText(BOOL powered) +static void PoweredText(HCRDC Hcr, BOOL powered) { if(InSimulationMode) { if(powered) - EmphText(); + EmphText(Hcr); else - NormText(); + NormText(Hcr); } } @@ -322,36 +322,36 @@ static int FormattedStrlen(const char *str) // Draw a string, centred in the space of a single position, with spaces on // the left and right. Draws on the upper line of the position. //----------------------------------------------------------------------------- -static void CenterWithSpaces(int cx, int cy, char *str, BOOL powered, +static void CenterWithSpaces(HCRDC Hcr, int cx, int cy, char *str, BOOL powered, BOOL isName) { int extra = POS_WIDTH - FormattedStrlen(str); - PoweredText(powered); - if(isName) NameText(); - DrawChars(cx + (extra/2), cy + (POS_HEIGHT/2) - 1, str); - if(isName) BodyText(); + PoweredText(Hcr, powered); + if(isName) NameText(Hcr); + DrawChars(Hcr, cx + (extra/2), cy + (POS_HEIGHT/2) - 1, str); + if(isName) BodyText(Hcr); } //----------------------------------------------------------------------------- // Like CenterWithWires, but for an arbitrary width position (e.g. for ADD // and SUB, which are double-width). //----------------------------------------------------------------------------- -static void CenterWithWiresWidth(int cx, int cy,const char *str, BOOL before, +static void CenterWithWiresWidth(HCRDC Hcr, int cx, int cy,const char *str, BOOL before, BOOL after, int totalWidth) { int extra = totalWidth - FormattedStrlen(str); - PoweredText(after); - DrawChars(cx + (extra/2), cy + (POS_HEIGHT/2), str); + PoweredText(Hcr, after); + DrawChars(Hcr, cx + (extra/2), cy + (POS_HEIGHT/2), str); - PoweredText(before); + PoweredText(Hcr, before); int i; for(i = 0; i < (extra/2); i++) { - DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); + DrawChars(Hcr, cx + i, cy + (POS_HEIGHT/2), "-"); } - PoweredText(after); + PoweredText(Hcr, after); for(i = FormattedStrlen(str)+(extra/2); i < totalWidth; i++) { - DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); + DrawChars(Hcr, cx + i, cy + (POS_HEIGHT/2), "-"); } } @@ -360,16 +360,16 @@ static void CenterWithWiresWidth(int cx, int cy,const char *str, BOOL before, // the left and right coloured according to the powered state. Draws on the // middle line. //----------------------------------------------------------------------------- -static void CenterWithWires(int cx, int cy, const char *str, BOOL before, BOOL after) +static void CenterWithWires(HCRDC Hcr, int cx, int cy, const char *str, BOOL before, BOOL after) { - CenterWithWiresWidth(cx, cy, str, before, after, POS_WIDTH); + CenterWithWiresWidth(Hcr, cx, cy, str, before, after, POS_WIDTH); } //----------------------------------------------------------------------------- // Draw an end of line element (coil, RES, MOV, etc.). Special things about // an end of line element: we must right-justify it. //----------------------------------------------------------------------------- -static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, +static BOOL DrawEndOfLine(HCRDC Hcr, int which, ElemLeaf *leaf, int *cx, int *cy, BOOL poweredBefore) { int cx0 = *cx, cy0 = *cy; @@ -390,8 +390,8 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, break; } - NormText(); - PoweredText(poweredBefore); + NormText(Hcr); + PoweredText(Hcr, poweredBefore); while(*cx < (ColsAvailable-thisWidth)*POS_WIDTH) { int gx = *cx/POS_WIDTH; int gy = *cy/POS_HEIGHT; @@ -405,14 +405,14 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, int i; for(i = 0; i < POS_WIDTH; i++) { - DrawChars(*cx + i, *cy + (POS_HEIGHT/2), "-"); + DrawChars(Hcr, *cx + i, *cy + (POS_HEIGHT/2), "-"); } *cx += POS_WIDTH; cx0 += POS_WIDTH; } if(leaf == Selected && !InSimulationMode) { - EmphText(); + EmphText(Hcr); ThisHighlighted = TRUE; } else { ThisHighlighted = FALSE; @@ -424,26 +424,26 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, ElemCounter *c = &leaf->d.counter; sprintf(buf, "{\x01""CTC\x02 0:%d}", c->max); - CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + CenterWithSpaces(Hcr, *cx, *cy, c->name, poweredAfter, TRUE); + CenterWithWires(Hcr, *cx, *cy, buf, poweredBefore, poweredAfter); break; } case ELEM_RES: { ElemReset *r = &leaf->d.reset; - CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, "{RES}", poweredBefore, poweredAfter); + CenterWithSpaces(Hcr, *cx, *cy, r->name, poweredAfter, TRUE); + CenterWithWires(Hcr, *cx, *cy, "{RES}", poweredBefore, poweredAfter); break; } case ELEM_READ_ADC: { ElemReadAdc *r = &leaf->d.readAdc; - CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, "{READ ADC}", poweredBefore, + CenterWithSpaces(Hcr, *cx, *cy, r->name, poweredAfter, TRUE); + CenterWithWires(Hcr, *cx, *cy, "{READ ADC}", poweredBefore, poweredAfter); break; } case ELEM_SET_PWM: { ElemSetPwm *s = &leaf->d.setPwm; - CenterWithSpaces(*cx, *cy, s->name, poweredAfter, TRUE); + CenterWithSpaces(Hcr, *cx, *cy, s->name, poweredAfter, TRUE); char l[50]; if(s->targetFreq >= 100000) { sprintf(l, "{PWM %d kHz}", (s->targetFreq+500)/1000); @@ -454,13 +454,13 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, } else { sprintf(l, "{PWM %d Hz}", s->targetFreq); } - CenterWithWires(*cx, *cy, l, poweredBefore, + CenterWithWires(Hcr, *cx, *cy, l, poweredBefore, poweredAfter); break; } case ELEM_PERSIST: - CenterWithSpaces(*cx, *cy, leaf->d.persist.var, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, "{PERSIST}", poweredBefore, poweredAfter); + CenterWithSpaces(Hcr, *cx, *cy, leaf->d.persist.var, poweredAfter, TRUE); + CenterWithWires(Hcr, *cx, *cy, "{PERSIST}", poweredBefore, poweredAfter); break; case ELEM_MOVE: { @@ -471,7 +471,7 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, if((strlen(m->dest) > (POS_WIDTH - 9)) || (strlen(m->src) > (POS_WIDTH - 9))) { - CenterWithWires(*cx, *cy, TOO_LONG, poweredBefore, + CenterWithWires(Hcr, *cx, *cy, TOO_LONG, poweredBefore, poweredAfter); break; } @@ -484,12 +484,12 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, strcpy(bot, "{ \x01MOV\x02}"); memcpy(bot+2, m->src, strlen(m->src)); - CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); - CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); + CenterWithSpaces(Hcr, *cx, *cy, top, poweredAfter, FALSE); + CenterWithWires(Hcr, *cx, *cy, bot, poweredBefore, poweredAfter); break; } case ELEM_MASTER_RELAY: - CenterWithWires(*cx, *cy, "{MASTER RLY}", poweredBefore, + CenterWithWires(Hcr, *cx, *cy, "{MASTER RLY}", poweredBefore, poweredAfter); break; @@ -502,9 +502,9 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, bot[strlen(bot)] = ' '; bot[13] = '}'; bot[14] = '\0'; - CenterWithSpaces(*cx, *cy, "{\x01SHIFT REG\x02 }", + CenterWithSpaces(Hcr, *cx, *cy, "{\x01SHIFT REG\x02 }", poweredAfter, FALSE); - CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); + CenterWithWires(Hcr, *cx, *cy, bot, poweredBefore, poweredAfter); break; } case ELEM_PIECEWISE_LINEAR: @@ -526,14 +526,14 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, top[strlen(top)] = ' '; top[13] = '}'; top[14] = '\0'; - CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); + CenterWithSpaces(Hcr, *cx, *cy, top, poweredAfter, FALSE); memset(bot, ' ', sizeof(bot)); bot[0] = '{'; sprintf(bot+2, " %s[%s]", str, index); bot[strlen(bot)] = ' '; bot[13] = '}'; bot[14] = '\0'; - CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); + CenterWithWires(Hcr, *cx, *cy, bot, poweredBefore, poweredAfter); break; } case ELEM_COIL: { @@ -553,8 +553,8 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, buf[2] = ')'; buf[3] = '\0'; - CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + CenterWithSpaces(Hcr, *cx, *cy, c->name, poweredAfter, TRUE); + CenterWithWires(Hcr, *cx, *cy, buf, poweredBefore, poweredAfter); break; } case ELEM_DIV: @@ -608,9 +608,9 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, bot[l] = '}'; bot[l+1] = '\0'; int extra = 2*POS_WIDTH - FormattedStrlen(top); - PoweredText(poweredAfter); - DrawChars(*cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, top); - CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, + PoweredText(Hcr, poweredAfter); + DrawChars(Hcr, *cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, top); + CenterWithWiresWidth(Hcr, *cx, *cy, bot, poweredBefore, poweredAfter, 2*POS_WIDTH); *cx += POS_WIDTH; @@ -631,7 +631,7 @@ static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, // Draw a leaf element. Special things about a leaf: no need to recurse // further, and we must put it into the display matrix. //----------------------------------------------------------------------------- -static BOOL DrawLeaf(int which, ElemLeaf *leaf, int *cx, int *cy, +static BOOL DrawLeaf(HCRDC Hcr, int which, ElemLeaf *leaf, int *cx, int *cy, BOOL poweredBefore) { int cx0 = *cx, cy0 = *cy; @@ -649,20 +649,20 @@ static BOOL DrawLeaf(int which, ElemLeaf *leaf, int *cx, int *cy, if(b[-1] == '\r') b[-1] = '\0'; *b = '\0'; sprintf(tlbuf, "\x03 ; %s\x02", tbuf); - DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); + DrawChars(Hcr, *cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); sprintf(tlbuf, "\x03 ; %s\x02", b+1); - DrawChars(*cx, *cy + (POS_HEIGHT/2), tlbuf); + DrawChars(Hcr, *cx, *cy + (POS_HEIGHT/2), tlbuf); } else { sprintf(tlbuf, "\x03 ; %s\x02", tbuf); - DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); + DrawChars(Hcr, *cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); } *cx += ColsAvailable*POS_WIDTH; break; } case ELEM_PLACEHOLDER: { - NormText(); - CenterWithWiresWidth(*cx, *cy, "--", FALSE, FALSE, 2); + NormText(Hcr); + CenterWithWiresWidth(Hcr, *cx, *cy, "--", FALSE, FALSE, 2); *cx += POS_WIDTH; break; } @@ -675,8 +675,8 @@ static BOOL DrawLeaf(int which, ElemLeaf *leaf, int *cx, int *cy, buf[2] = '['; buf[3] = '\0'; - CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + CenterWithSpaces(Hcr, *cx, *cy, c->name, poweredAfter, TRUE); + CenterWithWires(Hcr, *cx, *cy, buf, poweredBefore, poweredAfter); *cx += POS_WIDTH; break; @@ -717,19 +717,19 @@ cmp: strcpy(s2, TOO_LONG); } - CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); - CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); + CenterWithSpaces(Hcr, *cx, *cy, s1, poweredAfter, FALSE); + CenterWithWires(Hcr, *cx, *cy, s2, poweredBefore, poweredAfter); *cx += POS_WIDTH; break; } case ELEM_OPEN: - CenterWithWires(*cx, *cy, "+ +", poweredBefore, poweredAfter); + CenterWithWires(Hcr, *cx, *cy, "+ +", poweredBefore, poweredAfter); *cx += POS_WIDTH; break; case ELEM_SHORT: - CenterWithWires(*cx, *cy, "+------+", poweredBefore, poweredAfter); + CenterWithWires(Hcr, *cx, *cy, "+------+", poweredBefore, poweredAfter); *cx += POS_WIDTH; break; @@ -744,8 +744,8 @@ cmp: s2 = "[\x01OSF\x02 \\_]"; } else oops(); - CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); - CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); + CenterWithSpaces(Hcr, *cx, *cy, s1, poweredAfter, FALSE); + CenterWithWires(Hcr, *cx, *cy, s2, poweredBefore, poweredAfter); *cx += POS_WIDTH; break; @@ -763,8 +763,8 @@ cmp: ElemCounter *c = &leaf->d.counter; sprintf(buf, "[%s >=%d]", s, c->max); - CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + CenterWithSpaces(Hcr, *cx, *cy, c->name, poweredAfter, TRUE); + CenterWithWires(Hcr, *cx, *cy, buf, poweredBefore, poweredAfter); *cx += POS_WIDTH; break; @@ -791,8 +791,8 @@ cmp: sprintf(buf, "[%s %.2f ms]", s, t->delay/1000.0); } - CenterWithSpaces(*cx, *cy, t->name, poweredAfter, TRUE); - CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + CenterWithSpaces(Hcr, *cx, *cy, t->name, poweredAfter, TRUE); + CenterWithWires(Hcr, *cx, *cy, buf, poweredBefore, poweredAfter); *cx += POS_WIDTH; break; @@ -808,28 +808,28 @@ cmp: sprintf(bot, "{\"%s\"}", str); int extra = 2*POS_WIDTH - strlen(leaf->d.fmtdStr.var); - PoweredText(poweredAfter); - NameText(); - DrawChars(*cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, + PoweredText(Hcr, poweredAfter); + NameText(Hcr); + DrawChars(Hcr, *cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, leaf->d.fmtdStr.var); - BodyText(); + BodyText(Hcr); - CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, + CenterWithWiresWidth(Hcr, *cx, *cy, bot, poweredBefore, poweredAfter, 2*POS_WIDTH); *cx += 2*POS_WIDTH; break; } case ELEM_UART_RECV: case ELEM_UART_SEND: - CenterWithWires(*cx, *cy, + CenterWithWires(Hcr, *cx, *cy, (which == ELEM_UART_RECV) ? "{UART RECV}" : "{UART SEND}", poweredBefore, poweredAfter); - CenterWithSpaces(*cx, *cy, leaf->d.uart.name, poweredAfter, TRUE); + CenterWithSpaces(Hcr, *cx, *cy, leaf->d.uart.name, poweredAfter, TRUE); *cx += POS_WIDTH; break; default: - poweredAfter = DrawEndOfLine(which, leaf, cx, cy, poweredBefore); + poweredAfter = DrawEndOfLine(Hcr, which, leaf, cx, cy, poweredBefore); break; } @@ -926,19 +926,18 @@ cmp: // element, else FALSE. This is needed to colour all the wires correctly, // since the colouring indicates whether a wire is energized. //----------------------------------------------------------------------------- -BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) +BOOL DrawElement(HCRDC Hcr, int which, void *elem, int *cx, int *cy, BOOL poweredBefore) { BOOL poweredAfter; int cx0 = *cx, cy0 = *cy; ElemLeaf *leaf = (ElemLeaf *)elem; - - SetBkColor(DrawWindow,Hdc, InSimulationMode ? HighlightColours.simBg : + SetBkColor(DrawWindow,Hcr, InSimulationMode ? HighlightColours.simBg : HighlightColours.bg); - NormText(); + NormText(Hcr); if(elem == Selected && !InSimulationMode) { - EmphText(); + EmphText(Hcr); ThisHighlighted = TRUE; } else { ThisHighlighted = FALSE; @@ -950,7 +949,7 @@ BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) ElemSubcktSeries *s = (ElemSubcktSeries *)elem; poweredAfter = poweredBefore; for(i = 0; i < s->count; i++) { - poweredAfter = DrawElement(s->contents[i].which, + poweredAfter = DrawElement(Hcr, s->contents[i].which, s->contents[i].d.any, cx, cy, poweredAfter); } break; @@ -968,12 +967,12 @@ BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) for(i = 0; i < p->count; i++) { BOOL poweredThis; - poweredThis = DrawElement(p->contents[i].which, + poweredThis = DrawElement(Hcr, p->contents[i].which, p->contents[i].d.any, cx, cy, poweredBefore); if(InSimulationMode) { if(poweredThis) poweredAfter = TRUE; - PoweredText(poweredThis); + PoweredText(Hcr, poweredThis); } while((*cx - cx0) < widthMax*POS_WIDTH) { @@ -992,7 +991,7 @@ BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) buf[j] = '-'; } buf[j] = '\0'; - DrawChars(*cx, *cy + (POS_HEIGHT/2), buf); + DrawChars(Hcr, *cx, *cy + (POS_HEIGHT/2), buf); *cx += POS_WIDTH; } @@ -1015,37 +1014,37 @@ BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) if(*cx/POS_WIDTH != ColsAvailable) { needWire = FALSE; for(j = heightMax - 1; j >= 1; j--) { - if(j <= lowestPowered) PoweredText(poweredAfter); + if(j <= lowestPowered) PoweredText(Hcr, poweredAfter); if(DisplayMatrix[*cx/POS_WIDTH - 1][*cy/POS_HEIGHT + j]) { needWire = TRUE; } - if(needWire) VerticalWire(*cx - 1, *cy + j*POS_HEIGHT); + if(needWire) VerticalWire(Hcr, *cx - 1, *cy + j*POS_HEIGHT); } // stupid special case if(lowestPowered == 0 && InSimulationMode) { - EmphText(); - DrawChars(*cx - 1, *cy + (POS_HEIGHT/2), "+"); + EmphText(Hcr); + DrawChars(Hcr, *cx - 1, *cy + (POS_HEIGHT/2), "+"); } } - PoweredText(poweredBefore); + PoweredText(Hcr, poweredBefore); needWire = FALSE; for(j = heightMax - 1; j >= 1; j--) { if(DisplayMatrix[cx0/POS_WIDTH][*cy/POS_HEIGHT + j]) { needWire = TRUE; } - if(needWire) VerticalWire(cx0 - 1, *cy + j*POS_HEIGHT); + if(needWire) VerticalWire(Hcr, cx0 - 1, *cy + j*POS_HEIGHT); } break; } default: - poweredAfter = DrawLeaf(which, leaf, cx, cy, poweredBefore); + poweredAfter = DrawLeaf(Hcr, which, leaf, cx, cy, poweredBefore); break; } - NormText(); + NormText(Hcr); return poweredAfter; } @@ -1053,18 +1052,18 @@ BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) // Draw the rung that signals the end of the program. Kind of useless but // do it anyways, for convention. //----------------------------------------------------------------------------- -void DrawEndRung(int cx, int cy) +void DrawEndRung(HCRDC Hcr, int cx, int cy) { int i; char *str = "[END]"; int lead = (POS_WIDTH - strlen(str))/2; ThisHighlighted = TRUE; for(i = 0; i < lead; i++) { - DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); + DrawChars(Hcr, cx + i, cy + (POS_HEIGHT/2), "-"); } - DrawChars(cx + i, cy + (POS_HEIGHT/2), str); + DrawChars(Hcr, cx + i, cy + (POS_HEIGHT/2), str); i += strlen(str); for(; i < ColsAvailable*POS_WIDTH; i++) { - DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); + DrawChars(Hcr, cx + i, cy + (POS_HEIGHT/2), "-"); } } diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp index 5721d34..69f08ca 100644 --- a/ldmicro/draw_outputdev.cpp +++ b/ldmicro/draw_outputdev.cpp @@ -31,7 +31,7 @@ #include "ldmicro.h" -void (*DrawChars)(int, int, const char *); +void (*DrawChars)(HCRDC Hcr, int, int, const char *); // After an undo all the memory addresses change but make an effort to put // the cursor roughly where it should be. @@ -81,22 +81,63 @@ SyntaxHighlightingColours HighlightColours; // bottom, left, right) but we don't care; just go from the coordinates // computed when we drew the schematic in the paint procedure. //----------------------------------------------------------------------------- -void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time) +gboolean BlinkCursor(GtkWidget * window) //(HWND hwnd, UINT msg, UINT_PTR id, DWORD time) { - // if(!isFocus(MainWindow) && !CursorDrawn) return; - // if(Cursor.left == 0) return; + // if(GetFocus(MainWindow) != !CursorDrawn) return TRUE; + if(Cursor.left == 0) return TRUE; - // PlcCursor c; - // SettingsInstance = gtk_settings_get_default(); - // gtk_settings_install_property_parser (gtk-cursor-blink ,black); + PlcCursor c; + memcpy(&c, &Cursor, sizeof(c)); + c.top -= ScrollYOffset*POS_HEIGHT*FONT_HEIGHT; + c.left -= ScrollXOffset; + + if(c.top >= IoListTop) return TRUE; + + if(c.top + c.height >= IoListTop) { + c.height = IoListTop - c.top - 3; + } + + // if(!GDK_IS_DRAWING_CONTEXT(Hdc)) + // return FALSE; + + HCRDC Hcr = gdk_cairo_create(gtk_widget_get_window(DrawWindow));//gdk_drawing_context_get_cairo_context(Hdc);// + + static int PREV_x = c.left; + static int PREV_y = c.top; + static int PREV_w = c.width; + static int PREV_h = c.height; + + if (PREV_x != c.left || PREV_y != c.top || PREV_w != c.width || PREV_h != c.height) + { + PatBlt(Hcr, PREV_x, PREV_y, PREV_w, PREV_h, PATINVERT, (HBRUSH)GetStockObject(BLACK_BRUSH)); + PREV_x = c.left; + PREV_y = c.top; + PREV_w = c.width; + PREV_h = c.height; + + // MainWindowResized(); + // PaintWindow(Hcr); + gtk_widget_queue_draw(DrawWindow); + } + + if (CursorDrawn) + PatBlt(Hcr, c.left, c.top, c.width, c.height, PATINVERT, (HBRUSH)GetStockObject(WHITE_BRUSH)); + else + PatBlt(Hcr, c.left, c.top, c.width, c.height, PATINVERT, (HBRUSH)GetStockObject(BLACK_BRUSH)); + InvalidateRect(DrawWindow, NULL, FALSE); + // g_print("BLINK\n"); + cairo_destroy(Hcr); + CursorDrawn = !CursorDrawn; + + return TRUE; } //----------------------------------------------------------------------------- // Output a string to the screen at a particular location, in character- // sized units. //----------------------------------------------------------------------------- -static void DrawCharsToScreen(int cx, int cy, const char *str) +static void DrawCharsToScreen(HCRDC Hcr, int cx, int cy, const char *str) { cy -= ScrollYOffset*POS_HEIGHT; if(cy < -2) return; @@ -116,12 +157,12 @@ static void DrawCharsToScreen(int cx, int cy, const char *str) if(strchr("{}[]", *str) && hiOk && !inComment) { if(*str == '{' || *str == '[') inBrace++; if(inBrace == 1) { - prev = GetTextColor(Hdc); - SetTextColor(Hdc, HighlightColours.punct); - TextOut(DrawWindow, Hdc, x, y, str, 1); - SetTextColor(Hdc, prev); + prev = GetTextColor(Hcr); + SetTextColor(Hcr, HighlightColours.punct); + TextOut(DrawWindow, Hcr, x, y, str, 1); + SetTextColor(Hcr, prev); } else { - TextOut(DrawWindow, Hdc, x, y, str, 1); + TextOut(DrawWindow, Hcr, x, y, str, 1); } if(*str == ']' || *str == '}') inBrace--; } else if(( @@ -129,42 +170,42 @@ static void DrawCharsToScreen(int cx, int cy, const char *str) || str[-1] == ':' || str[-1] == '[')) || (*str == '-' && isdigit(str[1]))) && hiOk && !inComment) { - prev = GetTextColor(Hdc); - SetTextColor(Hdc, HighlightColours.lit); - TextOut(DrawWindow, Hdc, x, y, str, 1); - SetTextColor(Hdc, prev); + prev = GetTextColor(Hcr); + SetTextColor(Hcr, HighlightColours.lit); + TextOut(DrawWindow, Hcr, x, y, str, 1); + SetTextColor(Hcr, prev); inNumber = TRUE; } else if(*str == '\x01') { cx--; if(hiOk) { - prev = GetTextColor(Hdc); - SetTextColor(Hdc, HighlightColours.op); + prev = GetTextColor(Hcr); + SetTextColor(Hcr, HighlightColours.op); } } else if(*str == '\x02') { cx--; if(hiOk) { - SetTextColor(Hdc, prev); + SetTextColor(Hcr, prev); inComment = FALSE; } } else if(*str == '\x03') { cx--; if(hiOk) { - prev = GetTextColor(Hdc); - SetTextColor(Hdc, HighlightColours.comment); + prev = GetTextColor(Hcr); + SetTextColor(Hcr, HighlightColours.comment); inComment = TRUE; } } else if(inNumber) { if(isdigit(*str) || *str == '.') { - prev = GetTextColor(Hdc); - SetTextColor(Hdc, HighlightColours.lit); - TextOut(DrawWindow, Hdc, x, y, str, 1); - SetTextColor(Hdc, prev); + prev = GetTextColor(Hcr); + SetTextColor(Hcr, HighlightColours.lit); + TextOut(DrawWindow, Hcr, x, y, str, 1); + SetTextColor(Hcr, prev); } else { - TextOut(DrawWindow, Hdc, x, y, str, 1); + TextOut(DrawWindow, Hcr, x, y, str, 1); inNumber = FALSE; } } else { - TextOut(DrawWindow, Hdc, x, y, str, 1); + TextOut(DrawWindow, Hcr, x, y, str, 1); } firstTime = FALSE; @@ -205,7 +246,7 @@ int ScreenRowsAvailable(void) // cursor should go and fill in coordinates for BlinkCursor. Not allowed to // draw deeper than IoListTop, as we would run in to the I/O listbox. //----------------------------------------------------------------------------- -void PaintWindow() +void PaintWindow(HCRDC Hcr) { ok(); @@ -237,11 +278,11 @@ void PaintWindow() if(((cy + thisHeight) >= (ScrollYOffset - 8)*POS_HEIGHT) && (cy < (ScrollYOffset + rowsAvailable + 8)*POS_HEIGHT)) { - SetBkColor(DrawWindow, Hdc, InSimulationMode ? HighlightColours.simBg : + SetBkColor(DrawWindow, Hcr, InSimulationMode ? HighlightColours.simBg : HighlightColours.bg); - SetTextColor(Hdc, InSimulationMode ? HighlightColours.simRungNum : + SetTextColor(Hcr, InSimulationMode ? HighlightColours.simRungNum : HighlightColours.rungNum); - SelectObject(Hdc, FixedWidthFont); + SelectObject(Hcr, FixedWidthFont); int rung = i + 1; int y = Y_PADDING + FONT_HEIGHT*cy; int yp = y + FONT_HEIGHT*(POS_HEIGHT/2) - @@ -249,14 +290,14 @@ void PaintWindow() if(rung < 10) { char r[1] = { rung + '0' }; - TextOut(DrawWindow, Hdc, 8 + FONT_WIDTH, yp, r, 1); + TextOut(DrawWindow, Hcr, 8 + FONT_WIDTH, yp, r, 1); } else { char r[2] = { (rung / 10) + '0', (rung % 10) + '0' }; - TextOut(DrawWindow, Hdc, 8, yp, r, 2); + TextOut(DrawWindow, Hcr, 8, yp, r, 2); } int cx = 0; - DrawElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy, + DrawElement(Hcr, ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy, Prog.rungPowered[i]); } @@ -264,7 +305,7 @@ void PaintWindow() cy += POS_HEIGHT; } cy -= 2; - DrawEndRung(0, cy); + DrawEndRung(Hcr, 0, cy); if(SelectedGxAfterNextPaint >= 0) { MoveCursorNear(SelectedGxAfterNextPaint, SelectedGyAfterNextPaint); @@ -291,10 +332,11 @@ void PaintWindow() r.top = 0; r.right = r.left + 4; r.bottom = IoListTop; - FillRect(Hdc, &r, InSimulationMode ? BusLeftBrush : BusBrush); + FillRect(Hcr, &r, InSimulationMode ? BusLeftBrush : BusBrush); r.left += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; r.right += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; - FillRect(Hdc, &r, InSimulationMode ? BusRightBus : BusBrush); + FillRect(Hcr, &r, InSimulationMode ? BusRightBus : BusBrush); + InvalidateRect(DrawWindow, NULL, FALSE); CursorDrawn = FALSE; @@ -308,7 +350,6 @@ void PaintWindow() // SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor); // } - // Hdc = paintDc; ok(); } @@ -513,46 +554,46 @@ void ExportDrawingAsText(char *file) //----------------------------------------------------------------------------- void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert) { - // int totalHeight = 0; - // int i; - // for(i = 0; i < Prog.numRungs; i++) { - // totalHeight += CountHeightOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i]); - // totalHeight++; - // } - // totalHeight += 1; // for the end rung + int totalHeight = 0; + int i; + for(i = 0; i < Prog.numRungs; i++) { + totalHeight += CountHeightOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i]); + totalHeight++; + } + totalHeight += 1; // for the end rung - // int totalWidth = ProgCountWidestRow(); + int totalWidth = ProgCountWidestRow(); - // if(totalWidth <= ScreenColsAvailable()) { - // *horizShown = FALSE; - // ScrollXOffset = 0; - // ScrollXOffsetMax = 0; - // } else { - // *horizShown = TRUE; - // memset(horiz, 0, sizeof(*horiz)); - // horiz->cbSize = sizeof(*horiz); - // horiz->fMask = SIF_DISABLENOSCROLL | SIF_ALL; - // horiz->nMin = 0; - // horiz->nMax = X_PADDING + totalWidth*POS_WIDTH*FONT_WIDTH; - // RECT r; - // GetClientRect(MainWindow, &r); - // horiz->nPage = r.right - X_PADDING; - // horiz->nPos = ScrollXOffset; - - // ScrollXOffsetMax = horiz->nMax - horiz->nPage + 1; - // if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax; - // if(ScrollXOffset < 0) ScrollXOffset = 0; - // } + if(totalWidth <= ScreenColsAvailable()) { + *horizShown = FALSE; + ScrollXOffset = 0; + ScrollXOffsetMax = 0; + } else { + *horizShown = TRUE; + memset(horiz, 0, sizeof(*horiz)); + horiz->cbSize = sizeof(*horiz); + // horiz->fMask = SIF_DISABLENOSCROLL | SIF_ALL; + horiz->nMin = 0; + horiz->nMax = X_PADDING + totalWidth*POS_WIDTH*FONT_WIDTH; + RECT r; + GetClientRect(DrawWindow, &r); + horiz->nPage = r.right - X_PADDING; + horiz->nPos = ScrollXOffset; + + ScrollXOffsetMax = horiz->nMax - horiz->nPage + 1; + if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax; + if(ScrollXOffset < 0) ScrollXOffset = 0; + } - // vert->cbSize = sizeof(*vert); + vert->cbSize = sizeof(*vert); // vert->fMask = SIF_DISABLENOSCROLL | SIF_ALL; - // vert->nMin = 0; - // vert->nMax = totalHeight - 1; - // vert->nPos = ScrollYOffset; - // vert->nPage = ScreenRowsAvailable(); + vert->nMin = 0; + vert->nMax = totalHeight - 1; + vert->nPos = ScrollYOffset; + vert->nPage = ScreenRowsAvailable(); - // ScrollYOffsetMax = vert->nMax - vert->nPage + 1; + ScrollYOffsetMax = vert->nMax - vert->nPage + 1; - // if(ScrollYOffset > ScrollYOffsetMax) ScrollYOffset = ScrollYOffsetMax; - // if(ScrollYOffset < 0) ScrollYOffset = 0; + if(ScrollYOffset > ScrollYOffsetMax) ScrollYOffset = ScrollYOffsetMax; + if(ScrollYOffset < 0) ScrollYOffset = 0; } diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h index 719a256..a1a1c75 100644 --- a/ldmicro/includes/ldmicro.h +++ b/ldmicro/includes/ldmicro.h @@ -589,7 +589,7 @@ void RefreshScrollbars(void); extern HINSTANCE Instance; extern HWID MainWindow; extern HWID DrawWindow; -extern HCRDC Hdc; +// extern HCRDC Hcr; extern PlcProgram Prog; extern char CurrentSaveFile[MAX_PATH]; extern char CurrentCompileFile[MAX_PATH]; @@ -604,8 +604,8 @@ void CheckHeap(char *file, int line); // maincontrols.cpp void MakeMainWindowControls(void); HMENU MakeMainWindowMenus(void); -void VscrollProc(WPARAM wParam); -void HscrollProc(WPARAM wParam); +void VscrollProc(int wParam); +void HscrollProc(int wParam); void GenerateIoListDontLoseSelection(void); void RefreshControlsToSettings(void); void MainWindowResized(void); @@ -624,16 +624,16 @@ extern HMENU ScrollWindow; // draw.cpp int ProgCountWidestRow(void); int CountHeightOfElement(int which, void *elem); -BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore); -void DrawEndRung(int cx, int cy); +BOOL DrawElement(HCRDC Hcr, int which, void *elem, int *cx, int *cy, BOOL poweredBefore); +void DrawEndRung(HCRDC Hcr, int cx, int cy); extern int ColsAvailable; extern BOOL SelectionActive; extern BOOL ThisHighlighted; // draw_outputdev.cpp -extern void (*DrawChars)(int, int, const char *); -void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time); -void PaintWindow(); +extern void (*DrawChars)(HCRDC Hcr, int, int, const char *); +gboolean BlinkCursor(GtkWidget * window); +void PaintWindow(HCRDC Hcr); void ExportDrawingAsText(char *file); void InitForDrawing(void); void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert); diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index 0deea5a..aac5ba7 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -40,7 +40,7 @@ using namespace std; HINSTANCE Instance; HWID MainWindow; HWID DrawWindow; -HCRDC Hdc; +// HCRDC Hcr; // parameters used to capture the mouse when implementing our totally non- // general splitter control @@ -662,6 +662,8 @@ void LD_WM_Close_call(GtkWidget *widget, GdkEvent *event, gpointer user_data)//( * WM_CLOSE */ + // if(Hdc != NULL) + // cairo_destroy(Hdc); FreezeWindowPos(MainWindow); FreezeDWORD(IoListHeight); @@ -673,7 +675,7 @@ gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEvent *event, gpointer user_da /* Handles: * WM_KEYDOWN */ - + // g_print("ky call\n"); switch(event->key.state) { case GDK_SHIFT_MASK: @@ -968,6 +970,7 @@ gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEvent *event, gpointer user_da // InvalidateRect(MainWindow, NULL, FALSE); // } // break; + // g_print("ky call end\n"); return FALSE; } @@ -976,37 +979,57 @@ gboolean LD_GTK_mouse_click_hook(GtkWidget *widget, GdkEvent *event, gpointer us /* Handles: * WM_LBUTTONDBLCLK, WM_LBUTTONDOWN */ + // g_print("mo cl call\n"); + + GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ScrollWindow)); + // g_print("---\nadj = %f\n", gtk_adjustment_get_value(adjustment)); + // g_print("upper = %f\n", gtk_adjustment_get_upper(adjustment) - gtk_widget_get_allocated_height (ScrollWindow)); + // g_print("lower = %f\n", gtk_adjustment_get_lower(adjustment)); + // g_print("inc = %f\n", gtk_adjustment_get_step_increment(adjustment)); + // g_print("w width = %i\n", gtk_widget_get_allocated_width (DrawWindow)); + // g_print("w height = %i\n---\n", gtk_widget_get_allocated_height (ScrollWindow)); switch(event->button.type) { - case GDK_BUTTON_PRESS:// To Do: run only for left click - // int x = LOWORD(lParam); - // int y = HIWORD(lParam); - // if((y > (IoListTop - 9)) && (y < (IoListTop + 3))) { - // POINT pt; - // pt.x = x; pt.y = y; - // ClientToScreen(MainWindow, &pt); - // MouseY = pt.y; - // MouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL, - // (HOOKPROC)MouseHook, Instance, 0); - // } - // if(!InSimulationMode) MoveCursorMouseClick(x, y); - - // SetFocus(MainWindow); - // InvalidateRect(MainWindow, NULL, FALSE); + case GDK_BUTTON_PRESS: + if (event->button.button == 1) /// left click + { + int x = event->button.x; + int y = event->button.y - 30 + gtk_adjustment_get_value(adjustment); + + // if((y > (IoListTop - 9)) && (y < (IoListTop + 3))) { + // // POINT pt; + // // pt.x = x; pt.y = y; + // // ClientToScreen(MainWindow, &pt); + // MouseY = y; //pt.y; + // // MouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL, + // // (HOOKPROC)MouseHook, Instance, 0); + // } + if(!InSimulationMode) MoveCursorMouseClick(x, y); + + // SetFocus(MainWindow); + // InvalidateRect(DrawWindow, NULL, FALSE); + gtk_widget_queue_draw(DrawWindow); + } break; case GDK_2BUTTON_PRESS: - // int x = LOWORD(lParam); - // int y = HIWORD(lParam); - // if(InSimulationMode) { - // EditElementMouseDoubleclick(x, y); - // } else { - // CHANGING_PROGRAM(EditElementMouseDoubleclick(x, y)); - // } - // InvalidateRect(MainWindow, NULL, FALSE); + if (event->button.button == 1) /// left click + { + int x = event->button.x; + int y = event->button.y - 30 + gtk_adjustment_get_value(adjustment); + + if(InSimulationMode) { + EditElementMouseDoubleclick(x, y); + } else { + CHANGING_PROGRAM(EditElementMouseDoubleclick(x, y)); + } + // InvalidateRect(DrawWindow, NULL, FALSE); + gtk_widget_queue_draw(DrawWindow); + } break; } + // g_print("mo cl call end\n"); return FALSE; } @@ -1015,27 +1038,49 @@ gboolean LD_GTK_mouse_scroll_hook(GtkWidget *widget, GdkEvent *event, gpointer u /* Handles: * WM_VSCROLL, WM_HSCROLL, WM_MOUSEWHEEL */ - + // g_print("mo sc call\n"); + GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ScrollWindow)); + // g_print("adj = %f\n", gtk_adjustment_get_value(adjustment)); + // g_print("upper = %f\n", gtk_adjustment_get_upper(adjustment) - gtk_widget_get_allocated_height (ScrollWindow)); + // g_print("lower = %f\n", gtk_adjustment_get_lower(adjustment)); + // g_print("inc = %f\n", gtk_adjustment_get_step_increment(adjustment)); + // g_print("w width = %i\n", gtk_widget_get_allocated_width (DrawWindow)); + // g_print("w height = %i\n", gtk_widget_get_allocated_height (ScrollWindow)); + switch(event->scroll.direction) { case GDK_SCROLL_UP: + if (gtk_adjustment_get_value(adjustment) == gtk_adjustment_get_lower(adjustment)) + VscrollProc(SB_TOP); + else + VscrollProc(SB_LINEUP); + break; case GDK_SCROLL_DOWN: - // VscrollProc(wParam); + if (gtk_adjustment_get_value(adjustment) == gtk_adjustment_get_upper(adjustment) - gtk_widget_get_allocated_height (ScrollWindow)) + VscrollProc(SB_BOTTOM); + else + VscrollProc(SB_LINEDOWN); break; case GDK_SCROLL_LEFT: + HscrollProc(SB_LINEUP); + break; case GDK_SCROLL_RIGHT: - // HscrollProc(wParam); + HscrollProc(SB_LINEDOWN); break; case GDK_SCROLL_SMOOTH: - // if((GET_WHEEL_DELTA_WPARAM(wParam)) > 0) { - // VscrollProc(SB_LINEUP); - // } else { - // VscrollProc(SB_LINEDOWN); - // } - // gdk_event_get_scroll_deltas (const GdkEvent *event, gdouble *delta_x, gdouble *delta_y); + double d_x, d_y; + gdk_event_get_scroll_deltas (event, &d_x, &d_y); + if(d_y > 0) { + VscrollProc(SB_LINEUP); + } else { + VscrollProc(SB_LINEDOWN); + } break; } + + gtk_widget_queue_draw(DrawWindow); + // g_print("mo sc call end\n"); return FALSE; } @@ -1044,7 +1089,7 @@ gboolean LD_WM_MouseMove_call(GtkWidget *widget, GdkEvent *event, gpointer user_ /* Handles: * WM_MOUSEMOVE */ - + // g_print("mo mv call\n"); // g_print("x = %f\n", event->button.x_root); // g_print("y = %f\n", event->button.y_root); @@ -1061,47 +1106,77 @@ gboolean LD_WM_MouseMove_call(GtkWidget *widget, GdkEvent *event, gpointer user_ return FALSE; } -gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data) +gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data)//(HWID widget, GdkEventExpose *event)// { /* Handles: * WM_PAINT */ - // guint width, height; - // GdkRGBA color; - // GtkStyleContext *context; + // g_print("draw called----------------------------------\n"); + static BOOL Paint_call_first = TRUE; + + if (Paint_call_first) + { + gtk_widget_override_background_color(GTK_WIDGET(widget), + GTK_STATE_FLAG_NORMAL, (HBRUSH)GetStockObject(BLACK_BRUSH)); + gint width = gtk_widget_get_allocated_width (widget); + gint height = gtk_widget_get_allocated_height (widget); + + COLORREF col; + GtkStyleContext *context; + context = gtk_widget_get_style_context (widget); + gtk_style_context_get_color (context, + gtk_style_context_get_state (context), + &col); + gdk_cairo_set_source_rgba (cr, &col); + gtk_render_background (context, cr, 0, 0, width, height); + Paint_call_first = FALSE; + } - // context = gtk_widget_get_style_context (widget); + /// This draws the schematic. + MainWindowResized(); + PaintWindow(cr); - // width = gtk_widget_get_allocated_width (widget); - // height = gtk_widget_get_allocated_height (widget); - // // g_print("w = %i\n", width); - // // g_print("h = %i\n", height); + /* Cairo test code + guint width, height; + GdkRGBA color; + GtkStyleContext *context; - // // SetBkColor(widget, cr, HighlightColours.bg); + context = gtk_widget_get_style_context (widget); - // gtk_render_background (context, cr, 0, 0, width, height); - - // // cairo_arc (cr, - // // width / 2.0, height / 2.0, - // // MIN (width, height) / 3.0, - // // 0, 2 * G_PI); - - // cairo_rectangle(cr, 0, 0, width, height); - // cairo_stroke_preserve(cr); - - // gtk_style_context_get_color (context, - // gtk_style_context_get_state (context), - // &color); - // gdk_cairo_set_source_rgba (cr, &color); - - // cairo_fill (cr); - - Hdc = cr; - - /// This draws the schematic. - PaintWindow(); + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_height (widget); + g_print("w = %i\n", width); + g_print("h = %i\n", height); + SetBkColor(widget, cr, HighlightColours.bg); + + gtk_render_background (context, cr, 0, 0, width, height); + + // cairo_arc (cr, + // width / 2.0, height / 2.0, + // MIN (width, height) / 3.0, + // 0, 2 * G_PI); + + cairo_rectangle(cr, 0, 0, width, height); + cairo_stroke_preserve(cr); + + gtk_style_context_get_color (context, + gtk_style_context_get_state (context), + &color); + gdk_cairo_set_source_rgba (cr, &color); + + cairo_fill (cr); + + SetBkColor(DrawWindow, cr, InSimulationMode ? HighlightColours.simBg : + HighlightColours.bg); + SetTextColor(cr, InSimulationMode ? HighlightColours.simRungNum : + HighlightColours.rungNum); + SelectObject(cr, FixedWidthFont); + for (int xp = 0; xp<= width; xp += 7) + for (int yp = 0; yp <= height; yp += 7) + TextOut(DrawWindow, cr, xp, yp, "H", 1); + */ return FALSE; } @@ -1110,7 +1185,7 @@ gboolean LD_WM_Destroy_call(GtkWidget *widget, GdkEvent *event, gpointer user_da /* Handles: * WM_DESTROY */ - + // g_print("dis call\n"); // if(CheckSaveUserCancels()) break; // PostQuitMessage(0); @@ -1124,9 +1199,9 @@ gboolean LD_WM_Size_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) /* Handles: * WM_SIZE */ - + // g_print("size call\n"); MainWindowResized(); - + // g_print("size call end\n"); return FALSE; } @@ -1135,9 +1210,9 @@ gboolean LD_WM_SetFocus_call(GtkWidget *widget, GdkEvent *event, gpointer user_d /* Handles: * WM_SETFOCUS */ - + // g_print("focus call\n"); InvalidateRect(DrawWindow, NULL, FALSE); - + // g_print("focus call end\n"); return FALSE; } @@ -1207,6 +1282,12 @@ int main(int argc, char** argv) exit(0); } + //we need to initialize all these functions so that gtk knows + //to be thread-aware + if (!g_thread_supported ()){ g_thread_init(NULL); } + gdk_threads_init(); + gdk_threads_enter(); + gtk_init(&argc, &argv); Instance = NULL; /* TEST @@ -1239,12 +1320,6 @@ int main(int argc, char** argv) MainHeap = HeapCreate(0, 1024*64, 0); - // MakeDialogBoxClass(); - // MakeComponentListClass(); - // MakeSmplDialogClass(); - // MakeNamingListClass(); - HMENU top = MakeMainWindowMenus(); - /// Make main window MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(MainWindow), "LDmicro"); @@ -1259,6 +1334,8 @@ int main(int argc, char** argv) IMAGE_ICON, 32, 32, 0)); /// Make main window - end + MakeMainWindowMenus(); + InitForDrawing(); ThawWindowPos(MainWindow); @@ -1285,12 +1362,14 @@ int main(int argc, char** argv) NewProgram(); strcpy(CurrentSaveFile, ""); - // We are running interactively, or we would already have exited. We - // can therefore show the window now, and otherwise set up the GUI. + /// We are running interactively, or we would already have exited. We + /// can therefore show the window now, and otherwise set up the GUI. - // Displaying the window + /// Displaying the window gtk_widget_show_all(MainWindow); - // SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor); + + /// Blink cursor + g_timeout_add(200, (GSourceFunc)BlinkCursor, DrawWindow); if(argc >= 2) { // g_print("load prog: %s\n", argv[1]); @@ -1339,5 +1418,6 @@ int main(int argc, char** argv) // } gtk_main(); + gdk_threads_leave(); return EXIT_SUCCESS; }
\ No newline at end of file diff --git a/ldmicro/lib/freezeLD/freezeLD.cpp b/ldmicro/lib/freezeLD/freezeLD.cpp index 880dfab..b9cafb2 100644 --- a/ldmicro/lib/freezeLD/freezeLD.cpp +++ b/ldmicro/lib/freezeLD/freezeLD.cpp @@ -20,8 +20,8 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name) { //g_print("freezing"); char* Ld_CWD = (char *)malloc(MAX_PATH); - getcwd(Ld_CWD, sizeof(Ld_CWD)); - + getcwd(Ld_CWD, MAX_PATH); + if (!Ld_CWD) return; char* moveToKeyLocatin = (char *)malloc(strlen(name) + MAX_PATH); @@ -144,8 +144,8 @@ static void Clamp(LONG *v, LONG min, LONG max) void ThawWindowPosF(HWID hwid, char *subKey, char *name) { char* Ld_CWD = (char *)malloc(MAX_PATH); - getcwd(Ld_CWD, sizeof(Ld_CWD)); - + getcwd(Ld_CWD, MAX_PATH); + if (!Ld_CWD) return; @@ -254,7 +254,7 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name) void FreezeDWORDF(DWORD val, char *subKey, char *name) { char* Ld_CWD = (char *)malloc(MAX_PATH); - getcwd(Ld_CWD, sizeof(Ld_CWD)); + getcwd(Ld_CWD, MAX_PATH); if (!Ld_CWD) return; @@ -294,7 +294,7 @@ void FreezeDWORDF(DWORD val, char *subKey, char *name) DWORD ThawDWORDF(DWORD val, char *subKey, char *name) { char* Ld_CWD = (char *)malloc(MAX_PATH); - getcwd(Ld_CWD, sizeof(Ld_CWD)); + getcwd(Ld_CWD, MAX_PATH); if (!Ld_CWD) return val; @@ -339,7 +339,7 @@ DWORD ThawDWORDF(DWORD val, char *subKey, char *name) void FreezeStringF(char *val, char *subKey, char *name) { char* Ld_CWD = (char *)malloc(MAX_PATH); - getcwd(Ld_CWD, sizeof(Ld_CWD)); + getcwd(Ld_CWD, MAX_PATH); if (!Ld_CWD) return; @@ -377,7 +377,7 @@ void FreezeStringF(char *val, char *subKey, char *name) void ThawStringF(char *val, int max, char *subKey, char *name) { char* Ld_CWD = (char *)malloc(MAX_PATH); - getcwd(Ld_CWD, sizeof(Ld_CWD)); + getcwd(Ld_CWD, MAX_PATH); if (!Ld_CWD) return; diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h index 8a3e3a2..80f4471 100644 --- a/ldmicro/lib/linuxUI/linuxLD.h +++ b/ldmicro/lib/linuxUI/linuxLD.h @@ -16,6 +16,7 @@ #define CALLBACK #define CONST const +/// Meamory flags #define HEAP_ZERO_MEMORY 0x00000008 /// Image loading flags @@ -24,7 +25,6 @@ /// Macro functions #define max(_A, _B) std::max(_A, _B) -// #define min(_A, _B) std::min(_A, _B) /// Typedefs //typedef int64_t __int64; @@ -114,6 +114,14 @@ typedef class tagColorReferance: public GdkRGBA{ this->alpha = 1.0; } + bool operator== (tagColorReferance& arg1) + { + if( ((int)arg1.red == (int)this->red) && ((int)arg1.green == (int)this->green) && ((int)arg1.blue == (int)this->blue) ) + return true; + else + return false; + } + GdkRGBA* getThis() { return this; diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index 062d10c..52c4c36 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -25,7 +25,7 @@ HWID view; HTVC column; /// Wraper function for gtk_window_has_toplevel_focus -BOOL isFocus(HWID window) +BOOL GetFocus(HWID window) { return (BOOL) gtk_window_has_toplevel_focus(GTK_WINDOW(window)); } @@ -263,23 +263,24 @@ HFONT CreateFont(int nHeight, int nWidth, int nOrientation, int fnWeight, void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol) { - gtk_widget_override_background_color(GTK_WIDGET(widget), - GTK_STATE_FLAG_NORMAL, &bkCol); + // gtk_widget_override_background_color(GTK_WIDGET(widget), + // GTK_STATE_FLAG_NORMAL, &bkCol); - GtkStyleContext *context; - COLORREF col; + // gint width = gtk_widget_get_allocated_width (widget); + // gint height = gtk_widget_get_allocated_height (widget); - context = gtk_widget_get_style_context (widget); - gint width = gtk_widget_get_allocated_width (widget); - gint height = gtk_widget_get_allocated_height (widget); + // COLORREF col; + // GtkStyleContext *context; + + // context = gtk_widget_get_style_context (widget); - gtk_style_context_get_color (context, - gtk_style_context_get_state (context), - &col); + // gtk_style_context_get_color (context, + // gtk_style_context_get_state (context), + // &col); - gdk_cairo_set_source_rgba (hcr, &col); + // gdk_cairo_set_source_rgba (hcr, &col); - gtk_render_background (context, hcr, 0, 0, width, height); + // cairo_fill (hcr); } void SetTextColor(HCRDC hcr, COLORREF color) @@ -290,7 +291,7 @@ void SetTextColor(HCRDC hcr, COLORREF color) void TextOut(HWID hWid, HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, int cchString) { - nYStart += 20; + nYStart += 30; cairo_text_extents_t extents; cairo_text_extents (hcr, lpString, &extents); @@ -301,12 +302,14 @@ void TextOut(HWID hWid, HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, i if(nYStart+(extents.height/2.0) >= height) { - height += extents.height; + // g_print("Y extend\n"); + height += extents.height + 50; resize_flag = TRUE; } if (nXStart+(extents.width/2.0) >= width) { + // g_print("X extend\n"); width += extents.width; resize_flag = TRUE; } @@ -320,6 +323,8 @@ void TextOut(HWID hWid, HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, i cairo_move_to(hcr, nXStart, nYStart); cairo_show_text(hcr, text); + // g_print("%s", text); + cairo_fill (hcr); } @@ -336,7 +341,10 @@ COLORREF GetTextColor(HCRDC Hdc) BOOL InvalidateRect(HWID hWid, const RECT *lpRect, BOOL bErase) { if(!GDK_IS_WINDOW(hWid)) + { + // g_print("not window\n"); return FALSE; + } if (lpRect == NULL) { @@ -365,6 +373,17 @@ int FillRect(HCRDC hDC, const RECT *lprc, HBRUSH hbr) return 0; } +BOOL PatBlt(HCRDC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD dwRop, HBRUSH hbr) +{ + cairo_set_source_rgb(hdc, hbr->red, hbr->green, hbr->blue); + cairo_rectangle(hdc, nXLeft, nYLeft + 20, nWidth, nHeight); + cairo_stroke_preserve(hdc); + + cairo_fill(hdc); + + return TRUE; +} + BOOL GetClientRect(HWID hWid, PRECT pRect) { GtkAllocation allocation; diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h index 961822f..bda2c5d 100644 --- a/ldmicro/lib/linuxUI/linuxUI.h +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -33,11 +33,24 @@ #define MB_ICONWARNING 0x00000040L #define MB_ICONINFORMATION 0x00000080L +/// Scroll +#define SB_LINEUP 0x00000001 +#define SB_PAGEUP 0x00000002 +#define SB_LINEDOWN 0x00000004 +#define SB_PAGEDOWN 0x00000008 +#define SB_TOP 0x00000010 +#define SB_BOTTOM 0x00000020 +#define SB_THUMBTRACK 0x00000040 +#define SB_THUMBPOSITION 0x00000040 + /// open/save file #define OFN_PATHMUSTEXIST 0x00000100L #define OFN_HIDEREADONLY 0x00000200L #define OFN_OVERWRITEPROMPT 0x00000400L +/// PatBlt paint flags +#define PATINVERT 0x00000100L + /// window brushes #define BS_SOLID 0x00000001L #define BS_HOLLOW 0x00000002L @@ -87,7 +100,7 @@ typedef struct OpenFileInfoData { extern COLORREF HdcCurrentTextColor; /// functions -BOOL isFocus(HWID window); +BOOL GetFocus(HWID window); COLORREF RGB( int red, @@ -157,6 +170,15 @@ int FillRect( const RECT *lprc, HBRUSH hbr); +BOOL PatBlt( + HCRDC hdc, + int nXLeft, + int nYLeft, + int nWidth, + int nHeight, + DWORD dwRop, + HBRUSH hbr); + BOOL GetClientRect( HWID hWid, PRECT lpRect); diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp index d3d8e9b..cd01ea9 100644 --- a/ldmicro/maincontrols.cpp +++ b/ldmicro/maincontrols.cpp @@ -618,8 +618,17 @@ void MakeMainWindowControls(void) //----------------------------------------------------------------------------- void RefreshScrollbars(void) { - // SCROLLINFO vert, horiz; - // SetUpScrollbars(&NeedHoriz, &horiz, &vert); + SCROLLINFO vert, horiz; + SetUpScrollbars(&NeedHoriz, &horiz, &vert); + + GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ScrollWindow)); + // g_print("adj = %f\n", gtk_adjustment_get_value(adjustment)); + // g_print("upper = %f\n", gtk_adjustment_get_upper(adjustment) - gtk_widget_get_allocated_height (ScrollWindow)); + // g_print("lower = %f\n", gtk_adjustment_get_lower(adjustment)); + // g_print("inc = %f\n", gtk_adjustment_get_step_increment(adjustment)); + // g_print("w width = %i\n", gtk_widget_get_allocated_width (DrawWindow)); + // g_print("w height = %i\n", gtk_widget_get_allocated_height (ScrollWindow)); + // SetScrollInfo(HorizScrollBar, SB_CTL, &horiz, TRUE); // SetScrollInfo(VertScrollBar, SB_CTL, &vert, TRUE); @@ -640,44 +649,44 @@ void RefreshScrollbars(void) // MoveWindow(VertScrollBar, main.right - ScrollWidth - 2, 1, ScrollWidth, // NeedHoriz ? (IoListTop - ScrollHeight - 4) : (IoListTop - 3), TRUE); - // InvalidateRect(MainWindow, NULL, FALSE); + InvalidateRect(DrawWindow, NULL, FALSE); } //----------------------------------------------------------------------------- // Respond to a WM_VSCROLL sent to the main window, presumably by the one and // only vertical scrollbar that it has as a child. //----------------------------------------------------------------------------- -void VscrollProc(WPARAM wParam) +void VscrollProc(int wParam) { - // int prevY = ScrollYOffset; - // switch(LOWORD(wParam)) { - // case SB_LINEUP: - // case SB_PAGEUP: - // if(ScrollYOffset > 0) { - // ScrollYOffset--; - // } - // break; - - // case SB_LINEDOWN: - // case SB_PAGEDOWN: - // if(ScrollYOffset < ScrollYOffsetMax) { - // ScrollYOffset++; - // } - // break; - - // case SB_TOP: - // ScrollYOffset = 0; - // break; - - // case SB_BOTTOM: - // ScrollYOffset = ScrollYOffsetMax; - // break; - - // case SB_THUMBTRACK: - // case SB_THUMBPOSITION: - // ScrollYOffset = HIWORD(wParam); - // break; - // } + int prevY = ScrollYOffset; + switch(wParam) { + case SB_LINEUP: + case SB_PAGEUP: + if(ScrollYOffset > 0) { + ScrollYOffset--; + } + break; + + case SB_LINEDOWN: + case SB_PAGEDOWN: + if(ScrollYOffset < ScrollYOffsetMax) { + ScrollYOffset++; + } + break; + + case SB_TOP: + ScrollYOffset = 0; + break; + + case SB_BOTTOM: + ScrollYOffset = ScrollYOffsetMax; + break; + + // case SB_THUMBTRACK: + // case SB_THUMBPOSITION: + // ScrollYOffset = HIWORD(wParam); + // break; + } // if(prevY != ScrollYOffset) { // SCROLLINFO si; // si.cbSize = sizeof(si); @@ -693,42 +702,42 @@ void VscrollProc(WPARAM wParam) // Respond to a WM_HSCROLL sent to the main window, presumably by the one and // only horizontal scrollbar that it has as a child. //----------------------------------------------------------------------------- -void HscrollProc(WPARAM wParam) +void HscrollProc(int wParam) { - // int prevX = ScrollXOffset; - // switch(LOWORD(wParam)) { - // case SB_LINEUP: - // ScrollXOffset -= FONT_WIDTH; - // break; - - // case SB_PAGEUP: - // ScrollXOffset -= POS_WIDTH*FONT_WIDTH; - // break; - - // case SB_LINEDOWN: - // ScrollXOffset += FONT_WIDTH; - // break; - - // case SB_PAGEDOWN: - // ScrollXOffset += POS_WIDTH*FONT_WIDTH; - // break; - - // case SB_TOP: - // ScrollXOffset = 0; - // break; - - // case SB_BOTTOM: - // ScrollXOffset = ScrollXOffsetMax; - // break; - - // case SB_THUMBTRACK: - // case SB_THUMBPOSITION: - // ScrollXOffset = HIWORD(wParam); - // break; - // } + int prevX = ScrollXOffset; + switch(wParam) { + case SB_LINEUP: + ScrollXOffset -= FONT_WIDTH; + break; + + case SB_PAGEUP: + ScrollXOffset -= POS_WIDTH*FONT_WIDTH; + break; + + case SB_LINEDOWN: + ScrollXOffset += FONT_WIDTH; + break; + + case SB_PAGEDOWN: + ScrollXOffset += POS_WIDTH*FONT_WIDTH; + break; + + case SB_TOP: + ScrollXOffset = 0; + break; + + case SB_BOTTOM: + ScrollXOffset = ScrollXOffsetMax; + break; + + // case SB_THUMBTRACK: + // case SB_THUMBPOSITION: + // ScrollXOffset = HIWORD(wParam); + // break; + } - // if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax; - // if(ScrollXOffset < 0) ScrollXOffset = 0; + if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax; + if(ScrollXOffset < 0) ScrollXOffset = 0; // if(prevX != ScrollXOffset) { // SCROLLINFO si; diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp index b63e69d..5a91934 100644 --- a/ldmicro/schematic.cpp +++ b/ldmicro/schematic.cpp @@ -250,32 +250,32 @@ void ForgetEverything(void) //----------------------------------------------------------------------------- BOOL MoveCursorTopLeft(void) { -// int i, j; -// // Let us first try to place it somewhere on-screen, so start at the -// // vertical scroll offset, not the very top (to avoid placing the -// // cursor in a position that would force us to scroll to put it in to -// // view.) -// for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { -// for(j = ScrollYOffset; -// j < DISPLAY_MATRIX_Y_SIZE && j < (ScrollYOffset+16); j++) -// { -// if(VALID_LEAF(DisplayMatrix[i][j])) { -// SelectElement(i, j, SELECTED_LEFT); -// return TRUE; -// } -// } -// } + int i, j; + // Let us first try to place it somewhere on-screen, so start at the + // vertical scroll offset, not the very top (to avoid placing the + // cursor in a position that would force us to scroll to put it in to + // view.) + for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { + for(j = ScrollYOffset; + j < DISPLAY_MATRIX_Y_SIZE && j < (ScrollYOffset+16); j++) + { + if(VALID_LEAF(DisplayMatrix[i][j])) { + SelectElement(i, j, SELECTED_LEFT); + return TRUE; + } + } + } -// // If that didn't work, then try anywhere on the diagram before giving -// // up entirely. -// for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { -// for(j = 0; j < 16; j++) { -// if(VALID_LEAF(DisplayMatrix[i][j])) { -// SelectElement(i, j, SELECTED_LEFT); -// return TRUE; -// } -// } -// } + // If that didn't work, then try anywhere on the diagram before giving + // up entirely. + for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { + for(j = 0; j < 16; j++) { + if(VALID_LEAF(DisplayMatrix[i][j])) { + SelectElement(i, j, SELECTED_LEFT); + return TRUE; + } + } + } return FALSE; } @@ -287,108 +287,108 @@ BOOL MoveCursorTopLeft(void) //----------------------------------------------------------------------------- void MoveCursorKeyboard(int keyCode) { -// if(!Selected || Selected->selectedState == SELECTED_NONE) { -// MoveCursorTopLeft(); -// return; -// } - -// switch(keyCode) { -// case VK_LEFT: { -// if(!Selected || Selected->selectedState == SELECTED_NONE) { -// break; -// } -// if(Selected->selectedState != SELECTED_LEFT) { -// SelectElement(-1, -1, SELECTED_LEFT); -// break; -// } -// if(SelectedWhich == ELEM_COMMENT) break; -// int i, j; -// if(FindSelected(&i, &j)) { -// i--; -// while(i >= 0 && (!VALID_LEAF(DisplayMatrix[i][j]) || -// (DisplayMatrix[i][j] == Selected))) -// { -// i--; -// } -// if(i >= 0) { -// SelectElement(i, j, SELECTED_RIGHT); -// } -// } -// break; -// } -// case VK_RIGHT: { -// if(!Selected || Selected->selectedState == SELECTED_NONE) { -// break; -// } -// if(Selected->selectedState != SELECTED_RIGHT) { -// SelectElement(-1, -1, SELECTED_RIGHT); -// break; -// } -// if(SelectedWhich == ELEM_COMMENT) break; -// int i, j; -// if(FindSelected(&i, &j)) { -// i++; -// while(i < DISPLAY_MATRIX_X_SIZE && -// !VALID_LEAF(DisplayMatrix[i][j])) -// { -// i++; -// } -// if(i != DISPLAY_MATRIX_X_SIZE) { -// SelectElement(i, j, SELECTED_LEFT); -// } -// } -// break; -// } -// case VK_UP: { -// if(!Selected || Selected->selectedState == SELECTED_NONE) { -// break; -// } -// if(Selected->selectedState != SELECTED_ABOVE && -// SelectedWhich != ELEM_PLACEHOLDER) -// { -// SelectElement(-1, -1, SELECTED_ABOVE); -// break; -// } -// int i, j; -// if(FindSelected(&i, &j)) { -// j--; -// while(j >= 0 && !VALID_LEAF(DisplayMatrix[i][j])) -// j--; -// if(j >= 0) { -// SelectElement(i, j, SELECTED_BELOW); -// } -// } -// break; -// } -// case VK_DOWN: { -// if(!Selected || Selected->selectedState == SELECTED_NONE) { -// break; -// } -// if(Selected->selectedState != SELECTED_BELOW && -// SelectedWhich != ELEM_PLACEHOLDER) -// { -// SelectElement(-1, -1, SELECTED_BELOW); -// break; -// } -// int i, j; -// if(FindSelected(&i, &j)) { -// j++; -// while(j < DISPLAY_MATRIX_Y_SIZE && -// !VALID_LEAF(DisplayMatrix[i][j])) -// { -// j++; -// } -// if(j != DISPLAY_MATRIX_Y_SIZE) { -// SelectElement(i, j, SELECTED_ABOVE); -// } else if(ScrollYOffsetMax - ScrollYOffset < 3) { -// // special case: scroll the end marker into view -// ScrollYOffset = ScrollYOffsetMax; -// RefreshScrollbars(); -// } -// } -// break; -// } -// } + // if(!Selected || Selected->selectedState == SELECTED_NONE) { + // MoveCursorTopLeft(); + // return; + // } + + // switch(keyCode) { + // case VK_LEFT: { + // if(!Selected || Selected->selectedState == SELECTED_NONE) { + // break; + // } + // if(Selected->selectedState != SELECTED_LEFT) { + // SelectElement(-1, -1, SELECTED_LEFT); + // break; + // } + // if(SelectedWhich == ELEM_COMMENT) break; + // int i, j; + // if(FindSelected(&i, &j)) { + // i--; + // while(i >= 0 && (!VALID_LEAF(DisplayMatrix[i][j]) || + // (DisplayMatrix[i][j] == Selected))) + // { + // i--; + // } + // if(i >= 0) { + // SelectElement(i, j, SELECTED_RIGHT); + // } + // } + // break; + // } + // case VK_RIGHT: { + // if(!Selected || Selected->selectedState == SELECTED_NONE) { + // break; + // } + // if(Selected->selectedState != SELECTED_RIGHT) { + // SelectElement(-1, -1, SELECTED_RIGHT); + // break; + // } + // if(SelectedWhich == ELEM_COMMENT) break; + // int i, j; + // if(FindSelected(&i, &j)) { + // i++; + // while(i < DISPLAY_MATRIX_X_SIZE && + // !VALID_LEAF(DisplayMatrix[i][j])) + // { + // i++; + // } + // if(i != DISPLAY_MATRIX_X_SIZE) { + // SelectElement(i, j, SELECTED_LEFT); + // } + // } + // break; + // } + // case VK_UP: { + // if(!Selected || Selected->selectedState == SELECTED_NONE) { + // break; + // } + // if(Selected->selectedState != SELECTED_ABOVE && + // SelectedWhich != ELEM_PLACEHOLDER) + // { + // SelectElement(-1, -1, SELECTED_ABOVE); + // break; + // } + // int i, j; + // if(FindSelected(&i, &j)) { + // j--; + // while(j >= 0 && !VALID_LEAF(DisplayMatrix[i][j])) + // j--; + // if(j >= 0) { + // SelectElement(i, j, SELECTED_BELOW); + // } + // } + // break; + // } + // case VK_DOWN: { + // if(!Selected || Selected->selectedState == SELECTED_NONE) { + // break; + // } + // if(Selected->selectedState != SELECTED_BELOW && + // SelectedWhich != ELEM_PLACEHOLDER) + // { + // SelectElement(-1, -1, SELECTED_BELOW); + // break; + // } + // int i, j; + // if(FindSelected(&i, &j)) { + // j++; + // while(j < DISPLAY_MATRIX_Y_SIZE && + // !VALID_LEAF(DisplayMatrix[i][j])) + // { + // j++; + // } + // if(j != DISPLAY_MATRIX_Y_SIZE) { + // SelectElement(i, j, SELECTED_ABOVE); + // } else if(ScrollYOffsetMax - ScrollYOffset < 3) { + // // special case: scroll the end marker into view + // ScrollYOffset = ScrollYOffsetMax; + // RefreshScrollbars(); + // } + // } + // break; + // } + // } } //----------------------------------------------------------------------------- @@ -536,71 +536,71 @@ void EditElementMouseDoubleclick(int x, int y) //----------------------------------------------------------------------------- void MoveCursorMouseClick(int x, int y) { -// x += ScrollXOffset; + x += ScrollXOffset; -// y += FONT_HEIGHT/2; + y += FONT_HEIGHT/2; -// int gx0 = (x - X_PADDING)/(POS_WIDTH*FONT_WIDTH); -// int gy0 = (y - Y_PADDING)/(POS_HEIGHT*FONT_HEIGHT); + int gx0 = (x - X_PADDING)/(POS_WIDTH*FONT_WIDTH); + int gy0 = (y - Y_PADDING)/(POS_HEIGHT*FONT_HEIGHT); -// int gx = gx0; -// int gy = gy0 + ScrollYOffset; + int gx = gx0; + int gy = gy0 + ScrollYOffset; -// if(VALID_LEAF(DisplayMatrix[gx][gy])) { -// int i, j; -// for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { -// for(j = 0; j < DISPLAY_MATRIX_Y_SIZE; j++) { -// if(DisplayMatrix[i][j]) -// DisplayMatrix[i][j]->selectedState = SELECTED_NONE; -// } -// } -// int dx = x - (gx0*POS_WIDTH*FONT_WIDTH + X_PADDING); -// int dy = y - (gy0*POS_HEIGHT*FONT_HEIGHT + Y_PADDING); - -// int dtop = dy; -// int dbottom = POS_HEIGHT*FONT_HEIGHT - dy; -// int dleft = dx; -// int dright = POS_WIDTH*FONT_WIDTH - dx; - -// int extra = 1; -// if(DisplayMatrixWhich[gx][gy] == ELEM_COMMENT) { -// dleft += gx*POS_WIDTH*FONT_WIDTH; -// dright += (ColsAvailable - gx - 1)*POS_WIDTH*FONT_WIDTH; -// extra = ColsAvailable; -// } else { -// if((gx > 0) && (DisplayMatrix[gx-1][gy] == DisplayMatrix[gx][gy])) { -// dleft += POS_WIDTH*FONT_WIDTH; -// extra = 2; -// } -// if((gx < (DISPLAY_MATRIX_X_SIZE-1)) && -// (DisplayMatrix[gx+1][gy] == DisplayMatrix[gx][gy])) -// { -// dright += POS_WIDTH*FONT_WIDTH; -// extra = 2; -// } -// } + if(VALID_LEAF(DisplayMatrix[gx][gy])) { + int i, j; + for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { + for(j = 0; j < DISPLAY_MATRIX_Y_SIZE; j++) { + if(DisplayMatrix[i][j]) + DisplayMatrix[i][j]->selectedState = SELECTED_NONE; + } + } + int dx = x - (gx0*POS_WIDTH*FONT_WIDTH + X_PADDING); + int dy = y - (gy0*POS_HEIGHT*FONT_HEIGHT + Y_PADDING); + + int dtop = dy; + int dbottom = POS_HEIGHT*FONT_HEIGHT - dy; + int dleft = dx; + int dright = POS_WIDTH*FONT_WIDTH - dx; + + int extra = 1; + if(DisplayMatrixWhich[gx][gy] == ELEM_COMMENT) { + dleft += gx*POS_WIDTH*FONT_WIDTH; + dright += (ColsAvailable - gx - 1)*POS_WIDTH*FONT_WIDTH; + extra = ColsAvailable; + } else { + if((gx > 0) && (DisplayMatrix[gx-1][gy] == DisplayMatrix[gx][gy])) { + dleft += POS_WIDTH*FONT_WIDTH; + extra = 2; + } + if((gx < (DISPLAY_MATRIX_X_SIZE-1)) && + (DisplayMatrix[gx+1][gy] == DisplayMatrix[gx][gy])) + { + dright += POS_WIDTH*FONT_WIDTH; + extra = 2; + } + } -// int decideX = (dright - dleft); -// int decideY = (dtop - dbottom); - -// decideY = decideY*3*extra; - -// int state; -// if(abs(decideY) > abs(decideX)) { -// if(decideY > 0) { -// state = SELECTED_BELOW; -// } else { -// state = SELECTED_ABOVE; -// } -// } else { -// if(decideX > 0) { -// state = SELECTED_LEFT; -// } else { -// state = SELECTED_RIGHT; -// } -// } -// SelectElement(gx, gy, state); -// } + int decideX = (dright - dleft); + int decideY = (dtop - dbottom); + + decideY = decideY*3*extra; + + int state; + if(abs(decideY) > abs(decideX)) { + if(decideY > 0) { + state = SELECTED_BELOW; + } else { + state = SELECTED_ABOVE; + } + } else { + if(decideX > 0) { + state = SELECTED_LEFT; + } else { + state = SELECTED_RIGHT; + } + } + SelectElement(gx, gy, state); + } } //----------------------------------------------------------------------------- @@ -609,49 +609,49 @@ void MoveCursorMouseClick(int x, int y) //----------------------------------------------------------------------------- void MoveCursorNear(int gx, int gy) { -// int out = 0; - -// for(out = 0; out < 8; out++) { -// if(gx - out >= 0) { -// if(VALID_LEAF(DisplayMatrix[gx-out][gy])) { -// SelectElement(gx-out, gy, SELECTED_RIGHT); -// return; -// } -// } -// if(gx + out < DISPLAY_MATRIX_X_SIZE) { -// if(VALID_LEAF(DisplayMatrix[gx+out][gy])) { -// SelectElement(gx+out, gy, SELECTED_LEFT); -// return; -// } -// } -// if(gy - out >= 0) { -// if(VALID_LEAF(DisplayMatrix[gx][gy-out])) { -// SelectElement(gx, gy-out, SELECTED_BELOW); -// return; -// } -// } -// if(gy + out < DISPLAY_MATRIX_Y_SIZE) { -// if(VALID_LEAF(DisplayMatrix[gx][gy+out])) { -// SelectElement(gx, gy+out, SELECTED_ABOVE); -// return; -// } -// } + int out = 0; -// if(out == 1) { -// // Now see if we have a straight shot to the right; might be far -// // if we have to go up to a coil or other end of line element. -// int across; -// for(across = 1; gx+across < DISPLAY_MATRIX_X_SIZE; across++) { -// if(VALID_LEAF(DisplayMatrix[gx+across][gy])) { -// SelectElement(gx+across, gy, SELECTED_LEFT); -// return; -// } -// if(!DisplayMatrix[gx+across][gy]) break; -// } -// } -// } + for(out = 0; out < 8; out++) { + if(gx - out >= 0) { + if(VALID_LEAF(DisplayMatrix[gx-out][gy])) { + SelectElement(gx-out, gy, SELECTED_RIGHT); + return; + } + } + if(gx + out < DISPLAY_MATRIX_X_SIZE) { + if(VALID_LEAF(DisplayMatrix[gx+out][gy])) { + SelectElement(gx+out, gy, SELECTED_LEFT); + return; + } + } + if(gy - out >= 0) { + if(VALID_LEAF(DisplayMatrix[gx][gy-out])) { + SelectElement(gx, gy-out, SELECTED_BELOW); + return; + } + } + if(gy + out < DISPLAY_MATRIX_Y_SIZE) { + if(VALID_LEAF(DisplayMatrix[gx][gy+out])) { + SelectElement(gx, gy+out, SELECTED_ABOVE); + return; + } + } + + if(out == 1) { + // Now see if we have a straight shot to the right; might be far + // if we have to go up to a coil or other end of line element. + int across; + for(across = 1; gx+across < DISPLAY_MATRIX_X_SIZE; across++) { + if(VALID_LEAF(DisplayMatrix[gx+across][gy])) { + SelectElement(gx+across, gy, SELECTED_LEFT); + return; + } + if(!DisplayMatrix[gx+across][gy]) break; + } + } + } -// MoveCursorTopLeft(); + MoveCursorTopLeft(); } //----------------------------------------------------------------------------- |