summaryrefslogtreecommitdiff
path: root/ldmicro/draw_outputdev.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro/draw_outputdev.cpp')
-rw-r--r--ldmicro/draw_outputdev.cpp191
1 files changed, 116 insertions, 75 deletions
diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp
index 5721d34..69f08ca 100644
--- a/ldmicro/draw_outputdev.cpp
+++ b/ldmicro/draw_outputdev.cpp
@@ -31,7 +31,7 @@
#include "ldmicro.h"
-void (*DrawChars)(int, int, const char *);
+void (*DrawChars)(HCRDC Hcr, int, int, const char *);
// After an undo all the memory addresses change but make an effort to put
// the cursor roughly where it should be.
@@ -81,22 +81,63 @@ SyntaxHighlightingColours HighlightColours;
// bottom, left, right) but we don't care; just go from the coordinates
// computed when we drew the schematic in the paint procedure.
//-----------------------------------------------------------------------------
-void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time)
+gboolean BlinkCursor(GtkWidget * window) //(HWND hwnd, UINT msg, UINT_PTR id, DWORD time)
{
- // if(!isFocus(MainWindow) && !CursorDrawn) return;
- // if(Cursor.left == 0) return;
+ // if(GetFocus(MainWindow) != !CursorDrawn) return TRUE;
+ if(Cursor.left == 0) return TRUE;
- // PlcCursor c;
- // SettingsInstance = gtk_settings_get_default();
- // gtk_settings_install_property_parser (gtk-cursor-blink ,black);
+ PlcCursor c;
+ memcpy(&c, &Cursor, sizeof(c));
+ c.top -= ScrollYOffset*POS_HEIGHT*FONT_HEIGHT;
+ c.left -= ScrollXOffset;
+
+ if(c.top >= IoListTop) return TRUE;
+
+ if(c.top + c.height >= IoListTop) {
+ c.height = IoListTop - c.top - 3;
+ }
+
+ // if(!GDK_IS_DRAWING_CONTEXT(Hdc))
+ // return FALSE;
+
+ HCRDC Hcr = gdk_cairo_create(gtk_widget_get_window(DrawWindow));//gdk_drawing_context_get_cairo_context(Hdc);//
+
+ static int PREV_x = c.left;
+ static int PREV_y = c.top;
+ static int PREV_w = c.width;
+ static int PREV_h = c.height;
+
+ if (PREV_x != c.left || PREV_y != c.top || PREV_w != c.width || PREV_h != c.height)
+ {
+ PatBlt(Hcr, PREV_x, PREV_y, PREV_w, PREV_h, PATINVERT, (HBRUSH)GetStockObject(BLACK_BRUSH));
+ PREV_x = c.left;
+ PREV_y = c.top;
+ PREV_w = c.width;
+ PREV_h = c.height;
+
+ // MainWindowResized();
+ // PaintWindow(Hcr);
+ gtk_widget_queue_draw(DrawWindow);
+ }
+
+ if (CursorDrawn)
+ PatBlt(Hcr, c.left, c.top, c.width, c.height, PATINVERT, (HBRUSH)GetStockObject(WHITE_BRUSH));
+ else
+ PatBlt(Hcr, c.left, c.top, c.width, c.height, PATINVERT, (HBRUSH)GetStockObject(BLACK_BRUSH));
+ InvalidateRect(DrawWindow, NULL, FALSE);
+ // g_print("BLINK\n");
+ cairo_destroy(Hcr);
+ CursorDrawn = !CursorDrawn;
+
+ return TRUE;
}
//-----------------------------------------------------------------------------
// Output a string to the screen at a particular location, in character-
// sized units.
//-----------------------------------------------------------------------------
-static void DrawCharsToScreen(int cx, int cy, const char *str)
+static void DrawCharsToScreen(HCRDC Hcr, int cx, int cy, const char *str)
{
cy -= ScrollYOffset*POS_HEIGHT;
if(cy < -2) return;
@@ -116,12 +157,12 @@ static void DrawCharsToScreen(int cx, int cy, const char *str)
if(strchr("{}[]", *str) && hiOk && !inComment) {
if(*str == '{' || *str == '[') inBrace++;
if(inBrace == 1) {
- prev = GetTextColor(Hdc);
- SetTextColor(Hdc, HighlightColours.punct);
- TextOut(DrawWindow, Hdc, x, y, str, 1);
- SetTextColor(Hdc, prev);
+ prev = GetTextColor(Hcr);
+ SetTextColor(Hcr, HighlightColours.punct);
+ TextOut(DrawWindow, Hcr, x, y, str, 1);
+ SetTextColor(Hcr, prev);
} else {
- TextOut(DrawWindow, Hdc, x, y, str, 1);
+ TextOut(DrawWindow, Hcr, x, y, str, 1);
}
if(*str == ']' || *str == '}') inBrace--;
} else if((
@@ -129,42 +170,42 @@ static void DrawCharsToScreen(int cx, int cy, const char *str)
|| str[-1] == ':' || str[-1] == '[')) ||
(*str == '-' && isdigit(str[1]))) && hiOk && !inComment)
{
- prev = GetTextColor(Hdc);
- SetTextColor(Hdc, HighlightColours.lit);
- TextOut(DrawWindow, Hdc, x, y, str, 1);
- SetTextColor(Hdc, prev);
+ prev = GetTextColor(Hcr);
+ SetTextColor(Hcr, HighlightColours.lit);
+ TextOut(DrawWindow, Hcr, x, y, str, 1);
+ SetTextColor(Hcr, prev);
inNumber = TRUE;
} else if(*str == '\x01') {
cx--;
if(hiOk) {
- prev = GetTextColor(Hdc);
- SetTextColor(Hdc, HighlightColours.op);
+ prev = GetTextColor(Hcr);
+ SetTextColor(Hcr, HighlightColours.op);
}
} else if(*str == '\x02') {
cx--;
if(hiOk) {
- SetTextColor(Hdc, prev);
+ SetTextColor(Hcr, prev);
inComment = FALSE;
}
} else if(*str == '\x03') {
cx--;
if(hiOk) {
- prev = GetTextColor(Hdc);
- SetTextColor(Hdc, HighlightColours.comment);
+ prev = GetTextColor(Hcr);
+ SetTextColor(Hcr, HighlightColours.comment);
inComment = TRUE;
}
} else if(inNumber) {
if(isdigit(*str) || *str == '.') {
- prev = GetTextColor(Hdc);
- SetTextColor(Hdc, HighlightColours.lit);
- TextOut(DrawWindow, Hdc, x, y, str, 1);
- SetTextColor(Hdc, prev);
+ prev = GetTextColor(Hcr);
+ SetTextColor(Hcr, HighlightColours.lit);
+ TextOut(DrawWindow, Hcr, x, y, str, 1);
+ SetTextColor(Hcr, prev);
} else {
- TextOut(DrawWindow, Hdc, x, y, str, 1);
+ TextOut(DrawWindow, Hcr, x, y, str, 1);
inNumber = FALSE;
}
} else {
- TextOut(DrawWindow, Hdc, x, y, str, 1);
+ TextOut(DrawWindow, Hcr, x, y, str, 1);
}
firstTime = FALSE;
@@ -205,7 +246,7 @@ int ScreenRowsAvailable(void)
// cursor should go and fill in coordinates for BlinkCursor. Not allowed to
// draw deeper than IoListTop, as we would run in to the I/O listbox.
//-----------------------------------------------------------------------------
-void PaintWindow()
+void PaintWindow(HCRDC Hcr)
{
ok();
@@ -237,11 +278,11 @@ void PaintWindow()
if(((cy + thisHeight) >= (ScrollYOffset - 8)*POS_HEIGHT) &&
(cy < (ScrollYOffset + rowsAvailable + 8)*POS_HEIGHT))
{
- SetBkColor(DrawWindow, Hdc, InSimulationMode ? HighlightColours.simBg :
+ SetBkColor(DrawWindow, Hcr, InSimulationMode ? HighlightColours.simBg :
HighlightColours.bg);
- SetTextColor(Hdc, InSimulationMode ? HighlightColours.simRungNum :
+ SetTextColor(Hcr, InSimulationMode ? HighlightColours.simRungNum :
HighlightColours.rungNum);
- SelectObject(Hdc, FixedWidthFont);
+ SelectObject(Hcr, FixedWidthFont);
int rung = i + 1;
int y = Y_PADDING + FONT_HEIGHT*cy;
int yp = y + FONT_HEIGHT*(POS_HEIGHT/2) -
@@ -249,14 +290,14 @@ void PaintWindow()
if(rung < 10) {
char r[1] = { rung + '0' };
- TextOut(DrawWindow, Hdc, 8 + FONT_WIDTH, yp, r, 1);
+ TextOut(DrawWindow, Hcr, 8 + FONT_WIDTH, yp, r, 1);
} else {
char r[2] = { (rung / 10) + '0', (rung % 10) + '0' };
- TextOut(DrawWindow, Hdc, 8, yp, r, 2);
+ TextOut(DrawWindow, Hcr, 8, yp, r, 2);
}
int cx = 0;
- DrawElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy,
+ DrawElement(Hcr, ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy,
Prog.rungPowered[i]);
}
@@ -264,7 +305,7 @@ void PaintWindow()
cy += POS_HEIGHT;
}
cy -= 2;
- DrawEndRung(0, cy);
+ DrawEndRung(Hcr, 0, cy);
if(SelectedGxAfterNextPaint >= 0) {
MoveCursorNear(SelectedGxAfterNextPaint, SelectedGyAfterNextPaint);
@@ -291,10 +332,11 @@ void PaintWindow()
r.top = 0;
r.right = r.left + 4;
r.bottom = IoListTop;
- FillRect(Hdc, &r, InSimulationMode ? BusLeftBrush : BusBrush);
+ FillRect(Hcr, &r, InSimulationMode ? BusLeftBrush : BusBrush);
r.left += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2;
r.right += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2;
- FillRect(Hdc, &r, InSimulationMode ? BusRightBus : BusBrush);
+ FillRect(Hcr, &r, InSimulationMode ? BusRightBus : BusBrush);
+ InvalidateRect(DrawWindow, NULL, FALSE);
CursorDrawn = FALSE;
@@ -308,7 +350,6 @@ void PaintWindow()
// SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor);
// }
- // Hdc = paintDc;
ok();
}
@@ -513,46 +554,46 @@ void ExportDrawingAsText(char *file)
//-----------------------------------------------------------------------------
void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert)
{
- // int totalHeight = 0;
- // int i;
- // for(i = 0; i < Prog.numRungs; i++) {
- // totalHeight += CountHeightOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i]);
- // totalHeight++;
- // }
- // totalHeight += 1; // for the end rung
+ int totalHeight = 0;
+ int i;
+ for(i = 0; i < Prog.numRungs; i++) {
+ totalHeight += CountHeightOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i]);
+ totalHeight++;
+ }
+ totalHeight += 1; // for the end rung
- // int totalWidth = ProgCountWidestRow();
+ int totalWidth = ProgCountWidestRow();
- // if(totalWidth <= ScreenColsAvailable()) {
- // *horizShown = FALSE;
- // ScrollXOffset = 0;
- // ScrollXOffsetMax = 0;
- // } else {
- // *horizShown = TRUE;
- // memset(horiz, 0, sizeof(*horiz));
- // horiz->cbSize = sizeof(*horiz);
- // horiz->fMask = SIF_DISABLENOSCROLL | SIF_ALL;
- // horiz->nMin = 0;
- // horiz->nMax = X_PADDING + totalWidth*POS_WIDTH*FONT_WIDTH;
- // RECT r;
- // GetClientRect(MainWindow, &r);
- // horiz->nPage = r.right - X_PADDING;
- // horiz->nPos = ScrollXOffset;
-
- // ScrollXOffsetMax = horiz->nMax - horiz->nPage + 1;
- // if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax;
- // if(ScrollXOffset < 0) ScrollXOffset = 0;
- // }
+ if(totalWidth <= ScreenColsAvailable()) {
+ *horizShown = FALSE;
+ ScrollXOffset = 0;
+ ScrollXOffsetMax = 0;
+ } else {
+ *horizShown = TRUE;
+ memset(horiz, 0, sizeof(*horiz));
+ horiz->cbSize = sizeof(*horiz);
+ // horiz->fMask = SIF_DISABLENOSCROLL | SIF_ALL;
+ horiz->nMin = 0;
+ horiz->nMax = X_PADDING + totalWidth*POS_WIDTH*FONT_WIDTH;
+ RECT r;
+ GetClientRect(DrawWindow, &r);
+ horiz->nPage = r.right - X_PADDING;
+ horiz->nPos = ScrollXOffset;
+
+ ScrollXOffsetMax = horiz->nMax - horiz->nPage + 1;
+ if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax;
+ if(ScrollXOffset < 0) ScrollXOffset = 0;
+ }
- // vert->cbSize = sizeof(*vert);
+ vert->cbSize = sizeof(*vert);
// vert->fMask = SIF_DISABLENOSCROLL | SIF_ALL;
- // vert->nMin = 0;
- // vert->nMax = totalHeight - 1;
- // vert->nPos = ScrollYOffset;
- // vert->nPage = ScreenRowsAvailable();
+ vert->nMin = 0;
+ vert->nMax = totalHeight - 1;
+ vert->nPos = ScrollYOffset;
+ vert->nPage = ScreenRowsAvailable();
- // ScrollYOffsetMax = vert->nMax - vert->nPage + 1;
+ ScrollYOffsetMax = vert->nMax - vert->nPage + 1;
- // if(ScrollYOffset > ScrollYOffsetMax) ScrollYOffset = ScrollYOffsetMax;
- // if(ScrollYOffset < 0) ScrollYOffset = 0;
+ if(ScrollYOffset > ScrollYOffsetMax) ScrollYOffset = ScrollYOffsetMax;
+ if(ScrollYOffset < 0) ScrollYOffset = 0;
}