diff options
author | akshay-c | 2019-04-30 14:43:51 +0530 |
---|---|---|
committer | akshay-c | 2019-04-30 14:43:51 +0530 |
commit | 04e0f72fa0f240fb4f9b6c910d096492e22485ae (patch) | |
tree | 23096a5abc25465883bebfb558be6b4eaf992a24 /ldmicro | |
parent | c42da945ba01864b55358c95ed0833e37af8fcdc (diff) | |
download | LDmicroQt-04e0f72fa0f240fb4f9b6c910d096492e22485ae.tar.gz LDmicroQt-04e0f72fa0f240fb4f9b6c910d096492e22485ae.tar.bz2 LDmicroQt-04e0f72fa0f240fb4f9b6c910d096492e22485ae.zip |
UART simulation dialog completed
Diffstat (limited to 'ldmicro')
-rw-r--r-- | ldmicro/includes/ldmicro.h | 1 | ||||
-rw-r--r-- | ldmicro/ldmicro.cpp | 11 | ||||
-rw-r--r-- | ldmicro/maincontrols.cpp | 4 | ||||
-rw-r--r-- | ldmicro/miscutil.cpp | 16 | ||||
-rw-r--r-- | ldmicro/resetdialog.cpp | 2 | ||||
-rw-r--r-- | ldmicro/simulate.cpp | 154 |
6 files changed, 127 insertions, 61 deletions
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h index 38dd3d5..418e3e7 100644 --- a/ldmicro/includes/ldmicro.h +++ b/ldmicro/includes/ldmicro.h @@ -802,6 +802,7 @@ void MakeNamingListClass(void); void MakeDialogBoxClass(void); void NiceFont(HWID h); void FixedFont(HWID h); +void SetFont(HWID h, HFONT f); void CompileSuccessfulMessage(char *str); extern BOOL RunningInBatchMode; extern HFONT MyNiceFont; diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index 5639d1e..c8f266b 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -105,7 +105,7 @@ static BOOL SaveAsDialog(void) return TRUE; } } -/* + //----------------------------------------------------------------------------- // Get a filename with a common dialog box and then export the program as // an ASCII art drawing. @@ -131,7 +131,7 @@ static void ExportDialog(void) return; ExportDrawingAsText(exportFile); -}*/ +} //----------------------------------------------------------------------------- // If we already have a filename, save the program to that. Otherwise same @@ -383,17 +383,16 @@ static void ProcessMenu(int code) SaveAsDialog(); UpdateMainWindowTitleBar(); break; -/* + case MNU_EXPORT: ExportDialog(); break; case MNU_EXIT: if(CheckSaveUserCancels()) break; - LD_WM_Close_call(NULL, NULL, NULL); - // PostQuitMessage(0); + LDmicroApp->exit(); break; -*/ + case MNU_INSERT_COMMENT: CHANGING_PROGRAM(AddComment(_("--add comment here--"))); break; diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp index 6794fea..9ec30fe 100644 --- a/ldmicro/maincontrols.cpp +++ b/ldmicro/maincontrols.cpp @@ -984,9 +984,9 @@ void ToggleSimulationMode(void) ClearSimulationData(); // simulation.cpp, ldmicro.h // Recheck InSimulationMode, because there could have been a Compile // error, which would have kicked us out of simulation mode. - /*if(UartFunctionUsed() && InSimulationMode) { + if(UartFunctionUsed() && InSimulationMode) { ShowUartSimulationWindow(); // simulate.cpp - }*/ + } } else { RealTimeSimulationRunning = FALSE; diff --git a/ldmicro/miscutil.cpp b/ldmicro/miscutil.cpp index 0a9379f..6014731 100644 --- a/ldmicro/miscutil.cpp +++ b/ldmicro/miscutil.cpp @@ -102,7 +102,7 @@ void Error(char *str, ...) printf("%s\n", buf); } else { //HWND h = GetForegroundWindow(); - // MessageBox(MainWindow, buf, _("LDmicro Error"), MB_OK | MB_ICONERROR); + MessageBox(MainWindow, buf, _("LDmicro Error"), MB_OK | MB_ICONERROR); } } @@ -208,7 +208,7 @@ QDialog* CreateWindowClient(char *windowName, int x, int y, int width, int height, HWND parent) { QDialog* h = new QDialog(parent); - h->resize(width,height); + h->resize(width, height); h->setWindowTitle(windowName); // HWND h = CreateWindowEx(exStyle, className, windowName, style, x, y, // width, height, parent, menu, instance, param); @@ -292,6 +292,18 @@ void FixedFont(HWID h) // SendMessage(h, WM_SETFONT, (WPARAM)MyFixedFont, TRUE); } +void SetFont(HWID h, HFONT f) +{ + QFont qtfont = h->font(); + qtfont.setFamily(f->lpszFace); + qtfont.setPixelSize(f->nHeight - 3); + qtfont.setFixedPitch(TRUE); + qtfont.setStyle(f->fdwItalic ? QFont::StyleItalic : QFont::StyleNormal); + qtfont.setWeight(f->fnWeight == FW_BOLD ? QFont::Bold : QFont::Normal); + h->setFont(qtfont); + // SendMessage(h, WM_SETFONT, (WPARAM)MyFixedFont, TRUE); +} + //----------------------------------------------------------------------------- // Create our dialog box class, used for most of the popup dialogs. //----------------------------------------------------------------------------- diff --git a/ldmicro/resetdialog.cpp b/ldmicro/resetdialog.cpp index e398098..5764730 100644 --- a/ldmicro/resetdialog.cpp +++ b/ldmicro/resetdialog.cpp @@ -74,7 +74,7 @@ static void MakeControls(void) QObject::connect(ButtonBox, SIGNAL(rejected()), ResetDialog, SLOT(reject())); } -inline void DestroyWindow (){ +static inline void DestroyWindow (){ delete TypeTimerRadio; delete TypeCounterRadio; delete NameTextbox; diff --git a/ldmicro/simulate.cpp b/ldmicro/simulate.cpp index 9df6a58..0bb4fec 100644 --- a/ldmicro/simulate.cpp +++ b/ldmicro/simulate.cpp @@ -27,12 +27,14 @@ #include "linuxUI.h" //#include <commctrl.h> #include <stdio.h> +#include<iostream> #include <stdlib.h> #include <limits.h> #include "ldmicro.h" #include "intcode.h" #include "freezeLD.h" +#include <QDesktopWidget> static struct { char name[MAX_NAME_LEN]; @@ -70,6 +72,8 @@ static int AdcShadowsCount; // editing during simulation. BOOL InSimulationMode; +static BOOL UARTWindowInitialized = FALSE; + // Don't want to redraw the screen unless necessary; track whether a coil // changed state or a timer output switched to see if anything could have // changed (not just coil, as we show the intermediate steps too). @@ -89,13 +93,18 @@ static int IntPc; // A window to allow simulation with the UART stuff (insert keystrokes into // the program, view the output, like a terminal window). -static HWID UartSimulationWindow; -static HWID UartSimulationTextControl; +static QDialog* UartSimulationWindow; +static QPlainTextEdit* UartSimulationTextControl; static LONG_PTR PrevTextProc; static int QueuedUartCharacter = -1; static int SimulateUartTxCountdown = 0; +// Flags to verify textchange on UART terminal is due to external events +// and not due to program changes +static BOOL InternalChange = FALSE; +static BYTE ChangeChar; + static void AppendToUartSimulationTextControl(BYTE b); static void SimulateIntCode(void); @@ -843,9 +852,21 @@ void SimulationToggleContact(char *name) // // Ported: Read and write text fron the text view widget. //----------------------------------------------------------------------------- -static void UartSimulationTextProc(HWID hwid, UINT umsg, char *text, UINT uszbuf) +static void UartSimulationTextProc(/*HWID hwid, UINT umsg, char *text, UINT uszbuf*/) { - switch(umsg) + char text = UartSimulationTextControl->toPlainText().toStdString().back(); + if(InternalChange) + { + if(text != ChangeChar) + { + QueuedUartCharacter = (BYTE)(text); + InternalChange = FALSE; + } + return; + } + QueuedUartCharacter = (BYTE)(text); + + /*switch(umsg) { case WM_SETTEXT: { @@ -885,7 +906,7 @@ static void UartSimulationTextProc(HWID hwid, UINT umsg, char *text, UINT uszbuf } default: break; - } + }*/ } //----------------------------------------------------------------------------- @@ -893,7 +914,7 @@ static void UartSimulationTextProc(HWID hwid, UINT umsg, char *text, UINT uszbuf // characters that you type go into UART RECV instruction and whatever // the program puts into UART SEND shows up as text. //----------------------------------------------------------------------------- -/*void ShowUartSimulationWindow(void) +void ShowUartSimulationWindow(void) { DWORD TerminalX = 200, TerminalY = 200, TerminalW = 300, TerminalH = 150; @@ -905,12 +926,38 @@ static void UartSimulationTextProc(HWID hwid, UINT umsg, char *text, UINT uszbuf if(TerminalW > 800) TerminalW = 100; if(TerminalH > 800) TerminalH = 100; - UartSimulationWindow = CreateWindowClient(GTK_WINDOW_TOPLEVEL, GDK_WINDOW_TYPE_HINT_NORMAL, - "UART Simulation (Terminal)", TerminalX, TerminalY, TerminalW, TerminalH, NULL); - /// remove close button - gtk_window_set_deletable (GTK_WINDOW(UartSimulationWindow), FALSE); + QRect r = QApplication::desktop()->screenGeometry(); + + if(TerminalX >= (DWORD)(r.width() - 10)) TerminalX = 100; + if(TerminalY >= (DWORD)(r.height() - 10)) TerminalY = 100; - UartSimulationTextControl = gtk_text_view_new(); + UartSimulationWindow = CreateWindowClient("UART Simulation (Terminal)", + TerminalX, TerminalY, TerminalW, TerminalH, MainWindow); + // UartSimulationWindow->setWindowTitle("UART Simulation (Terminal)"); + /// remove close button + UartSimulationWindow->setWindowFlags(Qt::Window + | Qt::WindowMinimizeButtonHint | + Qt::WindowStaysOnTopHint); + UartSimulationWindow->setAttribute(Qt::WA_AlwaysStackOnTop); + + UartSimulationTextControl = new QPlainTextEdit(); + UartSimulationTextControl->resize(TerminalW, TerminalH); + + QVBoxLayout* UartSimLayout = new QVBoxLayout(UartSimulationWindow); + UartSimLayout->addWidget(UartSimulationTextControl); + + HFONT fixedFont = CreateFont(14, 0, 0, FW_REGULAR, FALSE, "Lucida Console"); + SetFont(UartSimulationTextControl, fixedFont); + QObject::connect(UartSimulationTextControl, + &QPlainTextEdit::modificationChanged, UartSimulationTextProc); + UartSimulationWindow->raise(); + UartSimulationWindow->show(); + MainWindow->setFocus(); + UARTWindowInitialized = TRUE; + // UartSimulationTextControl->document()->setModified(false); + // UartSimulationTextControl->setPlainText("H"); + + /*UartSimulationTextControl = gtk_text_view_new(); gtk_widget_override_font(GTK_WIDGET(UartSimulationTextControl), pango_font_description_from_string("Lucida Console")); @@ -929,8 +976,8 @@ static void UartSimulationTextProc(HWID hwid, UINT umsg, char *text, UINT uszbuf gtk_window_set_keep_above (GTK_WINDOW(MainWindow), TRUE); gtk_window_set_focus_visible (GTK_WINDOW(MainWindow), TRUE); - gtk_window_set_keep_above (GTK_WINDOW(MainWindow), FALSE); -}*/ + gtk_window_set_keep_above (GTK_WINDOW(MainWindow), FALSE);*/ +} //----------------------------------------------------------------------------- // Get rid of the UART simulation terminal-type window. @@ -940,27 +987,29 @@ void DestroyUartSimulationWindow(void) // Try not to destroy the window if it is already destroyed; that is // not for the sake of the window, but so that we don't trash the // stored position. - if(UartSimulationWindow == NULL) return; - DWORD TerminalX, TerminalY, TerminalW, TerminalH; - RECT r; + if(UARTWindowInitialized) + { + UARTWindowInitialized = FALSE; + + DWORD TerminalX, TerminalY, TerminalW, TerminalH; + QRect r; - GetClientRect(UartSimulationWindow, &r); - TerminalW = r.right - r.left; - TerminalH = r.bottom - r.top; + r = UartSimulationWindow->geometry(); + TerminalW = r.width(); + TerminalH = r.height(); - GetWindowRect(UartSimulationWindow, &r); - TerminalX = r.left; - TerminalY = r.top; + TerminalX = r.left(); + TerminalY = r.top(); - FreezeDWORD(TerminalX); - FreezeDWORD(TerminalY); - FreezeDWORD(TerminalW); - FreezeDWORD(TerminalH); + FreezeDWORD(TerminalX); + FreezeDWORD(TerminalY); + FreezeDWORD(TerminalW); + FreezeDWORD(TerminalH); - // DestroyWindow(UartSimulationWindow); - ProgramChanged(); - UartSimulationWindow = NULL; + delete UartSimulationTextControl; + delete UartSimulationWindow; + } } //----------------------------------------------------------------------------- @@ -968,27 +1017,32 @@ void DestroyUartSimulationWindow(void) //----------------------------------------------------------------------------- static void AppendToUartSimulationTextControl(BYTE b) { - char append[5]; - - if((isalnum(b) || strchr("[]{};':\",.<>/?`~ !@#$%^&*()-=_+|", b) || - b == '\r' || b == '\n') && b != '\0') + if(UARTWindowInitialized) { - append[0] = b; - append[1] = '\0'; - } else { - sprintf(append, "\\x%02x", b); - } - -#define MAX_SCROLLBACK 256 - char buf[MAX_SCROLLBACK]; - - UartSimulationTextProc(UartSimulationTextControl, WM_GETTEXT, buf, strlen(buf)); - - int overBy = (strlen(buf) + strlen(append) + 1) - sizeof(buf); - if(overBy > 0) { - memmove(buf, buf + overBy, strlen(buf)); + char append[5]; + + if((isalnum(b) || strchr("[]{};':\",.<>/?`~ !@#$%^&*()-=_+|", b) || + b == '\r' || b == '\n') && b != '\0') + { + append[0] = b; + append[1] = '\0'; + } else { + sprintf(append, "\\x%02x", b); + } + + #define MAX_SCROLLBACK 256 + char buf[MAX_SCROLLBACK] = "\0"; + strncpy(buf, + UartSimulationTextControl->toPlainText().toStdString().c_str(), + MAX_SCROLLBACK); + int overBy = (strlen(buf) + strlen(append) + 1) - sizeof(buf); + if(overBy > 0) { + memmove(buf, buf + overBy, strlen(buf)); + } + strcat(buf, append); + InternalChange = TRUE; + ChangeChar = b; + + UartSimulationTextControl->setPlainText(buf); } - strcat(buf, append); - - UartSimulationTextProc(UartSimulationTextControl, WM_SETTEXT, buf, strlen(buf)); } |