summaryrefslogtreecommitdiff
path: root/ldmicro/ldmicro.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro/ldmicro.cpp')
-rw-r--r--ldmicro/ldmicro.cpp242
1 files changed, 161 insertions, 81 deletions
diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp
index 0deea5a..aac5ba7 100644
--- a/ldmicro/ldmicro.cpp
+++ b/ldmicro/ldmicro.cpp
@@ -40,7 +40,7 @@ using namespace std;
HINSTANCE Instance;
HWID MainWindow;
HWID DrawWindow;
-HCRDC Hdc;
+// HCRDC Hcr;
// parameters used to capture the mouse when implementing our totally non-
// general splitter control
@@ -662,6 +662,8 @@ void LD_WM_Close_call(GtkWidget *widget, GdkEvent *event, gpointer user_data)//(
* WM_CLOSE
*/
+ // if(Hdc != NULL)
+ // cairo_destroy(Hdc);
FreezeWindowPos(MainWindow);
FreezeDWORD(IoListHeight);
@@ -673,7 +675,7 @@ gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEvent *event, gpointer user_da
/* Handles:
* WM_KEYDOWN
*/
-
+ // g_print("ky call\n");
switch(event->key.state)
{
case GDK_SHIFT_MASK:
@@ -968,6 +970,7 @@ gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEvent *event, gpointer user_da
// InvalidateRect(MainWindow, NULL, FALSE);
// }
// break;
+ // g_print("ky call end\n");
return FALSE;
}
@@ -976,37 +979,57 @@ gboolean LD_GTK_mouse_click_hook(GtkWidget *widget, GdkEvent *event, gpointer us
/* Handles:
* WM_LBUTTONDBLCLK, WM_LBUTTONDOWN
*/
+ // g_print("mo cl call\n");
+
+ GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(ScrollWindow));
+ // g_print("---\nadj = %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---\n", gtk_widget_get_allocated_height (ScrollWindow));
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 + gtk_adjustment_get_value(adjustment);
+
+ // 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);
+ gtk_widget_queue_draw(DrawWindow);
+ }
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 + gtk_adjustment_get_value(adjustment);
+
+ if(InSimulationMode) {
+ EditElementMouseDoubleclick(x, y);
+ } else {
+ CHANGING_PROGRAM(EditElementMouseDoubleclick(x, y));
+ }
+ // InvalidateRect(DrawWindow, NULL, FALSE);
+ gtk_widget_queue_draw(DrawWindow);
+ }
break;
}
+ // g_print("mo cl call end\n");
return FALSE;
}
@@ -1015,27 +1038,49 @@ gboolean LD_GTK_mouse_scroll_hook(GtkWidget *widget, GdkEvent *event, gpointer u
/* Handles:
* WM_VSCROLL, WM_HSCROLL, WM_MOUSEWHEEL
*/
-
+ // g_print("mo sc call\n");
+ 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:
+ if (gtk_adjustment_get_value(adjustment) == gtk_adjustment_get_lower(adjustment))
+ VscrollProc(SB_TOP);
+ else
+ VscrollProc(SB_LINEUP);
+ break;
case GDK_SCROLL_DOWN:
- // VscrollProc(wParam);
+ 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);
+ break;
case GDK_SCROLL_RIGHT:
- // HscrollProc(wParam);
+ HscrollProc(SB_LINEDOWN);
break;
case GDK_SCROLL_SMOOTH:
- // if((GET_WHEEL_DELTA_WPARAM(wParam)) > 0) {
- // VscrollProc(SB_LINEUP);
- // } else {
- // VscrollProc(SB_LINEDOWN);
- // }
- // gdk_event_get_scroll_deltas (const GdkEvent *event, gdouble *delta_x, gdouble *delta_y);
+ double d_x, d_y;
+ gdk_event_get_scroll_deltas (event, &d_x, &d_y);
+ if(d_y > 0) {
+ VscrollProc(SB_LINEUP);
+ } else {
+ VscrollProc(SB_LINEDOWN);
+ }
break;
}
+
+ gtk_widget_queue_draw(DrawWindow);
+ // g_print("mo sc call end\n");
return FALSE;
}
@@ -1044,7 +1089,7 @@ gboolean LD_WM_MouseMove_call(GtkWidget *widget, GdkEvent *event, gpointer user_
/* Handles:
* WM_MOUSEMOVE
*/
-
+ // g_print("mo mv call\n");
// g_print("x = %f\n", event->button.x_root);
// g_print("y = %f\n", event->button.y_root);
@@ -1061,47 +1106,77 @@ gboolean LD_WM_MouseMove_call(GtkWidget *widget, GdkEvent *event, gpointer user_
return FALSE;
}
-gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data)
+gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data)//(HWID widget, GdkEventExpose *event)//
{
/* Handles:
* WM_PAINT
*/
- // guint width, height;
- // GdkRGBA color;
- // GtkStyleContext *context;
+ // g_print("draw called----------------------------------\n");
+ 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);
+ Paint_call_first = FALSE;
+ }
- // context = gtk_widget_get_style_context (widget);
+ /// This draws the schematic.
+ MainWindowResized();
+ PaintWindow(cr);
- // 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);
+ /* Cairo test code
+ guint width, height;
+ GdkRGBA color;
+ GtkStyleContext *context;
- // // SetBkColor(widget, cr, HighlightColours.bg);
+ context = gtk_widget_get_style_context (widget);
- // 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);
-
- // gtk_style_context_get_color (context,
- // gtk_style_context_get_state (context),
- // &color);
- // gdk_cairo_set_source_rgba (cr, &color);
-
- // cairo_fill (cr);
-
- Hdc = cr;
-
- /// This draws the schematic.
- PaintWindow();
+ 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);
+
+ // 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);
+
+ gtk_style_context_get_color (context,
+ gtk_style_context_get_state (context),
+ &color);
+ gdk_cairo_set_source_rgba (cr, &color);
+
+ cairo_fill (cr);
+
+ SetBkColor(DrawWindow, cr, InSimulationMode ? HighlightColours.simBg :
+ HighlightColours.bg);
+ SetTextColor(cr, InSimulationMode ? HighlightColours.simRungNum :
+ HighlightColours.rungNum);
+ SelectObject(cr, FixedWidthFont);
+ for (int xp = 0; xp<= width; xp += 7)
+ for (int yp = 0; yp <= height; yp += 7)
+ TextOut(DrawWindow, cr, xp, yp, "H", 1);
+ */
return FALSE;
}
@@ -1110,7 +1185,7 @@ gboolean LD_WM_Destroy_call(GtkWidget *widget, GdkEvent *event, gpointer user_da
/* Handles:
* WM_DESTROY
*/
-
+ // g_print("dis call\n");
// if(CheckSaveUserCancels()) break;
// PostQuitMessage(0);
@@ -1124,9 +1199,9 @@ gboolean LD_WM_Size_call(GtkWidget *widget, GdkEvent *event, gpointer user_data)
/* Handles:
* WM_SIZE
*/
-
+ // g_print("size call\n");
MainWindowResized();
-
+ // g_print("size call end\n");
return FALSE;
}
@@ -1135,9 +1210,9 @@ gboolean LD_WM_SetFocus_call(GtkWidget *widget, GdkEvent *event, gpointer user_d
/* Handles:
* WM_SETFOCUS
*/
-
+ // g_print("focus call\n");
InvalidateRect(DrawWindow, NULL, FALSE);
-
+ // g_print("focus call end\n");
return FALSE;
}
@@ -1207,6 +1282,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
@@ -1239,12 +1320,6 @@ int main(int argc, char** argv)
MainHeap = HeapCreate(0, 1024*64, 0);
- // MakeDialogBoxClass();
- // MakeComponentListClass();
- // MakeSmplDialogClass();
- // MakeNamingListClass();
- HMENU top = MakeMainWindowMenus();
-
/// Make main window
MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(MainWindow), "LDmicro");
@@ -1259,6 +1334,8 @@ int main(int argc, char** argv)
IMAGE_ICON, 32, 32, 0));
/// Make main window - end
+ MakeMainWindowMenus();
+
InitForDrawing();
ThawWindowPos(MainWindow);
@@ -1285,12 +1362,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);
- // SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor);
+
+ /// Blink cursor
+ g_timeout_add(200, (GSourceFunc)BlinkCursor, DrawWindow);
if(argc >= 2) {
// g_print("load prog: %s\n", argv[1]);
@@ -1339,5 +1418,6 @@ int main(int argc, char** argv)
// }
gtk_main();
+ gdk_threads_leave();
return EXIT_SUCCESS;
} \ No newline at end of file