summaryrefslogtreecommitdiff
path: root/ldmicro
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro')
-rw-r--r--ldmicro/draw.cpp326
-rw-r--r--ldmicro/draw_outputdev.cpp282
-rw-r--r--ldmicro/includes/ldmicro.h4
-rw-r--r--ldmicro/ldmicro.cpp67
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h33
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp116
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h64
7 files changed, 528 insertions, 364 deletions
diff --git a/ldmicro/draw.cpp b/ldmicro/draw.cpp
index f08e34c..a231745 100644
--- a/ldmicro/draw.cpp
+++ b/ldmicro/draw.cpp
@@ -75,111 +75,111 @@ BOOL ThisHighlighted;
// of the widths of its members, and the width of a parallel circuit is
// the maximum of the widths of its members.
//-----------------------------------------------------------------------------
-// static int CountWidthOfElement(int which, void *elem, int soFar)
-// {
-// switch(which) {
-// case ELEM_PLACEHOLDER:
-// case ELEM_OPEN:
-// case ELEM_SHORT:
-// case ELEM_CONTACTS:
-// case ELEM_TON:
-// case ELEM_TOF:
-// case ELEM_RTO:
-// case ELEM_CTU:
-// case ELEM_CTD:
-// case ELEM_ONE_SHOT_RISING:
-// case ELEM_ONE_SHOT_FALLING:
-// case ELEM_EQU:
-// case ELEM_NEQ:
-// case ELEM_GRT:
-// case ELEM_GEQ:
-// case ELEM_LES:
-// case ELEM_LEQ:
-// case ELEM_UART_RECV:
-// case ELEM_UART_SEND:
-// return 1;
-
-// case ELEM_FORMATTED_STRING:
-// return 2;
-
-// case ELEM_COMMENT: {
-// if(soFar != 0) oops();
-
-// ElemLeaf *l = (ElemLeaf *)elem;
-// char tbuf[MAX_COMMENT_LEN];
-
-// strcpy(tbuf, l->d.comment.str);
-// char *b = strchr(tbuf, '\n');
-
-// int len;
-// if(b) {
-// *b = '\0';
-// len = max(strlen(tbuf)-1, strlen(b+1));
-// } else {
-// len = strlen(tbuf);
-// }
-// // round up, and allow space for lead-in
-// len = (len + 7 + (POS_WIDTH-1)) / POS_WIDTH;
-// return max(ColsAvailable, len);
-// }
-// case ELEM_CTC:
-// case ELEM_RES:
-// case ELEM_COIL:
-// case ELEM_MOVE:
-// case ELEM_SHIFT_REGISTER:
-// case ELEM_LOOK_UP_TABLE:
-// case ELEM_PIECEWISE_LINEAR:
-// case ELEM_MASTER_RELAY:
-// case ELEM_READ_ADC:
-// case ELEM_SET_PWM:
-// case ELEM_PERSIST:
-// if(ColsAvailable - soFar > 1) {
-// return ColsAvailable - soFar;
-// } else {
-// return 1;
-// }
-
-// case ELEM_ADD:
-// case ELEM_SUB:
-// case ELEM_MUL:
-// case ELEM_DIV:
-// if(ColsAvailable - soFar > 2) {
-// return ColsAvailable - soFar;
-// } else {
-// return 2;
-// }
-
-// case ELEM_SERIES_SUBCKT: {
-// // total of the width of the members
-// int total = 0;
-// int i;
-// ElemSubcktSeries *s = (ElemSubcktSeries *)elem;
-// for(i = 0; i < s->count; i++) {
-// total += CountWidthOfElement(s->contents[i].which,
-// s->contents[i].d.any, total+soFar);
-// }
-// return total;
-// }
-
-// case ELEM_PARALLEL_SUBCKT: {
-// // greatest of the width of the members
-// int max = 0;
-// int i;
-// ElemSubcktParallel *p = (ElemSubcktParallel *)elem;
-// for(i = 0; i < p->count; i++) {
-// int w = CountWidthOfElement(p->contents[i].which,
-// p->contents[i].d.any, soFar);
-// if(w > max) {
-// max = w;
-// }
-// }
-// return max;
-// }
-
-// default:
-// oops();
-// }
-// }
+static int CountWidthOfElement(int which, void *elem, int soFar)
+{
+ switch(which) {
+ case ELEM_PLACEHOLDER:
+ case ELEM_OPEN:
+ case ELEM_SHORT:
+ case ELEM_CONTACTS:
+ case ELEM_TON:
+ case ELEM_TOF:
+ case ELEM_RTO:
+ case ELEM_CTU:
+ case ELEM_CTD:
+ case ELEM_ONE_SHOT_RISING:
+ case ELEM_ONE_SHOT_FALLING:
+ case ELEM_EQU:
+ case ELEM_NEQ:
+ case ELEM_GRT:
+ case ELEM_GEQ:
+ case ELEM_LES:
+ case ELEM_LEQ:
+ case ELEM_UART_RECV:
+ case ELEM_UART_SEND:
+ return 1;
+
+ case ELEM_FORMATTED_STRING:
+ return 2;
+
+ case ELEM_COMMENT: {
+ if(soFar != 0) oops();
+
+ ElemLeaf *l = (ElemLeaf *)elem;
+ char tbuf[MAX_COMMENT_LEN];
+
+ strcpy(tbuf, l->d.comment.str);
+ char *b = strchr(tbuf, '\n');
+
+ int len;
+ if(b) {
+ *b = '\0';
+ len = max(strlen(tbuf)-1, strlen(b+1));
+ } else {
+ len = strlen(tbuf);
+ }
+ // round up, and allow space for lead-in
+ len = (len + 7 + (POS_WIDTH-1)) / POS_WIDTH;
+ return max(ColsAvailable, len);
+ }
+ case ELEM_CTC:
+ case ELEM_RES:
+ case ELEM_COIL:
+ case ELEM_MOVE:
+ case ELEM_SHIFT_REGISTER:
+ case ELEM_LOOK_UP_TABLE:
+ case ELEM_PIECEWISE_LINEAR:
+ case ELEM_MASTER_RELAY:
+ case ELEM_READ_ADC:
+ case ELEM_SET_PWM:
+ case ELEM_PERSIST:
+ if(ColsAvailable - soFar > 1) {
+ return ColsAvailable - soFar;
+ } else {
+ return 1;
+ }
+
+ case ELEM_ADD:
+ case ELEM_SUB:
+ case ELEM_MUL:
+ case ELEM_DIV:
+ if(ColsAvailable - soFar > 2) {
+ return ColsAvailable - soFar;
+ } else {
+ return 2;
+ }
+
+ case ELEM_SERIES_SUBCKT: {
+ // total of the width of the members
+ int total = 0;
+ int i;
+ ElemSubcktSeries *s = (ElemSubcktSeries *)elem;
+ for(i = 0; i < s->count; i++) {
+ total += CountWidthOfElement(s->contents[i].which,
+ s->contents[i].d.any, total+soFar);
+ }
+ return total;
+ }
+
+ case ELEM_PARALLEL_SUBCKT: {
+ // greatest of the width of the members
+ int max = 0;
+ int i;
+ ElemSubcktParallel *p = (ElemSubcktParallel *)elem;
+ for(i = 0; i < p->count; i++) {
+ int w = CountWidthOfElement(p->contents[i].which,
+ p->contents[i].d.any, soFar);
+ if(w > max) {
+ max = w;
+ }
+ }
+ return max;
+ }
+
+ default:
+ oops();
+ }
+}
//-----------------------------------------------------------------------------
// Determine the height, in leaf element units, of a particular subcircuit.
@@ -188,63 +188,63 @@ BOOL ThisHighlighted;
// maximum of the heights of its members. (This is the dual of the width
// case.)
//-----------------------------------------------------------------------------
-// int CountHeightOfElement(int which, void *elem)
-// {
-// switch(which) {
-// CASE_LEAF
-// return 1;
-
-// case ELEM_PARALLEL_SUBCKT: {
-// // total of the height of the members
-// int total = 0;
-// int i;
-// ElemSubcktParallel *s = (ElemSubcktParallel *)elem;
-// for(i = 0; i < s->count; i++) {
-// total += CountHeightOfElement(s->contents[i].which,
-// s->contents[i].d.any);
-// }
-// return total;
-// }
-
-// case ELEM_SERIES_SUBCKT: {
-// // greatest of the height of the members
-// int max = 0;
-// int i;
-// ElemSubcktSeries *s = (ElemSubcktSeries *)elem;
-// for(i = 0; i < s->count; i++) {
-// int w = CountHeightOfElement(s->contents[i].which,
-// s->contents[i].d.any);
-// if(w > max) {
-// max = w;
-// }
-// }
-// return max;
-// }
-
-// default:
-// oops();
-// }
-// }
+int CountHeightOfElement(int which, void *elem)
+{
+ switch(which) {
+ CASE_LEAF
+ return 1;
+
+ case ELEM_PARALLEL_SUBCKT: {
+ // total of the height of the members
+ int total = 0;
+ int i;
+ ElemSubcktParallel *s = (ElemSubcktParallel *)elem;
+ for(i = 0; i < s->count; i++) {
+ total += CountHeightOfElement(s->contents[i].which,
+ s->contents[i].d.any);
+ }
+ return total;
+ }
+
+ case ELEM_SERIES_SUBCKT: {
+ // greatest of the height of the members
+ int max = 0;
+ int i;
+ ElemSubcktSeries *s = (ElemSubcktSeries *)elem;
+ for(i = 0; i < s->count; i++) {
+ int w = CountHeightOfElement(s->contents[i].which,
+ s->contents[i].d.any);
+ if(w > max) {
+ max = w;
+ }
+ }
+ return max;
+ }
+
+ default:
+ oops();
+ }
+}
//-----------------------------------------------------------------------------
// Determine the width, in leaf element units, of the widest row of the PLC
// program (i.e. loop over all the rungs and find the widest).
//-----------------------------------------------------------------------------
-// int ProgCountWidestRow(void)
-// {
-// int i;
-// int max = 0;
-// int colsTemp = ColsAvailable;
-// ColsAvailable = 0;
-// for(i = 0; i < Prog.numRungs; i++) {
-// int w = CountWidthOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], 0);
-// if(w > max) {
-// max = w;
-// }
-// }
-// ColsAvailable = colsTemp;
-// return max;
-// }
+int ProgCountWidestRow(void)
+{
+ int i;
+ int max = 0;
+ int colsTemp = ColsAvailable;
+ ColsAvailable = 0;
+ for(i = 0; i < Prog.numRungs; i++) {
+ int w = CountWidthOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], 0);
+ if(w > max) {
+ max = w;
+ }
+ }
+ ColsAvailable = colsTemp;
+ return max;
+}
//-----------------------------------------------------------------------------
// Draw a vertical wire one leaf element unit high up from (cx, cy), where cx
@@ -926,8 +926,8 @@ BOOL ThisHighlighted;
// element, else FALSE. This is needed to colour all the wires correctly,
// since the colouring indicates whether a wire is energized.
//-----------------------------------------------------------------------------
-// BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore)
-// {
+BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore)
+{
// BOOL poweredAfter;
// int cx0 = *cx, cy0 = *cy;
@@ -1047,14 +1047,14 @@ BOOL ThisHighlighted;
// NormText();
// return poweredAfter;
-// }
+}
//-----------------------------------------------------------------------------
// Draw the rung that signals the end of the program. Kind of useless but
// do it anyways, for convention.
//-----------------------------------------------------------------------------
-// void DrawEndRung(int cx, int cy)
-// {
+void DrawEndRung(int cx, int cy)
+{
// int i;
// char *str = "[END]";
// int lead = (POS_WIDTH - strlen(str))/2;
@@ -1067,4 +1067,4 @@ BOOL ThisHighlighted;
// for(; i < ColsAvailable*POS_WIDTH; i++) {
// DrawChars(cx + i, cy + (POS_HEIGHT/2), "-");
// }
-// }
+}
diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp
index 5bdf58e..fdb8bc2 100644
--- a/ldmicro/draw_outputdev.cpp
+++ b/ldmicro/draw_outputdev.cpp
@@ -191,10 +191,9 @@ static void DrawCharsToScreen(int cx, int cy, char *str)
//-----------------------------------------------------------------------------
int ScreenColsAvailable(void)
{
- // RECT r;
- // GetClientRect(MainWindow, &r);
+ int rw = gtk_widget_get_allocated_width (DrawWindow);
- // return (r.right - (X_PADDING + X_RIGHT_PADDING)) / (POS_WIDTH*FONT_WIDTH);
+ return (rw - (X_PADDING + X_RIGHT_PADDING)) / (POS_WIDTH*FONT_WIDTH);
}
//-----------------------------------------------------------------------------
@@ -205,13 +204,13 @@ int ScreenColsAvailable(void)
//-----------------------------------------------------------------------------
int ScreenRowsAvailable(void)
{
- // int adj;
- // if(ScrollXOffsetMax == 0) {
- // adj = 0;
- // } else {
- // adj = 18;
- // }
- // return (IoListTop - Y_PADDING - adj) / (POS_HEIGHT*FONT_HEIGHT);
+ int adj;
+ if(ScrollXOffsetMax == 0) {
+ adj = 0;
+ } else {
+ adj = 18;
+ }
+ return (IoListTop - Y_PADDING - adj) / (POS_HEIGHT*FONT_HEIGHT);
}
//-----------------------------------------------------------------------------
@@ -219,18 +218,43 @@ 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)
+void PaintWindow(HCRDC hcr)
{
+ /*
+ cairo_set_source_rgb(cr, Cairo_R, Cairo_G, Cairo_G);
+
+ cairo_select_font_face(cr, "Purisa",
+ CAIRO_FONT_SLANT_NORMAL,
+ CAIRO_FONT_WEIGHT_BOLD);
+
+ cairo_set_font_size(cr, 20);
+
+ cairo_move_to(cr, 20, height / 2.0);
+ cairo_show_text(cr, "-----------THIS IS A TEST DRAW----------");
+
+ cairo_fill (cr);
+ */
+
+ SetBkColor(DrawWindow, hcr, InSimulationMode ? HighlightColours.simBg :
+ HighlightColours.bg);
+
+ SetTextColor(hcr, InSimulationMode ? HighlightColours.simRungNum :
+ HighlightColours.rungNum);
+
+ SelectObject(hcr, FixedWidthFont);
+
+ TextOut(hcr, 50, 100, "-----HELLO----", 14);
// static HBITMAP BackBitmap;
// static HDC BackDc;
// static int BitmapWidth;
- // ok();
+ ok();
// RECT r;
// GetClientRect(MainWindow, &r);
- // int bw = r.right;
- // int bh = IoListTop;
+
+ int bw = gtk_widget_get_allocated_width (DrawWindow);// = r.right;
+ int bh = IoListTop;
// HDC paintDc;
// if(!BackDc) {
@@ -251,103 +275,103 @@ void PaintWindow(void)
// fi.right = BitmapWidth; fi.bottom = bh;
// FillRect(Hdc, &fi, InSimulationMode ? SimBgBrush : BgBrush);
- // // now figure out how we should draw the ladder logic
- // ColsAvailable = ProgCountWidestRow();
- // if(ColsAvailable < ScreenColsAvailable()) {
- // ColsAvailable = ScreenColsAvailable();
- // }
- // memset(DisplayMatrix, 0, sizeof(DisplayMatrix));
- // SelectionActive = FALSE;
- // memset(&Cursor, 0, sizeof(Cursor));
-
- // DrawChars = DrawCharsToScreen;
-
- // int i;
- // int cy = 0;
- // int rowsAvailable = ScreenRowsAvailable();
- // for(i = 0; i < Prog.numRungs; i++) {
- // int thisHeight = POS_HEIGHT*CountHeightOfElement(ELEM_SERIES_SUBCKT,
- // Prog.rungs[i]);
-
- // // For speed, there is no need to draw everything all the time, but
- // // we still must draw a bit above and below so that the DisplayMatrix
- // // is filled in enough to make it possible to reselect using the
- // // cursor keys.
- // if(((cy + thisHeight) >= (ScrollYOffset - 8)*POS_HEIGHT) &&
- // (cy < (ScrollYOffset + rowsAvailable + 8)*POS_HEIGHT))
- // {
- // SetBkColor(Hdc, InSimulationMode ? HighlightColours.simBg :
- // HighlightColours.bg);
- // SetTextColor(Hdc, InSimulationMode ? HighlightColours.simRungNum :
- // HighlightColours.rungNum);
- // SelectObject(Hdc, FixedWidthFont);
- // int rung = i + 1;
- // int y = Y_PADDING + FONT_HEIGHT*cy;
- // int yp = y + FONT_HEIGHT*(POS_HEIGHT/2) -
- // POS_HEIGHT*FONT_HEIGHT*ScrollYOffset;
-
- // if(rung < 10) {
- // char r[1] = { rung + '0' };
- // TextOut(Hdc, 8 + FONT_WIDTH, yp, r, 1);
- // } else {
- // char r[2] = { (rung / 10) + '0', (rung % 10) + '0' };
- // TextOut(Hdc, 8, yp, r, 2);
- // }
-
- // int cx = 0;
- // DrawElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy,
- // Prog.rungPowered[i]);
- // }
+ /// now figure out how we should draw the ladder logic
+ ColsAvailable = ProgCountWidestRow();
+ if(ColsAvailable < ScreenColsAvailable()) {
+ ColsAvailable = ScreenColsAvailable();
+ }
+ memset(DisplayMatrix, 0, sizeof(DisplayMatrix));
+ SelectionActive = FALSE;
+ memset(&Cursor, 0, sizeof(Cursor));
+
+ DrawChars = DrawCharsToScreen;
+
+ int i;
+ int cy = 0;
+ int rowsAvailable = ScreenRowsAvailable();
+ for(i = 0; i < Prog.numRungs; i++) {
+ int thisHeight = POS_HEIGHT*CountHeightOfElement(ELEM_SERIES_SUBCKT,
+ Prog.rungs[i]);
+
+ // For speed, there is no need to draw everything all the time, but
+ // we still must draw a bit above and below so that the DisplayMatrix
+ // is filled in enough to make it possible to reselect using the
+ // cursor keys.
+ if(((cy + thisHeight) >= (ScrollYOffset - 8)*POS_HEIGHT) &&
+ (cy < (ScrollYOffset + rowsAvailable + 8)*POS_HEIGHT))
+ {
+ SetBkColor(DrawWindow, hcr, InSimulationMode ? HighlightColours.simBg :
+ HighlightColours.bg);
+ SetTextColor(hcr, InSimulationMode ? HighlightColours.simRungNum :
+ HighlightColours.rungNum);
+ SelectObject(hcr, FixedWidthFont);
+ int rung = i + 1;
+ int y = Y_PADDING + FONT_HEIGHT*cy;
+ int yp = y + FONT_HEIGHT*(POS_HEIGHT/2) -
+ POS_HEIGHT*FONT_HEIGHT*ScrollYOffset;
+
+ if(rung < 10) {
+ char r[1] = { rung + '0' };
+ TextOut(hcr, 8 + FONT_WIDTH, yp, r, 1);
+ } else {
+ char r[2] = { (rung / 10) + '0', (rung % 10) + '0' };
+ TextOut(hcr, 8, yp, r, 2);
+ }
+
+ // int cx = 0;
+ // // DrawElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy,
+ // // Prog.rungPowered[i]);
+ }
- // cy += thisHeight;
- // cy += POS_HEIGHT;
- // }
+ cy += thisHeight;
+ cy += POS_HEIGHT;
+ }
// cy -= 2;
- // DrawEndRung(0, cy);
+ // // DrawEndRung(0, cy);
// if(SelectedGxAfterNextPaint >= 0) {
- // MoveCursorNear(SelectedGxAfterNextPaint, SelectedGyAfterNextPaint);
- // InvalidateRect(MainWindow, NULL, FALSE);
- // SelectedGxAfterNextPaint = -1;
- // SelectedGyAfterNextPaint = -1;
+ // // 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);
+ // // SelectElement(-1, -1, Selected->selectedState);
+ // // ScrollSelectedIntoViewAfterNextPaint = FALSE;
+ // // InvalidateRect(MainWindow, NULL, FALSE);
// } else {
// if(!SelectionActive) {
// if(Prog.numRungs > 0) {
- // if(MoveCursorTopLeft()) {
- // InvalidateRect(MainWindow, NULL, FALSE);
- // }
+ // // if(MoveCursorTopLeft()) {
+ // // InvalidateRect(MainWindow, 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;
- // 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;
+ // // Hdc = paintDc;
// ok();
}
@@ -391,52 +415,38 @@ static void SetSyntaxHighlightingColours(void)
void InitForDrawing(void)
{
DrawWindow = gtk_drawing_area_new ();
- // SetSyntaxHighlightingColours();
-
- // FixedWidthFont = CreateFont(
- // FONT_HEIGHT, FONT_WIDTH,
- // 0, 0,
- // FW_REGULAR,
- // FALSE,
- // FALSE,
- // FALSE,
- // ANSI_CHARSET,
- // OUT_DEFAULT_PRECIS,
- // CLIP_DEFAULT_PRECIS,
- // DEFAULT_QUALITY,
- // FF_DONTCARE,
- // "Lucida Console");
-
- // FixedWidthFontBold = CreateFont(
- // FONT_HEIGHT, FONT_WIDTH,
- // 0, 0,
- // FW_REGULAR, // the bold text renders funny under Vista
- // FALSE,
- // FALSE,
- // FALSE,
- // ANSI_CHARSET,
- // OUT_DEFAULT_PRECIS,
- // CLIP_DEFAULT_PRECIS,
- // DEFAULT_QUALITY,
- // FF_DONTCARE,
- // "Lucida Console");
-
- // LOGBRUSH lb;
- // lb.lbStyle = BS_SOLID;
- // lb.lbColor = HighlightColours.simBusRight;
- // BusRightBus = CreateBrushIndirect(&lb);
-
- // lb.lbColor = HighlightColours.simBusLeft;
- // BusLeftBrush = CreateBrushIndirect(&lb);
-
- // lb.lbColor = HighlightColours.bus;
- // BusBrush = CreateBrushIndirect(&lb);
-
- // lb.lbColor = HighlightColours.bg;
- // BgBrush = CreateBrushIndirect(&lb);
-
- // lb.lbColor = HighlightColours.simBg;
- // SimBgBrush = CreateBrushIndirect(&lb);
+ SetSyntaxHighlightingColours();
+
+ FixedWidthFont = CreateFont(
+ FONT_HEIGHT, FONT_WIDTH,
+ 0,
+ FW_REGULAR,
+ FALSE,
+ "Lucida Console");
+
+ FixedWidthFontBold = CreateFont(
+ FONT_HEIGHT, FONT_WIDTH,
+ 0,
+ FW_REGULAR, // the bold text renders funny under Vista
+ FALSE,
+ "Lucida Console");
+
+ LOGBRUSH lb;
+ lb.lbStyle = BS_SOLID;
+ lb.lbColor = HighlightColours.simBusRight;
+ BusRightBus = CreateBrushIndirect(&lb);
+
+ lb.lbColor = HighlightColours.simBusLeft;
+ BusLeftBrush = CreateBrushIndirect(&lb);
+
+ lb.lbColor = HighlightColours.bus;
+ BusBrush = CreateBrushIndirect(&lb);
+
+ lb.lbColor = HighlightColours.bg;
+ BgBrush = CreateBrushIndirect(&lb);
+
+ lb.lbColor = HighlightColours.simBg;
+ SimBgBrush = CreateBrushIndirect(&lb);
}
//-----------------------------------------------------------------------------
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h
index eaf8dcd..257a8be 100644
--- a/ldmicro/includes/ldmicro.h
+++ b/ldmicro/includes/ldmicro.h
@@ -517,7 +517,7 @@ void RefreshScrollbars(void);
extern HINSTANCE Instance;
extern HWID MainWindow;
extern HWID DrawWindow;
-extern HDC Hdc;
+extern HCRDC Hdc;
extern PlcProgram Prog;
extern char CurrentSaveFile[MAX_PATH];
extern char CurrentCompileFile[MAX_PATH];
@@ -560,7 +560,7 @@ extern BOOL ThisHighlighted;
// draw_outputdev.cpp
extern void (*DrawChars)(int, int, char *);
void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time);
-void PaintWindow(void);
+void PaintWindow(cairo_t *cr);
void ExportDrawingAsText(char *file);
void InitForDrawing(void);
void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert);
diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp
index 1bea92c..2806cfa 100644
--- a/ldmicro/ldmicro.cpp
+++ b/ldmicro/ldmicro.cpp
@@ -36,7 +36,7 @@
HINSTANCE Instance;
HWID MainWindow;
HWID DrawWindow;
-HDC Hdc;
+HCRDC Hdc;
// parameters used to capture the mouse when implementing our totally non-
// general splitter control
@@ -1044,58 +1044,59 @@ gboolean LD_WM_MouseMove_call(GtkWidget *widget, GdkEvent *event, gpointer user_
return FALSE;
}
-gboolean LD_WM_Paint_call(GtkWidget *widget, cairo_t *cr, gpointer data)
+gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data)
{
/* Handles:
* WM_PAINT
*/
g_print("draw called\n");
-
- guint width, height;
- GdkRGBA color;
- GtkStyleContext *context;
- context = gtk_widget_get_style_context (widget);
+ // guint width, height;
+ // GdkRGBA color;
+ // GtkStyleContext *context;
+
+ // context = gtk_widget_get_style_context (widget);
- width = gtk_widget_get_allocated_width (widget);
- height = gtk_widget_get_allocated_height (widget);
+ // width = gtk_widget_get_allocated_width (widget);
+ // height = gtk_widget_get_allocated_height (widget);
- gtk_render_background (context, cr, 0, 0, width, height);
+ // gtk_render_background (context, cr, 0, 0, width, height);
- cairo_arc (cr,
- width / 2.0, height / 2.0,
- MIN (width, height) / 3.0,
- 0, 2 * G_PI);
+ // cairo_arc (cr,
+ // width / 2.0, height / 2.0,
+ // MIN (width, height) / 3.0,
+ // 0, 2 * G_PI);
- gtk_style_context_get_color (context,
- gtk_style_context_get_state (context),
- &color);
- gdk_cairo_set_source_rgba (cr, &color);
+ // gtk_style_context_get_color (context,
+ // gtk_style_context_get_state (context),
+ // &color);
+ // gdk_cairo_set_source_rgba (cr, &color);
- cairo_fill (cr);
- static double Cairo_R = 0.0, Cairo_G = 0.0, Cairo_B = 0.0;
- cairo_set_source_rgb(cr, Cairo_R, Cairo_G, Cairo_G);
- Cairo_R = (Cairo_R+0.2 > 0.4) ? 0 : Cairo_R+0.2;
- Cairo_G = (Cairo_G+0.4 > 1.0) ? 0.4 : Cairo_G+0.4;
- Cairo_B = (Cairo_B+0.1 > 0.5) ? 0 : Cairo_B+0.1;
+ // cairo_fill (cr);
+ // static double Cairo_R = 0.0, Cairo_G = 0.0, Cairo_B = 0.0;
+ // cairo_set_source_rgb(cr, Cairo_R, Cairo_G, Cairo_G);
+ // Cairo_R = (Cairo_R+0.2 > 0.4) ? 0 : Cairo_R+0.2;
+ // Cairo_G = (Cairo_G+0.4 > 1.0) ? 0.4 : Cairo_G+0.4;
+ // Cairo_B = (Cairo_B+0.1 > 0.5) ? 0 : Cairo_B+0.1;
- cairo_select_font_face(cr, "Purisa",
- CAIRO_FONT_SLANT_NORMAL,
- CAIRO_FONT_WEIGHT_BOLD);
+ // cairo_select_font_face(cr, "Purisa",
+ // CAIRO_FONT_SLANT_NORMAL,
+ // CAIRO_FONT_WEIGHT_BOLD);
- cairo_set_font_size(cr, 20);
+ // cairo_set_font_size(cr, 20);
- cairo_move_to(cr, 20, height / 2.0);
- cairo_show_text(cr, "-----------THIS IS A TEST DRAW----------");
+ // cairo_move_to(cr, 20, height / 2.0);
+ // cairo_show_text(cr, "-----------THIS IS A TEST DRAW----------");
- cairo_fill (cr);
+ // cairo_fill (cr);
+
// PAINTSTRUCT ps;
// Hdc = BeginPaint(hwnd, &ps);
- // // This draws the schematic.
- // PaintWindow();
+ /// This draws the schematic.
+ PaintWindow(cr);
// RECT r;
// // Fill around the scroll bars
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index 6f1e4f0..5f8e0e7 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -4,6 +4,7 @@
#include "linuxUI.h"
#include <ctype.h>
#include <vector>
+#include <math.h>
#include <algorithm>
#include <sys/mman.h>
@@ -21,6 +22,9 @@
#define IMAGE_ICON 1
#define LDMICRO_ICON "../ldmicro.ico"
+/// Macro functions
+#define max(_A, _B) std::max(_A, _B)
+
/// Typedefs
//typedef int64_t __int64;
typedef bool BOOL;
@@ -54,14 +58,14 @@ typedef CHAR *LPSTR;
typedef void *PVOID;
typedef void *LPVOID;
-typedef PVOID HFONT;
typedef PVOID HMODULE;
typedef PVOID HHOOK;
-typedef PVOID HFONT;
typedef PVOID HANDLE;
typedef HANDLE HINSTANCE;
-typedef HANDLE HDC;
+typedef HANDLE HGDIOBJ;
+
+typedef cairo_t *HCRDC;
typedef GtkWidget *HWID;
typedef GtkWidget *HMENU;
typedef GtkWindow *HWND;
@@ -106,6 +110,14 @@ typedef class tagColorReferance: public GdkRGBA{
this->alpha = 1.0;
}
+ // tagColorReferance(tagColorReferance &refCpy)
+ // {
+ // this->red = refCpy.red;
+ // this->green = refCpy.green;
+ // this->blue = refCpy.blue;
+ // this->alpha = refCpy.alpha;
+ // }
+
GdkRGBA* getThis()
{
return this;
@@ -143,6 +155,21 @@ typedef struct tagNMHDR {
UINT code;
} NMHDR;
+typedef struct FontTag {
+ int nHeight;
+ int nWidth;
+ int nOrientation;
+ int fnWeight;
+ DWORD fdwItalic;
+ LPCTSTR lpszFace;
+} *HFONT, FONT;
+
+typedef struct tagLOGBRUSH {
+ UINT lbStyle;
+ COLORREF lbColor;
+// ULONG_PTR lbHatch;
+} LOGBRUSH, *PLOGBRUSH;
+
/// Variables
extern std::vector<HEAPRECORD> HeapRecord;
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index f0c9124..23ac060 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -27,24 +27,6 @@ COLORREF RGB(int red, int green, int blue)
return col;
}
-HANDLE GetStockObject(int fnObject)
-{
- switch(fnObject)
- {
- case BLACK_BRUSH:
- return new COLORREF(0, 0, 0);
- break;
- case WHITE_BRUSH:
- return new COLORREF(255, 255, 255);
- break;
- case GREY_BRUSH:
- return new COLORREF(128, 128, 128);
- break;
- default:
- return new COLORREF(255, 255, 255);
- }
-}
-
int MessageBox(HWID pWindow, char* message, char* title, UINT mFlags)
{
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
@@ -96,6 +78,7 @@ int MessageBox(HWID pWindow, char* message, char* title, UINT mFlags)
return result;
}
+
BOOL GetSaveFileName(OPENFILENAME *ofn)
{
GtkWidget *dialog;
@@ -193,3 +176,100 @@ void CheckMenuItem(HMENU MenuName, HMENU MenuItem, UINT Check)
break;
}
}
+
+HANDLE GetStockObject(int fnObject)
+{
+ switch(fnObject)
+ {
+ case BLACK_BRUSH:
+ return new COLORREF(0, 0, 0);
+ break;
+ case WHITE_BRUSH:
+ return new COLORREF(255, 255, 255);
+ break;
+ case GREY_BRUSH:
+ return new COLORREF(128, 128, 128);
+ break;
+ default:
+ return new COLORREF(255, 255, 255);
+ }
+}
+
+void SelectObject(HCRDC hcr, HFONT hfont)
+{
+ cairo_select_font_face(hcr, hfont->lpszFace,
+ hfont->fdwItalic ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
+ hfont->fnWeight == FW_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
+
+ cairo_rotate(hcr, hfont->nOrientation);
+
+ cairo_text_extents_t extents;
+ cairo_text_extents (hcr, "H", &extents);
+
+ cairo_matrix_t matrix;
+ cairo_matrix_init_scale (&matrix,
+ (double)hfont->nWidth / extents.width,
+ (double)hfont->nHeight / extents.width);
+
+ cairo_set_font_matrix (hcr, &matrix);
+ g_print("wR = %f\nhR = %f\n", (double)hfont->nWidth / extents.width, (double)hfont->nHeight / extents.height);
+ g_print("tW = %f\ntH = %f\n", extents.width, extents.width);
+ // cairo_set_font_size(hcr, 20);
+}
+
+HBRUSH CreateBrushIndirect(PLOGBRUSH plb)
+{
+ COLORREF brush(plb->lbColor);
+ brush.alpha = (plb->lbStyle == BS_SOLID) ? 1 : 0.2;
+
+ return &brush;
+}
+
+HFONT CreateFont(int nHeight, int nWidth, int nOrientation, int fnWeight,
+ DWORD fdwItalic, LPCTSTR lpszFace)
+{
+ HFONT font = new FONT;
+ font->nHeight = nHeight;
+ font->nWidth = nWidth;
+ font->nOrientation = nOrientation;
+ font->fnWeight = fnWeight;
+ font->fdwItalic = fdwItalic;
+ font->lpszFace = lpszFace;
+
+ return font;
+}
+
+void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol)
+{
+ gtk_widget_override_background_color(GTK_WIDGET(widget),
+ GTK_STATE_FLAG_NORMAL, &bkCol);
+
+ GtkStyleContext *context;
+ COLORREF col;
+
+ context = gtk_widget_get_style_context (widget);
+ gint width = gtk_widget_get_allocated_width (widget);
+ gint height = gtk_widget_get_allocated_height (widget);
+
+ gtk_style_context_get_color (context,
+ gtk_style_context_get_state (context),
+ &col);
+
+ gdk_cairo_set_source_rgba (hcr, &col);
+
+ gtk_render_background (context, hcr, 0, 0, width, height);
+}
+
+void SetTextColor(HCRDC hcr, COLORREF color)
+{
+ gdk_cairo_set_source_rgba (hcr, &color);
+}
+
+void TextOut(HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, int cchString)
+{
+ cairo_move_to(hcr, nXStart, nYStart);
+ cairo_show_text(hcr, lpString);
+
+ cairo_fill (hcr);
+}
+
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index 85b5fa8..552a6af 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -39,9 +39,15 @@
#define OFN_OVERWRITEPROMPT 0x00000400L
/// window brushes
-#define BLACK_BRUSH 0x00000002L
-#define WHITE_BRUSH 0x00000004L
-#define GREY_BRUSH 0x00000008L
+#define BS_SOLID 0x00000001L
+#define BS_HOLLOW 0x00000002L
+#define BLACK_BRUSH 0x00000004L
+#define WHITE_BRUSH 0x00000008L
+#define GREY_BRUSH 0x00000010L
+
+/// Font flags
+#define FW_REGULAR 0x00000001L
+#define FW_BOLD 0x00000002L
/// EnableMenuItem variables
extern const UINT MF_ENABLED;
@@ -66,12 +72,52 @@ typedef struct OpenFileInfoData {
} OPENFILENAME;
/// functions
-BOOL isFocus(HWID);
-COLORREF RGB(int, int, int);
-int MessageBox(HWID, char*, char*, UINT);
-BOOL GetSaveFileName(OPENFILENAME* );
-void EnableMenuItem(HMENU, HMENU, UINT);
-void CheckMenuItem(HMENU, HMENU, UINT);
+BOOL isFocus(HWID window);
+
+COLORREF RGB(int red,
+ int green,
+ int blue);
+
+int MessageBox(HWID pWindow,
+ char* message,
+ char* title,
+ UINT mFlags);
+
+BOOL GetSaveFileName(OPENFILENAME *ofn);
+
+void EnableMenuItem(HMENU MenuName,
+ HMENU MenuItem,
+ UINT CheckEnabledItem);
+
+void CheckMenuItem(HMENU MenuName,
+ HMENU MenuItem,
+ UINT Check);
+
HANDLE GetStockObject(int fnObject);
+void SelectObject(HCRDC hcr,
+ HFONT hfont);
+
+HBRUSH CreateBrushIndirect(PLOGBRUSH plb);
+
+HFONT CreateFont(int nHeight,
+ int nWidth,
+ int nOrientation,
+ int fnWeight,
+ DWORD fdwItalic,
+ LPCTSTR lpszFace);
+
+void SetBkColor(HWID widget,
+ HCRDC hcr,
+ COLORREF bkCol);
+
+void SetTextColor(HCRDC hcr,
+ COLORREF color);
+
+void TextOut(HCRDC hcr,
+ int nXStart,
+ int nYStart,
+ LPCTSTR lpString,
+ int cchString);
+
#endif \ No newline at end of file