diff options
author | Rr42 | 2018-06-18 14:19:56 +0530 |
---|---|---|
committer | Rr42 | 2018-06-18 14:19:56 +0530 |
commit | a4052ae05814bdda4ec91e2e8d07e470428f06b1 (patch) | |
tree | f2481ae62789c9245b032ced6d028186e1efde58 /ldmicro | |
parent | 28777b68e7479e6515231fc849c61b3748da8712 (diff) | |
download | LDMicroGtk-a4052ae05814bdda4ec91e2e8d07e470428f06b1.tar.gz LDMicroGtk-a4052ae05814bdda4ec91e2e8d07e470428f06b1.tar.bz2 LDMicroGtk-a4052ae05814bdda4ec91e2e8d07e470428f06b1.zip |
cleand PaintWindow function
Diffstat (limited to 'ldmicro')
-rw-r--r-- | ldmicro/draw_outputdev.cpp | 45 | ||||
-rw-r--r-- | ldmicro/ldmicro.cpp | 30 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp | 3 | ||||
-rw-r--r-- | ldmicro/schematic.cpp | 212 |
4 files changed, 127 insertions, 163 deletions
diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp index edde2e8..9ac55ab 100644 --- a/ldmicro/draw_outputdev.cpp +++ b/ldmicro/draw_outputdev.cpp @@ -220,46 +220,10 @@ int ScreenRowsAvailable(void) //----------------------------------------------------------------------------- void PaintWindow() { - // SetBkColor(DrawWindow, hcr, InSimulationMode ? HighlightColours.simBg : - // HighlightColours.bg); - - // SetTextColor(hcr, InSimulationMode ? HighlightColours.simRungNum : - // HighlightColours.rungNum); - - // SelectObject(hcr, FixedWidthFont); - - // TextOut(DrawWindow, hcr, 5, 100, "-------] [-------------------------------------------------------------------------------------------------------------------------------------------------{RES}-------", 14); - - // static HBITMAP BackBitmap; - // static HDC BackDc; - // static int BitmapWidth; - ok(); - - // RECT r; - // GetClientRect(MainWindow, &r); - + int bw = gtk_widget_get_allocated_width (DrawWindow);// = r.right; int bh = IoListTop; - - // HDC paintDc; - // if(!BackDc) { - // HWND desktop = GetDesktopWindow(); - // RECT dk; - // GetClientRect(desktop, &dk); - - // BitmapWidth = max(2000, dk.right + 300); - // BackBitmap = CreateCompatibleBitmap(Hdc, BitmapWidth, dk.bottom + 300); - // BackDc = CreateCompatibleDC(Hdc); - // SelectObject(BackDc, BackBitmap); - // } - // paintDc = Hdc; - // Hdc = BackDc; - - // RECT fi; - // fi.left = 0; fi.top = 0; - // fi.right = BitmapWidth; fi.bottom = bh; - // FillRect(Hdc, &fi, InSimulationMode ? SimBgBrush : BgBrush); /// now figure out how we should draw the ladder logic ColsAvailable = ProgCountWidestRow(); @@ -295,7 +259,7 @@ void PaintWindow() 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(DrawWindow, Hdc, 8 + FONT_WIDTH, yp, r, 1); @@ -314,6 +278,7 @@ void PaintWindow() } cy -= 2; DrawEndRung(0, cy); + g_print("cy = %i\n", cy); if(SelectedGxAfterNextPaint >= 0) { MoveCursorNear(SelectedGxAfterNextPaint, SelectedGyAfterNextPaint); InvalidateRect(DrawWindow, NULL, FALSE); @@ -339,13 +304,9 @@ void PaintWindow() r.top = 0; r.right = r.left + 4; r.bottom = IoListTop; - g_print("IoList = %i\n", IoListTop); FillRect(Hdc, &r, InSimulationMode ? BusLeftBrush : BusBrush); - g_print("ColsAvailable = %i\n", ColsAvailable); r.left += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; r.right += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; - g_print("right = %i\n", r.right); - g_print("left = %i\n", r.left); FillRect(Hdc, &r, InSimulationMode ? BusRightBus : BusBrush); CursorDrawn = FALSE; diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index 49371d4..18b4f50 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -1053,36 +1053,36 @@ gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data) g_print("draw called\n"); - // guint width, height; - // GdkRGBA color; - // GtkStyleContext *context; + guint width, height; + GdkRGBA color; + GtkStyleContext *context; - // context = gtk_widget_get_style_context (widget); + 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); // g_print("w = %i\n", width); // g_print("h = %i\n", height); // SetBkColor(widget, cr, HighlightColours.bg); - // 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_rectangle(cr, 0, 0, width, height); - // cairo_stroke_preserve(cr); + cairo_rectangle(cr, 0, 0, width, height); + cairo_stroke_preserve(cr); - // 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); - // cairo_fill (cr); - // SetTextColor(cr, HighlightColours.rungNum); // SelectObject(cr, FixedWidthFont); diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index f21094e..d8bb06c 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -286,12 +286,15 @@ void SetTextColor(HCRDC hcr, COLORREF color) void TextOut(HWID hWid, HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, int cchString) { + nYStart += 20; + cairo_text_extents_t extents; cairo_text_extents (hcr, lpString, &extents); int width = gtk_widget_get_allocated_width (hWid); int height= gtk_widget_get_allocated_height (hWid); BOOL resize_flag = FALSE; // g_print("w = %f h = %f") + if(nYStart+(extents.height/2.0) >= height) { height += extents.height; diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp index 28d5eac..b63e69d 100644 --- a/ldmicro/schematic.cpp +++ b/ldmicro/schematic.cpp @@ -83,43 +83,43 @@ BOOL FindSelected(int *gx, int *gy) //----------------------------------------------------------------------------- void SelectElement(int gx, int gy, int state) { -// if(gx < 0 || gy < 0) { -// if(!FindSelected(&gx, &gy)) { -// return; -// } -// } + if(gx < 0 || gy < 0) { + if(!FindSelected(&gx, &gy)) { + return; + } + } -// if(Selected) Selected->selectedState = SELECTED_NONE; + if(Selected) Selected->selectedState = SELECTED_NONE; -// Selected = DisplayMatrix[gx][gy]; -// SelectedWhich = DisplayMatrixWhich[gx][gy]; + Selected = DisplayMatrix[gx][gy]; + SelectedWhich = DisplayMatrixWhich[gx][gy]; -// if(SelectedWhich == ELEM_PLACEHOLDER) { -// state = SELECTED_LEFT; -// } + if(SelectedWhich == ELEM_PLACEHOLDER) { + state = SELECTED_LEFT; + } -// if((gy - ScrollYOffset) >= ScreenRowsAvailable()) { -// ScrollYOffset = gy - ScreenRowsAvailable() + 1; -// RefreshScrollbars(); -// } -// if((gy - ScrollYOffset) < 0) { -// ScrollYOffset = gy; -// RefreshScrollbars(); -// } -// if((gx - ScrollXOffset*POS_WIDTH*FONT_WIDTH) >= ScreenColsAvailable()) { -// ScrollXOffset = gx*POS_WIDTH*FONT_WIDTH - ScreenColsAvailable(); -// RefreshScrollbars(); -// } -// if((gx - ScrollXOffset*POS_WIDTH*FONT_WIDTH) < 0) { -// ScrollXOffset = gx*POS_WIDTH*FONT_WIDTH; -// RefreshScrollbars(); -// } + if((gy - ScrollYOffset) >= ScreenRowsAvailable()) { + ScrollYOffset = gy - ScreenRowsAvailable() + 1; + RefreshScrollbars(); + } + if((gy - ScrollYOffset) < 0) { + ScrollYOffset = gy; + RefreshScrollbars(); + } + if((gx - ScrollXOffset*POS_WIDTH*FONT_WIDTH) >= ScreenColsAvailable()) { + ScrollXOffset = gx*POS_WIDTH*FONT_WIDTH - ScreenColsAvailable(); + RefreshScrollbars(); + } + if((gx - ScrollXOffset*POS_WIDTH*FONT_WIDTH) < 0) { + ScrollXOffset = gx*POS_WIDTH*FONT_WIDTH; + RefreshScrollbars(); + } -// ok(); -// Selected->selectedState = state; -// ok(); + ok(); + Selected->selectedState = state; + ok(); -// WhatCanWeDoFromCursorAndTopology(); + WhatCanWeDoFromCursorAndTopology(); } //----------------------------------------------------------------------------- @@ -129,86 +129,86 @@ void SelectElement(int gx, int gy, int state) //----------------------------------------------------------------------------- void WhatCanWeDoFromCursorAndTopology(void) { -// BOOL canNegate = FALSE, canNormal = FALSE; -// BOOL canResetOnly = FALSE, canSetOnly = FALSE; -// BOOL canPushUp = TRUE, canPushDown = TRUE; + BOOL canNegate = FALSE, canNormal = FALSE; + BOOL canResetOnly = FALSE, canSetOnly = FALSE; + BOOL canPushUp = TRUE, canPushDown = TRUE; -// BOOL canDelete = TRUE; + BOOL canDelete = TRUE; -// int i = RungContainingSelected(); -// if(i >= 0) { -// if(i == 0) canPushUp = FALSE; -// if(i == (Prog.numRungs-1)) canPushDown = FALSE; + int i = RungContainingSelected(); + if(i >= 0) { + if(i == 0) canPushUp = FALSE; + if(i == (Prog.numRungs-1)) canPushDown = FALSE; -// if(Prog.rungs[i]->count == 1 && -// Prog.rungs[i]->contents[0].which == ELEM_PLACEHOLDER) -// { -// canDelete = FALSE; -// } -// } + if(Prog.rungs[i]->count == 1 && + Prog.rungs[i]->contents[0].which == ELEM_PLACEHOLDER) + { + canDelete = FALSE; + } + } -// CanInsertEnd = FALSE; -// CanInsertOther = TRUE; - -// if(Selected && -// (SelectedWhich == ELEM_COIL || -// SelectedWhich == ELEM_RES || -// SelectedWhich == ELEM_ADD || -// SelectedWhich == ELEM_SUB || -// SelectedWhich == ELEM_MUL || -// SelectedWhich == ELEM_DIV || -// SelectedWhich == ELEM_CTC || -// SelectedWhich == ELEM_READ_ADC || -// SelectedWhich == ELEM_SET_PWM || -// SelectedWhich == ELEM_MASTER_RELAY || -// SelectedWhich == ELEM_SHIFT_REGISTER || -// SelectedWhich == ELEM_LOOK_UP_TABLE || -// SelectedWhich == ELEM_PIECEWISE_LINEAR || -// SelectedWhich == ELEM_PERSIST || -// SelectedWhich == ELEM_MOVE)) -// { -// if(SelectedWhich == ELEM_COIL) { -// canNegate = TRUE; -// canNormal = TRUE; -// canResetOnly = TRUE; -// canSetOnly = TRUE; -// } + CanInsertEnd = FALSE; + CanInsertOther = TRUE; + + if(Selected && + (SelectedWhich == ELEM_COIL || + SelectedWhich == ELEM_RES || + SelectedWhich == ELEM_ADD || + SelectedWhich == ELEM_SUB || + SelectedWhich == ELEM_MUL || + SelectedWhich == ELEM_DIV || + SelectedWhich == ELEM_CTC || + SelectedWhich == ELEM_READ_ADC || + SelectedWhich == ELEM_SET_PWM || + SelectedWhich == ELEM_MASTER_RELAY || + SelectedWhich == ELEM_SHIFT_REGISTER || + SelectedWhich == ELEM_LOOK_UP_TABLE || + SelectedWhich == ELEM_PIECEWISE_LINEAR || + SelectedWhich == ELEM_PERSIST || + SelectedWhich == ELEM_MOVE)) + { + if(SelectedWhich == ELEM_COIL) { + canNegate = TRUE; + canNormal = TRUE; + canResetOnly = TRUE; + canSetOnly = TRUE; + } -// if(Selected->selectedState == SELECTED_ABOVE || -// Selected->selectedState == SELECTED_BELOW) -// { -// CanInsertEnd = TRUE; -// CanInsertOther = FALSE; -// } else if(Selected->selectedState == SELECTED_RIGHT) { -// CanInsertEnd = FALSE; -// CanInsertOther = FALSE; -// } -// } else if(Selected) { -// if(Selected->selectedState == SELECTED_RIGHT || -// SelectedWhich == ELEM_PLACEHOLDER) -// { -// CanInsertEnd = ItemIsLastInCircuit(Selected); -// } -// } -// if(SelectedWhich == ELEM_CONTACTS) { -// canNegate = TRUE; -// canNormal = TRUE; -// } -// if(SelectedWhich == ELEM_PLACEHOLDER) { -// // a comment must be the only element in its rung, and it will fill -// // the rung entirely -// CanInsertComment = TRUE; -// } else { -// CanInsertComment = FALSE; -// } -// if(SelectedWhich == ELEM_COMMENT) { -// // if there's a comment there already then don't let anything else -// // into the rung -// CanInsertEnd = FALSE; -// CanInsertOther = FALSE; -// } -// SetMenusEnabled(canNegate, canNormal, canResetOnly, canSetOnly, canDelete, -// CanInsertEnd, CanInsertOther, canPushDown, canPushUp, CanInsertComment); + if(Selected->selectedState == SELECTED_ABOVE || + Selected->selectedState == SELECTED_BELOW) + { + CanInsertEnd = TRUE; + CanInsertOther = FALSE; + } else if(Selected->selectedState == SELECTED_RIGHT) { + CanInsertEnd = FALSE; + CanInsertOther = FALSE; + } + } else if(Selected) { + if(Selected->selectedState == SELECTED_RIGHT || + SelectedWhich == ELEM_PLACEHOLDER) + { + CanInsertEnd = ItemIsLastInCircuit(Selected); + } + } + if(SelectedWhich == ELEM_CONTACTS) { + canNegate = TRUE; + canNormal = TRUE; + } + if(SelectedWhich == ELEM_PLACEHOLDER) { + // a comment must be the only element in its rung, and it will fill + // the rung entirely + CanInsertComment = TRUE; + } else { + CanInsertComment = FALSE; + } + if(SelectedWhich == ELEM_COMMENT) { + // if there's a comment there already then don't let anything else + // into the rung + CanInsertEnd = FALSE; + CanInsertOther = FALSE; + } + SetMenusEnabled(canNegate, canNormal, canResetOnly, canSetOnly, canDelete, + CanInsertEnd, CanInsertOther, canPushDown, canPushUp, CanInsertComment); } //----------------------------------------------------------------------------- |