diff options
Diffstat (limited to 'ldmicro')
-rw-r--r-- | ldmicro/circuit.cpp | 12 | ||||
-rw-r--r-- | ldmicro/draw.cpp | 1606 | ||||
-rw-r--r-- | ldmicro/draw_outputdev.cpp | 299 | ||||
-rw-r--r-- | ldmicro/includes/ldmicro.h | 4 | ||||
-rw-r--r-- | ldmicro/ldmicro.cpp | 142 | ||||
-rw-r--r-- | ldmicro/lib/freezeLD/freezeLD.cpp | 42 | ||||
-rw-r--r-- | ldmicro/lib/freezeLD/freezeLD.h | 2 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxLD.cpp | 111 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxLD.h | 23 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp | 160 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.h | 125 | ||||
-rw-r--r-- | ldmicro/maincontrols.cpp | 29 | ||||
-rw-r--r-- | ldmicro/miscutil.cpp | 6 | ||||
-rw-r--r-- | ldmicro/schematic.cpp | 214 | ||||
-rw-r--r-- | ldmicro/undoredo.cpp | 3 |
15 files changed, 1466 insertions, 1312 deletions
diff --git a/ldmicro/circuit.cpp b/ldmicro/circuit.cpp index 1d9d3d7..8b1a8e9 100644 --- a/ldmicro/circuit.cpp +++ b/ldmicro/circuit.cpp @@ -24,9 +24,11 @@ #include <linuxUI.h> #include <stdio.h> #include <stdlib.h> +#include <iostream> #include "ldmicro.h" +using namespace std; static ElemSubcktSeries *LoadSeriesFromFile(FILE *f); @@ -35,10 +37,12 @@ static ElemSubcktSeries *LoadSeriesFromFile(FILE *f); //----------------------------------------------------------------------------- ElemLeaf *AllocLeaf(void) { + cout << "Inside AlocLeaf" << "\n"; return (ElemLeaf *)CheckMalloc(sizeof(ElemLeaf)); } ElemSubcktSeries *AllocSubcktSeries(void) { + cout << "Inside AllocSub" << "\n"; return (ElemSubcktSeries *)CheckMalloc(sizeof(ElemSubcktSeries)); } ElemSubcktParallel *AllocSubcktParallel(void) @@ -638,7 +642,7 @@ void FreeCircuit(int which, void *any) //----------------------------------------------------------------------------- void FreeEntireProgram(void) { - ForgetEverything(); + // ForgetEverything(); int i; for(i = 0; i < Prog.numRungs; i++) { @@ -742,11 +746,15 @@ void DeleteSelectedRung(void) //----------------------------------------------------------------------------- static ElemSubcktSeries *AllocEmptyRung(void) { + cout << "Inside AllocEmpty" << "\n"; ElemSubcktSeries *s = AllocSubcktSeries(); + cout << "Checking series count" << "\n"; s->count = 1; + cout << "Series count done" << "\n"; s->contents[0].which = ELEM_PLACEHOLDER; ElemLeaf *l = AllocLeaf(); s->contents[0].d.leaf = l; + cout << "Exiting AllocEmpty" << "\n"; return s; } @@ -815,7 +823,7 @@ void NewProgram(void) { UndoFlush(); FreeEntireProgram(); - + Prog.numRungs = 1; Prog.rungs[0] = AllocEmptyRung(); } diff --git a/ldmicro/draw.cpp b/ldmicro/draw.cpp index 78232ba..ad8259d 100644 --- a/ldmicro/draw.cpp +++ b/ldmicro/draw.cpp @@ -49,25 +49,25 @@ BOOL ThisHighlighted; if((gy) >= DISPLAY_MATRIX_Y_SIZE || (gy) < 0) oops(); \ } -// //----------------------------------------------------------------------------- -// // The display code is the only part of the program that knows how wide a -// // rung will be when it's displayed; so this is the only convenient place to -// // warn the user and undo their changes if they created something too wide. -// // This is not very clean. -// //----------------------------------------------------------------------------- -// static BOOL CheckBoundsUndoIfFails(int gx, int gy) -// { -// if(gx >= DISPLAY_MATRIX_X_SIZE || gx < 0 || -// gy >= DISPLAY_MATRIX_Y_SIZE || gy < 0) -// { -// if(CanUndo()) { -// UndoUndo(); -// Error(_("Too many elements in subcircuit!")); -// return TRUE; -// } -// } -// return FALSE; -// } +//----------------------------------------------------------------------------- +// The display code is the only part of the program that knows how wide a +// rung will be when it's displayed; so this is the only convenient place to +// warn the user and undo their changes if they created something too wide. +// This is not very clean. +//----------------------------------------------------------------------------- +static BOOL CheckBoundsUndoIfFails(int gx, int gy) +{ + if(gx >= DISPLAY_MATRIX_X_SIZE || gx < 0 || + gy >= DISPLAY_MATRIX_Y_SIZE || gy < 0) + { + if(CanUndo()) { + UndoUndo(); + Error(_("Too many elements in subcircuit!")); + return TRUE; + } + } + return FALSE; +} //----------------------------------------------------------------------------- // Determine the width, in leaf element units, of a particular subcircuit. @@ -246,675 +246,675 @@ int ProgCountWidestRow(void) return max; } -// //----------------------------------------------------------------------------- -// // 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) -// { -// int j; -// for(j = 1; j < POS_HEIGHT; j++) { -// DrawChars(cx, cy + (POS_HEIGHT/2 - j), "|"); -// } -// DrawChars(cx, cy + (POS_HEIGHT/2), "+"); -// DrawChars(cx, cy + (POS_HEIGHT/2 - POS_HEIGHT), "+"); -// } - -// //----------------------------------------------------------------------------- -// // Convenience functions for making the text colors pretty, for DrawElement. -// //----------------------------------------------------------------------------- -// static void NormText(void) -// { -// SetTextColor(Hdc, InSimulationMode ? HighlightColours.simOff : -// HighlightColours.def); -// SelectObject(Hdc, FixedWidthFont); -// } - -// static void EmphText(void) -// { -// SetTextColor(Hdc, InSimulationMode ? HighlightColours.simOn : -// HighlightColours.selected); -// SelectObject(Hdc, FixedWidthFontBold); -// } - -// static void NameText(void) -// { -// if(!InSimulationMode && !ThisHighlighted) { -// SetTextColor(Hdc, HighlightColours.name); -// } -// } - -// static void BodyText(void) -// { -// if(!InSimulationMode && !ThisHighlighted) { -// SetTextColor(Hdc, HighlightColours.def); -// } -// } - -// static void PoweredText(BOOL powered) -// { -// if(InSimulationMode) { -// if(powered) -// EmphText(); -// else -// NormText(); -// } -// } - -// //----------------------------------------------------------------------------- -// // Count the length of a string, in characters. Nonstandard because the -// // string may contain special characters to indicate formatting (syntax -// // highlighting). -// //----------------------------------------------------------------------------- -// static int FormattedStrlen(char *str) -// { -// int l = 0; -// while(*str) { -// if(*str > 10) { -// l++; -// } -// str++; -// } -// return l; -// } - -// //----------------------------------------------------------------------------- -// // 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, -// 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(); -// } - -// //----------------------------------------------------------------------------- -// // 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, 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(before); -// int i; -// for(i = 0; i < (extra/2); i++) { -// DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); -// } -// PoweredText(after); -// for(i = FormattedStrlen(str)+(extra/2); i < totalWidth; i++) { -// DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); -// } -// } +//----------------------------------------------------------------------------- +// 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) +{ + int j; + for(j = 1; j < POS_HEIGHT; j++) { + DrawChars(cx, cy + (POS_HEIGHT/2 - j), "|"); + } + DrawChars(cx, cy + (POS_HEIGHT/2), "+"); + DrawChars(cx, cy + (POS_HEIGHT/2 - POS_HEIGHT), "+"); +} + +//----------------------------------------------------------------------------- +// Convenience functions for making the text colors pretty, for DrawElement. +//----------------------------------------------------------------------------- +static void NormText(void) +{ + SetTextColor(Hdc, InSimulationMode ? HighlightColours.simOff : + HighlightColours.def); + SelectObject(Hdc, FixedWidthFont); +} + +static void EmphText(void) +{ + SetTextColor(Hdc, InSimulationMode ? HighlightColours.simOn : + HighlightColours.selected); + SelectObject(Hdc, FixedWidthFontBold); +} + +static void NameText(void) +{ + if(!InSimulationMode && !ThisHighlighted) { + SetTextColor(Hdc, HighlightColours.name); + } +} + +static void BodyText(void) +{ + if(!InSimulationMode && !ThisHighlighted) { + SetTextColor(Hdc, HighlightColours.def); + } +} + +static void PoweredText(BOOL powered) +{ + if(InSimulationMode) { + if(powered) + EmphText(); + else + NormText(); + } +} + +//----------------------------------------------------------------------------- +// Count the length of a string, in characters. Nonstandard because the +// string may contain special characters to indicate formatting (syntax +// highlighting). +//----------------------------------------------------------------------------- +static int FormattedStrlen(const char *str) +{ + int l = 0; + while(*str) { + if(*str > 10) { + l++; + } + str++; + } + return l; +} + +//----------------------------------------------------------------------------- +// 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, + 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(); +} + +//----------------------------------------------------------------------------- +// 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, + BOOL after, int totalWidth) +{ + int extra = totalWidth - FormattedStrlen(str); + + PoweredText(after); + DrawChars(cx + (extra/2), cy + (POS_HEIGHT/2), str); + + PoweredText(before); + int i; + for(i = 0; i < (extra/2); i++) { + DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); + } + PoweredText(after); + for(i = FormattedStrlen(str)+(extra/2); i < totalWidth; i++) { + DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); + } +} //----------------------------------------------------------------------------- // Draw a string, centred in the space of a single position, with en dashes on // the left and right coloured according to the powered state. Draws on the // middle line. //----------------------------------------------------------------------------- -// static void CenterWithWires(int cx, int cy, char *str, BOOL before, BOOL after) -// { -// CenterWithWiresWidth(cx, cy, str, before, after, POS_WIDTH); -// } +static void CenterWithWires(int cx, int cy, const char *str, BOOL before, BOOL after) +{ + CenterWithWiresWidth(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, -// BOOL poweredBefore) -// { -// int cx0 = *cx, cy0 = *cy; - -// BOOL poweredAfter = leaf->poweredAfter; - -// int thisWidth; -// switch(which) { -// case ELEM_ADD: -// case ELEM_SUB: -// case ELEM_MUL: -// case ELEM_DIV: -// thisWidth = 2; -// break; - -// default: -// thisWidth = 1; -// break; -// } - -// NormText(); -// PoweredText(poweredBefore); -// while(*cx < (ColsAvailable-thisWidth)*POS_WIDTH) { -// int gx = *cx/POS_WIDTH; -// int gy = *cy/POS_HEIGHT; - -// if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; - -// if(gx >= DISPLAY_MATRIX_X_SIZE) oops(); -// DM_BOUNDS(gx, gy); -// DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; -// DisplayMatrixWhich[gx][gy] = ELEM_PADDING; - -// int i; -// for(i = 0; i < POS_WIDTH; i++) { -// DrawChars(*cx + i, *cy + (POS_HEIGHT/2), "-"); -// } -// *cx += POS_WIDTH; -// cx0 += POS_WIDTH; -// } - -// if(leaf == Selected && !InSimulationMode) { -// EmphText(); -// ThisHighlighted = TRUE; -// } else { -// ThisHighlighted = FALSE; -// } - -// switch(which) { -// case ELEM_CTC: { -// char buf[256]; -// 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); -// break; -// } -// case ELEM_RES: { -// ElemReset *r = &leaf->d.reset; -// CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); -// CenterWithWires(*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, -// poweredAfter); -// break; -// } -// case ELEM_SET_PWM: { -// ElemSetPwm *s = &leaf->d.setPwm; -// CenterWithSpaces(*cx, *cy, s->name, poweredAfter, TRUE); -// char l[50]; -// if(s->targetFreq >= 100000) { -// sprintf(l, "{PWM %d kHz}", (s->targetFreq+500)/1000); -// } else if(s->targetFreq >= 10000) { -// sprintf(l, "{PWM %.1f kHz}", s->targetFreq/1000.0); -// } else if(s->targetFreq >= 1000) { -// sprintf(l, "{PWM %.2f kHz}", s->targetFreq/1000.0); -// } else { -// sprintf(l, "{PWM %d Hz}", s->targetFreq); -// } -// CenterWithWires(*cx, *cy, l, poweredBefore, -// poweredAfter); -// break; -// } -// case ELEM_PERSIST: -// CenterWithSpaces(*cx, *cy, leaf->d.persist.var, poweredAfter, TRUE); -// CenterWithWires(*cx, *cy, "{PERSIST}", poweredBefore, poweredAfter); -// break; - -// case ELEM_MOVE: { -// char top[256]; -// char bot[256]; -// ElemMove *m = &leaf->d.move; - -// if((strlen(m->dest) > (POS_WIDTH - 9)) || -// (strlen(m->src) > (POS_WIDTH - 9))) -// { -// CenterWithWires(*cx, *cy, TOO_LONG, poweredBefore, -// poweredAfter); -// break; -// } - -// strcpy(top, "{ }"); -// memcpy(top+1, m->dest, strlen(m->dest)); -// top[strlen(m->dest) + 3] = ':'; -// top[strlen(m->dest) + 4] = '='; - -// strcpy(bot, "{ \x01MOV\x02}"); -// memcpy(bot+2, m->src, strlen(m->src)); - -// CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); -// CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); -// break; -// } -// case ELEM_MASTER_RELAY: -// CenterWithWires(*cx, *cy, "{MASTER RLY}", poweredBefore, -// poweredAfter); -// break; - -// case ELEM_SHIFT_REGISTER: { -// char bot[MAX_NAME_LEN+20]; -// memset(bot, ' ', sizeof(bot)); -// bot[0] = '{'; -// sprintf(bot+2, "%s0..%d", leaf->d.shiftRegister.name, -// leaf->d.shiftRegister.stages-1); -// bot[strlen(bot)] = ' '; -// bot[13] = '}'; -// bot[14] = '\0'; -// CenterWithSpaces(*cx, *cy, "{\x01SHIFT REG\x02 }", -// poweredAfter, FALSE); -// CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); -// break; -// } -// case ELEM_PIECEWISE_LINEAR: -// case ELEM_LOOK_UP_TABLE: { -// char top[MAX_NAME_LEN+20], bot[MAX_NAME_LEN+20]; -// char *dest, *index, *str; -// if(which == ELEM_PIECEWISE_LINEAR) { -// dest = leaf->d.piecewiseLinear.dest; -// index = leaf->d.piecewiseLinear.index; -// str = "PWL"; -// } else { -// dest = leaf->d.lookUpTable.dest; -// index = leaf->d.lookUpTable.index; -// str = "LUT"; -// } -// memset(top, ' ', sizeof(top)); -// top[0] = '{'; -// sprintf(top+2, "%s :=", dest); -// top[strlen(top)] = ' '; -// top[13] = '}'; -// top[14] = '\0'; -// CenterWithSpaces(*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); -// break; -// } -// case ELEM_COIL: { -// char buf[4]; -// ElemCoil *c = &leaf->d.coil; - -// buf[0] = '('; -// if(c->negated) { -// buf[1] = '/'; -// } else if(c->setOnly) { -// buf[1] = 'S'; -// } else if(c->resetOnly) { -// buf[1] = 'R'; -// } else { -// buf[1] = ' '; -// } -// buf[2] = ')'; -// buf[3] = '\0'; - -// CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); -// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); -// break; -// } -// case ELEM_DIV: -// case ELEM_MUL: -// case ELEM_SUB: -// case ELEM_ADD: { -// char top[POS_WIDTH*2-3+2]; -// char bot[POS_WIDTH*2-3]; - -// memset(top, ' ', sizeof(top)-1); -// top[0] = '{'; - -// memset(bot, ' ', sizeof(bot)-1); -// bot[0] = '{'; - -// int lt = 1; -// if(which == ELEM_ADD) { -// memcpy(top+lt, "\x01""ADD\x02", 5); -// } else if(which == ELEM_SUB) { -// memcpy(top+lt, "\x01SUB\x02", 5); -// } else if(which == ELEM_MUL) { -// memcpy(top+lt, "\x01MUL\x02", 5); -// } else if(which == ELEM_DIV) { -// memcpy(top+lt, "\x01""DIV\x02", 5); -// } else oops(); - -// lt += 7; -// memcpy(top+lt, leaf->d.math.dest, strlen(leaf->d.math.dest)); -// lt += strlen(leaf->d.math.dest) + 2; -// top[lt++] = ':'; -// top[lt++] = '='; - -// int lb = 2; -// memcpy(bot+lb, leaf->d.math.op1, strlen(leaf->d.math.op1)); -// lb += strlen(leaf->d.math.op1) + 1; -// if(which == ELEM_ADD) { -// bot[lb++] = '+'; -// } else if(which == ELEM_SUB) { -// bot[lb++] = '-'; -// } else if(which == ELEM_MUL) { -// bot[lb++] = '*'; -// } else if(which == ELEM_DIV) { -// bot[lb++] = '/'; -// } else oops(); -// lb++; -// memcpy(bot+lb, leaf->d.math.op2, strlen(leaf->d.math.op2)); -// lb += strlen(leaf->d.math.op2); - -// int l = max(lb, lt - 2); -// top[l+2] = '}'; top[l+3] = '\0'; -// 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, -// 2*POS_WIDTH); - -// *cx += POS_WIDTH; - -// break; -// } -// default: -// oops(); -// break; -// } - -// *cx += POS_WIDTH; - -// return poweredAfter; -// } +static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, + BOOL poweredBefore) +{ + int cx0 = *cx, cy0 = *cy; + + BOOL poweredAfter = leaf->poweredAfter; + + int thisWidth; + switch(which) { + case ELEM_ADD: + case ELEM_SUB: + case ELEM_MUL: + case ELEM_DIV: + thisWidth = 2; + break; + + default: + thisWidth = 1; + break; + } + + NormText(); + PoweredText(poweredBefore); + while(*cx < (ColsAvailable-thisWidth)*POS_WIDTH) { + int gx = *cx/POS_WIDTH; + int gy = *cy/POS_HEIGHT; + + if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; + + if(gx >= DISPLAY_MATRIX_X_SIZE) oops(); + DM_BOUNDS(gx, gy); + DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; + DisplayMatrixWhich[gx][gy] = ELEM_PADDING; + + int i; + for(i = 0; i < POS_WIDTH; i++) { + DrawChars(*cx + i, *cy + (POS_HEIGHT/2), "-"); + } + *cx += POS_WIDTH; + cx0 += POS_WIDTH; + } + + if(leaf == Selected && !InSimulationMode) { + EmphText(); + ThisHighlighted = TRUE; + } else { + ThisHighlighted = FALSE; + } + + switch(which) { + case ELEM_CTC: { + char buf[256]; + 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); + break; + } + case ELEM_RES: { + ElemReset *r = &leaf->d.reset; + CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); + CenterWithWires(*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, + poweredAfter); + break; + } + case ELEM_SET_PWM: { + ElemSetPwm *s = &leaf->d.setPwm; + CenterWithSpaces(*cx, *cy, s->name, poweredAfter, TRUE); + char l[50]; + if(s->targetFreq >= 100000) { + sprintf(l, "{PWM %d kHz}", (s->targetFreq+500)/1000); + } else if(s->targetFreq >= 10000) { + sprintf(l, "{PWM %.1f kHz}", s->targetFreq/1000.0); + } else if(s->targetFreq >= 1000) { + sprintf(l, "{PWM %.2f kHz}", s->targetFreq/1000.0); + } else { + sprintf(l, "{PWM %d Hz}", s->targetFreq); + } + CenterWithWires(*cx, *cy, l, poweredBefore, + poweredAfter); + break; + } + case ELEM_PERSIST: + CenterWithSpaces(*cx, *cy, leaf->d.persist.var, poweredAfter, TRUE); + CenterWithWires(*cx, *cy, "{PERSIST}", poweredBefore, poweredAfter); + break; + + case ELEM_MOVE: { + char top[256]; + char bot[256]; + ElemMove *m = &leaf->d.move; + + if((strlen(m->dest) > (POS_WIDTH - 9)) || + (strlen(m->src) > (POS_WIDTH - 9))) + { + CenterWithWires(*cx, *cy, TOO_LONG, poweredBefore, + poweredAfter); + break; + } + + strcpy(top, "{ }"); + memcpy(top+1, m->dest, strlen(m->dest)); + top[strlen(m->dest) + 3] = ':'; + top[strlen(m->dest) + 4] = '='; + + strcpy(bot, "{ \x01MOV\x02}"); + memcpy(bot+2, m->src, strlen(m->src)); + + CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); + CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); + break; + } + case ELEM_MASTER_RELAY: + CenterWithWires(*cx, *cy, "{MASTER RLY}", poweredBefore, + poweredAfter); + break; + + case ELEM_SHIFT_REGISTER: { + char bot[MAX_NAME_LEN+20]; + memset(bot, ' ', sizeof(bot)); + bot[0] = '{'; + sprintf(bot+2, "%s0..%d", leaf->d.shiftRegister.name, + leaf->d.shiftRegister.stages-1); + bot[strlen(bot)] = ' '; + bot[13] = '}'; + bot[14] = '\0'; + CenterWithSpaces(*cx, *cy, "{\x01SHIFT REG\x02 }", + poweredAfter, FALSE); + CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); + break; + } + case ELEM_PIECEWISE_LINEAR: + case ELEM_LOOK_UP_TABLE: { + char top[MAX_NAME_LEN+20], bot[MAX_NAME_LEN+20]; + char *dest, *index, *str; + if(which == ELEM_PIECEWISE_LINEAR) { + dest = leaf->d.piecewiseLinear.dest; + index = leaf->d.piecewiseLinear.index; + str = "PWL"; + } else { + dest = leaf->d.lookUpTable.dest; + index = leaf->d.lookUpTable.index; + str = "LUT"; + } + memset(top, ' ', sizeof(top)); + top[0] = '{'; + sprintf(top+2, "%s :=", dest); + top[strlen(top)] = ' '; + top[13] = '}'; + top[14] = '\0'; + CenterWithSpaces(*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); + break; + } + case ELEM_COIL: { + char buf[4]; + ElemCoil *c = &leaf->d.coil; + + buf[0] = '('; + if(c->negated) { + buf[1] = '/'; + } else if(c->setOnly) { + buf[1] = 'S'; + } else if(c->resetOnly) { + buf[1] = 'R'; + } else { + buf[1] = ' '; + } + buf[2] = ')'; + buf[3] = '\0'; + + CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); + CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + break; + } + case ELEM_DIV: + case ELEM_MUL: + case ELEM_SUB: + case ELEM_ADD: { + char top[POS_WIDTH*2-3+2]; + char bot[POS_WIDTH*2-3]; + + memset(top, ' ', sizeof(top)-1); + top[0] = '{'; + + memset(bot, ' ', sizeof(bot)-1); + bot[0] = '{'; + + int lt = 1; + if(which == ELEM_ADD) { + memcpy(top+lt, "\x01""ADD\x02", 5); + } else if(which == ELEM_SUB) { + memcpy(top+lt, "\x01SUB\x02", 5); + } else if(which == ELEM_MUL) { + memcpy(top+lt, "\x01MUL\x02", 5); + } else if(which == ELEM_DIV) { + memcpy(top+lt, "\x01""DIV\x02", 5); + } else oops(); + + lt += 7; + memcpy(top+lt, leaf->d.math.dest, strlen(leaf->d.math.dest)); + lt += strlen(leaf->d.math.dest) + 2; + top[lt++] = ':'; + top[lt++] = '='; + + int lb = 2; + memcpy(bot+lb, leaf->d.math.op1, strlen(leaf->d.math.op1)); + lb += strlen(leaf->d.math.op1) + 1; + if(which == ELEM_ADD) { + bot[lb++] = '+'; + } else if(which == ELEM_SUB) { + bot[lb++] = '-'; + } else if(which == ELEM_MUL) { + bot[lb++] = '*'; + } else if(which == ELEM_DIV) { + bot[lb++] = '/'; + } else oops(); + lb++; + memcpy(bot+lb, leaf->d.math.op2, strlen(leaf->d.math.op2)); + lb += strlen(leaf->d.math.op2); + + int l = max(lb, lt - 2); + top[l+2] = '}'; top[l+3] = '\0'; + 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, + 2*POS_WIDTH); + + *cx += POS_WIDTH; + + break; + } + default: + oops(); + break; + } + + *cx += POS_WIDTH; + + return poweredAfter; +} //----------------------------------------------------------------------------- // 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, -// BOOL poweredBefore) -// { -// int cx0 = *cx, cy0 = *cy; -// BOOL poweredAfter = leaf->poweredAfter; - -// switch(which) { -// case ELEM_COMMENT: { -// char tbuf[MAX_COMMENT_LEN]; -// char tlbuf[MAX_COMMENT_LEN+8]; - -// strcpy(tbuf, leaf->d.comment.str); -// char *b = strchr(tbuf, '\n'); - -// if(b) { -// if(b[-1] == '\r') b[-1] = '\0'; -// *b = '\0'; -// sprintf(tlbuf, "\x03 ; %s\x02", tbuf); -// DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); -// sprintf(tlbuf, "\x03 ; %s\x02", b+1); -// DrawChars(*cx, *cy + (POS_HEIGHT/2), tlbuf); -// } else { -// sprintf(tlbuf, "\x03 ; %s\x02", tbuf); -// DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); -// } - -// *cx += ColsAvailable*POS_WIDTH; -// break; -// } -// case ELEM_PLACEHOLDER: { -// NormText(); -// CenterWithWiresWidth(*cx, *cy, "--", FALSE, FALSE, 2); -// *cx += POS_WIDTH; -// break; -// } -// case ELEM_CONTACTS: { -// char buf[4]; -// ElemContacts *c = &leaf->d.contacts; - -// buf[0] = ']'; -// buf[1] = c->negated ? '/' : ' '; -// buf[2] = '['; -// buf[3] = '\0'; - -// CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); -// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); - -// *cx += POS_WIDTH; -// break; -// } -// { -// char *s; -// case ELEM_EQU: -// s = "=="; goto cmp; -// case ELEM_NEQ: -// s = "/="; goto cmp; -// case ELEM_GRT: -// s = ">"; goto cmp; -// case ELEM_GEQ: -// s = ">="; goto cmp; -// case ELEM_LES: -// s = "<"; goto cmp; -// case ELEM_LEQ: -// s = "<="; goto cmp; -// cmp: -// char s1[POS_WIDTH+10], s2[POS_WIDTH+10]; -// int l1, l2, lmax; - -// l1 = 2 + 1 + strlen(s) + strlen(leaf->d.cmp.op1); -// l2 = 2 + 1 + strlen(leaf->d.cmp.op2); -// lmax = max(l1, l2); - -// if(lmax < POS_WIDTH) { -// memset(s1, ' ', sizeof(s1)); -// s1[0] = '['; -// s1[lmax-1] = ']'; -// s1[lmax] = '\0'; -// strcpy(s2, s1); -// memcpy(s1+1, leaf->d.cmp.op1, strlen(leaf->d.cmp.op1)); -// memcpy(s1+strlen(leaf->d.cmp.op1)+2, s, strlen(s)); -// memcpy(s2+2, leaf->d.cmp.op2, strlen(leaf->d.cmp.op2)); -// } else { -// strcpy(s1, ""); -// strcpy(s2, TOO_LONG); -// } - -// CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); -// CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); - -// *cx += POS_WIDTH; -// break; -// } -// case ELEM_OPEN: -// CenterWithWires(*cx, *cy, "+ +", poweredBefore, poweredAfter); -// *cx += POS_WIDTH; -// break; - -// case ELEM_SHORT: -// CenterWithWires(*cx, *cy, "+------+", poweredBefore, poweredAfter); -// *cx += POS_WIDTH; -// break; - -// case ELEM_ONE_SHOT_RISING: -// case ELEM_ONE_SHOT_FALLING: { -// char *s1, *s2; -// if(which == ELEM_ONE_SHOT_RISING) { -// s1 = " _ "; -// s2 = "[\x01OSR\x02_/ ]"; -// } else if(which == ELEM_ONE_SHOT_FALLING) { -// s1 = " _ "; -// s2 = "[\x01OSF\x02 \\_]"; -// } else oops(); - -// CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); -// CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); - -// *cx += POS_WIDTH; -// break; -// } -// case ELEM_CTU: -// case ELEM_CTD: { -// char *s; -// if(which == ELEM_CTU) -// s = "\x01""CTU\x02"; -// else if(which == ELEM_CTD) -// s = "\x01""CTD\x02"; -// else oops(); - -// char buf[256]; -// 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); - -// *cx += POS_WIDTH; -// break; -// } -// case ELEM_RTO: -// case ELEM_TON: -// case ELEM_TOF: { -// char *s; -// if(which == ELEM_TON) -// s = "\x01TON\x02"; -// else if(which == ELEM_TOF) -// s = "\x01TOF\x02"; -// else if(which == ELEM_RTO) -// s = "\x01RTO\x02"; -// else oops(); - -// char buf[256]; -// ElemTimer *t = &leaf->d.timer; -// if(t->delay >= 1000*1000) { -// sprintf(buf, "[%s %.3f s]", s, t->delay/1000000.0); -// } else if(t->delay >= 100*1000) { -// sprintf(buf, "[%s %.1f ms]", s, t->delay/1000.0); -// } else { -// sprintf(buf, "[%s %.2f ms]", s, t->delay/1000.0); -// } - -// CenterWithSpaces(*cx, *cy, t->name, poweredAfter, TRUE); -// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); - -// *cx += POS_WIDTH; -// break; -// } -// case ELEM_FORMATTED_STRING: { -// // Careful, string could be longer than fits in our space. -// char str[POS_WIDTH*2]; -// memset(str, 0, sizeof(str)); -// char *srcStr = leaf->d.fmtdStr.string; -// memcpy(str, srcStr, min(strlen(srcStr), POS_WIDTH*2 - 7)); - -// char bot[100]; -// 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, -// leaf->d.fmtdStr.var); -// BodyText(); - -// CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, -// 2*POS_WIDTH); -// *cx += 2*POS_WIDTH; -// break; -// } -// case ELEM_UART_RECV: -// case ELEM_UART_SEND: -// CenterWithWires(*cx, *cy, -// (which == ELEM_UART_RECV) ? "{UART RECV}" : "{UART SEND}", -// poweredBefore, poweredAfter); -// CenterWithSpaces(*cx, *cy, leaf->d.uart.name, poweredAfter, TRUE); -// *cx += POS_WIDTH; -// break; - -// default: -// poweredAfter = DrawEndOfLine(which, leaf, cx, cy, poweredBefore); -// break; -// } - -// // And now we can enter the element into the display matrix so that the -// // UI routines know what element is at position (gx, gy) when the user -// // clicks there, and so that we know where to put the cursor if this -// // element is selected. - -// // Don't use original cx0, as an end of line element might be further -// // along than that. -// cx0 = *cx - POS_WIDTH; - -// int gx = cx0/POS_WIDTH; -// int gy = cy0/POS_HEIGHT; -// if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; -// DM_BOUNDS(gx, gy); - -// DisplayMatrix[gx][gy] = leaf; -// DisplayMatrixWhich[gx][gy] = which; - -// int xadj = 0; -// switch(which) { -// case ELEM_ADD: -// case ELEM_SUB: -// case ELEM_MUL: -// case ELEM_DIV: -// case ELEM_FORMATTED_STRING: -// DM_BOUNDS(gx-1, gy); -// DisplayMatrix[gx-1][gy] = leaf; -// DisplayMatrixWhich[gx-1][gy] = which; -// xadj = POS_WIDTH*FONT_WIDTH; -// break; -// } - -// if(which == ELEM_COMMENT) { -// int i; -// for(i = 0; i < ColsAvailable; i++) { -// DisplayMatrix[i][gy] = leaf; -// DisplayMatrixWhich[i][gy] = ELEM_COMMENT; -// } -// xadj = (ColsAvailable-1)*POS_WIDTH*FONT_WIDTH; -// } - -// int x0 = X_PADDING + cx0*FONT_WIDTH; -// int y0 = Y_PADDING + cy0*FONT_HEIGHT; - -// if(leaf->selectedState != SELECTED_NONE && leaf == Selected) { -// SelectionActive = TRUE; -// } -// switch(leaf->selectedState) { -// case SELECTED_LEFT: -// Cursor.left = x0 + FONT_WIDTH - 4 - xadj; -// Cursor.top = y0 - FONT_HEIGHT/2; -// Cursor.width = 2; -// Cursor.height = POS_HEIGHT*FONT_HEIGHT; -// break; - -// case SELECTED_RIGHT: -// Cursor.left = x0 + (POS_WIDTH-1)*FONT_WIDTH - 5; -// Cursor.top = y0 - FONT_HEIGHT/2; -// Cursor.width = 2; -// Cursor.height = POS_HEIGHT*FONT_HEIGHT; -// break; - -// case SELECTED_ABOVE: -// Cursor.left = x0 + FONT_WIDTH/2 - xadj; -// Cursor.top = y0 - 2; -// Cursor.width = (POS_WIDTH-2)*FONT_WIDTH + xadj; -// Cursor.height = 2; -// break; - -// case SELECTED_BELOW: -// Cursor.left = x0 + FONT_WIDTH/2 - xadj; -// Cursor.top = y0 + (POS_HEIGHT-1)*FONT_HEIGHT + -// FONT_HEIGHT/2 - 2; -// Cursor.width = (POS_WIDTH-2)*(FONT_WIDTH) + xadj; -// Cursor.height = 2; -// break; - -// default: -// break; -// } - -// return poweredAfter; -// } +static BOOL DrawLeaf(int which, ElemLeaf *leaf, int *cx, int *cy, + BOOL poweredBefore) +{ + int cx0 = *cx, cy0 = *cy; + BOOL poweredAfter = leaf->poweredAfter; + + switch(which) { + case ELEM_COMMENT: { + char tbuf[MAX_COMMENT_LEN]; + char tlbuf[MAX_COMMENT_LEN+8]; + + strcpy(tbuf, leaf->d.comment.str); + char *b = strchr(tbuf, '\n'); + + if(b) { + if(b[-1] == '\r') b[-1] = '\0'; + *b = '\0'; + sprintf(tlbuf, "\x03 ; %s\x02", tbuf); + DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); + sprintf(tlbuf, "\x03 ; %s\x02", b+1); + DrawChars(*cx, *cy + (POS_HEIGHT/2), tlbuf); + } else { + sprintf(tlbuf, "\x03 ; %s\x02", tbuf); + DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); + } + + *cx += ColsAvailable*POS_WIDTH; + break; + } + case ELEM_PLACEHOLDER: { + NormText(); + CenterWithWiresWidth(*cx, *cy, "--", FALSE, FALSE, 2); + *cx += POS_WIDTH; + break; + } + case ELEM_CONTACTS: { + char buf[4]; + ElemContacts *c = &leaf->d.contacts; + + buf[0] = ']'; + buf[1] = c->negated ? '/' : ' '; + buf[2] = '['; + buf[3] = '\0'; + + CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); + CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + + *cx += POS_WIDTH; + break; + } + { + char *s; + case ELEM_EQU: + s = "=="; goto cmp; + case ELEM_NEQ: + s = "/="; goto cmp; + case ELEM_GRT: + s = ">"; goto cmp; + case ELEM_GEQ: + s = ">="; goto cmp; + case ELEM_LES: + s = "<"; goto cmp; + case ELEM_LEQ: + s = "<="; goto cmp; +cmp: + char s1[POS_WIDTH+10], s2[POS_WIDTH+10]; + int l1, l2, lmax; + + l1 = 2 + 1 + strlen(s) + strlen(leaf->d.cmp.op1); + l2 = 2 + 1 + strlen(leaf->d.cmp.op2); + lmax = max(l1, l2); + + if(lmax < POS_WIDTH) { + memset(s1, ' ', sizeof(s1)); + s1[0] = '['; + s1[lmax-1] = ']'; + s1[lmax] = '\0'; + strcpy(s2, s1); + memcpy(s1+1, leaf->d.cmp.op1, strlen(leaf->d.cmp.op1)); + memcpy(s1+strlen(leaf->d.cmp.op1)+2, s, strlen(s)); + memcpy(s2+2, leaf->d.cmp.op2, strlen(leaf->d.cmp.op2)); + } else { + strcpy(s1, ""); + strcpy(s2, TOO_LONG); + } + + CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); + CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); + + *cx += POS_WIDTH; + break; + } + case ELEM_OPEN: + CenterWithWires(*cx, *cy, "+ +", poweredBefore, poweredAfter); + *cx += POS_WIDTH; + break; + + case ELEM_SHORT: + CenterWithWires(*cx, *cy, "+------+", poweredBefore, poweredAfter); + *cx += POS_WIDTH; + break; + + case ELEM_ONE_SHOT_RISING: + case ELEM_ONE_SHOT_FALLING: { + char *s1, *s2; + if(which == ELEM_ONE_SHOT_RISING) { + s1 = " _ "; + s2 = "[\x01OSR\x02_/ ]"; + } else if(which == ELEM_ONE_SHOT_FALLING) { + s1 = " _ "; + s2 = "[\x01OSF\x02 \\_]"; + } else oops(); + + CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); + CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); + + *cx += POS_WIDTH; + break; + } + case ELEM_CTU: + case ELEM_CTD: { + char *s; + if(which == ELEM_CTU) + s = "\x01""CTU\x02"; + else if(which == ELEM_CTD) + s = "\x01""CTD\x02"; + else oops(); + + char buf[256]; + 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); + + *cx += POS_WIDTH; + break; + } + case ELEM_RTO: + case ELEM_TON: + case ELEM_TOF: { + char *s; + if(which == ELEM_TON) + s = "\x01TON\x02"; + else if(which == ELEM_TOF) + s = "\x01TOF\x02"; + else if(which == ELEM_RTO) + s = "\x01RTO\x02"; + else oops(); + + char buf[256]; + ElemTimer *t = &leaf->d.timer; + if(t->delay >= 1000*1000) { + sprintf(buf, "[%s %.3f s]", s, t->delay/1000000.0); + } else if(t->delay >= 100*1000) { + sprintf(buf, "[%s %.1f ms]", s, t->delay/1000.0); + } else { + sprintf(buf, "[%s %.2f ms]", s, t->delay/1000.0); + } + + CenterWithSpaces(*cx, *cy, t->name, poweredAfter, TRUE); + CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + + *cx += POS_WIDTH; + break; + } + case ELEM_FORMATTED_STRING: { + // Careful, string could be longer than fits in our space. + char str[POS_WIDTH*2]; + memset(str, 0, sizeof(str)); + char *srcStr = leaf->d.fmtdStr.string; + memcpy(str, srcStr, std::min<size_t>(strlen(srcStr), (size_t)(POS_WIDTH*2 - 7) )); + + char bot[100]; + 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, + leaf->d.fmtdStr.var); + BodyText(); + + CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, + 2*POS_WIDTH); + *cx += 2*POS_WIDTH; + break; + } + case ELEM_UART_RECV: + case ELEM_UART_SEND: + CenterWithWires(*cx, *cy, + (which == ELEM_UART_RECV) ? "{UART RECV}" : "{UART SEND}", + poweredBefore, poweredAfter); + CenterWithSpaces(*cx, *cy, leaf->d.uart.name, poweredAfter, TRUE); + *cx += POS_WIDTH; + break; + + default: + poweredAfter = DrawEndOfLine(which, leaf, cx, cy, poweredBefore); + break; + } + + // And now we can enter the element into the display matrix so that the + // UI routines know what element is at position (gx, gy) when the user + // clicks there, and so that we know where to put the cursor if this + // element is selected. + + // Don't use original cx0, as an end of line element might be further + // along than that. + cx0 = *cx - POS_WIDTH; + + int gx = cx0/POS_WIDTH; + int gy = cy0/POS_HEIGHT; + if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; + DM_BOUNDS(gx, gy); + + DisplayMatrix[gx][gy] = leaf; + DisplayMatrixWhich[gx][gy] = which; + + int xadj = 0; + switch(which) { + case ELEM_ADD: + case ELEM_SUB: + case ELEM_MUL: + case ELEM_DIV: + case ELEM_FORMATTED_STRING: + DM_BOUNDS(gx-1, gy); + DisplayMatrix[gx-1][gy] = leaf; + DisplayMatrixWhich[gx-1][gy] = which; + xadj = POS_WIDTH*FONT_WIDTH; + break; + } + + if(which == ELEM_COMMENT) { + int i; + for(i = 0; i < ColsAvailable; i++) { + DisplayMatrix[i][gy] = leaf; + DisplayMatrixWhich[i][gy] = ELEM_COMMENT; + } + xadj = (ColsAvailable-1)*POS_WIDTH*FONT_WIDTH; + } + + int x0 = X_PADDING + cx0*FONT_WIDTH; + int y0 = Y_PADDING + cy0*FONT_HEIGHT; + + if(leaf->selectedState != SELECTED_NONE && leaf == Selected) { + SelectionActive = TRUE; + } + switch(leaf->selectedState) { + case SELECTED_LEFT: + Cursor.left = x0 + FONT_WIDTH - 4 - xadj; + Cursor.top = y0 - FONT_HEIGHT/2; + Cursor.width = 2; + Cursor.height = POS_HEIGHT*FONT_HEIGHT; + break; + + case SELECTED_RIGHT: + Cursor.left = x0 + (POS_WIDTH-1)*FONT_WIDTH - 5; + Cursor.top = y0 - FONT_HEIGHT/2; + Cursor.width = 2; + Cursor.height = POS_HEIGHT*FONT_HEIGHT; + break; + + case SELECTED_ABOVE: + Cursor.left = x0 + FONT_WIDTH/2 - xadj; + Cursor.top = y0 - 2; + Cursor.width = (POS_WIDTH-2)*FONT_WIDTH + xadj; + Cursor.height = 2; + break; + + case SELECTED_BELOW: + Cursor.left = x0 + FONT_WIDTH/2 - xadj; + Cursor.top = y0 + (POS_HEIGHT-1)*FONT_HEIGHT + + FONT_HEIGHT/2 - 2; + Cursor.width = (POS_WIDTH-2)*(FONT_WIDTH) + xadj; + Cursor.height = 2; + break; + + default: + break; + } + + return poweredAfter; +} //----------------------------------------------------------------------------- // Draw a particular subcircuit with its top left corner at *cx and *cy (in @@ -928,125 +928,125 @@ int ProgCountWidestRow(void) //----------------------------------------------------------------------------- BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) { -// BOOL poweredAfter; - -// int cx0 = *cx, cy0 = *cy; -// ElemLeaf *leaf = (ElemLeaf *)elem; - -// SetBkColor(Hdc, InSimulationMode ? HighlightColours.simBg : -// HighlightColours.bg); -// NormText(); - -// if(elem == Selected && !InSimulationMode) { -// EmphText(); -// ThisHighlighted = TRUE; -// } else { -// ThisHighlighted = FALSE; -// } - -// switch(which) { -// case ELEM_SERIES_SUBCKT: { -// int i; -// ElemSubcktSeries *s = (ElemSubcktSeries *)elem; -// poweredAfter = poweredBefore; -// for(i = 0; i < s->count; i++) { -// poweredAfter = DrawElement(s->contents[i].which, -// s->contents[i].d.any, cx, cy, poweredAfter); -// } -// break; -// } -// case ELEM_PARALLEL_SUBCKT: { -// int i; -// ElemSubcktParallel *p = (ElemSubcktParallel *)elem; -// int widthMax = CountWidthOfElement(which, elem, (*cx)/POS_WIDTH); -// int heightMax = CountHeightOfElement(which, elem); - -// poweredAfter = FALSE; - -// int lowestPowered = -1; -// int downBy = 0; -// for(i = 0; i < p->count; i++) { -// BOOL poweredThis; - -// poweredThis = DrawElement(p->contents[i].which, -// p->contents[i].d.any, cx, cy, poweredBefore); - -// if(InSimulationMode) { -// if(poweredThis) poweredAfter = TRUE; -// PoweredText(poweredThis); -// } - -// while((*cx - cx0) < widthMax*POS_WIDTH) { -// int gx = *cx/POS_WIDTH; -// int gy = *cy/POS_HEIGHT; - -// if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; - -// DM_BOUNDS(gx, gy); -// DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; -// DisplayMatrixWhich[gx][gy] = ELEM_PADDING; - -// char buf[256]; -// int j; -// for(j = 0; j < POS_WIDTH; j++) { -// buf[j] = '-'; -// } -// buf[j] = '\0'; -// DrawChars(*cx, *cy + (POS_HEIGHT/2), buf); -// *cx += POS_WIDTH; -// } - -// *cx = cx0; -// int justDrewHeight = CountHeightOfElement(p->contents[i].which, -// p->contents[i].d.any); -// *cy += POS_HEIGHT*justDrewHeight; - -// downBy += justDrewHeight; -// if(poweredThis) { -// lowestPowered = downBy - 1; -// } -// } -// *cx = cx0 + POS_WIDTH*widthMax; -// *cy = cy0; - -// int j; -// BOOL needWire; - -// if(*cx/POS_WIDTH != ColsAvailable) { -// needWire = FALSE; -// for(j = heightMax - 1; j >= 1; j--) { -// if(j <= lowestPowered) PoweredText(poweredAfter); -// if(DisplayMatrix[*cx/POS_WIDTH - 1][*cy/POS_HEIGHT + j]) { -// needWire = TRUE; -// } -// if(needWire) VerticalWire(*cx - 1, *cy + j*POS_HEIGHT); -// } -// // stupid special case -// if(lowestPowered == 0 && InSimulationMode) { -// EmphText(); -// DrawChars(*cx - 1, *cy + (POS_HEIGHT/2), "+"); -// } -// } - -// PoweredText(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); -// } - -// break; -// } -// default: -// poweredAfter = DrawLeaf(which, leaf, cx, cy, poweredBefore); -// break; -// } - - -// NormText(); -// return poweredAfter; + BOOL poweredAfter; + + int cx0 = *cx, cy0 = *cy; + ElemLeaf *leaf = (ElemLeaf *)elem; + + SetBkColor(DrawWindow,Hdc, InSimulationMode ? HighlightColours.simBg : + HighlightColours.bg); + NormText(); + + if(elem == Selected && !InSimulationMode) { + EmphText(); + ThisHighlighted = TRUE; + } else { + ThisHighlighted = FALSE; + } + + switch(which) { + case ELEM_SERIES_SUBCKT: { + int i; + ElemSubcktSeries *s = (ElemSubcktSeries *)elem; + poweredAfter = poweredBefore; + for(i = 0; i < s->count; i++) { + poweredAfter = DrawElement(s->contents[i].which, + s->contents[i].d.any, cx, cy, poweredAfter); + } + break; + } + case ELEM_PARALLEL_SUBCKT: { + int i; + ElemSubcktParallel *p = (ElemSubcktParallel *)elem; + int widthMax = CountWidthOfElement(which, elem, (*cx)/POS_WIDTH); + int heightMax = CountHeightOfElement(which, elem); + + poweredAfter = FALSE; + + int lowestPowered = -1; + int downBy = 0; + for(i = 0; i < p->count; i++) { + BOOL poweredThis; + + poweredThis = DrawElement(p->contents[i].which, + p->contents[i].d.any, cx, cy, poweredBefore); + + if(InSimulationMode) { + if(poweredThis) poweredAfter = TRUE; + PoweredText(poweredThis); + } + + while((*cx - cx0) < widthMax*POS_WIDTH) { + int gx = *cx/POS_WIDTH; + int gy = *cy/POS_HEIGHT; + + if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; + + DM_BOUNDS(gx, gy); + DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; + DisplayMatrixWhich[gx][gy] = ELEM_PADDING; + + char buf[256]; + int j; + for(j = 0; j < POS_WIDTH; j++) { + buf[j] = '-'; + } + buf[j] = '\0'; + DrawChars(*cx, *cy + (POS_HEIGHT/2), buf); + *cx += POS_WIDTH; + } + + *cx = cx0; + int justDrewHeight = CountHeightOfElement(p->contents[i].which, + p->contents[i].d.any); + *cy += POS_HEIGHT*justDrewHeight; + + downBy += justDrewHeight; + if(poweredThis) { + lowestPowered = downBy - 1; + } + } + *cx = cx0 + POS_WIDTH*widthMax; + *cy = cy0; + + int j; + BOOL needWire; + + if(*cx/POS_WIDTH != ColsAvailable) { + needWire = FALSE; + for(j = heightMax - 1; j >= 1; j--) { + if(j <= lowestPowered) PoweredText(poweredAfter); + if(DisplayMatrix[*cx/POS_WIDTH - 1][*cy/POS_HEIGHT + j]) { + needWire = TRUE; + } + if(needWire) VerticalWire(*cx - 1, *cy + j*POS_HEIGHT); + } + // stupid special case + if(lowestPowered == 0 && InSimulationMode) { + EmphText(); + DrawChars(*cx - 1, *cy + (POS_HEIGHT/2), "+"); + } + } + + PoweredText(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); + } + + break; + } + default: + poweredAfter = DrawLeaf(which, leaf, cx, cy, poweredBefore); + break; + } + + + NormText(); + return poweredAfter; } //----------------------------------------------------------------------------- @@ -1055,16 +1055,16 @@ BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) //----------------------------------------------------------------------------- void DrawEndRung(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(cx + i, cy + (POS_HEIGHT/2), str); -// i += strlen(str); -// for(; i < ColsAvailable*POS_WIDTH; i++) { -// DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); -// } + 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(cx + i, cy + (POS_HEIGHT/2), str); + i += strlen(str); + for(; i < ColsAvailable*POS_WIDTH; i++) { + DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); + } } diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp index 3788ff8..5721d34 100644 --- a/ldmicro/draw_outputdev.cpp +++ b/ldmicro/draw_outputdev.cpp @@ -31,8 +31,7 @@ #include "ldmicro.h" -void (*DrawChars)(int, int, char *); -GtkSettings *SettingsInstance; +void (*DrawChars)(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. @@ -97,79 +96,79 @@ void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time) // Output a string to the screen at a particular location, in character- // sized units. //----------------------------------------------------------------------------- -static void DrawCharsToScreen(int cx, int cy, char *str) +static void DrawCharsToScreen(int cx, int cy, const char *str) { - // cy -= ScrollYOffset*POS_HEIGHT; - // if(cy < -2) return; - // if(cy*FONT_HEIGHT + Y_PADDING > IoListTop) return; - - // COLORREF prev; - // BOOL firstTime = TRUE; - // BOOL inNumber = FALSE; - // BOOL inComment = FALSE; - // int inBrace = 0; - // for(; *str; str++, cx++) { - // int x = cx*FONT_WIDTH + X_PADDING; - // int y = cy*FONT_HEIGHT + Y_PADDING; - - // BOOL hiOk = !(InSimulationMode || ThisHighlighted); - - // if(strchr("{}[]", *str) && hiOk && !inComment) { - // if(*str == '{' || *str == '[') inBrace++; - // if(inBrace == 1) { - // prev = GetTextColor(Hdc); - // SetTextColor(Hdc, HighlightColours.punct); - // TextOut(Hdc, x, y, str, 1); - // SetTextColor(Hdc, prev); - // } else { - // TextOut(Hdc, x, y, str, 1); - // } - // if(*str == ']' || *str == '}') inBrace--; - // } else if(( - // (isdigit(*str) && (firstTime || isspace(str[-1]) - // || str[-1] == ':' || str[-1] == '[')) || - // (*str == '-' && isdigit(str[1]))) && hiOk && !inComment) - // { - // prev = GetTextColor(Hdc); - // SetTextColor(Hdc, HighlightColours.lit); - // TextOut(Hdc, x, y, str, 1); - // SetTextColor(Hdc, prev); - // inNumber = TRUE; - // } else if(*str == '\x01') { - // cx--; - // if(hiOk) { - // prev = GetTextColor(Hdc); - // SetTextColor(Hdc, HighlightColours.op); - // } - // } else if(*str == '\x02') { - // cx--; - // if(hiOk) { - // SetTextColor(Hdc, prev); - // inComment = FALSE; - // } - // } else if(*str == '\x03') { - // cx--; - // if(hiOk) { - // prev = GetTextColor(Hdc); - // SetTextColor(Hdc, HighlightColours.comment); - // inComment = TRUE; - // } - // } else if(inNumber) { - // if(isdigit(*str) || *str == '.') { - // prev = GetTextColor(Hdc); - // SetTextColor(Hdc, HighlightColours.lit); - // TextOut(Hdc, x, y, str, 1); - // SetTextColor(Hdc, prev); - // } else { - // TextOut(Hdc, x, y, str, 1); - // inNumber = FALSE; - // } - // } else { - // TextOut(Hdc, x, y, str, 1); - // } + cy -= ScrollYOffset*POS_HEIGHT; + if(cy < -2) return; + if(cy*FONT_HEIGHT + Y_PADDING > IoListTop) return; + + COLORREF prev; + BOOL firstTime = TRUE; + BOOL inNumber = FALSE; + BOOL inComment = FALSE; + int inBrace = 0; + for(; *str; str++, cx++) { + int x = cx*FONT_WIDTH + X_PADDING; + int y = cy*FONT_HEIGHT + Y_PADDING; + + BOOL hiOk = !(InSimulationMode || ThisHighlighted); + + 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); + } else { + TextOut(DrawWindow, Hdc, x, y, str, 1); + } + if(*str == ']' || *str == '}') inBrace--; + } else if(( + (isdigit(*str) && (firstTime || isspace(str[-1]) + || 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); + inNumber = TRUE; + } else if(*str == '\x01') { + cx--; + if(hiOk) { + prev = GetTextColor(Hdc); + SetTextColor(Hdc, HighlightColours.op); + } + } else if(*str == '\x02') { + cx--; + if(hiOk) { + SetTextColor(Hdc, prev); + inComment = FALSE; + } + } else if(*str == '\x03') { + cx--; + if(hiOk) { + prev = GetTextColor(Hdc); + SetTextColor(Hdc, 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); + } else { + TextOut(DrawWindow, Hdc, x, y, str, 1); + inNumber = FALSE; + } + } else { + TextOut(DrawWindow, Hdc, x, y, str, 1); + } - // firstTime = FALSE; - // } + firstTime = FALSE; + } } //----------------------------------------------------------------------------- @@ -206,62 +205,12 @@ 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(HCRDC hcr) +void PaintWindow() { - /* - cairo_set_source_rgb(cr, Cairo_R, Cairo_G, Cairo_G); - - cairo_select_font_face(cr, "Purisa", - CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_WEIGHT_BOLD); - - cairo_set_font_size(cr, 20); - - cairo_move_to(cr, 20, height / 2.0); - cairo_show_text(cr, "-----------THIS IS A TEST DRAW----------"); - - cairo_fill (cr); - */ - - SetBkColor(DrawWindow, hcr, InSimulationMode ? HighlightColours.simBg : - HighlightColours.bg); - - SetTextColor(hcr, InSimulationMode ? HighlightColours.simRungNum : - HighlightColours.rungNum); - - SelectObject(hcr, FixedWidthFont); - - TextOut(hcr, 5, 100, "-------] [-------------------------------------------------------------------------------------------------------------------------------------------------{RES}-------", 14); - // static HBITMAP BackBitmap; - // static HDC BackDc; - // static int BitmapWidth; - ok(); - - // RECT r; - // GetClientRect(MainWindow, &r); - + int bw = gtk_widget_get_allocated_width (DrawWindow);// = r.right; int bh = IoListTop; - - // HDC paintDc; - // if(!BackDc) { - // HWND desktop = GetDesktopWindow(); - // RECT dk; - // GetClientRect(desktop, &dk); - - // BitmapWidth = max(2000, dk.right + 300); - // BackBitmap = CreateCompatibleBitmap(Hdc, BitmapWidth, dk.bottom + 300); - // BackDc = CreateCompatibleDC(Hdc); - // SelectObject(BackDc, BackBitmap); - // } - // paintDc = Hdc; - // Hdc = BackDc; - - // RECT fi; - // fi.left = 0; fi.top = 0; - // fi.right = BitmapWidth; fi.bottom = bh; - // FillRect(Hdc, &fi, InSimulationMode ? SimBgBrush : BgBrush); /// now figure out how we should draw the ladder logic ColsAvailable = ProgCountWidestRow(); @@ -288,79 +237,79 @@ void PaintWindow(HCRDC hcr) if(((cy + thisHeight) >= (ScrollYOffset - 8)*POS_HEIGHT) && (cy < (ScrollYOffset + rowsAvailable + 8)*POS_HEIGHT)) { - SetBkColor(DrawWindow, hcr, InSimulationMode ? HighlightColours.simBg : + SetBkColor(DrawWindow, Hdc, InSimulationMode ? HighlightColours.simBg : HighlightColours.bg); - SetTextColor(hcr, InSimulationMode ? HighlightColours.simRungNum : + SetTextColor(Hdc, InSimulationMode ? HighlightColours.simRungNum : HighlightColours.rungNum); - SelectObject(hcr, FixedWidthFont); + SelectObject(Hdc, FixedWidthFont); int rung = i + 1; int y = Y_PADDING + FONT_HEIGHT*cy; int yp = y + FONT_HEIGHT*(POS_HEIGHT/2) - POS_HEIGHT*FONT_HEIGHT*ScrollYOffset; - + if(rung < 10) { char r[1] = { rung + '0' }; - TextOut(hcr, 8 + FONT_WIDTH, yp, r, 1); + TextOut(DrawWindow, Hdc, 8 + FONT_WIDTH, yp, r, 1); } else { char r[2] = { (rung / 10) + '0', (rung % 10) + '0' }; - TextOut(hcr, 8, yp, r, 2); + TextOut(DrawWindow, Hdc, 8, yp, r, 2); } - // int cx = 0; - // // DrawElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy, - // // Prog.rungPowered[i]); + int cx = 0; + DrawElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy, + Prog.rungPowered[i]); } cy += thisHeight; cy += POS_HEIGHT; } - // cy -= 2; - // // DrawEndRung(0, cy); - - // if(SelectedGxAfterNextPaint >= 0) { - // // MoveCursorNear(SelectedGxAfterNextPaint, SelectedGyAfterNextPaint); - // // InvalidateRect(MainWindow, NULL, FALSE); - // // SelectedGxAfterNextPaint = -1; - // // SelectedGyAfterNextPaint = -1; - // } else if(ScrollSelectedIntoViewAfterNextPaint && Selected) { - // // SelectElement(-1, -1, Selected->selectedState); - // // ScrollSelectedIntoViewAfterNextPaint = FALSE; - // // InvalidateRect(MainWindow, NULL, FALSE); - // } else { - // if(!SelectionActive) { - // if(Prog.numRungs > 0) { - // // if(MoveCursorTopLeft()) { - // // InvalidateRect(MainWindow, NULL, FALSE); - // // } - // } - // } - // } - - // /// draw the `buses' at either side of the screen - // // r.left = X_PADDING - FONT_WIDTH; - // // r.top = 0; - // // r.right = r.left + 4; - // // r.bottom = IoListTop; - // // FillRect(Hdc, &r, InSimulationMode ? BusLeftBrush : BusBrush); + cy -= 2; + DrawEndRung(0, cy); + + if(SelectedGxAfterNextPaint >= 0) { + MoveCursorNear(SelectedGxAfterNextPaint, SelectedGyAfterNextPaint); + InvalidateRect(DrawWindow, NULL, FALSE); + SelectedGxAfterNextPaint = -1; + SelectedGyAfterNextPaint = -1; + } else if(ScrollSelectedIntoViewAfterNextPaint && Selected) { + SelectElement(-1, -1, Selected->selectedState); + ScrollSelectedIntoViewAfterNextPaint = FALSE; + InvalidateRect(DrawWindow, NULL, FALSE); + } else { + if(!SelectionActive) { + if(Prog.numRungs > 0) { + if(MoveCursorTopLeft()) { + InvalidateRect(DrawWindow, NULL, FALSE); + } + } + } + } - // // r.left += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; - // // r.right += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; - // // FillRect(Hdc, &r, InSimulationMode ? BusRightBus : BusBrush); + /// draw the `buses' at either side of the screen + RECT r; + r.left = X_PADDING - FONT_WIDTH; + r.top = 0; + r.right = r.left + 4; + r.bottom = IoListTop; + FillRect(Hdc, &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); - // CursorDrawn = FALSE; + CursorDrawn = FALSE; - // // BitBlt(paintDc, 0, 0, bw, bh, BackDc, ScrollXOffset, 0, SRCCOPY); + // BitBlt(paintDc, 0, 0, bw, bh, BackDc, ScrollXOffset, 0, SRCCOPY); // if(InSimulationMode) { - // // KillTimer(MainWindow, TIMER_BLINK_CURSOR); + // KillTimer(MainWindow, TIMER_BLINK_CURSOR); // } else { - // // KillTimer(MainWindow, TIMER_BLINK_CURSOR); - // // BlinkCursor(NULL, 0, NULL, 0); - // // SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor); + // KillTimer(MainWindow, TIMER_BLINK_CURSOR); + // BlinkCursor(NULL, 0, NULL, 0); + // SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor); // } - // // Hdc = paintDc; - // ok(); + // Hdc = paintDc; + ok(); } //----------------------------------------------------------------------------- @@ -415,7 +364,7 @@ void InitForDrawing(void) FixedWidthFontBold = CreateFont( FONT_HEIGHT, FONT_WIDTH, 0, - FW_REGULAR, // the bold text renders funny under Vista + FW_BOLD, // the bold text renders funny under Vista FALSE, "Lucida Console"); @@ -426,7 +375,7 @@ void InitForDrawing(void) lb.lbColor = HighlightColours.simBusLeft; BusLeftBrush = CreateBrushIndirect(&lb); - + lb.lbColor = HighlightColours.bus; BusBrush = CreateBrushIndirect(&lb); diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h index 6513078..719a256 100644 --- a/ldmicro/includes/ldmicro.h +++ b/ldmicro/includes/ldmicro.h @@ -631,9 +631,9 @@ extern BOOL SelectionActive; extern BOOL ThisHighlighted; // draw_outputdev.cpp -extern void (*DrawChars)(int, int, char *); +extern void (*DrawChars)(int, int, const char *); void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time); -void PaintWindow(cairo_t *cr); +void PaintWindow(); 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 0d02d8d..c2e2e25 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -1041,6 +1041,12 @@ gboolean LD_WM_MouseMove_call(GtkWidget *widget, GdkEvent *event, gpointer user_ * WM_MOUSEMOVE */ +<<<<<<< HEAD +======= + // g_print("x = %f\n", event->button.x_root); + // g_print("y = %f\n", event->button.y_root); + +>>>>>>> akshay-c-GUI_port // int x = LOWORD(lParam); // int y = HIWORD(lParam); @@ -1065,16 +1071,23 @@ gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data) // GtkStyleContext *context; // context = gtk_widget_get_style_context (widget); - + // 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_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), @@ -1082,54 +1095,11 @@ gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data) // gdk_cairo_set_source_rgba (cr, &color); // cairo_fill (cr); - // static double Cairo_R = 0.0, Cairo_G = 0.0, Cairo_B = 0.0; - // cairo_set_source_rgb(cr, Cairo_R, Cairo_G, Cairo_G); - // Cairo_R = (Cairo_R+0.2 > 0.4) ? 0 : Cairo_R+0.2; - // Cairo_G = (Cairo_G+0.4 > 1.0) ? 0.4 : Cairo_G+0.4; - // Cairo_B = (Cairo_B+0.1 > 0.5) ? 0 : Cairo_B+0.1; - - // cairo_select_font_face(cr, "Purisa", - // CAIRO_FONT_SLANT_NORMAL, - // CAIRO_FONT_WEIGHT_BOLD); - - // cairo_set_font_size(cr, 20); - // cairo_move_to(cr, 20, height / 2.0); - // cairo_show_text(cr, "-----------THIS IS A TEST DRAW----------"); - - // cairo_fill (cr); - - - // PAINTSTRUCT ps; - // Hdc = BeginPaint(hwnd, &ps); + Hdc = cr; /// This draws the schematic. - PaintWindow(cr); - - // RECT r; - // // Fill around the scroll bars - // if(NeedHoriz) { - // r.top = IoListTop - ScrollHeight - 2; - // r.bottom = IoListTop - 2; - // FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH)); - // } - // GetClientRect(MainWindow, &r); - // r.left = r.right - ScrollWidth - 2; - // FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH)); - - // // Draw the splitter thing to grab to resize the I/O listview. - // GetClientRect(MainWindow, &r); - // r.top = IoListTop - 2; - // r.bottom = IoListTop; - // FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH)); - // r.top = IoListTop - 2; - // r.bottom = IoListTop - 1; - // FillRect(Hdc, &r, (HBRUSH)GetStockObject(WHITE_BRUSH)); - // r.top = IoListTop; - // r.bottom = IoListTop + 1; - // FillRect(Hdc, &r, (HBRUSH)GetStockObject(DKGRAY_BRUSH)); - - // EndPaint(hwnd, &ps); + PaintWindow(); return FALSE; } @@ -1154,8 +1124,7 @@ gboolean LD_WM_Size_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) * WM_SIZE */ - // MainWindowResized(); - // break; + MainWindowResized(); return FALSE; } @@ -1166,8 +1135,7 @@ gboolean LD_WM_SetFocus_call(GtkWidget *widget, GdkEvent *event, gpointer user_d * WM_SETFOCUS */ - // InvalidateRect(MainWindow, NULL, FALSE); - // break; + InvalidateRect(DrawWindow, NULL, FALSE); return FALSE; } @@ -1180,18 +1148,17 @@ int main(int argc, char** argv) /// Check if we're running in non-interactive mode; in that case we should /// load the file, compile, and exit. - if(argc >= 2) { + if(argc >= 2 && !(argc < 4) ) { RunningInBatchMode = TRUE; char *err = "Bad command line arguments: run 'ldmicro /c src.ld dest.hex'"; - if (argc < 4) - { - printf("throwing error...\n"); - Error(err); - exit(-1); - } + // if (argc < 4) + // { + // Error(err); + // exit(-1); + // } char *source = (char*)malloc(strlen(argv[2]) + strlen(argv[3]) + 2); sprintf(source, "%s %s", argv[2], argv[3]); @@ -1284,7 +1251,7 @@ int main(int argc, char** argv) gtk_window_resize (GTK_WINDOW(MainWindow), 800, 600); gtk_window_move(GTK_WINDOW(MainWindow), 10, 10); gtk_widget_override_background_color(GTK_WIDGET(MainWindow), - GTK_STATE_FLAG_NORMAL, ((HBRUSH)GetStockObject(GREY_BRUSH))->getThis()); + GTK_STATE_FLAG_NORMAL, ((HBRUSH)GetStockObject(GRAY_BRUSH))->getThis()); gtk_window_set_default_icon(LoadImage(Instance, LDMICRO_ICON, IMAGE_ICON, 32, 32, 0)); gtk_window_set_icon(GTK_WINDOW(MainWindow), LoadImage(Instance, LDMICRO_ICON, @@ -1315,36 +1282,42 @@ int main(int argc, char** argv) /// Keyboard and mouse hooks equivalent to MainWndProc - end NewProgram(); +<<<<<<< HEAD // strcpy(CurrentSaveFile, ""); +======= + strcpy(CurrentSaveFile, ""); +>>>>>>> akshay-c-GUI_port // We are running interactively, or we would already have exited. We // can therefore show the window now, and otherwise set up the GUI. - // ShowWindow(MainWindow, SW_SHOW); + // Displaying the window + gtk_widget_show_all(MainWindow); // SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor); - // if(strlen(lpCmdLine) > 0) { - // char line[MAX_PATH]; - // if(*lpCmdLine == '"') { - // strcpy(line, lpCmdLine+1); - // } else { - // strcpy(line, lpCmdLine); - // } - // if(strchr(line, '"')) *strchr(line, '"') = '\0'; - - // char *s; - // GetFullPathName(line, sizeof(CurrentSaveFile), CurrentSaveFile, &s); - // if(!LoadProjectFromFile(CurrentSaveFile)) { - // NewProgram(); - // Error(_("Couldn't open '%s'."), CurrentSaveFile); - // CurrentSaveFile[0] = '\0'; - // } - // UndoFlush(); - // } + if(argc >= 2) { + // g_print("load prog: %s\n", argv[1]); + char line[MAX_PATH]; + if(*argv[1] == '"') { + strcpy(line, argv[1]+1); + } else { + strcpy(line, argv[1]); + } + if(strchr(line, '"')) *strchr(line, '"') = '\0'; + + realpath(line, CurrentSaveFile); + // g_print("resolved path: %s\n", CurrentSaveFile); + if(!LoadProjectFromFile(CurrentSaveFile)) { + NewProgram(); + Error(_("Couldn't open '%s'."), CurrentSaveFile); + CurrentSaveFile[0] = '\0'; + } + UndoFlush(); + } - // GenerateIoListDontLoseSelection(); ~ + GenerateIoListDontLoseSelection(); //~ // RefreshScrollbars(); - // UpdateMainWindowTitleBar(); ~ + UpdateMainWindowTitleBar(); //~ // MSG msg; // DWORD ret; @@ -1367,9 +1340,6 @@ int main(int argc, char** argv) // TranslateMessage(&msg); // DispatchMessage(&msg); // } - - // Displaying the window - gtk_widget_show_all(MainWindow); gtk_main(); return EXIT_SUCCESS; diff --git a/ldmicro/lib/freezeLD/freezeLD.cpp b/ldmicro/lib/freezeLD/freezeLD.cpp index ea3fae2..880dfab 100644 --- a/ldmicro/lib/freezeLD/freezeLD.cpp +++ b/ldmicro/lib/freezeLD/freezeLD.cpp @@ -24,15 +24,16 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name) if (!Ld_CWD) return; - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + char* moveToKeyLocatin = (char *)malloc(strlen(name) + MAX_PATH); if(!moveToKeyLocatin) { free(Ld_CWD); return; } - sprintf(moveToKeyLocatin, "mkdir -p %s/%s", FREEZE_REGISTER, subKey); + + sprintf(moveToKeyLocatin, "mkdir -p %s/%s/%s", getenv("HOME"), FREEZE_REGISTER, subKey); system(moveToKeyLocatin); - sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey); + sprintf(moveToKeyLocatin, "%s/%s/%s", getenv("HOME"), FREEZE_REGISTER, subKey); if (-1 == chdir(moveToKeyLocatin)) { free(Ld_CWD); @@ -148,13 +149,14 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name) if (!Ld_CWD) return; - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + char* moveToKeyLocatin = (char *)malloc(strlen(name) + MAX_PATH); if(!moveToKeyLocatin) { free(Ld_CWD); return; } - sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey); + + sprintf(moveToKeyLocatin, "%s/%s/%s", getenv("HOME"), FREEZE_REGISTER, subKey); if (-1 == chdir(moveToKeyLocatin)) { free(Ld_CWD); @@ -162,8 +164,8 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name) return; } free(moveToKeyLocatin); - - char *keyName = (char *)malloc(strlen(name) + 30); + + char *keyName = (char *)malloc(strlen(name) + MAX_PATH); if(!keyName) { free(Ld_CWD); @@ -257,15 +259,16 @@ void FreezeDWORDF(DWORD val, char *subKey, char *name) if (!Ld_CWD) return; - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + char* moveToKeyLocatin = (char *)malloc(strlen(name) + MAX_PATH); if(!moveToKeyLocatin) { free(Ld_CWD); return; } - sprintf(moveToKeyLocatin, "mkdir -p %s/%s", FREEZE_REGISTER, subKey); + + sprintf(moveToKeyLocatin, "mkdir -p %s/%s/%s", getenv("HOME"), FREEZE_REGISTER, subKey); system(moveToKeyLocatin); - sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey); + sprintf(moveToKeyLocatin, "%s/%s/%s", getenv("HOME"), FREEZE_REGISTER, subKey); if (-1 == chdir(moveToKeyLocatin)) { free(Ld_CWD); @@ -296,13 +299,14 @@ DWORD ThawDWORDF(DWORD val, char *subKey, char *name) if (!Ld_CWD) return val; - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + char* moveToKeyLocatin = (char *)malloc(strlen(name) + MAX_PATH); if(!moveToKeyLocatin) { free(Ld_CWD); return val; } - sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey); + + sprintf(moveToKeyLocatin, "%s/%s/%s", getenv("HOME"), FREEZE_REGISTER, subKey); if (-1 == chdir(moveToKeyLocatin)) { free(Ld_CWD); @@ -340,15 +344,16 @@ void FreezeStringF(char *val, char *subKey, char *name) if (!Ld_CWD) return; - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + char* moveToKeyLocatin = (char *)malloc(strlen(name) + MAX_PATH); if(!moveToKeyLocatin) { free(Ld_CWD); return; } - sprintf(moveToKeyLocatin, "mkdir -p %s/%s", FREEZE_REGISTER, subKey); + + sprintf(moveToKeyLocatin, "mkdir -p %s/%s/%s", getenv("HOME"), FREEZE_REGISTER, subKey); system(moveToKeyLocatin); - sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey); + sprintf(moveToKeyLocatin, "%s/%s/%s", getenv("HOME"), FREEZE_REGISTER, subKey); if (-1 == chdir(moveToKeyLocatin)) { free(Ld_CWD); @@ -356,7 +361,7 @@ void FreezeStringF(char *val, char *subKey, char *name) return; } free(moveToKeyLocatin); - + std::ofstream Register(name, std::ios::trunc); Register << strlen(val)+1 << "\n"; Register << val; @@ -377,13 +382,14 @@ void ThawStringF(char *val, int max, char *subKey, char *name) if (!Ld_CWD) return; - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + char* moveToKeyLocatin = (char *)malloc(strlen(name) + MAX_PATH); if(!moveToKeyLocatin) { free(Ld_CWD); return; } - sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey); + + sprintf(moveToKeyLocatin, "%s/%s/%s", getenv("HOME"), FREEZE_REGISTER, subKey); if (-1 == chdir(moveToKeyLocatin)) { free(Ld_CWD); diff --git a/ldmicro/lib/freezeLD/freezeLD.h b/ldmicro/lib/freezeLD/freezeLD.h index 5c00504..581466d 100644 --- a/ldmicro/lib/freezeLD/freezeLD.h +++ b/ldmicro/lib/freezeLD/freezeLD.h @@ -10,7 +10,7 @@ #ifndef __FREEZE_H #define __FREEZE_H -#define FREEZE_REGISTER "/usr/share/ldmicro" +#define FREEZE_REGISTER ".ldmicro" #define FREEZE_SUBKEY "LDMicro" diff --git a/ldmicro/lib/linuxUI/linuxLD.cpp b/ldmicro/lib/linuxUI/linuxLD.cpp index cdeb190..a83d15e 100644 --- a/ldmicro/lib/linuxUI/linuxLD.cpp +++ b/ldmicro/lib/linuxUI/linuxLD.cpp @@ -1,4 +1,7 @@ #include "linuxUI.h" +#include <iostream> + +using namespace std; std::vector<HEAPRECORD> HeapRecords; @@ -7,7 +10,7 @@ HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize) HANDLE hHeap = NULL; HEAPRECORD hHeapRecord; hHeapRecord.dwMaximumSize = dwMaximumSize; - hHeap = malloc(dwInitialSize); + // hHeap = malloc(dwInitialSize); if (hHeap == NULL) return NULL; @@ -23,79 +26,79 @@ HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize) LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes) { - if (hHeap == NULL) - { + // if (hHeap == NULL) + // { // printf("Alloc**********NULL HEAP***************\n"); LPVOID p = malloc(dwBytes); return p; - } + // } - auto it = std::find_if(HeapRecords.begin(), HeapRecords.end(), [&hHeap](HEAPRECORD &Record) { return Record.hHeap == hHeap; }); + // auto it = std::find_if(HeapRecords.begin(), HeapRecords.end(), [&hHeap](HEAPRECORD &Record) { return Record.hHeap == hHeap; }); - if (it == HeapRecords.end()) - return NULL; - - if ((*it).dwAllocatedSizeOffset + dwBytes > (*it).dwSize) - { - if ((*it).dwMaximumSize != 0) - if((*it).dwAllocatedSizeOffset + dwBytes > (*it).dwMaximumSize) - return NULL; + // if (it == HeapRecords.end()) + // return NULL; + + // if ((*it).dwAllocatedSizeOffset + dwBytes > (*it).dwSize) + // { + // if ((*it).dwMaximumSize != 0) + // if((*it).dwAllocatedSizeOffset + dwBytes > (*it).dwMaximumSize) + // return NULL; - (*it).hHeap = realloc((*it).hHeap, (*it).dwAllocatedSizeOffset + dwBytes); - hHeap = (*it).hHeap; - } + // (*it).hHeap = realloc((*it).hHeap, (*it).dwAllocatedSizeOffset + dwBytes); + // hHeap = (*it).hHeap; + // } - /// HEAP_ZERO_MEMORY is set by default - DWORD flags = MAP_ANONYMOUS; + // /// HEAP_ZERO_MEMORY is set by default + // DWORD flags = MAP_ANONYMOUS; - // if ( !((dwFlags & HEAP_ZERO_MEMORY) == HEAP_ZERO_MEMORY) ) - // flags = MAP_ANONYMOUS | MAP_UNINITIALIZED; + // // if ( !((dwFlags & HEAP_ZERO_MEMORY) == HEAP_ZERO_MEMORY) ) + // // flags = MAP_ANONYMOUS | MAP_UNINITIALIZED; - /* Use for setting a meamory chunck with some value - * void * memset ( void * ptr, int value, size_t num ); - */ - LPVOID p = mmap(hHeap + (*it).dwAllocatedSizeOffset, dwBytes, PROT_EXEC, flags, -1, 0); + // /* Use for setting a meamory chunck with some value + // * void * memset ( void * ptr, int value, size_t num ); + // */ + // LPVOID p = mmap(hHeap + (*it).dwAllocatedSizeOffset, dwBytes, PROT_EXEC, flags, -1, 0); - if (p == NULL) - return NULL; + // if (p == NULL) + // return NULL; - (*it).dwAllocatedSizeOffset += dwBytes; - HEAPCHUNCK chunck; - chunck.Chunck = p; - chunck.dwSize = dwBytes; - (*it).Element.push_back(chunck); - - return p; + // (*it).dwAllocatedSizeOffset += dwBytes; + // HEAPCHUNCK chunck; + // chunck.Chunck = p; + // chunck.dwSize = dwBytes; + // (*it).Element.push_back(chunck); + + // return p; } BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem) { /// if NULL free() - if (hHeap == NULL) - { + // if (hHeap == NULL) + // { // printf("free*********NULL HEAP***************\n"); free(lpMem); return TRUE; - } - auto heap_it = std::find_if(HeapRecords.begin(), HeapRecords.end(), [&hHeap](HEAPRECORD &Record) { return Record.hHeap == hHeap; }); + // } + // auto heap_it = std::find_if(HeapRecords.begin(), HeapRecords.end(), [&hHeap](HEAPRECORD &Record) { return Record.hHeap == hHeap; }); - if (heap_it == HeapRecords.end()) - return FALSE; + // if (heap_it == HeapRecords.end()) + // return FALSE; - auto chunck_it = std::find_if((*heap_it).Element.begin(), (*heap_it).Element.end(), [&lpMem](HEAPCHUNCK &Chunck) { return Chunck.Chunck == lpMem; }); + // auto chunck_it = std::find_if((*heap_it).Element.begin(), (*heap_it).Element.end(), [&lpMem](HEAPCHUNCK &Chunck) { return Chunck.Chunck == lpMem; }); - if (chunck_it == (*heap_it).Element.end()) - return FALSE; + // if (chunck_it == (*heap_it).Element.end()) + // return FALSE; - int result = munmap((*chunck_it).Chunck, (*chunck_it).dwSize); + // int result = munmap((*chunck_it).Chunck, (*chunck_it).dwSize); - if (result == 0) - { - (*heap_it).Element.erase(chunck_it); - return TRUE; - } - else - return FALSE; + // if (result == 0) + // { + // (*heap_it).Element.erase(chunck_it); + // return TRUE; + // } + // else + // return FALSE; } @@ -114,6 +117,14 @@ HICON LoadImage(HINSTANCE hinst, LPCTSTR lpszName, UINT uType, int cxDesired, return pixbuf; } +void RECT_to_GDRECT(const RECT *rc, GDRECT *gdrc) +{ + gdrc->x = rc->left; + gdrc->y = rc->top; + gdrc->width = rc->right - rc->left; + gdrc->height = rc->bottom - rc->top; +} + void OutputDebugString(char* str) { diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h index 5f8e0e7..8a3e3a2 100644 --- a/ldmicro/lib/linuxUI/linuxLD.h +++ b/ldmicro/lib/linuxUI/linuxLD.h @@ -24,6 +24,7 @@ /// Macro functions #define max(_A, _B) std::max(_A, _B) +// #define min(_A, _B) std::min(_A, _B) /// Typedefs //typedef int64_t __int64; @@ -73,6 +74,9 @@ typedef GtkListStore *HLIST; typedef GtkApplication *HAPP; typedef GtkTreeViewColumn *HTVC; typedef GdkPixbuf *HICON; +typedef GdkRectangle GDRECT; +typedef GdkRectangle *PGDRECT; + /// Check if system is x64 or x86 #if defined(__UNIX64) typedef uint64_t UINT_PTR; @@ -110,14 +114,6 @@ typedef class tagColorReferance: public GdkRGBA{ this->alpha = 1.0; } - // tagColorReferance(tagColorReferance &refCpy) - // { - // this->red = refCpy.red; - // this->green = refCpy.green; - // this->blue = refCpy.blue; - // this->alpha = refCpy.alpha; - // } - GdkRGBA* getThis() { return this; @@ -170,6 +166,13 @@ typedef struct tagLOGBRUSH { // ULONG_PTR lbHatch; } LOGBRUSH, *PLOGBRUSH; +typedef struct _RECT { + LONG left; + LONG top; + LONG right; + LONG bottom; +} RECT, *PRECT; + /// Variables extern std::vector<HEAPRECORD> HeapRecord; @@ -198,6 +201,10 @@ HICON LoadImage( UINT fuLoad ); +void RECT_to_GDRECT( + const RECT *rc, + GDRECT *gdrc); + /// functions to be ported void OutputDebugString(char*); double GetTickCount(void); diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index bbaa001..062d10c 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -1,6 +1,14 @@ #include "linuxUI.h" -void AddMenuAccelerators (void); +/// Brushes +const COLORREF BLACK_BR(0, 0, 0); +const COLORREF WHITE_BR(255, 255, 255); +const COLORREF GRAY_BR(128, 128, 128); +const COLORREF LTGRAY_BR(211, 211, 211); +const COLORREF DKGRAY_BR(169, 169, 169); + +/// Variable to current text color +COLORREF HdcCurrentTextColor; /// EnableMenuItem Variables const UINT MF_ENABLED = 0; @@ -188,16 +196,22 @@ HANDLE GetStockObject(int fnObject) switch(fnObject) { case BLACK_BRUSH: - return new COLORREF(0, 0, 0); + return (HANDLE)&BLACK_BR; break; case WHITE_BRUSH: - return new COLORREF(255, 255, 255); + return (HANDLE)&WHITE_BR; + break; + case GRAY_BRUSH: + return (HANDLE)&GRAY_BR; + break; + case LTGRAY_BRUSH: + return (HANDLE)<GRAY_BR; break; - case GREY_BRUSH: - return new COLORREF(128, 128, 128); + case DKGRAY_BRUSH: + return (HANDLE)&DKGRAY_BR; break; default: - return new COLORREF(255, 255, 255); + return (HANDLE)&WHITE_BR; } } @@ -208,27 +222,29 @@ void SelectObject(HCRDC hcr, HFONT hfont) hfont->fnWeight == FW_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL); cairo_rotate(hcr, hfont->nOrientation); - // cairo_text_extents_t extents; - // cairo_text_extents (hcr, "H", &extents); - + // cairo_text_extents (hcr, "Z", &extents); // cairo_matrix_t matrix; // cairo_matrix_init_scale (&matrix, - // (double)hfont->nWidth / extents.width, - // (double)hfont->nHeight / extents.width); + // (double)hfont->nWidth, + // (double)hfont->nHeight); // cairo_set_font_matrix (hcr, &matrix); + // g_print("wR = %f\nhR = %f\n", (double)hfont->nWidth / extents.width, (double)hfont->nHeight / extents.height); - // g_print("tW = %f\ntH = %f\n", extents.width, extents.width); - cairo_set_font_size(hcr, 15); + // g_print("tW = %f tH = %f\n", extents.width, extents.width); + cairo_set_font_size(hcr, 10); } HBRUSH CreateBrushIndirect(PLOGBRUSH plb) { - COLORREF brush(plb->lbColor); - brush.alpha = (plb->lbStyle == BS_SOLID) ? 1 : 0.2; + COLORREF* brush = new COLORREF; + brush->red = plb->lbColor.red; + brush->green = plb->lbColor.green; + brush->blue = plb->lbColor.blue; + brush->alpha = (plb->lbStyle == BS_SOLID) ? 1 : 0.2; - return &brush; + return brush; } HFONT CreateFont(int nHeight, int nWidth, int nOrientation, int fnWeight, @@ -268,13 +284,121 @@ void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol) void SetTextColor(HCRDC hcr, COLORREF color) { + HdcCurrentTextColor = color; gdk_cairo_set_source_rgba (hcr, &color); } -void TextOut(HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, int cchString) +void TextOut(HWID hWid, HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, int cchString) { + nYStart += 20; + + cairo_text_extents_t extents; + cairo_text_extents (hcr, lpString, &extents); + int width = gtk_widget_get_allocated_width (hWid); + int height= gtk_widget_get_allocated_height (hWid); + BOOL resize_flag = FALSE; + // g_print("w = %f h = %f") + + if(nYStart+(extents.height/2.0) >= height) + { + height += extents.height; + resize_flag = TRUE; + } + + if (nXStart+(extents.width/2.0) >= width) + { + width += extents.width; + resize_flag = TRUE; + } + + if (resize_flag) + gtk_widget_set_size_request(hWid, width, height); + char* text = (char*)malloc(cchString); + strncpy(text, lpString, cchString); + text[cchString] = '\0'; + cairo_move_to(hcr, nXStart, nYStart); - cairo_show_text(hcr, lpString); + cairo_show_text(hcr, text); cairo_fill (hcr); +} + +COLORREF GetTextColor(HCRDC Hdc) +{ + // COLORREF col; + // gtk_style_context_get_color (Hdc, + // gtk_style_context_get_state (Hdc), + // &col); + + return HdcCurrentTextColor; +} + +BOOL InvalidateRect(HWID hWid, const RECT *lpRect, BOOL bErase) +{ + if(!GDK_IS_WINDOW(hWid)) + return FALSE; + + if (lpRect == NULL) + { + gdk_window_invalidate_rect (gtk_widget_get_window (hWid), NULL, FALSE); + return TRUE; + } + + GDRECT Gdrect; + RECT_to_GDRECT(lpRect, &Gdrect); + // gtk_widget_queue_draw(hWid); + gdk_window_invalidate_rect (gtk_widget_get_window (hWid), &Gdrect, FALSE); + + return TRUE; +} + +int FillRect(HCRDC hDC, const RECT *lprc, HBRUSH hbr) +{ + GDRECT gdrc; + RECT_to_GDRECT(lprc, &gdrc); + + cairo_set_source_rgb(hDC, hbr->red, hbr->green, hbr->blue); + cairo_rectangle(hDC, gdrc.x, gdrc.y, gdrc.width, gdrc.height); + cairo_stroke_preserve(hDC); + cairo_fill(hDC); + + return 0; +} + +BOOL GetClientRect(HWID hWid, PRECT pRect) +{ + GtkAllocation allocation; + gtk_widget_get_allocation (hWid, &allocation); + + pRect->top = allocation.x; + pRect->left = allocation.y; + pRect->right = allocation.width; + pRect->bottom = allocation.height; + + return TRUE; +} + +BOOL MoveWindow(HWID hWid, int X, int Y, int nWidth, int nHeight, BOOL bRepaint) +{ + gtk_window_move(GTK_WINDOW(hWid), X, Y); + gtk_window_resize(GTK_WINDOW(hWid), nWidth, nHeight); + + if (bRepaint) + gdk_window_invalidate_rect (gtk_widget_get_window (hWid), NULL, FALSE); + + return TRUE; +} + + +BOOL GetWindowRect(HWID hWid, PRECT pRect) +{ + GtkAllocation allocation; + gtk_widget_get_allocation (hWid, &allocation); + + pRect->top = allocation.x; + pRect->left = allocation.y; + pRect->right = allocation.width; + pRect->bottom = allocation.height; + + return TRUE; }
\ No newline at end of file diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h index 08dab39..961822f 100644 --- a/ldmicro/lib/linuxUI/linuxUI.h +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -18,36 +18,44 @@ /// Flags /// message box -#define MB_OK 0x00000001L -#define MB_OKCANCEL 0x00000002L -#define MB_YESNO 0x00000004L -#define MB_YESNOCANCEL 0x00000008L +#define MB_OK 0x00000001L +#define MB_OKCANCEL 0x00000002L +#define MB_YESNO 0x00000004L +#define MB_YESNOCANCEL 0x00000008L -#define IDOK 1 -#define IDCANCEL 2 -#define IDYES 3 -#define IDNO 4 +#define IDOK 1 +#define IDCANCEL 2 +#define IDYES 3 +#define IDNO 4 -#define MB_ICONERROR 0x00000010L -#define MB_ICONQUESTION 0x00000020L -#define MB_ICONWARNING 0x00000040L -#define MB_ICONINFORMATION 0x00000080L +#define MB_ICONERROR 0x00000010L +#define MB_ICONQUESTION 0x00000020L +#define MB_ICONWARNING 0x00000040L +#define MB_ICONINFORMATION 0x00000080L /// open/save file -#define OFN_PATHMUSTEXIST 0x00000100L -#define OFN_HIDEREADONLY 0x00000200L -#define OFN_OVERWRITEPROMPT 0x00000400L +#define OFN_PATHMUSTEXIST 0x00000100L +#define OFN_HIDEREADONLY 0x00000200L +#define OFN_OVERWRITEPROMPT 0x00000400L /// window brushes -#define BS_SOLID 0x00000001L -#define BS_HOLLOW 0x00000002L -#define BLACK_BRUSH 0x00000004L -#define WHITE_BRUSH 0x00000008L -#define GREY_BRUSH 0x00000010L +#define BS_SOLID 0x00000001L +#define BS_HOLLOW 0x00000002L +#define BLACK_BRUSH 0x00000004L +#define WHITE_BRUSH 0x00000008L +#define GRAY_BRUSH 0x00000010L +#define LTGRAY_BRUSH 0x00000020L +#define DKGRAY_BRUSH 0x00000040L + +extern const COLORREF BLACK_BR; +extern const COLORREF WHITE_BR; +extern const COLORREF GRAY_BR; +extern const COLORREF LTGRAY_BR; +extern const COLORREF DKGRAY_BR; /// Font flags -#define FW_REGULAR 0x00000001L -#define FW_BOLD 0x00000002L +#define FW_REGULAR 0x00000001L +#define FW_BOLD 0x00000002L /// EnableMenuItem variables extern const UINT MF_ENABLED; @@ -63,7 +71,7 @@ extern GClosure* closure; extern HWID view; extern HTVC column; -/// data types +/// Structures typedef struct OpenFileInfoData { DWORD lStructSize; HWID parentWindow; @@ -75,53 +83,94 @@ typedef struct OpenFileInfoData { LPCTSTR lpstrDefExt; } OPENFILENAME; +/// Variables +extern COLORREF HdcCurrentTextColor; + /// functions BOOL isFocus(HWID window); -COLORREF RGB(int red, - int green, - int blue); +COLORREF RGB( + int red, + int green, + int blue); -int MessageBox(HWID pWindow, +int MessageBox( + HWID pWindow, char* message, char* title, UINT mFlags); BOOL GetSaveFileName(OPENFILENAME *ofn); -void EnableMenuItem(HMENU MenuName, +void EnableMenuItem( + HMENU MenuName, HMENU MenuItem, UINT CheckEnabledItem); -void CheckMenuItem(HMENU MenuName, +void CheckMenuItem( + HMENU MenuName, HMENU MenuItem, UINT Check); HANDLE GetStockObject(int fnObject); -void SelectObject(HCRDC hcr, +void SelectObject( + HCRDC hcr, HFONT hfont); HBRUSH CreateBrushIndirect(PLOGBRUSH plb); -HFONT CreateFont(int nHeight, +HFONT CreateFont( + int nHeight, int nWidth, int nOrientation, int fnWeight, DWORD fdwItalic, LPCTSTR lpszFace); -void SetBkColor(HWID widget, +void SetBkColor( + HWID widget, HCRDC hcr, COLORREF bkCol); -void SetTextColor(HCRDC hcr, +void SetTextColor( + HCRDC hcr, COLORREF color); -void TextOut(HCRDC hcr, - int nXStart, - int nYStart, - LPCTSTR lpString, - int cchString); +void TextOut( + HWID hWid, + HCRDC hcr, + int nXStart, + int nYStart, + LPCTSTR lpString, + int cchString); + +COLORREF GetTextColor(HCRDC Hdc); + +BOOL InvalidateRect( + HWID hWId, + const RECT *lpRect, + BOOL bErase); + +int FillRect( + HCRDC hDC, + const RECT *lprc, + HBRUSH hbr); + +BOOL GetClientRect( + HWID hWid, + PRECT lpRect); + +BOOL MoveWindow( + HWID hWid, + int X, + int Y, + int nWidth, + int nHeight, + BOOL bRepaint); + +BOOL GetWindowRect( + HWID hWid, + PRECT pRect); #endif
\ No newline at end of file diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp index 5921c3f..60f6a2b 100644 --- a/ldmicro/maincontrols.cpp +++ b/ldmicro/maincontrols.cpp @@ -105,9 +105,9 @@ HMENU AboutMenu; // scrollbars for the ladder logic area // static HWND HorizScrollBar; // static HWND VertScrollBar; -// int ScrollWidth; -// int ScrollHeight; -// BOOL NeedHoriz; +int ScrollWidth; +int ScrollHeight; +BOOL NeedHoriz; // status bar at the bottom of the screen, to display settings static HMENU StatusBar; @@ -994,10 +994,33 @@ void GenerateIoListDontLoseSelection(void) //----------------------------------------------------------------------------- void MainWindowResized(void) { + RECT main; + GetClientRect(DrawWindow, &main); + + RECT status; + GetWindowRect(StatusBar, &status); + int statusHeight = status.bottom - status.top; + + // MoveWindow(StatusBar, 0, main.bottom - statusHeight, main.right, + // statusHeight, TRUE); + // Make sure that the I/O list can't disappear entirely. if(IoListHeight < 30) { IoListHeight = 30; } + IoListTop = main.bottom ;//- IoListHeight - statusHeight; + + // Make sure that we can't drag the top of the I/O list above the + // bottom of the menu bar, because it then becomes inaccessible. + if(IoListTop < 5) { + IoListHeight = main.bottom - statusHeight - 5; + IoListTop = main.bottom - IoListHeight - statusHeight; + } + // MoveWindow(IoList, 0, IoListTop, main.right, IoListHeight, TRUE); + + RefreshScrollbars(); + + InvalidateRect(DrawWindow, NULL, FALSE); } //----------------------------------------------------------------------------- diff --git a/ldmicro/miscutil.cpp b/ldmicro/miscutil.cpp index 092f606..8f63398 100644 --- a/ldmicro/miscutil.cpp +++ b/ldmicro/miscutil.cpp @@ -23,9 +23,11 @@ #include "linuxUI.h" #include <stdio.h> #include <stdlib.h> - +#include <iostream> #include "ldmicro.h" +using namespace std; + // We should display messages to the user differently if we are running // interactively vs. in batch (command-line) mode. BOOL RunningInBatchMode = FALSE; @@ -158,8 +160,10 @@ void CheckHeap(char *file, int line) //----------------------------------------------------------------------------- void *CheckMalloc(size_t n) { + cout << "Inside CheckMalloc" << "\n"; ok(); void *p = HeapAlloc(MainHeap, HEAP_ZERO_MEMORY, n); + cout << "Exiting CheckMalloc" << "\n"; return p; } void CheckFree(void *p) diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp index 849093e..b63e69d 100644 --- a/ldmicro/schematic.cpp +++ b/ldmicro/schematic.cpp @@ -83,43 +83,43 @@ BOOL FindSelected(int *gx, int *gy) //----------------------------------------------------------------------------- void SelectElement(int gx, int gy, int state) { -// if(gx < 0 || gy < 0) { -// if(!FindSelected(&gx, &gy)) { -// return; -// } -// } + if(gx < 0 || gy < 0) { + if(!FindSelected(&gx, &gy)) { + return; + } + } -// if(Selected) Selected->selectedState = SELECTED_NONE; + if(Selected) Selected->selectedState = SELECTED_NONE; -// Selected = DisplayMatrix[gx][gy]; -// SelectedWhich = DisplayMatrixWhich[gx][gy]; + Selected = DisplayMatrix[gx][gy]; + SelectedWhich = DisplayMatrixWhich[gx][gy]; -// if(SelectedWhich == ELEM_PLACEHOLDER) { -// state = SELECTED_LEFT; -// } + if(SelectedWhich == ELEM_PLACEHOLDER) { + state = SELECTED_LEFT; + } -// if((gy - ScrollYOffset) >= ScreenRowsAvailable()) { -// ScrollYOffset = gy - ScreenRowsAvailable() + 1; -// RefreshScrollbars(); -// } -// if((gy - ScrollYOffset) < 0) { -// ScrollYOffset = gy; -// RefreshScrollbars(); -// } -// if((gx - ScrollXOffset*POS_WIDTH*FONT_WIDTH) >= ScreenColsAvailable()) { -// ScrollXOffset = gx*POS_WIDTH*FONT_WIDTH - ScreenColsAvailable(); -// RefreshScrollbars(); -// } -// if((gx - ScrollXOffset*POS_WIDTH*FONT_WIDTH) < 0) { -// ScrollXOffset = gx*POS_WIDTH*FONT_WIDTH; -// RefreshScrollbars(); -// } + if((gy - ScrollYOffset) >= ScreenRowsAvailable()) { + ScrollYOffset = gy - ScreenRowsAvailable() + 1; + RefreshScrollbars(); + } + if((gy - ScrollYOffset) < 0) { + ScrollYOffset = gy; + RefreshScrollbars(); + } + if((gx - ScrollXOffset*POS_WIDTH*FONT_WIDTH) >= ScreenColsAvailable()) { + ScrollXOffset = gx*POS_WIDTH*FONT_WIDTH - ScreenColsAvailable(); + RefreshScrollbars(); + } + if((gx - ScrollXOffset*POS_WIDTH*FONT_WIDTH) < 0) { + ScrollXOffset = gx*POS_WIDTH*FONT_WIDTH; + RefreshScrollbars(); + } -// ok(); -// Selected->selectedState = state; -// ok(); + ok(); + Selected->selectedState = state; + ok(); -// WhatCanWeDoFromCursorAndTopology(); + WhatCanWeDoFromCursorAndTopology(); } //----------------------------------------------------------------------------- @@ -129,86 +129,86 @@ void SelectElement(int gx, int gy, int state) //----------------------------------------------------------------------------- void WhatCanWeDoFromCursorAndTopology(void) { -// BOOL canNegate = FALSE, canNormal = FALSE; -// BOOL canResetOnly = FALSE, canSetOnly = FALSE; -// BOOL canPushUp = TRUE, canPushDown = TRUE; + BOOL canNegate = FALSE, canNormal = FALSE; + BOOL canResetOnly = FALSE, canSetOnly = FALSE; + BOOL canPushUp = TRUE, canPushDown = TRUE; -// BOOL canDelete = TRUE; + BOOL canDelete = TRUE; -// int i = RungContainingSelected(); -// if(i >= 0) { -// if(i == 0) canPushUp = FALSE; -// if(i == (Prog.numRungs-1)) canPushDown = FALSE; + int i = RungContainingSelected(); + if(i >= 0) { + if(i == 0) canPushUp = FALSE; + if(i == (Prog.numRungs-1)) canPushDown = FALSE; -// if(Prog.rungs[i]->count == 1 && -// Prog.rungs[i]->contents[0].which == ELEM_PLACEHOLDER) -// { -// canDelete = FALSE; -// } -// } + if(Prog.rungs[i]->count == 1 && + Prog.rungs[i]->contents[0].which == ELEM_PLACEHOLDER) + { + canDelete = FALSE; + } + } -// CanInsertEnd = FALSE; -// CanInsertOther = TRUE; - -// if(Selected && -// (SelectedWhich == ELEM_COIL || -// SelectedWhich == ELEM_RES || -// SelectedWhich == ELEM_ADD || -// SelectedWhich == ELEM_SUB || -// SelectedWhich == ELEM_MUL || -// SelectedWhich == ELEM_DIV || -// SelectedWhich == ELEM_CTC || -// SelectedWhich == ELEM_READ_ADC || -// SelectedWhich == ELEM_SET_PWM || -// SelectedWhich == ELEM_MASTER_RELAY || -// SelectedWhich == ELEM_SHIFT_REGISTER || -// SelectedWhich == ELEM_LOOK_UP_TABLE || -// SelectedWhich == ELEM_PIECEWISE_LINEAR || -// SelectedWhich == ELEM_PERSIST || -// SelectedWhich == ELEM_MOVE)) -// { -// if(SelectedWhich == ELEM_COIL) { -// canNegate = TRUE; -// canNormal = TRUE; -// canResetOnly = TRUE; -// canSetOnly = TRUE; -// } + CanInsertEnd = FALSE; + CanInsertOther = TRUE; + + if(Selected && + (SelectedWhich == ELEM_COIL || + SelectedWhich == ELEM_RES || + SelectedWhich == ELEM_ADD || + SelectedWhich == ELEM_SUB || + SelectedWhich == ELEM_MUL || + SelectedWhich == ELEM_DIV || + SelectedWhich == ELEM_CTC || + SelectedWhich == ELEM_READ_ADC || + SelectedWhich == ELEM_SET_PWM || + SelectedWhich == ELEM_MASTER_RELAY || + SelectedWhich == ELEM_SHIFT_REGISTER || + SelectedWhich == ELEM_LOOK_UP_TABLE || + SelectedWhich == ELEM_PIECEWISE_LINEAR || + SelectedWhich == ELEM_PERSIST || + SelectedWhich == ELEM_MOVE)) + { + if(SelectedWhich == ELEM_COIL) { + canNegate = TRUE; + canNormal = TRUE; + canResetOnly = TRUE; + canSetOnly = TRUE; + } -// if(Selected->selectedState == SELECTED_ABOVE || -// Selected->selectedState == SELECTED_BELOW) -// { -// CanInsertEnd = TRUE; -// CanInsertOther = FALSE; -// } else if(Selected->selectedState == SELECTED_RIGHT) { -// CanInsertEnd = FALSE; -// CanInsertOther = FALSE; -// } -// } else if(Selected) { -// if(Selected->selectedState == SELECTED_RIGHT || -// SelectedWhich == ELEM_PLACEHOLDER) -// { -// CanInsertEnd = ItemIsLastInCircuit(Selected); -// } -// } -// if(SelectedWhich == ELEM_CONTACTS) { -// canNegate = TRUE; -// canNormal = TRUE; -// } -// if(SelectedWhich == ELEM_PLACEHOLDER) { -// // a comment must be the only element in its rung, and it will fill -// // the rung entirely -// CanInsertComment = TRUE; -// } else { -// CanInsertComment = FALSE; -// } -// if(SelectedWhich == ELEM_COMMENT) { -// // if there's a comment there already then don't let anything else -// // into the rung -// CanInsertEnd = FALSE; -// CanInsertOther = FALSE; -// } -// SetMenusEnabled(canNegate, canNormal, canResetOnly, canSetOnly, canDelete, -// CanInsertEnd, CanInsertOther, canPushDown, canPushUp, CanInsertComment); + if(Selected->selectedState == SELECTED_ABOVE || + Selected->selectedState == SELECTED_BELOW) + { + CanInsertEnd = TRUE; + CanInsertOther = FALSE; + } else if(Selected->selectedState == SELECTED_RIGHT) { + CanInsertEnd = FALSE; + CanInsertOther = FALSE; + } + } else if(Selected) { + if(Selected->selectedState == SELECTED_RIGHT || + SelectedWhich == ELEM_PLACEHOLDER) + { + CanInsertEnd = ItemIsLastInCircuit(Selected); + } + } + if(SelectedWhich == ELEM_CONTACTS) { + canNegate = TRUE; + canNormal = TRUE; + } + if(SelectedWhich == ELEM_PLACEHOLDER) { + // a comment must be the only element in its rung, and it will fill + // the rung entirely + CanInsertComment = TRUE; + } else { + CanInsertComment = FALSE; + } + if(SelectedWhich == ELEM_COMMENT) { + // if there's a comment there already then don't let anything else + // into the rung + CanInsertEnd = FALSE; + CanInsertOther = FALSE; + } + SetMenusEnabled(canNegate, canNormal, canResetOnly, canSetOnly, canDelete, + CanInsertEnd, CanInsertOther, canPushDown, canPushUp, CanInsertComment); } //----------------------------------------------------------------------------- @@ -276,7 +276,7 @@ BOOL MoveCursorTopLeft(void) // } // } // } -// return FALSE; + return FALSE; } //----------------------------------------------------------------------------- diff --git a/ldmicro/undoredo.cpp b/ldmicro/undoredo.cpp index 69831d8..2a3c2fd 100644 --- a/ldmicro/undoredo.cpp +++ b/ldmicro/undoredo.cpp @@ -25,9 +25,12 @@ #include "linuxUI.h" #include <stdio.h> #include <stdlib.h> +#include <iostream> #include "ldmicro.h" +using namespace std; + // Store a `deep copy' of the entire program before every change, in a // circular buffer so that the first one scrolls out as soon as the buffer // is full and we try to push another one. |