summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakshay-c2019-03-18 12:52:03 +0530
committerakshay-c2019-03-18 12:52:03 +0530
commit08ca539a8d6624e979bf4e85a61ff00567575667 (patch)
treedbdce755481abdbe999fdd83be9408c002401a71
parent0dbffa99fda94203c74b955f6f9fe534f30c6421 (diff)
downloadLDmicroQt-08ca539a8d6624e979bf4e85a61ff00567575667.tar.gz
LDmicroQt-08ca539a8d6624e979bf4e85a61ff00567575667.tar.bz2
LDmicroQt-08ca539a8d6624e979bf4e85a61ff00567575667.zip
Cursor updates
-rw-r--r--ldmicro/CMakeLists.txt2
-rw-r--r--ldmicro/circuit.cpp16
-rw-r--r--ldmicro/draw.cpp45
-rw-r--r--ldmicro/draw_outputdev.cpp142
-rw-r--r--ldmicro/includes/ldmicro.h14
-rw-r--r--ldmicro/ldmicro.cpp16
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h2
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp126
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h22
-rw-r--r--ldmicro/maincontrols.cpp38
-rw-r--r--ldmicro/schematic.cpp17
-rw-r--r--ldmicro/simulate.cpp12
-rw-r--r--ldmicro/undoredo.cpp12
13 files changed, 268 insertions, 196 deletions
diff --git a/ldmicro/CMakeLists.txt b/ldmicro/CMakeLists.txt
index 3f799c6..8e60465 100644
--- a/ldmicro/CMakeLists.txt
+++ b/ldmicro/CMakeLists.txt
@@ -146,7 +146,7 @@ endif()
#coildialog.cpp
#contactsdialog.cpp
#commentdialog.cpp
- # simulate.cpp
+ simulate.cpp
loadsave.cpp
undoredo.cpp
circuit.cpp
diff --git a/ldmicro/circuit.cpp b/ldmicro/circuit.cpp
index c04059c..72c59c7 100644
--- a/ldmicro/circuit.cpp
+++ b/ldmicro/circuit.cpp
@@ -657,7 +657,7 @@ void FreeEntireProgram(void)
//-----------------------------------------------------------------------------
// Returns true if the given subcircuit contains the given leaf.
//-----------------------------------------------------------------------------
-/*static BOOL ContainsElem(int which, void *any, ElemLeaf *seek)
+static BOOL ContainsElem(int which, void *any, ElemLeaf *seek)
{
switch(which) {
case ELEM_SERIES_SUBCKT: {
@@ -693,12 +693,12 @@ void FreeEntireProgram(void)
oops();
}
return FALSE;
-}*/
+}
//-----------------------------------------------------------------------------
// Use ContainsElem to find the rung containing the cursor.
//-----------------------------------------------------------------------------
-/*int RungContainingSelected(void)
+int RungContainingSelected(void)
{
int i;
for(i = 0; i < Prog.numRungs; i++) {
@@ -708,7 +708,7 @@ void FreeEntireProgram(void)
}
return -1;
-}*/
+}
//-----------------------------------------------------------------------------
// Delete the rung that contains the cursor.
@@ -829,7 +829,7 @@ void NewProgram(void)
// position of a series subcircuit that may be in a parallel subcircuit that
// etc.)
//-----------------------------------------------------------------------------
-/*static void LastInCircuit(int which, void *any, ElemLeaf *seek,
+static void LastInCircuit(int which, void *any, ElemLeaf *seek,
BOOL *found, BOOL *andItemAfter)
{
switch(which) {
@@ -854,7 +854,7 @@ void NewProgram(void)
if(any == seek) *found = TRUE;
break;
}
-}*/
+}
//-----------------------------------------------------------------------------
// Is an item the last one in the circuit (i.e. does one of its terminals go
@@ -862,7 +862,7 @@ void NewProgram(void)
// circumstance in which it is okay to insert a coil, RES, etc. after
// something
//-----------------------------------------------------------------------------
-/*BOOL ItemIsLastInCircuit(ElemLeaf *item)
+BOOL ItemIsLastInCircuit(ElemLeaf *item)
{
int i = RungContainingSelected();
if(i < 0) return FALSE;
@@ -875,7 +875,7 @@ void NewProgram(void)
if(found) return !andItemAfter;
return FALSE;
-}*/
+}
//-----------------------------------------------------------------------------
// Returns TRUE if the subcircuit contains any of the given instruction
diff --git a/ldmicro/draw.cpp b/ldmicro/draw.cpp
index ed5c6be..d2feca2 100644
--- a/ldmicro/draw.cpp
+++ b/ldmicro/draw.cpp
@@ -48,7 +48,7 @@ BOOL ThisHighlighted;
if((gx) >= DISPLAY_MATRIX_X_SIZE || (gx) < 0) oops(); \
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
@@ -68,7 +68,7 @@ static BOOL CheckBoundsUndoIfFails(int gx, int gy)
}
return FALSE;
}
-*/
+
//-----------------------------------------------------------------------------
// Determine the width, in leaf element units, of a particular subcircuit.
// The width of a leaf is 1, the width of a series circuit is the sum of
@@ -250,7 +250,7 @@ int ProgCountWidestRow(void)
// Draw a vertical wire one leaf element unit high up from (cx, cy), where cx
// and cy are in charcter units.
//-----------------------------------------------------------------------------
-/*static void VerticalWire(HCRDC Hcr, int cx, int cy)
+static void VerticalWire(HCRDC Hcr, int cx, int cy)
{
int j;
for(j = 1; j < POS_HEIGHT; j++) {
@@ -881,32 +881,32 @@ cmp:
}
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;
+ Cursor.setLeft(x0 + FONT_WIDTH - 4 - xadj);
+ Cursor.setTop(y0 - FONT_HEIGHT/2);
+ Cursor.setWidth(2);
+ Cursor.setHeight(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;
+ Cursor.setLeft(x0 + (POS_WIDTH-1)*FONT_WIDTH - 5);
+ Cursor.setTop(y0 - FONT_HEIGHT/2);
+ Cursor.setWidth(2);
+ Cursor.setHeight(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;
+ Cursor.setLeft(x0 + FONT_WIDTH/2 - xadj);
+ Cursor.setTop(y0 - 2);
+ Cursor.setWidth((POS_WIDTH-2)*FONT_WIDTH + xadj);
+ Cursor.setHeight(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;
+ Cursor.setLeft(x0 + FONT_WIDTH/2 - xadj);
+ Cursor.setTop(y0 + (POS_HEIGHT-1)*FONT_HEIGHT +
+ FONT_HEIGHT/2 - 2);
+ Cursor.setWidth((POS_WIDTH-2)*(FONT_WIDTH) + xadj);
+ Cursor.setHeight(2);
break;
default:
@@ -915,7 +915,6 @@ cmp:
return poweredAfter;
}
-*/
//-----------------------------------------------------------------------------
// Draw a particular subcircuit with its top left corner at *cx and *cy (in
// characters). If it is a leaf element then just print it and return; else
@@ -934,7 +933,7 @@ BOOL DrawElement(HCRDC Hcr, int which, void *elem, int *cx, int *cy, BOOL powere
ElemLeaf *leaf = (ElemLeaf *)elem;
SetBkColor(DrawWindow,Hcr, InSimulationMode ? HighlightColours.simBg :
HighlightColours.bg);
- /*NormText(Hcr);
+ NormText(Hcr);
if(elem == Selected && !InSimulationMode) {
EmphText(Hcr);
@@ -1044,7 +1043,7 @@ BOOL DrawElement(HCRDC Hcr, int which, void *elem, int *cx, int *cy, BOOL powere
}
- NormText(Hcr);*/
+ NormText(Hcr);
return poweredAfter;
}
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
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h
index fcbadb4..4372bfd 100644
--- a/ldmicro/includes/ldmicro.h
+++ b/ldmicro/includes/ldmicro.h
@@ -38,11 +38,7 @@ typedef signed long SDWORD;
// Size of the font that we will use to draw the ladder diagrams, in pixels
#define FONT_WIDTH 7
-#define FONT_HEIGHT 13
-
-// Timer IDs associated with the main window.
-#define TIMER_BLINK_CURSOR 1
-#define TIMER_SIMULATE 2
+#define FONT_HEIGHT 14
//-----------------------------------------------
// Constants for the GUI. We have drop-down menus, a listview for the I/Os,
@@ -299,6 +295,10 @@ extern HWID PinList;
#define MAX_COMMENT_LEN 384
#define MAX_LOOK_UP_TABLE_LEN 60
+// Timer IDs associated with the main window.
+extern int CursorTimer;
+extern int SimulateTimer;
+
typedef struct ElemSubckParallelTag ElemSubcktParallel;
typedef struct ElemCommentTag {
@@ -495,7 +495,7 @@ typedef struct PlcProgramTag {
#define X_PADDING 35
#define Y_PADDING 14
-typedef struct PlcCursorTag {
+typedef class PlcCursorTag{
int left;
int top;
int width;
@@ -683,7 +683,7 @@ extern ElemLeaf DisplayMatrixFiller;
extern ElemLeaf *Selected;
extern int SelectedWhich;
-extern PlcCursor Cursor;
+extern QRect Cursor;
extern BOOL CanInsertEnd;
extern BOOL CanInsertOther;
extern BOOL CanInsertComment;
diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp
index 2b27ce5..95074a7 100644
--- a/ldmicro/ldmicro.cpp
+++ b/ldmicro/ldmicro.cpp
@@ -44,11 +44,14 @@ QApplication* LDmicroApp;
HWID MainWindow;
QIcon* MWIcon;
QMenuBar* MainMenu;
+QGroupBox* CursorObject;
HWID DrawWindow;
// parameters used to capture the mouse when implementing our totally non-
// general splitter control
//static HHOOK MouseHookHandle;
static int MouseY;
+int CursorTimer;
+int SimulateTimer;
// For the open/save dialog boxes
#define LDMICRO_PATTERN "LDmicro Ladder Logic Programs (*.ld)\0*.ld\0" \
@@ -282,7 +285,7 @@ static void OpenDialog(void)
RefreshScrollbars();
UpdateMainWindowTitleBar();
}
-
+*/
//-----------------------------------------------------------------------------
// Housekeeping required when the program changes: mark the program as
// changed so that we ask if user wants to save before exiting, and update
@@ -298,7 +301,7 @@ void ProgramChanged(void)
UndoRemember(); \
x; \
ProgramChanged();\
- }*/
+ }
//-----------------------------------------------------------------------------
// Hook that we install when the user starts dragging the `splitter,' in case
@@ -1255,9 +1258,13 @@ int main(int argc, char** argv)
QSize MwSize(800,600);
// Make main window
- MainWindow = new QWidget;
+ MainWindow = new QWidget();
MWIcon = new QIcon(LDMICRO_ICON);
MainMenu = new QMenuBar(MainWindow);
+
+ // Initialize cursor and set color
+ CursorObject = new QGroupBox(DrawWindow);
+ // CursorObject->setColor();
// QMenu TopMenu("Top Menu", MainWindow);
// MainMenu->addMenu(&TopMenu);
@@ -1288,6 +1295,9 @@ int main(int argc, char** argv)
MainWindow->show();
+ /// Blink cursor
+ CursorTimer = SetTimer(DrawWindow, TIMER_BLINK_CURSOR, 500, CursorTimer);
+
GenerateIoListDontLoseSelection();
// MakeDialogBoxClass();
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index 29e6ebc..470c7cc 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -78,7 +78,7 @@ typedef GtkTreeIter ITLIST;
typedef GDRECT* PGDRECT;
typedef QMenu* HMENU;
typedef ITLIST* HITLIST;
-typedef QPalette* HCRDC;
+typedef QPainter* HCRDC;
typedef QWidget* HWID;
typedef QWidget* HWND;
typedef GdkPixbuf* HICON;
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index 727fea8..3f8896c 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -236,28 +236,40 @@ BOOL GetOpenFileName(OPENFILENAME *ofn)
}
+void EnableMenuItem(HMENU MenuName, QAction* MenuItem, UINT CheckEnabledItem)
+{
+ switch (CheckEnabledItem){
+ case MF_ENABLED :
+ MenuItem->setEnabled(true);
+ break;
+ case MF_GRAYED :
+ MenuItem->setEnabled(false);
+ break;
+ }
+}
+
void EnableMenuItem(HMENU MenuName, HMENU MenuItem, UINT CheckEnabledItem)
{
- /*switch (CheckEnabledItem){
+ switch (CheckEnabledItem){
case MF_ENABLED :
- gtk_widget_set_sensitive (MenuItem, true);
+ MenuItem->setEnabled(true);
break;
case MF_GRAYED :
- gtk_widget_set_sensitive (MenuItem, false);
+ MenuItem->setEnabled(false);
break;
- }*/
+ }
}
-void CheckMenuItem(HMENU MenuName, HMENU MenuItem, UINT Check)
+void CheckMenuItem(HMENU MenuName, QAction* MenuItem, UINT Check)
{
- /*switch (Check){
+ switch (Check){
case MF_CHECKED :
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(MenuItem), true);
+ MenuItem->setChecked(true);
break;
case MF_UNCHECKED :
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(MenuItem), false);
+ MenuItem->setChecked(false);
break;
- }*/
+ }
}
HANDLE GetStockObject(int fnObject)
@@ -284,15 +296,17 @@ HANDLE GetStockObject(int fnObject)
}
}
-void SelectObject(QPainter* hcr, HFONT hfont)
+void SelectObject(HCRDC hcr, HFONT hfont)
{
if (hcr ==NULL)
return;
- QFont qtfont(hfont->lpszFace);
- qtfont.setPointSize(hfont->nHeight);
+ QFont qtfont = hcr->font();
+ qtfont.setFamily(hfont->lpszFace);
+ qtfont.setPixelSize(hfont->nHeight - 3);
+ qtfont.setFixedPitch(TRUE);
qtfont.setStyle(hfont->fdwItalic ? QFont::StyleItalic : QFont::StyleNormal);
qtfont.setWeight(hfont->fnWeight == FW_BOLD ? QFont::Bold : QFont::Normal);
- hcr->setFont();
+ hcr->setFont(qtfont);
}
HBRUSH CreateBrushIndirect(PLOGBRUSH plb)
@@ -323,21 +337,54 @@ HFONT CreateFont(int nHeight, int nWidth, int nOrientation, int fnWeight,
void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol)
{
- hcr->setColor(QPalette::Background, bkCol);
- widget->setPalette(*hcr);
+ QPalette pal = widget->palette();
+ pal.setColor(QPalette::Background, bkCol);
+ widget->setPalette(pal);
}
void SetTextColor(HCRDC hcr, COLORREF color)
{
if (hcr == NULL)
return;
-
+ QPen qtpen = hcr->pen();
+ qtpen.setColor(color);
+ hcr->setPen(qtpen);
HdcCurrentTextColor = color;
// gdk_cairo_set_source_rgba (hcr, &color);
}
void TextOut(HWID hWid, HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, int cchString)
{
+ if (hcr == NULL)
+ return;
+ int width = hWid->width();
+ int height = hWid->height();
+ BOOL resize_flag = FALSE;
+ QFont newFont= hcr->font();
+ // newFont
+ /*if(nYStart+(extents.height/2.0) >= height)
+ {
+ height += extents.height + 50;
+ resize_flag = TRUE;
+ }
+
+ if (nXStart+(extents.width/2.0) >= width)
+ {
+ width += extents.width;
+ resize_flag = TRUE;
+ }*/
+ char* text = (char*)malloc(cchString);
+ strncpy(text, lpString, cchString);
+ text[cchString] = '\0';
+
+ hcr->drawText(nXStart, nYStart, (QString)text);
+ // cairo_move_to(hcr, nXStart, nYStart);
+ // cairo_show_text(hcr, text);
+
+ // cairo_fill (hcr);
+
+ /*if (resize_flag) // To do later
+ hcr->setWindow();*/
/*if (hcr == NULL)
return;
@@ -400,13 +447,19 @@ BOOL InvalidateRect(HWID hWid, const RECT *lpRect, BOOL bErase)
// gtk_widget_queue_draw(hWid);
gdk_window_invalidate_rect (gtk_widget_get_window (hWid), &Gdrect, FALSE);
*/
+ hWid->repaint();
return TRUE;
}
-int FillRect(HCRDC hDC, const RECT *lprc, HBRUSH hbr)
+int FillRect(HCRDC hDC, const QRect *lprc, HBRUSH hbr)
{
if (hDC == NULL)
return -1;
+ QBrush curbrush = hDC->brush();
+ curbrush.setColor(*hbr);
+ curbrush.setStyle(Qt::SolidPattern);
+ hDC->setBrush(curbrush);
+ hDC->drawRect(*lprc);
/*
GDRECT gdrc;
RECT_to_GDRECT(lprc, &gdrc);
@@ -419,7 +472,7 @@ int FillRect(HCRDC hDC, const RECT *lprc, HBRUSH hbr)
return 0;
}
-BOOL PatBlt(HCRDC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD dwRop, HBRUSH hbr)
+BOOL PatBlt(HWID hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD dwRop, HBRUSH hbr)
{
if (hdc == NULL)
return FALSE;
@@ -472,20 +525,37 @@ BOOL GetWindowRect(HWID hWid, PRECT pRect)
}
-UINT SetTimer(HWID hWid, UINT nIDEvent, UINT uElapse, BOOL (*lpTimerFunc)(BOOL) )
+UINT SetTimer(HWID hWid, UINT nIDEvent, UINT uElapse, UINT TimerID)
{
- auto record_it = std::find_if(timerRecords.begin(), timerRecords.end(), [&nIDEvent](TimerRecord &Record) { return Record.ufID == nIDEvent; });
+ if(TimerID != NULL)
+ return nIDEvent;
+ if(nIDEvent == TIMER_BLINK_CURSOR)
+ {
+ TimerID = hWid->startTimer(uElapse);
+ CursorObject = new QGroupBox(hWid);
+
+ QPalette pal = CursorObject->palette();
+ pal.setColor(QPalette::Background, Qt::white);
+ CursorObject->setAutoFillBackground(true);
+ CursorObject->setPalette(pal);
+ // CursorObject->setGeometry(100,100,2,20);
+ }
+ // if(hWid!=NULL)
+ // CursorObject->setVisible(TRUE);
+
+ return TimerID;
+ // auto record_it = std::find_if(timerRecords.begin(), timerRecords.end(), [&nIDEvent](TimerRecord &Record) { return Record.ufID == nIDEvent; });
- if (record_it != timerRecords.end())
- return 0;
+ // if (record_it != timerRecords.end())
+ // return 0;
- TimerRecord tr;
- tr.pfun = lpTimerFunc;
- tr.ufID = nIDEvent;
- tr.utID = g_timeout_add(uElapse, (GSourceFunc)lpTimerFunc, FALSE);
+ // TimerRecord tr;
+ // tr.pfun = lpTimerFunc;
+ // tr.ufID = nIDEvent;
+ // tr.utID = g_timeout_add(uElapse, (GSourceFunc)lpTimerFunc, FALSE);
- timerRecords.push_back(tr);
- return tr.utID;
+ // timerRecords.push_back(tr);
+ // return tr.utID;
}
BOOL KillTimer(HWID hWid, UINT uIDEvent)
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index 88a89c4..7054b61 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -10,6 +10,7 @@
#include <QVBoxLayout>
#include <QLabel>
#include <QPainter>
+#include <QGroupBox>
// #include <QtGui>
// #include <QSize>
// #include "freezeLD.h"
@@ -27,6 +28,10 @@
#define LDMicro_VERSION_MAJOR 1
#define LDMicro_VERSION_MINOR 0
+// Timer IDs associated with the main window.
+#define TIMER_BLINK_CURSOR 1
+#define TIMER_SIMULATE 2
+
/// Flags
/// message box
#define MB_OK 0x00000001L
@@ -129,6 +134,7 @@ extern const UINT MF_UNCHECKED;
/// Accelerators (keyboard shortcuts)
extern GtkAccelGroup* AccelGroup;
extern GClosure* closure;
+extern QGroupBox* CursorObject;
/// ListStore
extern HWID view;
@@ -177,18 +183,23 @@ BOOL GetOpenFileName(OPENFILENAME *ofn);
void EnableMenuItem(
HMENU MenuName,
+ QAction* MenuItem,
+ UINT CheckEnabledItem);
+
+void EnableMenuItem(
+ HMENU MenuName,
HMENU MenuItem,
UINT CheckEnabledItem);
void CheckMenuItem(
HMENU MenuName,
- HMENU MenuItem,
+ QAction* MenuItem,
UINT Check);
HANDLE GetStockObject(int fnObject);
void SelectObject(
- QPainter* hcr,
+ HCRDC hcr,
HFONT hfont);
HBRUSH CreateBrushIndirect(PLOGBRUSH plb);
@@ -227,11 +238,11 @@ BOOL InvalidateRect(
int FillRect(
HCRDC hDC,
- const RECT *lprc,
+ const QRect *lprc,
HBRUSH hbr);
BOOL PatBlt(
- HCRDC hdc,
+ HWID hdc,
int nXLeft,
int nYLeft,
int nWidth,
@@ -259,7 +270,7 @@ UINT SetTimer(
HWID hWid,
UINT nIDEvent,
UINT uElapse,
- BOOL (*lpTimerFunc)(BOOL));
+ UINT TimerID);
BOOL KillTimer(
HWID hWid,
@@ -275,6 +286,7 @@ public:
protected:
void paintEvent(QPaintEvent *event);
+ void timerEvent(QTimerEvent *event);
signals:
public slots:
diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp
index 5b4a924..fa45cdd 100644
--- a/ldmicro/maincontrols.cpp
+++ b/ldmicro/maincontrols.cpp
@@ -710,7 +710,7 @@ void MakeMainWindowControls(void)
/// Adding box to Main Window
gtk_container_add(GTK_CONTAINER(MainWindow), PackBoxMenu);*/
}
-/*
+
//-----------------------------------------------------------------------------
// Adjust the size and visibility of the scrollbars as necessary, either due
// to a change in the size of the program or a change in the size of the
@@ -718,8 +718,8 @@ void MakeMainWindowControls(void)
//-----------------------------------------------------------------------------
void RefreshScrollbars(void)
{
- SCROLLINFO vert, horiz;
- SetUpScrollbars(&NeedHoriz, &horiz, &vert);
+ // SCROLLINFO vert, horiz;
+ // SetUpScrollbars(&NeedHoriz, &horiz, &vert);
// SetScrollInfo(HorizScrollBar, SB_CTL, &horiz, TRUE);
// SetScrollInfo(VertScrollBar, SB_CTL, &vert, TRUE);
@@ -741,9 +741,9 @@ void RefreshScrollbars(void)
// MoveWindow(VertScrollBar, main.right - ScrollWidth - 2, 1, ScrollWidth,
// NeedHoriz ? (IoListTop - ScrollHeight - 4) : (IoListTop - 3), TRUE);
- InvalidateRect(DrawWindow, NULL, FALSE);
+ // InvalidateRect(DrawWindow, NULL, FALSE);
}
-
+/*
//-----------------------------------------------------------------------------
// Respond to a WM_VSCROLL sent to the main window, presumably by the one and
// only vertical scrollbar that it has as a child.
@@ -866,7 +866,7 @@ void UpdateMainWindowTitleBar(void)
gtk_window_set_title (GTK_WINDOW (MainWindow), line);
}
-
+*/
//-----------------------------------------------------------------------------
// Set the enabled state of the logic menu items to reflect where we are on
// the schematic (e.g. can't insert two coils in series).
@@ -935,7 +935,7 @@ void SetMenusEnabled(BOOL canNegate, BOOL canNormal, BOOL canResetOnly,
EnableMenuItem(InstructionMenu, InsertUartSendMenu, t);
EnableMenuItem(InstructionMenu, InsertUartRecvMenu, t);
EnableMenuItem(InstructionMenu, InsertFmtdStrMenu, t);
-}*/
+}
//-----------------------------------------------------------------------------
// Set the enabled state of the undo/redo menus.
@@ -950,7 +950,7 @@ void SetUndoEnabled(BOOL undoEnabled, BOOL redoEnabled)
// Toggle whether we are in simulation mode. A lot of options are only
// available in one mode or the other.
//-----------------------------------------------------------------------------
-/*void ToggleSimulationMode(void)
+void ToggleSimulationMode(void)
{
InSimulationMode = !InSimulationMode;
if(InSimulationMode) {
@@ -973,13 +973,13 @@ void SetUndoEnabled(BOOL undoEnabled, BOOL redoEnabled)
ClearSimulationData(); // simulation.cpp, ldmicro.h
// Recheck InSimulationMode, because there could have been a Compile
// error, which would have kicked us out of simulation mode.
- if(UartFunctionUsed() && InSimulationMode) {
+ /*if(UartFunctionUsed() && InSimulationMode) {
ShowUartSimulationWindow(); // simulate.cpp
- }
+ }*/
}
else {
RealTimeSimulationRunning = FALSE;
- KillTimer(MainWindow, TIMER_SIMULATE);
+ // KillTimer(MainWindow, TIMER_SIMULATE);
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_GRAYED);
EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_GRAYED);
@@ -1003,10 +1003,10 @@ void SetUndoEnabled(BOOL undoEnabled, BOOL redoEnabled)
}
}
- UpdateMainWindowTitleBar();
+ // UpdateMainWindowTitleBar();
RefreshControlsToSettings();
}
-*/
+
//-----------------------------------------------------------------------------
// Cause the status bar and the list view to be in sync with the actual data
// structures describing the settings and the I/O configuration. Listview
@@ -1156,6 +1156,7 @@ void GenerateIoListDontLoseSelection(void)
//-----------------------------------------------------------------------------
void MainWindowResized(void)
{
+ IoListTop = DrawWindow->height();
//PaintWindow();
/*RECT main;
//GetClientRect(DrawWindow, &main);
@@ -1185,8 +1186,9 @@ void MainWindowResized(void)
// RefreshScrollbars();
// InvalidateRect(DrawWindow, NULL, FALSE);
+
}
-/*
+
//-----------------------------------------------------------------------------
// Start real-time simulation. Have to update the controls grayed status
// to reflect this.
@@ -1197,7 +1199,7 @@ void StartSimulation(void)
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_GRAYED);
EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_ENABLED);
StartSimulationTimer();
- UpdateMainWindowTitleBar();
+ // UpdateMainWindowTitleBar();
}
//-----------------------------------------------------------------------------
@@ -1210,7 +1212,7 @@ void StopSimulation(void)
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_ENABLED);
EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_GRAYED);
- KillTimer(MainWindow, TIMER_SIMULATE);
+ // KillTimer(MainWindow, TIMER_SIMULATE);
- UpdateMainWindowTitleBar();
-}*/ \ No newline at end of file
+ // UpdateMainWindowTitleBar();
+} \ No newline at end of file
diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp
index 9c5e9b3..b2a61ec 100644
--- a/ldmicro/schematic.cpp
+++ b/ldmicro/schematic.cpp
@@ -52,13 +52,13 @@ ElemLeaf DisplayMatrixFiller;
// where the cursor should go and calculate the coordinates (in pixels)
// of the rectangle that describes it; then BlinkCursor just has to XOR
// the requested rectangle at periodic intervals.
-PlcCursor Cursor;
+QRect Cursor;
//-----------------------------------------------------------------------------
// Find the address in the DisplayMatrix of the selected leaf element. Set
// *gx and *gy if we succeed and return TRUE, else return FALSE.
//-----------------------------------------------------------------------------
-/*BOOL FindSelected(int *gx, int *gy)
+BOOL FindSelected(int *gx, int *gy)
{
if(!Selected) return FALSE;
@@ -213,7 +213,7 @@ void WhatCanWeDoFromCursorAndTopology(void)
SetMenusEnabled(canNegate, canNormal, canResetOnly, canSetOnly, canDelete,
CanInsertEnd, CanInsertOther, canPushDown, canPushUp, CanInsertComment);
}
-*/
+
//-----------------------------------------------------------------------------
// Rub out freed element from the DisplayMatrix, just so we don't confuse
// ourselves too much (or access freed memory)...
@@ -250,7 +250,7 @@ void ForgetEverything(void)
// to do so, FALSE if not. The latter occurs given a completely empty
// program.
//-----------------------------------------------------------------------------
-/*BOOL MoveCursorTopLeft(void)
+BOOL MoveCursorTopLeft(void)
{
int i, j;
// Let us first try to place it somewhere on-screen, so start at the
@@ -402,7 +402,7 @@ void EditSelectedElement(void)
{
if(!Selected || Selected->selectedState == SELECTED_NONE) return;
- switch(SelectedWhich) {
+ /*switch(SelectedWhich) {
case ELEM_COMMENT:
ShowCommentDialog(Selected->d.comment.str);
break;
@@ -493,7 +493,7 @@ void EditSelectedElement(void)
case ELEM_LOOK_UP_TABLE:
ShowLookUpTableDialog(Selected);
break;
- }
+ }*/
}
//-----------------------------------------------------------------------------
@@ -514,7 +514,7 @@ void EditElementMouseDoubleclick(int x, int y)
gy += ScrollYOffset;
- if(InSimulationMode) {
+ /*if(InSimulationMode) {
ElemLeaf *l = DisplayMatrix[gx][gy];
if(l && DisplayMatrixWhich[gx][gy] == ELEM_CONTACTS) {
char *name = l->d.contacts.name;
@@ -528,7 +528,7 @@ void EditElementMouseDoubleclick(int x, int y)
if(DisplayMatrix[gx][gy] == Selected) {
EditSelectedElement();
}
- }
+ }*/
}
//-----------------------------------------------------------------------------
@@ -726,4 +726,3 @@ void MakeResetOnlySelected(void)
c->setOnly = FALSE;
c->negated = FALSE;
}
-*/ \ No newline at end of file
diff --git a/ldmicro/simulate.cpp b/ldmicro/simulate.cpp
index 59e7b6e..61c691c 100644
--- a/ldmicro/simulate.cpp
+++ b/ldmicro/simulate.cpp
@@ -693,7 +693,7 @@ void SimulateOneCycle(BOOL forceRefresh)
// event loop, and there is risk that we would go recursive. So let
// us fix that. (Note that there are no concurrency issues; we really
// would get called recursively, not just reentrantly.)
- static BOOL Simulating = FALSE;
+/* static BOOL Simulating = FALSE;
if(Simulating) return;
Simulating = TRUE;
@@ -719,7 +719,7 @@ void SimulateOneCycle(BOOL forceRefresh)
SimulateRedrawAfterNextCycle = FALSE;
if(NeedRedraw) SimulateRedrawAfterNextCycle = TRUE;
- Simulating = FALSE;
+ Simulating = FALSE;*/
}
//-----------------------------------------------------------------------------
@@ -730,14 +730,14 @@ void SimulateOneCycle(BOOL forceRefresh)
//-----------------------------------------------------------------------------
void StartSimulationTimer(void)
{
- int p = Prog.cycleTime/1000;
+ /* int p = Prog.cycleTime/1000;
if(p < 5) {
SetTimer(MainWindow, TIMER_SIMULATE, 10, PlcCycleTimer);
CyclesPerTimerTick = 10000 / Prog.cycleTime;
} else {
SetTimer(MainWindow, TIMER_SIMULATE, p, PlcCycleTimer);
CyclesPerTimerTick = 1;
- }
+ }*/
}
//-----------------------------------------------------------------------------
@@ -891,7 +891,7 @@ static void UartSimulationTextProc(HWID hwid, UINT umsg, char *text, UINT uszbuf
// characters that you type go into UART RECV instruction and whatever
// the program puts into UART SEND shows up as text.
//-----------------------------------------------------------------------------
-void ShowUartSimulationWindow(void)
+/*void ShowUartSimulationWindow(void)
{
DWORD TerminalX = 200, TerminalY = 200, TerminalW = 300, TerminalH = 150;
@@ -928,7 +928,7 @@ void ShowUartSimulationWindow(void)
gtk_window_set_keep_above (GTK_WINDOW(MainWindow), TRUE);
gtk_window_set_focus_visible (GTK_WINDOW(MainWindow), TRUE);
gtk_window_set_keep_above (GTK_WINDOW(MainWindow), FALSE);
-}
+}*/
//-----------------------------------------------------------------------------
// Get rid of the UART simulation terminal-type window.
diff --git a/ldmicro/undoredo.cpp b/ldmicro/undoredo.cpp
index 915aaa4..8bcfcc8 100644
--- a/ldmicro/undoredo.cpp
+++ b/ldmicro/undoredo.cpp
@@ -55,7 +55,7 @@ static struct {
// whenever we change it, for undo purposes. Fast enough that we shouldn't
// need to be smart.
//-----------------------------------------------------------------------------
-/*static void *DeepCopy(int which, void *any)
+static void *DeepCopy(int which, void *any)
{
switch(which) {
CASE_LEAF {
@@ -93,7 +93,7 @@ static struct {
break;
}
}
-*/
+
//-----------------------------------------------------------------------------
// Empty out a ProgramStack data structure, either .undo or .redo: set the
// count to zero and free all the program copies in it.
@@ -112,7 +112,7 @@ static void EmptyProgramStack(ProgramStack *ps)
}
}
}
-/*
+
//-----------------------------------------------------------------------------
// Push the current program onto a program stack. Can either make a deep or
// a shallow copy of the linked data structures.
@@ -228,7 +228,7 @@ void UndoRedo(void)
RefreshScrollbars();
InvalidateRect(MainWindow, NULL, FALSE);
}
-*/
+
//-----------------------------------------------------------------------------
// Empty out our undo history entirely, as when loading a new file.
//-----------------------------------------------------------------------------
@@ -245,8 +245,8 @@ void UndoFlush(void)
// notices that easily is the display code, which will respond by undoing
// the last operation, presumably the one that added the long line.
//-----------------------------------------------------------------------------
-/*BOOL CanUndo(void)
+BOOL CanUndo(void)
{
return (Undo.undo.count > 0);
-}*/
+}