summaryrefslogtreecommitdiff
path: root/ldmicro/lib/linuxUI
diff options
context:
space:
mode:
authorNatsuDrag92018-06-15 15:39:36 +0530
committerNatsuDrag92018-06-15 15:39:36 +0530
commitf43bd6c34fc3bae64223806c90f431e6f70a5a0e (patch)
tree30a677d50539e18393f8cc2ea9c5e967e5ca7888 /ldmicro/lib/linuxUI
parentc05949bafcc68a09153201097f7e46103bdb8864 (diff)
parent7ee6d232a84e011ce51313912fa547058985987c (diff)
downloadLDMicroGtk-f43bd6c34fc3bae64223806c90f431e6f70a5a0e.tar.gz
LDMicroGtk-f43bd6c34fc3bae64223806c90f431e6f70a5a0e.tar.bz2
LDMicroGtk-f43bd6c34fc3bae64223806c90f431e6f70a5a0e.zip
Merged
Diffstat (limited to 'ldmicro/lib/linuxUI')
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.cpp11
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h54
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp134
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h81
4 files changed, 180 insertions, 100 deletions
diff --git a/ldmicro/lib/linuxUI/linuxLD.cpp b/ldmicro/lib/linuxUI/linuxLD.cpp
index ce9899b..cdeb190 100644
--- a/ldmicro/lib/linuxUI/linuxLD.cpp
+++ b/ldmicro/lib/linuxUI/linuxLD.cpp
@@ -1,7 +1,6 @@
#include "linuxUI.h"
std::vector<HEAPRECORD> HeapRecords;
-std::vector<WNDCLASSEX> WindClassRecord;
HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
{
@@ -100,13 +99,7 @@ BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
}
-BOOL RegisterClassEx(const WNDCLASSEX *lpwcx)
-{
- WindClassRecord.push_back(*lpwcx);
- return TRUE;
-}
-
-HANDLE LoadImage(HINSTANCE hinst, LPCTSTR lpszName, UINT uType, int cxDesired,
+HICON LoadImage(HINSTANCE hinst, LPCTSTR lpszName, UINT uType, int cxDesired,
int cyDesired, UINT fuLoad)
{
HICON pixbuf;
@@ -118,7 +111,7 @@ HANDLE LoadImage(HINSTANCE hinst, LPCTSTR lpszName, UINT uType, int cxDesired,
g_error_free(error);
}
- return (HANDLE) pixbuf;
+ return pixbuf;
}
void OutputDebugString(char* str)
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index 25d42bb..5f8e0e7 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -4,6 +4,7 @@
#include "linuxUI.h"
#include <ctype.h>
#include <vector>
+#include <math.h>
#include <algorithm>
#include <sys/mman.h>
@@ -19,7 +20,10 @@
/// Image loading flags
#define IMAGE_ICON 1
-#define LDMICRO_ICON "ldmicro.ico"
+#define LDMICRO_ICON "../ldmicro.ico"
+
+/// Macro functions
+#define max(_A, _B) std::max(_A, _B)
/// Typedefs
//typedef int64_t __int64;
@@ -54,14 +58,14 @@ typedef CHAR *LPSTR;
typedef void *PVOID;
typedef void *LPVOID;
-typedef PVOID HFONT;
typedef PVOID HMODULE;
typedef PVOID HHOOK;
-typedef PVOID HFONT;
typedef PVOID HANDLE;
typedef HANDLE HINSTANCE;
-typedef HANDLE HDC;
+typedef HANDLE HGDIOBJ;
+
+typedef cairo_t *HCRDC;
typedef GtkWidget *HWID;
typedef GtkWidget *HMENU;
typedef GtkWindow *HWND;
@@ -106,6 +110,14 @@ typedef class tagColorReferance: public GdkRGBA{
this->alpha = 1.0;
}
+ // tagColorReferance(tagColorReferance &refCpy)
+ // {
+ // this->red = refCpy.red;
+ // this->green = refCpy.green;
+ // this->blue = refCpy.blue;
+ // this->alpha = refCpy.alpha;
+ // }
+
GdkRGBA* getThis()
{
return this;
@@ -143,25 +155,23 @@ typedef struct tagNMHDR {
UINT code;
} NMHDR;
-typedef struct tagWNDCLASSEX {
- UINT cbSize;
- UINT style;
-// WNDPROC lpfnWndProc;
- int cbClsExtra;
- int cbWndExtra;
- HINSTANCE hInstance;
- HICON hIcon;
-// HCURSOR hCursor;
- HBRUSH hbrBackground;
- LPCTSTR lpszMenuName;
- LPCTSTR lpszClassName;
- HICON hIconSm;
-} WNDCLASSEX, *PWNDCLASSEX;
-
+typedef struct FontTag {
+ int nHeight;
+ int nWidth;
+ int nOrientation;
+ int fnWeight;
+ DWORD fdwItalic;
+ LPCTSTR lpszFace;
+} *HFONT, FONT;
+
+typedef struct tagLOGBRUSH {
+ UINT lbStyle;
+ COLORREF lbColor;
+// ULONG_PTR lbHatch;
+} LOGBRUSH, *PLOGBRUSH;
/// Variables
extern std::vector<HEAPRECORD> HeapRecord;
-extern std::vector<WNDCLASSEX> WindClassRecord;
/// Functions
HANDLE HeapCreate(
@@ -179,9 +189,7 @@ BOOL HeapFree(
DWORD dwFlags,
LPVOID lpMem);
-BOOL RegisterClassEx(const WNDCLASSEX *lpwcx);
-
-HANDLE LoadImage(
+HICON LoadImage(
HINSTANCE hinst,
LPCTSTR lpszName,
UINT uType,
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index 670e864..bbaa001 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -33,19 +33,6 @@ COLORREF RGB(int red, int green, int blue)
return col;
}
-HBRUSH GetStockObject(int fnObject)
-{
- switch(fnObject)
- {
- case BLACK_BRUSH:
- return new COLORREF(0, 0, 0);
- break;
-
- default:
- return new COLORREF(255, 255, 255);
- }
-}
-
int MessageBox(HWID pWindow, char* message, char* title, UINT mFlags)
{
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
@@ -97,6 +84,7 @@ int MessageBox(HWID pWindow, char* message, char* title, UINT mFlags)
return result;
}
+
BOOL GetSaveFileName(OPENFILENAME *ofn)
{
GtkWidget *dialog;
@@ -195,38 +183,98 @@ void CheckMenuItem(HMENU MenuName, HMENU MenuItem, UINT Check)
}
}
-HWID CreateWindowEx(DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName,
- DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent,
- HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
+HANDLE GetStockObject(int fnObject)
{
-
- auto WinClR_it = std::find_if(WindClassRecord.begin(), WindClassRecord.end(), [&lpClassName](WNDCLASSEX &Record) { return Record.lpszClassName == lpClassName; });
+ 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);
+ }
+}
- if (WinClR_it == WindClassRecord.end())
- return NULL;
+void SelectObject(HCRDC hcr, HFONT hfont)
+{
+ cairo_select_font_face(hcr, hfont->lpszFace,
+ hfont->fdwItalic ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
+ hfont->fnWeight == FW_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
+
+ cairo_rotate(hcr, hfont->nOrientation);
+
+ // cairo_text_extents_t extents;
+ // cairo_text_extents (hcr, "H", &extents);
+
+ // cairo_matrix_t matrix;
+ // cairo_matrix_init_scale (&matrix,
+ // (double)hfont->nWidth / extents.width,
+ // (double)hfont->nHeight / extents.width);
+
+ // cairo_set_font_matrix (hcr, &matrix);
+ // g_print("wR = %f\nhR = %f\n", (double)hfont->nWidth / extents.width, (double)hfont->nHeight / extents.height);
+ // g_print("tW = %f\ntH = %f\n", extents.width, extents.width);
+ cairo_set_font_size(hcr, 15);
+}
+
+HBRUSH CreateBrushIndirect(PLOGBRUSH plb)
+{
+ COLORREF brush(plb->lbColor);
+ brush.alpha = (plb->lbStyle == BS_SOLID) ? 1 : 0.2;
+
+ return &brush;
+}
+
+HFONT CreateFont(int nHeight, int nWidth, int nOrientation, int fnWeight,
+ DWORD fdwItalic, LPCTSTR lpszFace)
+{
+ HFONT font = new FONT;
+ font->nHeight = nHeight;
+ font->nWidth = nWidth;
+ font->nOrientation = nOrientation;
+ font->fnWeight = fnWeight;
+ font->fdwItalic = fdwItalic;
+ font->lpszFace = lpszFace;
+
+ return font;
+}
+
+void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol)
+{
+ gtk_widget_override_background_color(GTK_WIDGET(widget),
+ GTK_STATE_FLAG_NORMAL, &bkCol);
+
+ GtkStyleContext *context;
+ COLORREF col;
+
+ context = gtk_widget_get_style_context (widget);
+ gint width = gtk_widget_get_allocated_width (widget);
+ gint height = gtk_widget_get_allocated_height (widget);
+
+ gtk_style_context_get_color (context,
+ gtk_style_context_get_state (context),
+ &col);
- HWID window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(window), lpWindowName);
- gtk_window_set_default_size (GTK_WINDOW(window), nWidth, nHeight);
- gtk_window_resize (GTK_WINDOW(window), nWidth, nHeight);
- gtk_window_move(GTK_WINDOW(window), x, y);
- gtk_widget_override_background_color(GTK_WIDGET(window), GTK_STATE_FLAG_NORMAL, WinClR_it->hbrBackground->getThis());
- gtk_window_set_default_icon(WinClR_it->hIcon);
- gtk_window_set_icon(GTK_WINDOW(window), WinClR_it->hIcon);
-
- return window;
+ gdk_cairo_set_source_rgba (hcr, &col);
+
+ gtk_render_background (context, hcr, 0, 0, width, height);
+}
+
+void SetTextColor(HCRDC hcr, COLORREF color)
+{
+ gdk_cairo_set_source_rgba (hcr, &color);
}
-// bool KeyPressEnter(HWID widget, GdkEventKey* event, gpointer* data) {
-// if (event->keyval == GDK_KEY_Return){
-// return TRUE;
-// }
-// return FALSE;
-// }
-
-// bool KeyPressEsc(HWID widget, GdkEventKey* event, gpointer* data) {
-// if (event->keyval == GDK_KEY_Escape){
-// return TRUE;
-// }
-// return FALSE;
-// }
+void TextOut(HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, int cchString)
+{
+ cairo_move_to(hcr, nXStart, nYStart);
+ cairo_show_text(hcr, lpString);
+
+ cairo_fill (hcr);
+} \ No newline at end of file
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index 279bf86..08dab39 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -39,7 +39,15 @@
#define OFN_OVERWRITEPROMPT 0x00000400L
/// window brushes
-#define BLACK_BRUSH 0x00000401L
+#define BS_SOLID 0x00000001L
+#define BS_HOLLOW 0x00000002L
+#define BLACK_BRUSH 0x00000004L
+#define WHITE_BRUSH 0x00000008L
+#define GREY_BRUSH 0x00000010L
+
+/// Font flags
+#define FW_REGULAR 0x00000001L
+#define FW_BOLD 0x00000002L
/// EnableMenuItem variables
extern const UINT MF_ENABLED;
@@ -68,29 +76,52 @@ typedef struct OpenFileInfoData {
} OPENFILENAME;
/// functions
-BOOL isFocus(HWID);
-COLORREF RGB(int, int, int);
-int MessageBox(HWID, char*, char*, UINT);
-BOOL GetSaveFileName(OPENFILENAME* );
-void EnableMenuItem(HMENU, HMENU, UINT);
-void CheckMenuItem(HMENU, HMENU, UINT);
-HBRUSH GetStockObject(int fnObject);
-// bool KeyPressEnter (HWID, GdkEventKey, gpointer);
-// bool KeyPressEsc (HWID, GdkEventKey, gpointer);
-
-HWID CreateWindowEx(
- DWORD dwExStyle,
- LPCTSTR lpClassName,
- LPCTSTR lpWindowName,
- DWORD dwStyle,
- int x,
- int y,
- int nWidth,
- int nHeight,
- HWND hWndParent,
- HMENU hMenu,
- HINSTANCE hInstance,
- LPVOID lpParam
-);
+BOOL isFocus(HWID window);
+
+COLORREF RGB(int red,
+ int green,
+ int blue);
+
+int MessageBox(HWID pWindow,
+ char* message,
+ char* title,
+ UINT mFlags);
+
+BOOL GetSaveFileName(OPENFILENAME *ofn);
+
+void EnableMenuItem(HMENU MenuName,
+ HMENU MenuItem,
+ UINT CheckEnabledItem);
+
+void CheckMenuItem(HMENU MenuName,
+ HMENU MenuItem,
+ UINT Check);
+
+HANDLE GetStockObject(int fnObject);
+
+void SelectObject(HCRDC hcr,
+ HFONT hfont);
+
+HBRUSH CreateBrushIndirect(PLOGBRUSH plb);
+
+HFONT CreateFont(int nHeight,
+ int nWidth,
+ int nOrientation,
+ int fnWeight,
+ DWORD fdwItalic,
+ LPCTSTR lpszFace);
+
+void SetBkColor(HWID widget,
+ HCRDC hcr,
+ COLORREF bkCol);
+
+void SetTextColor(HCRDC hcr,
+ COLORREF color);
+
+void TextOut(HCRDC hcr,
+ int nXStart,
+ int nYStart,
+ LPCTSTR lpString,
+ int cchString);
#endif \ No newline at end of file