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.cpp142
1 files changed, 61 insertions, 81 deletions
diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp
index 3068c23..1775104 100644
--- a/ldmicro/draw_outputdev.cpp
+++ b/ldmicro/draw_outputdev.cpp
@@ -31,7 +31,6 @@
#include "ldmicro.h"
-BOOL InSimulationMode; //Temporary
void (*DrawChars)(HCRDC Hcr, int, int, const char *);
@@ -75,7 +74,7 @@ static BOOL CursorDrawn;
SyntaxHighlightingColours HighlightColours;
#define X_RIGHT_PADDING 30
-/*
+
//-----------------------------------------------------------------------------
// Blink the cursor on the schematic; called by a Windows timer. We XOR
// draw it so just draw the same rectangle every time to show/erase the
@@ -87,63 +86,70 @@ BOOL BlinkCursor(BOOL kill = FALSE)
{
// if(GetFocus(MainWindow) != !CursorDrawn) return TRUE;
- if(Cursor.left == 0) return TRUE;
+ if(Cursor.left() == 0) return TRUE;
- PlcCursor c;
+ QRect c;
memcpy(&c, &Cursor, sizeof(c));
- c.top -= ScrollYOffset*POS_HEIGHT*FONT_HEIGHT;
- c.left -= ScrollXOffset;
+ c.setTop(c.top() - ScrollYOffset*POS_HEIGHT*FONT_HEIGHT);
+ c.setLeft(c.left() - ScrollXOffset);
- if(c.top >= IoListTop) return TRUE;
+ if(c.top() >= IoListTop) return TRUE;
- if(c.top + c.height >= IoListTop) {
- c.height = IoListTop - c.top - 3;
+ if(c.top() + c.height() >= IoListTop) {
+ c.setHeight(IoListTop - c.top() - 3);
}
+ if(DrawWindow == NULL)
+ return FALSE;
// if(!GDK_IS_DRAWING_CONTEXT(Hdc))
// return FALSE;
- HCRDC Hcr = gdk_cairo_create(gtk_widget_get_window(DrawWindow));
+ // HCRDC Hcr = gdk_cairo_create(gtk_widget_get_window(DrawWindow));
+ HWID Hcr = DrawWindow;
- static int PREV_x = c.left;
- static int PREV_y = c.top;
- static int PREV_w = c.width;
- static int PREV_h = c.height;
+ 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)
+ 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;
+ CursorObject->setGeometry(c);
+ CursorObject->setVisible(TRUE);
+ PREV_x = c.left();
+ PREV_y = c.top();
+ PREV_w = c.width();
+ PREV_h = c.height();
// MainWindowResized();
// PaintWindow(Hcr);
- gtk_widget_queue_draw(DrawWindow);
+ // gtk_widget_queue_draw(DrawWindow);
}
+ CursorObject->setGeometry(c);
- if (CursorDrawn)
- PatBlt(Hcr, c.left, c.top, c.width, c.height, PATINVERT, (HBRUSH)GetStockObject(WHITE_BRUSH));
+ if (CursorObject->isVisible())
+ CursorObject->setVisible(FALSE);
else
- PatBlt(Hcr, c.left, c.top, c.width, c.height, PATINVERT, (HBRUSH)GetStockObject(BLACK_BRUSH));
+ // PatBlt(Hcr, c.left(), c.top(), c.width(), c.height(), PATINVERT, (HBRUSH)GetStockObject(BLACK_BRUSH));
+ CursorObject->setVisible(TRUE);
InvalidateRect(DrawWindow, NULL, FALSE);
- cairo_destroy(Hcr);
- CursorDrawn = !CursorDrawn;
+ // cairo_destroy(Hcr);
+ // CursorDrawn = !CursorDrawn;
return !kill;
}
-*/
+
//-----------------------------------------------------------------------------
// Output a string to the screen at a particular location, in character-
// sized units.
//-----------------------------------------------------------------------------
static void DrawCharsToScreen(HCRDC Hcr, int cx, int cy, const char *str)
{
- /*cy -= ScrollYOffset*POS_HEIGHT;
+ cy -= ScrollYOffset*POS_HEIGHT;
if(cy < -2) return;
if(cy*FONT_HEIGHT + Y_PADDING > IoListTop) return;
+ // IoListTop not initialized.
COLORREF prev;
BOOL firstTime = TRUE;
@@ -211,8 +217,7 @@ static void DrawCharsToScreen(HCRDC Hcr, int cx, int cy, const char *str)
}
firstTime = FALSE;
- }*/
- printf("DrawCharsToScreen\n");
+ }
}
//-----------------------------------------------------------------------------
@@ -244,6 +249,12 @@ int ScreenRowsAvailable(void)
return (IoListTop - Y_PADDING - adj) / (POS_HEIGHT*FONT_HEIGHT);
}
+void PaintWidget::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == CursorTimer)
+ BlinkCursor();
+}
+
//-----------------------------------------------------------------------------
// Paint the ladder logic program to the screen. Also figure out where the
// cursor should go and fill in coordinates for BlinkCursor. Not allowed to
@@ -253,38 +264,8 @@ void PaintWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setClipping(true);
- QPalette pal = DrawWindow->palette();
- HCRDC Hcr = &pal;
- //a simple line
-/* painter.drawLine(1,1,100,100);
-
- //create a black pen that has solid line
- //and the width is 2.
- QPen myPen(Qt::blue, 2, Qt::SolidLine);
- painter.setPen(myPen);
- painter.drawLine(100,100,100,1);
-
- //draw a point
- myPen.setColor(Qt::red);
- painter.setPen(myPen);
- painter.drawPoint(110,110);
-
- //draw a polygon
- QPolygon polygon;
- polygon << QPoint(130, 140) << QPoint(180, 170)
- << QPoint(180, 140) << QPoint(220, 110)
- << QPoint(140, 100);
- painter.drawPolygon(polygon);
-
- //draw an ellipse
- //The setRenderHint() call enables antialiasing, telling QPainter to use different
- //color intensities on the edges to reduce the visual distortion that normally
- //occurs when the edges of a shape are converted into pixels
- painter.setRenderHint(QPainter::Antialiasing, true);
- painter.setPen(QPen(Qt::blue, 3, Qt::DashDotLine, Qt::RoundCap));
- painter.setBrush(QBrush(Qt::green, Qt::SolidPattern));
- painter.drawEllipse(200, 80, 400, 240);
-*/
+ painter.setRenderHint(QPainter::TextAntialiasing);
+ HCRDC Hcr = &painter;
ok();
@@ -321,7 +302,7 @@ void PaintWidget::paintEvent(QPaintEvent *event)
HighlightColours.bg);
SetTextColor(Hcr, InSimulationMode ? HighlightColours.simRungNum :
HighlightColours.rungNum);
- SelectObject(painter, FixedWidthFont);
+ SelectObject(Hcr, FixedWidthFont);
int rung = i + 1;
int y = Y_PADDING + FONT_HEIGHT*cy;
int yp = y + FONT_HEIGHT*(POS_HEIGHT/2) -
@@ -343,50 +324,50 @@ void PaintWidget::paintEvent(QPaintEvent *event)
cy += thisHeight;
cy += POS_HEIGHT;
}
- /*cy -= 2;
+ cy -= 2;
DrawEndRung(Hcr, 0, cy);
if(SelectedGxAfterNextPaint >= 0) {
MoveCursorNear(SelectedGxAfterNextPaint, SelectedGyAfterNextPaint);
- InvalidateRect(DrawWindow, NULL, FALSE);
+ // InvalidateRect(DrawWindow, NULL, FALSE);
SelectedGxAfterNextPaint = -1;
SelectedGyAfterNextPaint = -1;
} else if(ScrollSelectedIntoViewAfterNextPaint && Selected) {
SelectElement(-1, -1, Selected->selectedState);
ScrollSelectedIntoViewAfterNextPaint = FALSE;
- InvalidateRect(DrawWindow, NULL, FALSE);
+ // InvalidateRect(DrawWindow, NULL, FALSE);
} else {
if(!SelectionActive) {
if(Prog.numRungs > 0) {
if(MoveCursorTopLeft()) {
- InvalidateRect(DrawWindow, NULL, FALSE);
+ // InvalidateRect(DrawWindow, NULL, FALSE);
}
}
}
}
/// 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;
+ QRect r;
+ r.setLeft(X_PADDING - FONT_WIDTH);
+ r.setTop(0);
+ r.setRight(r.left() + 4);
+ r.setBottom(IoListTop);
FillRect(Hcr, &r, InSimulationMode ? BusLeftBrush : BusBrush);
- r.left += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2;
- r.right += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2;
+ r.setLeft(POS_WIDTH*FONT_WIDTH*ColsAvailable + 32);
+ r.setRight(POS_WIDTH*FONT_WIDTH*ColsAvailable + 32);
FillRect(Hcr, &r, InSimulationMode ? BusRightBus : BusBrush);
- InvalidateRect(DrawWindow, NULL, FALSE);
+ // InvalidateRect(DrawWindow, NULL, FALSE);
- CursorDrawn = FALSE;
+ // CursorDrawn = FALSE;
// BitBlt(paintDc, 0, 0, bw, bh, BackDc, ScrollXOffset, 0, SRCCOPY);
- if(InSimulationMode) {
+ /*if(InSimulationMode) {
KillTimer(DrawWindow, TIMER_BLINK_CURSOR);
} else {
SetTimer(DrawWindow, TIMER_BLINK_CURSOR, 200, BlinkCursor);
- }
-*/
+ }*/
+
ok();
}
@@ -468,7 +449,7 @@ void InitForDrawing(void)
// DrawChars function, for drawing to the export buffer instead of to the
// screen.
//-----------------------------------------------------------------------------
-/*static void DrawCharsToExportBuffer(HCRDC Hcr, int cx, int cy, const char *str)
+static void DrawCharsToExportBuffer(HCRDC Hcr, int cx, int cy, const char *str)
{
while(*str) {
if(*str >= 10) {
@@ -635,4 +616,3 @@ void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert)
if(ScrollYOffset > ScrollYOffsetMax) ScrollYOffset = ScrollYOffsetMax;
if(ScrollYOffset < 0) ScrollYOffset = 0;
}
-*/ \ No newline at end of file