summaryrefslogtreecommitdiff
path: root/ldmicro/lib/linuxUI
diff options
context:
space:
mode:
authorAkshay Chipkar2019-03-18 13:02:50 +0530
committerGitHub2019-03-18 13:02:50 +0530
commit7cb2c053c6e68616230bd5c645977c90ccaa6056 (patch)
treedbdce755481abdbe999fdd83be9408c002401a71 /ldmicro/lib/linuxUI
parenta962c0a7965f6c0d80c867ba9f3fbe797ac14de7 (diff)
parent08ca539a8d6624e979bf4e85a61ff00567575667 (diff)
downloadLDmicroQt-7cb2c053c6e68616230bd5c645977c90ccaa6056.tar.gz
LDmicroQt-7cb2c053c6e68616230bd5c645977c90ccaa6056.tar.bz2
LDmicroQt-7cb2c053c6e68616230bd5c645977c90ccaa6056.zip
Merge pull request #1 from akshay-c/Akshay
Cursor update and basic screen drawing
Diffstat (limited to 'ldmicro/lib/linuxUI')
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.cpp8
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h25
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp161
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h35
4 files changed, 148 insertions, 81 deletions
diff --git a/ldmicro/lib/linuxUI/linuxLD.cpp b/ldmicro/lib/linuxUI/linuxLD.cpp
index a83d15e..d43fd0e 100644
--- a/ldmicro/lib/linuxUI/linuxLD.cpp
+++ b/ldmicro/lib/linuxUI/linuxLD.cpp
@@ -119,10 +119,10 @@ HICON LoadImage(HINSTANCE hinst, LPCTSTR lpszName, UINT uType, int cxDesired,
void RECT_to_GDRECT(const RECT *rc, GDRECT *gdrc)
{
- gdrc->x = rc->left;
- gdrc->y = rc->top;
- gdrc->width = rc->right - rc->left;
- gdrc->height = rc->bottom - rc->top;
+ // gdrc->x = rc->left;
+ // gdrc->y = rc->top;
+ // gdrc->width = rc->right - rc->left;
+ // gdrc->height = rc->bottom - rc->top;
}
void OutputDebugString(char* str)
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index f1abbaf..470c7cc 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -70,18 +70,19 @@ typedef PVOID HANDLE;
typedef HANDLE HINSTANCE;
typedef HANDLE HGDIOBJ;
-typedef cairo_t *HCRDC;
-typedef QWidget* HWID;
-typedef QWidget* HWND;
-typedef QTreeWidget *HLIST;
-typedef GtkTreeIter ITLIST;
-typedef GtkApplication *HAPP;
-typedef GtkTreeViewColumn *HTVC;
-typedef GdkPixbuf *HICON;
-typedef GdkRectangle GDRECT;
-typedef GDRECT *PGDRECT;
-typedef QMenu* HMENU;
-typedef ITLIST *HITLIST;
+typedef GtkApplication* HAPP;
+typedef GtkTreeViewColumn* HTVC;
+typedef GdkRectangle* GDRECT;
+typedef QTreeWidget* HLIST;
+typedef GtkTreeIter ITLIST;
+typedef GDRECT* PGDRECT;
+typedef QMenu* HMENU;
+typedef ITLIST* HITLIST;
+typedef QPainter* HCRDC;
+typedef QWidget* HWID;
+typedef QWidget* HWND;
+typedef GdkPixbuf* HICON;
+
/// Check if system is x64 or x86
#if defined(__UNIX64)
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index e8a8ab5..3f8896c 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -236,28 +236,40 @@ BOOL GetOpenFileName(OPENFILENAME *ofn)
}
+void EnableMenuItem(HMENU MenuName, QAction* MenuItem, UINT CheckEnabledItem)
+{
+ switch (CheckEnabledItem){
+ case MF_ENABLED :
+ MenuItem->setEnabled(true);
+ break;
+ case MF_GRAYED :
+ MenuItem->setEnabled(false);
+ break;
+ }
+}
+
void EnableMenuItem(HMENU MenuName, HMENU MenuItem, UINT CheckEnabledItem)
{
- /*switch (CheckEnabledItem){
+ switch (CheckEnabledItem){
case MF_ENABLED :
- gtk_widget_set_sensitive (MenuItem, true);
+ MenuItem->setEnabled(true);
break;
case MF_GRAYED :
- gtk_widget_set_sensitive (MenuItem, false);
+ MenuItem->setEnabled(false);
break;
- }*/
+ }
}
-void CheckMenuItem(HMENU MenuName, HMENU MenuItem, UINT Check)
+void CheckMenuItem(HMENU MenuName, QAction* MenuItem, UINT Check)
{
- /*switch (Check){
+ switch (Check){
case MF_CHECKED :
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(MenuItem), true);
+ MenuItem->setChecked(true);
break;
case MF_UNCHECKED :
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(MenuItem), false);
+ MenuItem->setChecked(false);
break;
- }*/
+ }
}
HANDLE GetStockObject(int fnObject)
@@ -288,22 +300,13 @@ void SelectObject(HCRDC hcr, HFONT hfont)
{
if (hcr ==NULL)
return;
-
- 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, "Z", &extents);
- // cairo_matrix_t matrix;
- // cairo_matrix_init_scale (&matrix,
- // (double)hfont->nWidth,
- // (double)hfont->nHeight);
-
- // cairo_set_font_matrix (hcr, &matrix);
-
- cairo_set_font_size(hcr, 10);
+ QFont qtfont = hcr->font();
+ qtfont.setFamily(hfont->lpszFace);
+ qtfont.setPixelSize(hfont->nHeight - 3);
+ qtfont.setFixedPitch(TRUE);
+ qtfont.setStyle(hfont->fdwItalic ? QFont::StyleItalic : QFont::StyleNormal);
+ qtfont.setWeight(hfont->fnWeight == FW_BOLD ? QFont::Bold : QFont::Normal);
+ hcr->setFont(qtfont);
}
HBRUSH CreateBrushIndirect(PLOGBRUSH plb)
@@ -334,41 +337,54 @@ HFONT CreateFont(int nHeight, int nWidth, int nOrientation, int fnWeight,
void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol)
{
-/* if (hcr == NULL)
- return;
-
- gtk_widget_override_background_color(GTK_WIDGET(widget),
- GTK_STATE_FLAG_NORMAL, &bkCol);
-
- 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 (hcr, &bkCol);
- // cairo_rectangle(hcr, 0, 0, width, height);
- // cairo_stroke_preserve(hcr);
-
- cairo_fill (hcr);*/
+ QPalette pal = widget->palette();
+ pal.setColor(QPalette::Background, bkCol);
+ widget->setPalette(pal);
}
void SetTextColor(HCRDC hcr, COLORREF color)
{
if (hcr == NULL)
return;
-
+ QPen qtpen = hcr->pen();
+ qtpen.setColor(color);
+ hcr->setPen(qtpen);
HdcCurrentTextColor = color;
// gdk_cairo_set_source_rgba (hcr, &color);
}
void TextOut(HWID hWid, HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, int cchString)
{
+ if (hcr == NULL)
+ return;
+ int width = hWid->width();
+ int height = hWid->height();
+ BOOL resize_flag = FALSE;
+ QFont newFont= hcr->font();
+ // newFont
+ /*if(nYStart+(extents.height/2.0) >= height)
+ {
+ height += extents.height + 50;
+ resize_flag = TRUE;
+ }
+
+ if (nXStart+(extents.width/2.0) >= width)
+ {
+ width += extents.width;
+ resize_flag = TRUE;
+ }*/
+ char* text = (char*)malloc(cchString);
+ strncpy(text, lpString, cchString);
+ text[cchString] = '\0';
+
+ hcr->drawText(nXStart, nYStart, (QString)text);
+ // cairo_move_to(hcr, nXStart, nYStart);
+ // cairo_show_text(hcr, text);
+
+ // cairo_fill (hcr);
+
+ /*if (resize_flag) // To do later
+ hcr->setWindow();*/
/*if (hcr == NULL)
return;
@@ -431,13 +447,19 @@ BOOL InvalidateRect(HWID hWid, const RECT *lpRect, BOOL bErase)
// gtk_widget_queue_draw(hWid);
gdk_window_invalidate_rect (gtk_widget_get_window (hWid), &Gdrect, FALSE);
*/
+ hWid->repaint();
return TRUE;
}
-int FillRect(HCRDC hDC, const RECT *lprc, HBRUSH hbr)
+int FillRect(HCRDC hDC, const QRect *lprc, HBRUSH hbr)
{
if (hDC == NULL)
return -1;
+ QBrush curbrush = hDC->brush();
+ curbrush.setColor(*hbr);
+ curbrush.setStyle(Qt::SolidPattern);
+ hDC->setBrush(curbrush);
+ hDC->drawRect(*lprc);
/*
GDRECT gdrc;
RECT_to_GDRECT(lprc, &gdrc);
@@ -450,7 +472,7 @@ 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)
+BOOL PatBlt(HWID hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD dwRop, HBRUSH hbr)
{
if (hdc == NULL)
return FALSE;
@@ -503,20 +525,37 @@ BOOL GetWindowRect(HWID hWid, PRECT pRect)
}
-UINT SetTimer(HWID hWid, UINT nIDEvent, UINT uElapse, BOOL (*lpTimerFunc)(BOOL) )
+UINT SetTimer(HWID hWid, UINT nIDEvent, UINT uElapse, UINT TimerID)
{
- auto record_it = std::find_if(timerRecords.begin(), timerRecords.end(), [&nIDEvent](TimerRecord &Record) { return Record.ufID == nIDEvent; });
+ if(TimerID != NULL)
+ return nIDEvent;
+ if(nIDEvent == TIMER_BLINK_CURSOR)
+ {
+ TimerID = hWid->startTimer(uElapse);
+ CursorObject = new QGroupBox(hWid);
+
+ QPalette pal = CursorObject->palette();
+ pal.setColor(QPalette::Background, Qt::white);
+ CursorObject->setAutoFillBackground(true);
+ CursorObject->setPalette(pal);
+ // CursorObject->setGeometry(100,100,2,20);
+ }
+ // if(hWid!=NULL)
+ // CursorObject->setVisible(TRUE);
- if (record_it != timerRecords.end())
- return 0;
+ return TimerID;
+ // auto record_it = std::find_if(timerRecords.begin(), timerRecords.end(), [&nIDEvent](TimerRecord &Record) { return Record.ufID == nIDEvent; });
- TimerRecord tr;
- tr.pfun = lpTimerFunc;
- tr.ufID = nIDEvent;
- tr.utID = g_timeout_add(uElapse, (GSourceFunc)lpTimerFunc, FALSE);
+ // if (record_it != timerRecords.end())
+ // return 0;
- timerRecords.push_back(tr);
- return tr.utID;
+ // TimerRecord tr;
+ // tr.pfun = lpTimerFunc;
+ // tr.ufID = nIDEvent;
+ // tr.utID = g_timeout_add(uElapse, (GSourceFunc)lpTimerFunc, FALSE);
+
+ // timerRecords.push_back(tr);
+ // return tr.utID;
}
BOOL KillTimer(HWID hWid, UINT uIDEvent)
@@ -540,3 +579,5 @@ void DestroyWindow (HWID widget)
gtk_widget_destroy (widget);
}*/
}
+
+
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index e482051..7054b61 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -9,6 +9,9 @@
#include <QMenuBar>
#include <QVBoxLayout>
#include <QLabel>
+#include <QPainter>
+#include <QGroupBox>
+// #include <QtGui>
// #include <QSize>
// #include "freezeLD.h"
// #include "linuxLD.h"
@@ -25,6 +28,10 @@
#define LDMicro_VERSION_MAJOR 1
#define LDMicro_VERSION_MINOR 0
+// Timer IDs associated with the main window.
+#define TIMER_BLINK_CURSOR 1
+#define TIMER_SIMULATE 2
+
/// Flags
/// message box
#define MB_OK 0x00000001L
@@ -127,6 +134,7 @@ extern const UINT MF_UNCHECKED;
/// Accelerators (keyboard shortcuts)
extern GtkAccelGroup* AccelGroup;
extern GClosure* closure;
+extern QGroupBox* CursorObject;
/// ListStore
extern HWID view;
@@ -175,12 +183,17 @@ BOOL GetOpenFileName(OPENFILENAME *ofn);
void EnableMenuItem(
HMENU MenuName,
+ QAction* MenuItem,
+ UINT CheckEnabledItem);
+
+void EnableMenuItem(
+ HMENU MenuName,
HMENU MenuItem,
UINT CheckEnabledItem);
void CheckMenuItem(
HMENU MenuName,
- HMENU MenuItem,
+ QAction* MenuItem,
UINT Check);
HANDLE GetStockObject(int fnObject);
@@ -225,11 +238,11 @@ BOOL InvalidateRect(
int FillRect(
HCRDC hDC,
- const RECT *lprc,
+ const QRect *lprc,
HBRUSH hbr);
BOOL PatBlt(
- HCRDC hdc,
+ HWID hdc,
int nXLeft,
int nYLeft,
int nWidth,
@@ -257,7 +270,7 @@ UINT SetTimer(
HWID hWid,
UINT nIDEvent,
UINT uElapse,
- BOOL (*lpTimerFunc)(BOOL));
+ UINT TimerID);
BOOL KillTimer(
HWID hWid,
@@ -265,6 +278,18 @@ BOOL KillTimer(
void DestroyWindow (HWID widget);
-
+class PaintWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ // MyWidget();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void timerEvent(QTimerEvent *event);
+signals:
+
+public slots:
+};
#endif \ No newline at end of file