From bb64af7e74193001c52c97766ec72894bf604437 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Sun, 17 Jun 2018 15:37:54 +0530 Subject: Updated window painting, ported draw.cpp, fixed cont char* error --- ldmicro/draw_outputdev.cpp | 251 +++++++++++++++++++++++---------------------- 1 file changed, 126 insertions(+), 125 deletions(-) (limited to 'ldmicro/draw_outputdev.cpp') diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp index c9a75d3..3dfeeff 100644 --- a/ldmicro/draw_outputdev.cpp +++ b/ldmicro/draw_outputdev.cpp @@ -31,7 +31,7 @@ #include "ldmicro.h" -void (*DrawChars)(int, int, char *); +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. @@ -109,79 +109,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(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); + } - // firstTime = FALSE; - // } + firstTime = FALSE; + } } //----------------------------------------------------------------------------- @@ -218,7 +218,7 @@ int ScreenRowsAvailable(void) // cursor should go and fill in coordinates for BlinkCursor. Not allowed to // draw deeper than IoListTop, as we would run in to the I/O listbox. //----------------------------------------------------------------------------- -void PaintWindow(HCRDC hcr) +void PaintWindow() { /* cairo_set_source_rgb(cr, Cairo_R, Cairo_G, Cairo_G); @@ -235,15 +235,16 @@ void PaintWindow(HCRDC hcr) cairo_fill (cr); */ - SetBkColor(DrawWindow, hcr, InSimulationMode ? HighlightColours.simBg : - HighlightColours.bg); + // SetBkColor(DrawWindow, hcr, InSimulationMode ? HighlightColours.simBg : + // HighlightColours.bg); - SetTextColor(hcr, InSimulationMode ? HighlightColours.simRungNum : - HighlightColours.rungNum); + // SetTextColor(hcr, InSimulationMode ? HighlightColours.simRungNum : + // HighlightColours.rungNum); - SelectObject(hcr, FixedWidthFont); + // SelectObject(hcr, FixedWidthFont); - TextOut(hcr, 5, 100, "-------] [-------------------------------------------------------------------------------------------------------------------------------------------------{RES}-------", 14); + // TextOut(hcr, 5, 100, "-------] [-------------------------------------------------------------------------------------------------------------------------------------------------{RES}-------", 14); + // static HBITMAP BackBitmap; // static HDC BackDc; // static int BitmapWidth; @@ -300,11 +301,11 @@ 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) - @@ -312,67 +313,67 @@ void PaintWindow(HCRDC hcr) if(rung < 10) { char r[1] = { rung + '0' }; - TextOut(hcr, 8 + FONT_WIDTH, yp, r, 1); + TextOut(Hdc, 8 + FONT_WIDTH, yp, r, 1); } else { char r[2] = { (rung / 10) + '0', (rung % 10) + '0' }; - TextOut(hcr, 8, yp, r, 2); + TextOut(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); - // // } - // } - // } - // } + 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); + } + } + } + } - // /// 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); + /// 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); - // // r.left += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; - // // r.right += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; - // // FillRect(Hdc, &r, InSimulationMode ? BusRightBus : 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(); } //----------------------------------------------------------------------------- -- cgit