summaryrefslogtreecommitdiff
path: root/ldmicro/draw_outputdev.cpp
diff options
context:
space:
mode:
authorNatsuDrag92018-06-27 09:57:32 +0530
committerGitHub2018-06-27 09:57:32 +0530
commit78fc70bd2d6d296697060bce13221edc909b71a5 (patch)
treeea1a20104ed2930aeb7e044988bdee35a3a109eb /ldmicro/draw_outputdev.cpp
parent6e9f72cb9a98eae5ef9ba403f905a2a9228f0b2b (diff)
parentbb4567164fdbeaaa47dd5525f9081e81e769725e (diff)
downloadLDMicroGtk-78fc70bd2d6d296697060bce13221edc909b71a5.tar.gz
LDMicroGtk-78fc70bd2d6d296697060bce13221edc909b71a5.tar.bz2
LDMicroGtk-78fc70bd2d6d296697060bce13221edc909b71a5.zip
Merge pull request #26 from NatsuDrag9/GUI_port
Gui port
Diffstat (limited to 'ldmicro/draw_outputdev.cpp')
-rw-r--r--ldmicro/draw_outputdev.cpp205
1 files changed, 102 insertions, 103 deletions
diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp
index 69f08ca..cf2cae4 100644
--- a/ldmicro/draw_outputdev.cpp
+++ b/ldmicro/draw_outputdev.cpp
@@ -81,9 +81,10 @@ 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.
//-----------------------------------------------------------------------------
-gboolean BlinkCursor(GtkWidget * window) //(HWND hwnd, UINT msg, UINT_PTR id, DWORD time)
+BOOL BlinkCursor(BOOL kill = FALSE)
{
// if(GetFocus(MainWindow) != !CursorDrawn) return TRUE;
+
if(Cursor.left == 0) return TRUE;
PlcCursor c;
@@ -101,7 +102,7 @@ gboolean BlinkCursor(GtkWidget * window) //(HWND hwnd, UINT msg, UINT_PTR id, DW
// 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);//
+ HCRDC Hcr = gdk_cairo_create(gtk_widget_get_window(DrawWindow));
static int PREV_x = c.left;
static int PREV_y = c.top;
@@ -126,11 +127,10 @@ gboolean BlinkCursor(GtkWidget * window) //(HWND hwnd, UINT msg, UINT_PTR id, DW
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;
+ return !kill;
}
//-----------------------------------------------------------------------------
@@ -342,13 +342,11 @@ void PaintWindow(HCRDC Hcr)
// BitBlt(paintDc, 0, 0, bw, bh, BackDc, ScrollXOffset, 0, SRCCOPY);
- // if(InSimulationMode) {
- // KillTimer(MainWindow, TIMER_BLINK_CURSOR);
- // } else {
- // KillTimer(MainWindow, TIMER_BLINK_CURSOR);
- // BlinkCursor(NULL, 0, NULL, 0);
- // SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor);
- // }
+ if(InSimulationMode) {
+ KillTimer(DrawWindow, TIMER_BLINK_CURSOR);
+ } else {
+ SetTimer(DrawWindow, TIMER_BLINK_CURSOR, 200, BlinkCursor);
+ }
ok();
}
@@ -431,7 +429,7 @@ void InitForDrawing(void)
// DrawChars function, for drawing to the export buffer instead of to the
// screen.
//-----------------------------------------------------------------------------
-static void DrawCharsToExportBuffer(int cx, int cy, char *str)
+static void DrawCharsToExportBuffer(HCRDC Hcr, int cx, int cy, const char *str)
{
while(*str) {
if(*str >= 10) {
@@ -447,105 +445,106 @@ static void DrawCharsToExportBuffer(int cx, int cy, char *str)
//-----------------------------------------------------------------------------
void ExportDrawingAsText(char *file)
{
- // int maxWidth = ProgCountWidestRow();
- // ColsAvailable = maxWidth;
-
- // int totalHeight = 0;
- // int i;
- // for(i = 0; i < Prog.numRungs; i++) {
- // totalHeight += CountHeightOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i]);
- // totalHeight += 1;
- // }
- // totalHeight *= POS_HEIGHT;
- // totalHeight += 3;
-
- // ExportBuffer = (char **)CheckMalloc(totalHeight * sizeof(char *));
+ int maxWidth = ProgCountWidestRow();
+ ColsAvailable = maxWidth;
+
+ int totalHeight = 0;
+ int i;
+ for(i = 0; i < Prog.numRungs; i++) {
+ totalHeight += CountHeightOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i]);
+ totalHeight += 1;
+ }
+ totalHeight *= POS_HEIGHT;
+ totalHeight += 3;
+
+ ExportBuffer = (char **)CheckMalloc(totalHeight * sizeof(char *));
- // int l = maxWidth*POS_WIDTH + 8;
- // for(i = 0; i < totalHeight; i++) {
- // ExportBuffer[i] = (char *)CheckMalloc(l);
- // memset(ExportBuffer[i], ' ', l-1);
- // ExportBuffer[i][4] = '|';
- // ExportBuffer[i][3] = '|';
- // ExportBuffer[i][l-3] = '|';
- // ExportBuffer[i][l-2] = '|';
- // ExportBuffer[i][l-1] = '\0';
- // }
-
- // DrawChars = DrawCharsToExportBuffer;
-
- // int cy = 1;
- // for(i = 0; i < Prog.numRungs; i++) {
- // int cx = 5;
- // DrawElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy,
- // Prog.rungPowered[i]);
-
- // if((i + 1) < 10) {
- // ExportBuffer[cy+1][1] = '0' + (i + 1);
- // } else {
- // ExportBuffer[cy+1][1] = '0' + ((i + 1) % 10);
- // ExportBuffer[cy+1][0] = '0' + ((i + 1) / 10);
- // }
-
- // cy += POS_HEIGHT*CountHeightOfElement(ELEM_SERIES_SUBCKT,
- // Prog.rungs[i]);
- // cy += POS_HEIGHT;
- // }
- // cy -= 2;
- // DrawEndRung(5, cy);
-
- // FILE *f = fopen(file, "w");
- // if(!f) {
- // Error(_("Couldn't open '%s'\n"), f);
- // return;
- // }
-
- // fprintf(f, "LDmicro export text\n");
-
- // if(Prog.mcu) {
- // fprintf(f, "for '%s', %.6f MHz crystal, %.1f ms cycle time\n\n",
- // Prog.mcu->mcuName, Prog.mcuClock/1e6, Prog.cycleTime/1e3);
- // } else {
- // fprintf(f, "no MCU assigned, %.6f MHz crystal, %.1f ms cycle time\n\n",
- // Prog.mcuClock/1e6, Prog.cycleTime/1e3);
- // }
-
- // fprintf(f, "\nLADDER DIAGRAM:\n\n");
-
- // for(i = 0; i < totalHeight; i++) {
- // ExportBuffer[i][4] = '|';
- // fprintf(f, "%s\n", ExportBuffer[i]);
- // CheckFree(ExportBuffer[i]);
- // }
- // CheckFree(ExportBuffer);
- // ExportBuffer = NULL;
-
- // fprintf(f, _("\n\nI/O ASSIGNMENT:\n\n"));
+ int l = maxWidth*POS_WIDTH + 8;
+ for(i = 0; i < totalHeight; i++) {
+ ExportBuffer[i] = (char *)CheckMalloc(l);
+ memset(ExportBuffer[i], ' ', l-1);
+ ExportBuffer[i][4] = '|';
+ ExportBuffer[i][3] = '|';
+ ExportBuffer[i][l-3] = '|';
+ ExportBuffer[i][l-2] = '|';
+ ExportBuffer[i][l-1] = '\0';
+ }
+
+ DrawChars = DrawCharsToExportBuffer;
+
+ int cy = 1;
+
+ for(i = 0; i < Prog.numRungs; i++) {
+ int cx = 5;
+ DrawElement(NULL, ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy,
+ Prog.rungPowered[i]);
+
+ if((i + 1) < 10) {
+ ExportBuffer[cy+1][1] = '0' + (i + 1);
+ } else {
+ ExportBuffer[cy+1][1] = '0' + ((i + 1) % 10);
+ ExportBuffer[cy+1][0] = '0' + ((i + 1) / 10);
+ }
+
+ cy += POS_HEIGHT*CountHeightOfElement(ELEM_SERIES_SUBCKT,
+ Prog.rungs[i]);
+ cy += POS_HEIGHT;
+ }
+ cy -= 2;
+ DrawEndRung(NULL, 5, cy);
+
+ FILE *f = fopen(file, "w");
+ if(!f) {
+ Error(_("Couldn't open '%s'\n"), f);
+ return;
+ }
+
+ fprintf(f, "LDmicro export text\n");
+
+ if(Prog.mcu) {
+ fprintf(f, "for '%s', %.6f MHz crystal, %.1f ms cycle time\n\n",
+ Prog.mcu->mcuName, Prog.mcuClock/1e6, Prog.cycleTime/1e3);
+ } else {
+ fprintf(f, "no MCU assigned, %.6f MHz crystal, %.1f ms cycle time\n\n",
+ Prog.mcuClock/1e6, Prog.cycleTime/1e3);
+ }
+
+ fprintf(f, "\nLADDER DIAGRAM:\n\n");
+
+ for(i = 0; i < totalHeight; i++) {
+ ExportBuffer[i][4] = '|';
+ fprintf(f, "%s\n", ExportBuffer[i]);
+ CheckFree(ExportBuffer[i]);
+ }
+ CheckFree(ExportBuffer);
+ ExportBuffer = NULL;
+
+ fprintf(f, _("\n\nI/O ASSIGNMENT:\n\n"));
- // fprintf(f, _(" Name | Type | Pin\n"));
- // fprintf(f, " ----------------------------+--------------------+------\n");
- // for(i = 0; i < Prog.io.count; i++) {
- // char b[1024];
- // memset(b, '\0', sizeof(b));
+ fprintf(f, _(" Name | Type | Pin\n"));
+ fprintf(f, " ----------------------------+--------------------+------\n");
+ for(i = 0; i < Prog.io.count; i++) {
+ char b[1024];
+ memset(b, '\0', sizeof(b));
- // PlcProgramSingleIo *io = &Prog.io.assignment[i];
- // char *type = IoTypeToString(io->type);
- // char pin[MAX_NAME_LEN];
+ PlcProgramSingleIo *io = &Prog.io.assignment[i];
+ char *type = IoTypeToString(io->type);
+ char pin[MAX_NAME_LEN];
- // PinNumberForIo(pin, io);
+ PinNumberForIo(pin, io);
- // sprintf(b, " | | %s\n",
- // pin);
+ sprintf(b, " | | %s\n",
+ pin);
- // memcpy(b+2, io->name, strlen(io->name));
- // memcpy(b+31, type, strlen(type));
- // fprintf(f, "%s", b);
- // }
+ memcpy(b+2, io->name, strlen(io->name));
+ memcpy(b+31, type, strlen(type));
+ fprintf(f, "%s", b);
+ }
- // fclose(f);
+ fclose(f);
- // // we may have trashed the grid tables a bit; a repaint will fix that
- // InvalidateRect(MainWindow, NULL, FALSE);
+ // we may have trashed the grid tables a bit; a repaint will fix that
+ InvalidateRect(MainWindow, NULL, FALSE);
}
//-----------------------------------------------------------------------------