diff options
Diffstat (limited to 'ldmicro')
-rw-r--r-- | ldmicro/CMakeLists.txt | 2 | ||||
-rw-r--r-- | ldmicro/includes/linuxUI/linuxUI.h | 27 | ||||
-rw-r--r-- | ldmicro/linuxUI.cpp | 66 |
3 files changed, 90 insertions, 5 deletions
diff --git a/ldmicro/CMakeLists.txt b/ldmicro/CMakeLists.txt index 2e20552..635fdff 100644 --- a/ldmicro/CMakeLists.txt +++ b/ldmicro/CMakeLists.txt @@ -59,7 +59,7 @@ ENDIF ( GTK3_FOUND) ## Dummy compile and install to test linuxUI ## to compile LDmicro uncomment the below 2 line2 -add_executable (LDMicro ldmicro.cpp)# miscutil.cpp draw_outputdev.cpp) +#add_executable (LDMicro ldmicro.cpp)# miscutil.cpp draw_outputdev.cpp) # install (TARGETS LDMicro DESTINATION bin) add_executable (linuxUI linuxUI.cpp) install (TARGETS linuxUI DESTINATION bin) diff --git a/ldmicro/includes/linuxUI/linuxUI.h b/ldmicro/includes/linuxUI/linuxUI.h index 02691b5..bfbf3bc 100644 --- a/ldmicro/includes/linuxUI/linuxUI.h +++ b/ldmicro/includes/linuxUI/linuxUI.h @@ -17,18 +17,19 @@ /// typedefs //typedef int64_t __int64; typedef bool BOOL; -typedef GdkRGBA COLORREF; typedef unsigned char BYTE; typedef unsigned int DWORD; /// all handles will hold a GtkWindow* type typedef void* PVOID; -typedef GtkWindow* HANDLE; +typedef GtkWidget* HANDLE; typedef HANDLE HINSTANCE; typedef HANDLE HWND; typedef HANDLE HDC; typedef HANDLE HMENU; +typedef GtkApplication* HAPP; + /* /// Check if system is x64 or x86 using GCC #if __GNUC__ @@ -52,7 +53,27 @@ typedef unsigned int UINT_PTR; typedef UINT_PTR WPARAM; typedef unsigned int UINT; +/// custom classes +class COLORREF : public GdkRGBA{ + public: + COLORREF() + { + this->red = 0.0; + this->green = 0.0; + this->blue = 0.0; + this->alpha = 1.0; + } + COLORREF(int r, int g, int b) + { + this->red = r/255.0; + this->green = g/255.0; + this->blue = b/255.0; + this->alpha = 1.0; + } +}; + /// common windows referances for linux - end /// functions -BOOL isFocus(HWND);
\ No newline at end of file +BOOL isFocus(HWND); +COLORREF RGB(int, int, int);
\ No newline at end of file diff --git a/ldmicro/linuxUI.cpp b/ldmicro/linuxUI.cpp index 2722101..16e8368 100644 --- a/ldmicro/linuxUI.cpp +++ b/ldmicro/linuxUI.cpp @@ -3,5 +3,69 @@ /// Wraper function for gtk_window_has_toplevel_focus BOOL isFocus(HWND window) { - return (BOOL) gtk_window_has_toplevel_focus(GTK_WINDOW(window)); + return (BOOL) gtk_window_has_toplevel_focus(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(window)))); +} + +COLORREF RGB(int red, int green, int blue) +{ + COLORREF col; + col.red = red/255.0; + col.green = green/255.0; + col.blue = blue/255.0; + col.alpha = 1.0; + + return col; +} + +gboolean draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data) +{ + guint width, height; + COLORREF color = RGB (255, 0, 0); + + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_height (widget); + cairo_arc (cr, + width / 2.0, height / 2.0, + MIN (width, height) / 2.0, + 0, 2 * G_PI); + + gtk_style_context_get_color (gtk_widget_get_style_context (widget), + GTK_STATE_FLAG_NORMAL, + &color); + + gdk_cairo_set_source_rgba (cr, &color); + + cairo_fill (cr); + + return FALSE; +} + +static void load (GtkApplication* app, gpointer user_data) +{ + /// Make window + HWND window = gtk_application_window_new(app); + gtk_window_set_title(GTK_WINDOW(window), "Window"); + gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); + + HWND drawing_area = gtk_drawing_area_new (); + gtk_widget_set_size_request (drawing_area, 100, 100); + g_signal_connect (G_OBJECT (drawing_area), "draw", G_CALLBACK (draw_callback), NULL); + + gtk_container_add(GTK_CONTAINER(window), drawing_area); + + gtk_widget_show_all (window); +} + +int main (int argc, char** argv) +{ + /// Make app + HAPP app; + int status; + + app = gtk_application_new ("org.git.ldmicro", G_APPLICATION_FLAGS_NONE); + g_signal_connect (app, "activate", G_CALLBACK (load), NULL); + status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + + return status; }
\ No newline at end of file |