diff options
-rw-r--r-- | ldmicro/draw_outputdev.cpp | 120 | ||||
-rw-r--r-- | ldmicro/includes/ldmicro.h | 2 | ||||
-rw-r--r-- | ldmicro/ldmicro.cpp | 122 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp | 13 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.h | 14 | ||||
-rw-r--r-- | ldmicro/maincontrols.cpp | 15 | ||||
-rw-r--r-- | ldmicro/schematic.cpp | 456 |
7 files changed, 433 insertions, 309 deletions
diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp index 363aef0..4c8a021 100644 --- a/ldmicro/draw_outputdev.cpp +++ b/ldmicro/draw_outputdev.cpp @@ -81,15 +81,51 @@ 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. //----------------------------------------------------------------------------- -void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time) +gboolean BlinkCursor(GtkWidget * window) //(HWND hwnd, UINT msg, UINT_PTR id, DWORD time) { - // if(!isFocus(MainWindow) && !CursorDrawn) return; - // if(Cursor.left == 0) return; + static int PREV_x = -100; + static int PREV_y = -100; - // PlcCursor c; - // SettingsInstance = gtk_settings_get_default(); - // gtk_settings_install_property_parser (gtk-cursor-blink ,black); + // if(GetFocus(MainWindow) != !CursorDrawn) return TRUE; + if(Cursor.left == 0) return TRUE; + PlcCursor c; + memcpy(&c, &Cursor, sizeof(c)); + + c.top -= ScrollYOffset*POS_HEIGHT*FONT_HEIGHT; + c.left -= ScrollXOffset; + + if(c.top >= IoListTop) return TRUE; + + if(c.top + c.height >= IoListTop) { + c.height = IoListTop - c.top - 3; + } + + HCRDC hCr = gdk_cairo_create(gtk_widget_get_window(DrawWindow)); + + if (PREV_x == -100 || PREV_y == -100) + { + PREV_x = c.left; + PREV_y = c.top; + } + + if (PREV_x != c.left || PREV_y != c.top) + { + PatBlt(hCr, PREV_x, PREV_y, c.width, c.height, PATINVERT, (HBRUSH)GetStockObject(BLACK_BRUSH)); + PREV_x = c.left; + PREV_y = c.top; + // PaintWindow(); + } + + if (CursorDrawn) + PatBlt(hCr, c.left, c.top, c.width, c.height, PATINVERT, (HBRUSH)GetStockObject(WHITE_BRUSH)); + else + PatBlt(hCr, c.left, c.top, c.width, c.height, PATINVERT, (HBRUSH)GetStockObject(BLACK_BRUSH)); + InvalidateRect(DrawWindow, NULL, FALSE); + cairo_destroy(hCr); + CursorDrawn = !CursorDrawn; + + return TRUE; } //----------------------------------------------------------------------------- @@ -514,46 +550,46 @@ void ExportDrawingAsText(char *file) //----------------------------------------------------------------------------- void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert) { - // int totalHeight = 0; - // int i; - // for(i = 0; i < Prog.numRungs; i++) { - // totalHeight += CountHeightOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i]); - // totalHeight++; - // } - // totalHeight += 1; // for the end rung + int totalHeight = 0; + int i; + for(i = 0; i < Prog.numRungs; i++) { + totalHeight += CountHeightOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i]); + totalHeight++; + } + totalHeight += 1; // for the end rung - // int totalWidth = ProgCountWidestRow(); + int totalWidth = ProgCountWidestRow(); - // if(totalWidth <= ScreenColsAvailable()) { - // *horizShown = FALSE; - // ScrollXOffset = 0; - // ScrollXOffsetMax = 0; - // } else { - // *horizShown = TRUE; - // memset(horiz, 0, sizeof(*horiz)); - // horiz->cbSize = sizeof(*horiz); - // horiz->fMask = SIF_DISABLENOSCROLL | SIF_ALL; - // horiz->nMin = 0; - // horiz->nMax = X_PADDING + totalWidth*POS_WIDTH*FONT_WIDTH; - // RECT r; - // GetClientRect(MainWindow, &r); - // horiz->nPage = r.right - X_PADDING; - // horiz->nPos = ScrollXOffset; - - // ScrollXOffsetMax = horiz->nMax - horiz->nPage + 1; - // if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax; - // if(ScrollXOffset < 0) ScrollXOffset = 0; - // } + if(totalWidth <= ScreenColsAvailable()) { + *horizShown = FALSE; + ScrollXOffset = 0; + ScrollXOffsetMax = 0; + } else { + *horizShown = TRUE; + memset(horiz, 0, sizeof(*horiz)); + horiz->cbSize = sizeof(*horiz); + // horiz->fMask = SIF_DISABLENOSCROLL | SIF_ALL; + horiz->nMin = 0; + horiz->nMax = X_PADDING + totalWidth*POS_WIDTH*FONT_WIDTH; + RECT r; + GetClientRect(DrawWindow, &r); + horiz->nPage = r.right - X_PADDING; + horiz->nPos = ScrollXOffset; + + ScrollXOffsetMax = horiz->nMax - horiz->nPage + 1; + if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax; + if(ScrollXOffset < 0) ScrollXOffset = 0; + } - // vert->cbSize = sizeof(*vert); + vert->cbSize = sizeof(*vert); // vert->fMask = SIF_DISABLENOSCROLL | SIF_ALL; - // vert->nMin = 0; - // vert->nMax = totalHeight - 1; - // vert->nPos = ScrollYOffset; - // vert->nPage = ScreenRowsAvailable(); + vert->nMin = 0; + vert->nMax = totalHeight - 1; + vert->nPos = ScrollYOffset; + vert->nPage = ScreenRowsAvailable(); - // ScrollYOffsetMax = vert->nMax - vert->nPage + 1; + ScrollYOffsetMax = vert->nMax - vert->nPage + 1; - // if(ScrollYOffset > ScrollYOffsetMax) ScrollYOffset = ScrollYOffsetMax; - // if(ScrollYOffset < 0) ScrollYOffset = 0; + if(ScrollYOffset > ScrollYOffsetMax) ScrollYOffset = ScrollYOffsetMax; + if(ScrollYOffset < 0) ScrollYOffset = 0; } diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h index 23d82fb..3db6fbd 100644 --- a/ldmicro/includes/ldmicro.h +++ b/ldmicro/includes/ldmicro.h @@ -632,7 +632,7 @@ extern BOOL ThisHighlighted; // draw_outputdev.cpp extern void (*DrawChars)(int, int, const char *); -void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time); +gboolean BlinkCursor(GtkWidget * window); void PaintWindow(); void ExportDrawingAsText(char *file); void InitForDrawing(void); diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index cdc9e7f..6976091 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -972,34 +972,42 @@ gboolean LD_GTK_mouse_click_hook(GtkWidget *widget, GdkEvent *event, gpointer us /* Handles: * WM_LBUTTONDBLCLK, WM_LBUTTONDOWN */ - + switch(event->button.type) { - case GDK_BUTTON_PRESS:// To Do: run only for left click - // int x = LOWORD(lParam); - // int y = HIWORD(lParam); - // if((y > (IoListTop - 9)) && (y < (IoListTop + 3))) { - // POINT pt; - // pt.x = x; pt.y = y; - // ClientToScreen(MainWindow, &pt); - // MouseY = pt.y; - // MouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL, - // (HOOKPROC)MouseHook, Instance, 0); - // } - // if(!InSimulationMode) MoveCursorMouseClick(x, y); - - // SetFocus(MainWindow); - // InvalidateRect(MainWindow, NULL, FALSE); + case GDK_BUTTON_PRESS: + if (event->button.button == 1) /// left click + { + int x = event->button.x; + int y = event->button.y - 30; + + // if((y > (IoListTop - 9)) && (y < (IoListTop + 3))) { + // // POINT pt; + // // pt.x = x; pt.y = y; + // // ClientToScreen(MainWindow, &pt); + // MouseY = y; //pt.y; + // // MouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL, + // // (HOOKPROC)MouseHook, Instance, 0); + // } + if(!InSimulationMode) MoveCursorMouseClick(x, y); + + // SetFocus(MainWindow); + InvalidateRect(DrawWindow, NULL, FALSE); + } break; case GDK_2BUTTON_PRESS: - // int x = LOWORD(lParam); - // int y = HIWORD(lParam); - // if(InSimulationMode) { - // EditElementMouseDoubleclick(x, y); - // } else { - // CHANGING_PROGRAM(EditElementMouseDoubleclick(x, y)); - // } - // InvalidateRect(MainWindow, NULL, FALSE); + if (event->button.button == 1) /// left click + { + int x = event->button.x; + int y = event->button.y - 30; + + if(InSimulationMode) { + EditElementMouseDoubleclick(x, y); + } else { + CHANGING_PROGRAM(EditElementMouseDoubleclick(x, y)); + } + InvalidateRect(DrawWindow, NULL, FALSE); + } break; } @@ -1011,17 +1019,28 @@ gboolean LD_GTK_mouse_scroll_hook(GtkWidget *widget, GdkEvent *event, gpointer u /* Handles: * WM_VSCROLL, WM_HSCROLL, WM_MOUSEWHEEL */ - - MainWindowResized(); - PaintWindow(); - + + GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ScrollWindow)); + // g_print("adj = %f\n", gtk_adjustment_get_value(adjustment)); + // g_print("upper = %f\n", gtk_adjustment_get_upper(adjustment) - gtk_widget_get_allocated_height (ScrollWindow)); + // g_print("lower = %f\n", gtk_adjustment_get_lower(adjustment)); + // g_print("inc = %f\n", gtk_adjustment_get_step_increment(adjustment)); + // g_print("w width = %i\n", gtk_widget_get_allocated_width (DrawWindow)); + // g_print("w height = %i\n", gtk_widget_get_allocated_height (ScrollWindow)); + switch(event->scroll.direction) { case GDK_SCROLL_UP: - VscrollProc(SB_LINEUP); + if (gtk_adjustment_get_value(adjustment) == gtk_adjustment_get_lower(adjustment)) + VscrollProc(SB_TOP); + else + VscrollProc(SB_LINEUP); break; case GDK_SCROLL_DOWN: - VscrollProc(SB_LINEDOWN); + if (gtk_adjustment_get_value(adjustment) == gtk_adjustment_get_upper(adjustment) - gtk_widget_get_allocated_height (ScrollWindow)) + VscrollProc(SB_BOTTOM); + else + VscrollProc(SB_LINEDOWN); break; case GDK_SCROLL_LEFT: HscrollProc(SB_LINEUP); @@ -1040,6 +1059,10 @@ gboolean LD_GTK_mouse_scroll_hook(GtkWidget *widget, GdkEvent *event, gpointer u break; } + + MainWindowResized(); + PaintWindow(); + return FALSE; } @@ -1071,6 +1094,29 @@ gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data) * WM_PAINT */ + static BOOL Paint_call_first = TRUE; + + if (Paint_call_first) + { + gtk_widget_override_background_color(GTK_WIDGET(widget), + GTK_STATE_FLAG_NORMAL, (HBRUSH)GetStockObject(BLACK_BRUSH)); + + gint width = gtk_widget_get_allocated_width (widget); + gint height = gtk_widget_get_allocated_height (widget); + + COLORREF col; + GtkStyleContext *context; + + context = gtk_widget_get_style_context (widget); + + gtk_style_context_get_color (context, + gtk_style_context_get_state (context), + &col); + + gdk_cairo_set_source_rgba (cr, &col); + + gtk_render_background (context, cr, 0, 0, width, height); + } // g_print("draw called----------------------------------\n"); // guint width, height; @@ -1222,6 +1268,12 @@ int main(int argc, char** argv) exit(0); } + //we need to initialize all these functions so that gtk knows + //to be thread-aware + if (!g_thread_supported ()){ g_thread_init(NULL); } + gdk_threads_init(); + gdk_threads_enter(); + gtk_init(&argc, &argv); Instance = NULL; /* TEST @@ -1300,11 +1352,14 @@ int main(int argc, char** argv) NewProgram(); strcpy(CurrentSaveFile, ""); - // We are running interactively, or we would already have exited. We - // can therefore show the window now, and otherwise set up the GUI. + /// We are running interactively, or we would already have exited. We + /// can therefore show the window now, and otherwise set up the GUI. - // Displaying the window + /// Displaying the window gtk_widget_show_all(MainWindow); + + /// Blink cursor + g_timeout_add(200, (GSourceFunc)BlinkCursor, DrawWindow); // SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor); if(argc >= 2) { @@ -1354,5 +1409,6 @@ int main(int argc, char** argv) // } gtk_main(); + gdk_threads_leave(); return EXIT_SUCCESS; }
\ No newline at end of file diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index bb6600b..1d525c5 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -25,7 +25,7 @@ HWID view; HTVC column; /// Wraper function for gtk_window_has_toplevel_focus -BOOL isFocus(HWID window) +BOOL GetFocus(HWID window) { return (BOOL) gtk_window_has_toplevel_focus(GTK_WINDOW(window)); } @@ -373,6 +373,17 @@ 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) +{ + cairo_set_source_rgb(hdc, hbr->red, hbr->green, hbr->blue); + cairo_rectangle(hdc, nXLeft, nYLeft + 20, nWidth, nHeight); + cairo_stroke_preserve(hdc); + + cairo_fill(hdc); + + return TRUE; +} + BOOL GetClientRect(HWID hWid, PRECT pRect) { GtkAllocation allocation; diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h index 2f13e79..bda2c5d 100644 --- a/ldmicro/lib/linuxUI/linuxUI.h +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -48,6 +48,9 @@ #define OFN_HIDEREADONLY 0x00000200L #define OFN_OVERWRITEPROMPT 0x00000400L +/// PatBlt paint flags +#define PATINVERT 0x00000100L + /// window brushes #define BS_SOLID 0x00000001L #define BS_HOLLOW 0x00000002L @@ -97,7 +100,7 @@ typedef struct OpenFileInfoData { extern COLORREF HdcCurrentTextColor; /// functions -BOOL isFocus(HWID window); +BOOL GetFocus(HWID window); COLORREF RGB( int red, @@ -167,6 +170,15 @@ int FillRect( const RECT *lprc, HBRUSH hbr); +BOOL PatBlt( + HCRDC hdc, + int nXLeft, + int nYLeft, + int nWidth, + int nHeight, + DWORD dwRop, + HBRUSH hbr); + BOOL GetClientRect( HWID hWid, PRECT lpRect); diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp index ff7f5a8..4d9a128 100644 --- a/ldmicro/maincontrols.cpp +++ b/ldmicro/maincontrols.cpp @@ -618,8 +618,17 @@ void MakeMainWindowControls(void) //----------------------------------------------------------------------------- void RefreshScrollbars(void) { - // SCROLLINFO vert, horiz; - // SetUpScrollbars(&NeedHoriz, &horiz, &vert); + SCROLLINFO vert, horiz; + SetUpScrollbars(&NeedHoriz, &horiz, &vert); + + GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ScrollWindow)); + g_print("adj = %f\n", gtk_adjustment_get_value(adjustment)); + g_print("upper = %f\n", gtk_adjustment_get_upper(adjustment) - gtk_widget_get_allocated_height (ScrollWindow)); + g_print("lower = %f\n", gtk_adjustment_get_lower(adjustment)); + g_print("inc = %f\n", gtk_adjustment_get_step_increment(adjustment)); + g_print("w width = %i\n", gtk_widget_get_allocated_width (DrawWindow)); + g_print("w height = %i\n", gtk_widget_get_allocated_height (ScrollWindow)); + // SetScrollInfo(HorizScrollBar, SB_CTL, &horiz, TRUE); // SetScrollInfo(VertScrollBar, SB_CTL, &vert, TRUE); @@ -640,7 +649,7 @@ void RefreshScrollbars(void) // MoveWindow(VertScrollBar, main.right - ScrollWidth - 2, 1, ScrollWidth, // NeedHoriz ? (IoListTop - ScrollHeight - 4) : (IoListTop - 3), TRUE); - // InvalidateRect(MainWindow, NULL, FALSE); + InvalidateRect(DrawWindow, NULL, FALSE); } //----------------------------------------------------------------------------- diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp index b63e69d..5a91934 100644 --- a/ldmicro/schematic.cpp +++ b/ldmicro/schematic.cpp @@ -250,32 +250,32 @@ void ForgetEverything(void) //----------------------------------------------------------------------------- BOOL MoveCursorTopLeft(void) { -// int i, j; -// // Let us first try to place it somewhere on-screen, so start at the -// // vertical scroll offset, not the very top (to avoid placing the -// // cursor in a position that would force us to scroll to put it in to -// // view.) -// for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { -// for(j = ScrollYOffset; -// j < DISPLAY_MATRIX_Y_SIZE && j < (ScrollYOffset+16); j++) -// { -// if(VALID_LEAF(DisplayMatrix[i][j])) { -// SelectElement(i, j, SELECTED_LEFT); -// return TRUE; -// } -// } -// } + int i, j; + // Let us first try to place it somewhere on-screen, so start at the + // vertical scroll offset, not the very top (to avoid placing the + // cursor in a position that would force us to scroll to put it in to + // view.) + for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { + for(j = ScrollYOffset; + j < DISPLAY_MATRIX_Y_SIZE && j < (ScrollYOffset+16); j++) + { + if(VALID_LEAF(DisplayMatrix[i][j])) { + SelectElement(i, j, SELECTED_LEFT); + return TRUE; + } + } + } -// // If that didn't work, then try anywhere on the diagram before giving -// // up entirely. -// for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { -// for(j = 0; j < 16; j++) { -// if(VALID_LEAF(DisplayMatrix[i][j])) { -// SelectElement(i, j, SELECTED_LEFT); -// return TRUE; -// } -// } -// } + // If that didn't work, then try anywhere on the diagram before giving + // up entirely. + for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { + for(j = 0; j < 16; j++) { + if(VALID_LEAF(DisplayMatrix[i][j])) { + SelectElement(i, j, SELECTED_LEFT); + return TRUE; + } + } + } return FALSE; } @@ -287,108 +287,108 @@ BOOL MoveCursorTopLeft(void) //----------------------------------------------------------------------------- void MoveCursorKeyboard(int keyCode) { -// if(!Selected || Selected->selectedState == SELECTED_NONE) { -// MoveCursorTopLeft(); -// return; -// } - -// switch(keyCode) { -// case VK_LEFT: { -// if(!Selected || Selected->selectedState == SELECTED_NONE) { -// break; -// } -// if(Selected->selectedState != SELECTED_LEFT) { -// SelectElement(-1, -1, SELECTED_LEFT); -// break; -// } -// if(SelectedWhich == ELEM_COMMENT) break; -// int i, j; -// if(FindSelected(&i, &j)) { -// i--; -// while(i >= 0 && (!VALID_LEAF(DisplayMatrix[i][j]) || -// (DisplayMatrix[i][j] == Selected))) -// { -// i--; -// } -// if(i >= 0) { -// SelectElement(i, j, SELECTED_RIGHT); -// } -// } -// break; -// } -// case VK_RIGHT: { -// if(!Selected || Selected->selectedState == SELECTED_NONE) { -// break; -// } -// if(Selected->selectedState != SELECTED_RIGHT) { -// SelectElement(-1, -1, SELECTED_RIGHT); -// break; -// } -// if(SelectedWhich == ELEM_COMMENT) break; -// int i, j; -// if(FindSelected(&i, &j)) { -// i++; -// while(i < DISPLAY_MATRIX_X_SIZE && -// !VALID_LEAF(DisplayMatrix[i][j])) -// { -// i++; -// } -// if(i != DISPLAY_MATRIX_X_SIZE) { -// SelectElement(i, j, SELECTED_LEFT); -// } -// } -// break; -// } -// case VK_UP: { -// if(!Selected || Selected->selectedState == SELECTED_NONE) { -// break; -// } -// if(Selected->selectedState != SELECTED_ABOVE && -// SelectedWhich != ELEM_PLACEHOLDER) -// { -// SelectElement(-1, -1, SELECTED_ABOVE); -// break; -// } -// int i, j; -// if(FindSelected(&i, &j)) { -// j--; -// while(j >= 0 && !VALID_LEAF(DisplayMatrix[i][j])) -// j--; -// if(j >= 0) { -// SelectElement(i, j, SELECTED_BELOW); -// } -// } -// break; -// } -// case VK_DOWN: { -// if(!Selected || Selected->selectedState == SELECTED_NONE) { -// break; -// } -// if(Selected->selectedState != SELECTED_BELOW && -// SelectedWhich != ELEM_PLACEHOLDER) -// { -// SelectElement(-1, -1, SELECTED_BELOW); -// break; -// } -// int i, j; -// if(FindSelected(&i, &j)) { -// j++; -// while(j < DISPLAY_MATRIX_Y_SIZE && -// !VALID_LEAF(DisplayMatrix[i][j])) -// { -// j++; -// } -// if(j != DISPLAY_MATRIX_Y_SIZE) { -// SelectElement(i, j, SELECTED_ABOVE); -// } else if(ScrollYOffsetMax - ScrollYOffset < 3) { -// // special case: scroll the end marker into view -// ScrollYOffset = ScrollYOffsetMax; -// RefreshScrollbars(); -// } -// } -// break; -// } -// } + // if(!Selected || Selected->selectedState == SELECTED_NONE) { + // MoveCursorTopLeft(); + // return; + // } + + // switch(keyCode) { + // case VK_LEFT: { + // if(!Selected || Selected->selectedState == SELECTED_NONE) { + // break; + // } + // if(Selected->selectedState != SELECTED_LEFT) { + // SelectElement(-1, -1, SELECTED_LEFT); + // break; + // } + // if(SelectedWhich == ELEM_COMMENT) break; + // int i, j; + // if(FindSelected(&i, &j)) { + // i--; + // while(i >= 0 && (!VALID_LEAF(DisplayMatrix[i][j]) || + // (DisplayMatrix[i][j] == Selected))) + // { + // i--; + // } + // if(i >= 0) { + // SelectElement(i, j, SELECTED_RIGHT); + // } + // } + // break; + // } + // case VK_RIGHT: { + // if(!Selected || Selected->selectedState == SELECTED_NONE) { + // break; + // } + // if(Selected->selectedState != SELECTED_RIGHT) { + // SelectElement(-1, -1, SELECTED_RIGHT); + // break; + // } + // if(SelectedWhich == ELEM_COMMENT) break; + // int i, j; + // if(FindSelected(&i, &j)) { + // i++; + // while(i < DISPLAY_MATRIX_X_SIZE && + // !VALID_LEAF(DisplayMatrix[i][j])) + // { + // i++; + // } + // if(i != DISPLAY_MATRIX_X_SIZE) { + // SelectElement(i, j, SELECTED_LEFT); + // } + // } + // break; + // } + // case VK_UP: { + // if(!Selected || Selected->selectedState == SELECTED_NONE) { + // break; + // } + // if(Selected->selectedState != SELECTED_ABOVE && + // SelectedWhich != ELEM_PLACEHOLDER) + // { + // SelectElement(-1, -1, SELECTED_ABOVE); + // break; + // } + // int i, j; + // if(FindSelected(&i, &j)) { + // j--; + // while(j >= 0 && !VALID_LEAF(DisplayMatrix[i][j])) + // j--; + // if(j >= 0) { + // SelectElement(i, j, SELECTED_BELOW); + // } + // } + // break; + // } + // case VK_DOWN: { + // if(!Selected || Selected->selectedState == SELECTED_NONE) { + // break; + // } + // if(Selected->selectedState != SELECTED_BELOW && + // SelectedWhich != ELEM_PLACEHOLDER) + // { + // SelectElement(-1, -1, SELECTED_BELOW); + // break; + // } + // int i, j; + // if(FindSelected(&i, &j)) { + // j++; + // while(j < DISPLAY_MATRIX_Y_SIZE && + // !VALID_LEAF(DisplayMatrix[i][j])) + // { + // j++; + // } + // if(j != DISPLAY_MATRIX_Y_SIZE) { + // SelectElement(i, j, SELECTED_ABOVE); + // } else if(ScrollYOffsetMax - ScrollYOffset < 3) { + // // special case: scroll the end marker into view + // ScrollYOffset = ScrollYOffsetMax; + // RefreshScrollbars(); + // } + // } + // break; + // } + // } } //----------------------------------------------------------------------------- @@ -536,71 +536,71 @@ void EditElementMouseDoubleclick(int x, int y) //----------------------------------------------------------------------------- void MoveCursorMouseClick(int x, int y) { -// x += ScrollXOffset; + x += ScrollXOffset; -// y += FONT_HEIGHT/2; + y += FONT_HEIGHT/2; -// int gx0 = (x - X_PADDING)/(POS_WIDTH*FONT_WIDTH); -// int gy0 = (y - Y_PADDING)/(POS_HEIGHT*FONT_HEIGHT); + int gx0 = (x - X_PADDING)/(POS_WIDTH*FONT_WIDTH); + int gy0 = (y - Y_PADDING)/(POS_HEIGHT*FONT_HEIGHT); -// int gx = gx0; -// int gy = gy0 + ScrollYOffset; + int gx = gx0; + int gy = gy0 + ScrollYOffset; -// if(VALID_LEAF(DisplayMatrix[gx][gy])) { -// int i, j; -// for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { -// for(j = 0; j < DISPLAY_MATRIX_Y_SIZE; j++) { -// if(DisplayMatrix[i][j]) -// DisplayMatrix[i][j]->selectedState = SELECTED_NONE; -// } -// } -// int dx = x - (gx0*POS_WIDTH*FONT_WIDTH + X_PADDING); -// int dy = y - (gy0*POS_HEIGHT*FONT_HEIGHT + Y_PADDING); - -// int dtop = dy; -// int dbottom = POS_HEIGHT*FONT_HEIGHT - dy; -// int dleft = dx; -// int dright = POS_WIDTH*FONT_WIDTH - dx; - -// int extra = 1; -// if(DisplayMatrixWhich[gx][gy] == ELEM_COMMENT) { -// dleft += gx*POS_WIDTH*FONT_WIDTH; -// dright += (ColsAvailable - gx - 1)*POS_WIDTH*FONT_WIDTH; -// extra = ColsAvailable; -// } else { -// if((gx > 0) && (DisplayMatrix[gx-1][gy] == DisplayMatrix[gx][gy])) { -// dleft += POS_WIDTH*FONT_WIDTH; -// extra = 2; -// } -// if((gx < (DISPLAY_MATRIX_X_SIZE-1)) && -// (DisplayMatrix[gx+1][gy] == DisplayMatrix[gx][gy])) -// { -// dright += POS_WIDTH*FONT_WIDTH; -// extra = 2; -// } -// } + if(VALID_LEAF(DisplayMatrix[gx][gy])) { + int i, j; + for(i = 0; i < DISPLAY_MATRIX_X_SIZE; i++) { + for(j = 0; j < DISPLAY_MATRIX_Y_SIZE; j++) { + if(DisplayMatrix[i][j]) + DisplayMatrix[i][j]->selectedState = SELECTED_NONE; + } + } + int dx = x - (gx0*POS_WIDTH*FONT_WIDTH + X_PADDING); + int dy = y - (gy0*POS_HEIGHT*FONT_HEIGHT + Y_PADDING); + + int dtop = dy; + int dbottom = POS_HEIGHT*FONT_HEIGHT - dy; + int dleft = dx; + int dright = POS_WIDTH*FONT_WIDTH - dx; + + int extra = 1; + if(DisplayMatrixWhich[gx][gy] == ELEM_COMMENT) { + dleft += gx*POS_WIDTH*FONT_WIDTH; + dright += (ColsAvailable - gx - 1)*POS_WIDTH*FONT_WIDTH; + extra = ColsAvailable; + } else { + if((gx > 0) && (DisplayMatrix[gx-1][gy] == DisplayMatrix[gx][gy])) { + dleft += POS_WIDTH*FONT_WIDTH; + extra = 2; + } + if((gx < (DISPLAY_MATRIX_X_SIZE-1)) && + (DisplayMatrix[gx+1][gy] == DisplayMatrix[gx][gy])) + { + dright += POS_WIDTH*FONT_WIDTH; + extra = 2; + } + } -// int decideX = (dright - dleft); -// int decideY = (dtop - dbottom); - -// decideY = decideY*3*extra; - -// int state; -// if(abs(decideY) > abs(decideX)) { -// if(decideY > 0) { -// state = SELECTED_BELOW; -// } else { -// state = SELECTED_ABOVE; -// } -// } else { -// if(decideX > 0) { -// state = SELECTED_LEFT; -// } else { -// state = SELECTED_RIGHT; -// } -// } -// SelectElement(gx, gy, state); -// } + int decideX = (dright - dleft); + int decideY = (dtop - dbottom); + + decideY = decideY*3*extra; + + int state; + if(abs(decideY) > abs(decideX)) { + if(decideY > 0) { + state = SELECTED_BELOW; + } else { + state = SELECTED_ABOVE; + } + } else { + if(decideX > 0) { + state = SELECTED_LEFT; + } else { + state = SELECTED_RIGHT; + } + } + SelectElement(gx, gy, state); + } } //----------------------------------------------------------------------------- @@ -609,49 +609,49 @@ void MoveCursorMouseClick(int x, int y) //----------------------------------------------------------------------------- void MoveCursorNear(int gx, int gy) { -// int out = 0; - -// for(out = 0; out < 8; out++) { -// if(gx - out >= 0) { -// if(VALID_LEAF(DisplayMatrix[gx-out][gy])) { -// SelectElement(gx-out, gy, SELECTED_RIGHT); -// return; -// } -// } -// if(gx + out < DISPLAY_MATRIX_X_SIZE) { -// if(VALID_LEAF(DisplayMatrix[gx+out][gy])) { -// SelectElement(gx+out, gy, SELECTED_LEFT); -// return; -// } -// } -// if(gy - out >= 0) { -// if(VALID_LEAF(DisplayMatrix[gx][gy-out])) { -// SelectElement(gx, gy-out, SELECTED_BELOW); -// return; -// } -// } -// if(gy + out < DISPLAY_MATRIX_Y_SIZE) { -// if(VALID_LEAF(DisplayMatrix[gx][gy+out])) { -// SelectElement(gx, gy+out, SELECTED_ABOVE); -// return; -// } -// } + int out = 0; -// if(out == 1) { -// // Now see if we have a straight shot to the right; might be far -// // if we have to go up to a coil or other end of line element. -// int across; -// for(across = 1; gx+across < DISPLAY_MATRIX_X_SIZE; across++) { -// if(VALID_LEAF(DisplayMatrix[gx+across][gy])) { -// SelectElement(gx+across, gy, SELECTED_LEFT); -// return; -// } -// if(!DisplayMatrix[gx+across][gy]) break; -// } -// } -// } + for(out = 0; out < 8; out++) { + if(gx - out >= 0) { + if(VALID_LEAF(DisplayMatrix[gx-out][gy])) { + SelectElement(gx-out, gy, SELECTED_RIGHT); + return; + } + } + if(gx + out < DISPLAY_MATRIX_X_SIZE) { + if(VALID_LEAF(DisplayMatrix[gx+out][gy])) { + SelectElement(gx+out, gy, SELECTED_LEFT); + return; + } + } + if(gy - out >= 0) { + if(VALID_LEAF(DisplayMatrix[gx][gy-out])) { + SelectElement(gx, gy-out, SELECTED_BELOW); + return; + } + } + if(gy + out < DISPLAY_MATRIX_Y_SIZE) { + if(VALID_LEAF(DisplayMatrix[gx][gy+out])) { + SelectElement(gx, gy+out, SELECTED_ABOVE); + return; + } + } + + if(out == 1) { + // Now see if we have a straight shot to the right; might be far + // if we have to go up to a coil or other end of line element. + int across; + for(across = 1; gx+across < DISPLAY_MATRIX_X_SIZE; across++) { + if(VALID_LEAF(DisplayMatrix[gx+across][gy])) { + SelectElement(gx+across, gy, SELECTED_LEFT); + return; + } + if(!DisplayMatrix[gx+across][gy]) break; + } + } + } -// MoveCursorTopLeft(); + MoveCursorTopLeft(); } //----------------------------------------------------------------------------- |