diff options
Diffstat (limited to 'ldmicro')
-rw-r--r-- | ldmicro/draw_outputdev.cpp | 1 | ||||
-rw-r--r-- | ldmicro/includes/ldmicro.h | 1 | ||||
-rw-r--r-- | ldmicro/ldmicro.cpp | 143 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp | 9 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.h | 6 | ||||
-rw-r--r-- | ldmicro/maincontrols.cpp | 23 |
6 files changed, 142 insertions, 41 deletions
diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp index 5b05db5..5bdf58e 100644 --- a/ldmicro/draw_outputdev.cpp +++ b/ldmicro/draw_outputdev.cpp @@ -390,6 +390,7 @@ static void SetSyntaxHighlightingColours(void) //----------------------------------------------------------------------------- void InitForDrawing(void) { + DrawWindow = gtk_drawing_area_new (); // SetSyntaxHighlightingColours(); // FixedWidthFont = CreateFont( diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h index 7796a01..eaf8dcd 100644 --- a/ldmicro/includes/ldmicro.h +++ b/ldmicro/includes/ldmicro.h @@ -516,6 +516,7 @@ void SetUndoEnabled(BOOL undoEnabled, BOOL redoEnabled); void RefreshScrollbars(void); extern HINSTANCE Instance; extern HWID MainWindow; +extern HWID DrawWindow; extern HDC Hdc; extern PlcProgram Prog; extern char CurrentSaveFile[MAX_PATH]; diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index b1a4c0e..1bea92c 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -35,6 +35,7 @@ HINSTANCE Instance; HWID MainWindow; +HWID DrawWindow; HDC Hdc; // parameters used to capture the mouse when implementing our totally non- @@ -637,16 +638,24 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return 1; } -void LD_GTK_delete_call(GtkWidget *widget, GdkEvent *event, gpointer user_data)//(HWND window) +void LD_WM_Close_call(GtkWidget *widget, GdkEvent *event, gpointer user_data)//(HWND window) { + /* Handles: + * WM_CLOSE + */ + FreezeWindowPos(MainWindow); FreezeDWORD(IoListHeight); gtk_main_quit(); } -gboolean LD_GTK_keybord_hook(GtkWidget *widget, GdkEvent *event, gpointer user_data) -{ +gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + /* Handles: + * WM_KEYDOWN + */ + switch(event->key.state) { case GDK_SHIFT_MASK: @@ -941,16 +950,20 @@ gboolean LD_GTK_keybord_hook(GtkWidget *widget, GdkEvent *event, gpointer user_d // InvalidateRect(MainWindow, NULL, FALSE); // } // break; - + return FALSE; } gboolean LD_GTK_mouse_click_hook(GtkWidget *widget, GdkEvent *event, gpointer user_data) { + /* Handles: + * WM_LBUTTONDBLCLK, WM_LBUTTONDOWN + */ + g_print("x = %f\n", event->button.x_root); g_print("y = %f\n", event->button.y_root); switch(event->button.type) { - case GDK_BUTTON_PRESS: + 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))) { @@ -978,10 +991,15 @@ gboolean LD_GTK_mouse_click_hook(GtkWidget *widget, GdkEvent *event, gpointer us break; } + return FALSE; } gboolean LD_GTK_mouse_scroll_hook(GtkWidget *widget, GdkEvent *event, gpointer user_data) { + /* Handles: + * WM_VSCROLL, WM_HSCROLL, WM_MOUSEWHEEL + */ + switch(event->scroll.direction) { case GDK_SCROLL_UP: @@ -1002,10 +1020,15 @@ gboolean LD_GTK_mouse_scroll_hook(GtkWidget *widget, GdkEvent *event, gpointer u break; } + return FALSE; } -gboolean LD_GTK_mouse_move_hook(GtkWidget *widget, GdkEvent *event, gpointer user_data) +gboolean LD_WM_MouseMove_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) { + /* Handles: + * WM_MOUSEMOVE + */ + g_print("x = %f\n", event->button.x_root); g_print("y = %f\n", event->button.y_root); // int x = LOWORD(lParam); @@ -1018,11 +1041,56 @@ gboolean LD_GTK_mouse_move_hook(GtkWidget *widget, GdkEvent *event, gpointer use // } // break; + return FALSE; } -gboolean LD_GTK_paint_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) +gboolean LD_WM_Paint_call(GtkWidget *widget, cairo_t *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); + + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_height (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); + + 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_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); + // PAINTSTRUCT ps; // Hdc = BeginPaint(hwnd, &ps); @@ -1053,27 +1121,46 @@ gboolean LD_GTK_paint_call(GtkWidget *widget, GdkEvent *event, gpointer user_dat // FillRect(Hdc, &r, (HBRUSH)GetStockObject(DKGRAY_BRUSH)); // EndPaint(hwnd, &ps); - // return 1; + + return FALSE; } -gboolean LD_GTK_destroy_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) +gboolean LD_WM_Destroy_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) { + /* Handles: + * WM_DESTROY + */ + // if(CheckSaveUserCancels()) break; // PostQuitMessage(0); // return 1; + + return FALSE; } -gboolean LD_GTK_size_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) +gboolean LD_WM_Size_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) { + /* Handles: + * WM_SIZE + */ + // MainWindowResized(); // break; + + return FALSE; } -gboolean LD_GTK_set_focus_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) +gboolean LD_WM_SetFocus_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) { + /* Handles: + * WM_SETFOCUS + */ + // InvalidateRect(MainWindow, NULL, FALSE); // break; + + return FALSE; } //----------------------------------------------------------------------------- @@ -1188,34 +1275,34 @@ int main(int argc, char** argv) gtk_window_resize (GTK_WINDOW(MainWindow), 800, 600); gtk_window_move(GTK_WINDOW(MainWindow), 10, 10); gtk_widget_override_background_color(GTK_WIDGET(MainWindow), - GTK_STATE_FLAG_NORMAL, GetStockObject(BLACK_BRUSH)->getThis()); + GTK_STATE_FLAG_NORMAL, ((HBRUSH)GetStockObject(GREY_BRUSH))->getThis()); gtk_window_set_default_icon(LoadImage(Instance, LDMICRO_ICON, IMAGE_ICON, 32, 32, 0)); gtk_window_set_icon(GTK_WINDOW(MainWindow), LoadImage(Instance, LDMICRO_ICON, IMAGE_ICON, 32, 32, 0)); + /// Make main window - end + + InitForDrawing(); - /// Keyboard and mouse hooks equivalent to MainWndProc - g_signal_connect (MainWindow, "delete_event", G_CALLBACK (LD_GTK_delete_call), NULL); - g_signal_connect (MainWindow, "key_press_event", G_CALLBACK (LD_GTK_keybord_hook), NULL); - g_signal_connect (MainWindow, "button_press_event", G_CALLBACK (LD_GTK_mouse_click_hook), NULL); - g_signal_connect (MainWindow, "scroll_event", G_CALLBACK (LD_GTK_mouse_scroll_hook), NULL); - g_signal_connect (MainWindow, "motion_notify_event", G_CALLBACK (LD_GTK_mouse_move_hook), NULL); - // g_signal_connect (DrawWindow, "draw", G_CALLBACK (LD_GTK_paint_call), NULL); - g_signal_connect (MainWindow, "destroy_event", G_CALLBACK (LD_GTK_destroy_call), NULL); - g_signal_connect (MainWindow, "configure_event", G_CALLBACK (LD_GTK_size_call), NULL); - g_signal_connect (MainWindow, "focus_in_event", G_CALLBACK (LD_GTK_set_focus_call), NULL); - - ThawWindowPos(MainWindow); IoListHeight = 100; ThawDWORD(IoListHeight); - InitForDrawing(); - - - MakeMainWindowControls(); /// takes care of MakeMainWindowMenus() MainWindowResized(); + + /// Keyboard and mouse hooks equivalent to MainWndProc + g_signal_connect (MainWindow, "delete_event", G_CALLBACK (LD_WM_Close_call), NULL); + g_signal_connect (MainWindow, "key_press_event", G_CALLBACK (LD_WM_KeyDown_call), NULL); + g_signal_connect (MainWindow, "button_press_event", G_CALLBACK (LD_GTK_mouse_click_hook), NULL); + g_signal_connect (MainWindow, "scroll_event", G_CALLBACK (LD_GTK_mouse_scroll_hook), NULL); + g_signal_connect (MainWindow, "motion_notify_event", G_CALLBACK (LD_WM_MouseMove_call), NULL); + g_signal_connect (DrawWindow, "draw", G_CALLBACK (LD_WM_Paint_call), NULL); + g_signal_connect (MainWindow, "destroy_event", G_CALLBACK (LD_WM_Destroy_call), NULL); + g_signal_connect (MainWindow, "configure_event", G_CALLBACK (LD_WM_Size_call), NULL); + g_signal_connect (MainWindow, "focus_in_event", G_CALLBACK (LD_WM_SetFocus_call), NULL); + /// Keyboard and mouse hooks equivalent to MainWndProc - end + // NewProgram(); // strcpy(CurrentSaveFile, ""); diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index 524046d..f0c9124 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -27,14 +27,19 @@ COLORREF RGB(int red, int green, int blue) return col; } -HBRUSH GetStockObject(int fnObject) +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); } diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h index 7e2ea84..85b5fa8 100644 --- a/ldmicro/lib/linuxUI/linuxUI.h +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -39,7 +39,9 @@ #define OFN_OVERWRITEPROMPT 0x00000400L /// window brushes -#define BLACK_BRUSH 0x00000401L +#define BLACK_BRUSH 0x00000002L +#define WHITE_BRUSH 0x00000004L +#define GREY_BRUSH 0x00000008L /// EnableMenuItem variables extern const UINT MF_ENABLED; @@ -70,6 +72,6 @@ int MessageBox(HWID, char*, char*, UINT); BOOL GetSaveFileName(OPENFILENAME* ); void EnableMenuItem(HMENU, HMENU, UINT); void CheckMenuItem(HMENU, HMENU, UINT); -HBRUSH GetStockObject(int fnObject); +HANDLE GetStockObject(int fnObject); #endif
\ No newline at end of file diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp index 2d2716b..a45152e 100644 --- a/ldmicro/maincontrols.cpp +++ b/ldmicro/maincontrols.cpp @@ -413,6 +413,7 @@ void MakeMainWindowControls(void) { HWID PackBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); HWID grid = gtk_grid_new(); + /// Pane to separate Scrolled Window and other widgets HWID pane = gtk_paned_new (GTK_ORIENTATION_VERTICAL); IoList = gtk_list_store_new (5, @@ -426,7 +427,7 @@ void MakeMainWindowControls(void) int pinWidth = 100; int portWidth = 90; - // Creating a list + /// Creating a list view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(IoList)); gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (IoList)); @@ -465,33 +466,37 @@ void MakeMainWindowControls(void) gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); gtk_tree_view_column_set_min_width (column, portWidth); - // Appending Menus to grid + /// Appending Menus to grid gtk_grid_attach (GTK_GRID (grid), MakeMainWindowMenus(), 0, 0, 1, 1); - // Creating Scrolled Window + /// Creating Scrolled Window ScrollWindow = gtk_scrolled_window_new (NULL, NULL); + HWID viewport = gtk_viewport_new (NULL,NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ScrollWindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); + gtk_widget_set_hexpand(GTK_WIDGET(ScrollWindow), TRUE); + gtk_widget_set_vexpand(GTK_WIDGET(ScrollWindow), TRUE); - // Creating a pane to separate Scrolled Window and other widgets + /// Adding DrawWindow to pane + gtk_container_add (GTK_CONTAINER(viewport), DrawWindow); + gtk_container_add (GTK_CONTAINER(ScrollWindow), viewport); gtk_paned_add1 (GTK_PANED (pane), ScrollWindow); gtk_paned_set_position (GTK_PANED (pane), 0); - gtk_widget_set_vexpand (ScrollWindow, TRUE); - gtk_widget_set_hexpand (ScrollWindow, TRUE); + - // Appending tree view to pane and pane to grid + /// Appending tree view to pane and pane to grid gtk_paned_pack2 (GTK_PANED(pane), view, FALSE, FALSE); gtk_paned_set_position (GTK_PANED (pane), 250); gtk_grid_attach (GTK_GRID (grid), pane, 0, 0, 1, 1); - // Creating Status Bar and attaching to grid + /// Creating Status Bar and attaching to grid StatusBar = gtk_statusbar_new(); gtk_statusbar_push (GTK_STATUSBAR (StatusBar), gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar), "Introduction"), "LDMicro Started"); - // Appneding Status Bar to box which is then added to Main Window + /// Appneding Status Bar to box which is then added to Main Window gtk_box_pack_start(GTK_BOX(PackBox), grid, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(PackBox), StatusBar, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(MainWindow), PackBox); |