Author Topic: How to create a text window in c++ as an inline function?  (Read 6052 times)

Brigetiol

  • Guest
How to create a text window in c++ as an inline function?
« on: June 17, 2018, 02:23:16 AM »
Hi,

A few months ago I got help to customize the main VA window using C++ , to improve my Elite Dangerous dashboard.

Based on that I got the idea, that it would be easy to create a text window and write out texts using the actual variables of VA (and Elite). That way, I could use the main VA window to supervise what VA is doing, as a 'control monitor', and in the separate window, I could write out detailed stuff, like a ship-computer info panel, and the ship-computer would speak out only the most necessary info. And first of all, it would be lots of fun to create this and customize spoken txt/info panel, would give a lot to immersion  ;).

I imagine something like this:



This would be easy to realize, if I had any C++ programming knowledge. I've found some examples on the web about creating text window, but it is not just CTRL+C CTRL+V  :-[ ...

So I'm asking for your help: could you create a template for a borderless text-window? Based on the parameters inside, I think I'll be able to customize it (font, colors, font size, position, etc...) to my needs.

Thank you very much in advance!

Brigetiol

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4787
  • RTFM
Re: How to create a text window in c++ as an inline function?
« Reply #1 on: June 17, 2018, 09:58:49 AM »
VoiceAttack is written in C#, which is related to but still different than C++. While you can combine one with the other in theory, you'll probably want to use C#.


If you have some web development knowledge, you could also use the Panels plugin to do something similar(though that requires a browser or something else that can render web pages).

Brigetiol

  • Guest
Re: How to create a text window in c++ as an inline function?
« Reply #2 on: June 17, 2018, 11:11:06 PM »
Hi,

thanks, you already helped me, I was unobservant and mixed up C++ and C#. I'm an amateur, forgive me :)

I've already checked the panels plugin, would be a perfect solution for virtual buttons too, I just lack the programming knowledge for it too...

Brigetiol

Brigetiol

  • Guest
Re: How to create a text window in c++ as an inline function?
« Reply #3 on: June 18, 2018, 03:40:48 AM »
Hi,

I made this script with Visual Studio (it wasn't so hard :) ).

It (mostly) works, as I'd like, when I run it from VS.

Quote
namespace WindowsFormsApp1
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            //
            // textBox1
            //
            this.textBox1.BackColor = System.Drawing.SystemColors.MenuText;
            this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.textBox1.Font = new System.Drawing.Font("Euro Caps", 13.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.textBox1.ForeColor = System.Drawing.Color.Lime;
            this.textBox1.Location = new System.Drawing.Point(0, 0);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.ReadOnly = true;
            this.textBox1.Size = new System.Drawing.Size(627, 282);
            this.textBox1.TabIndex = 0;
            this.textBox1.Text = "Welcome, Commander Brigetiol!\r\n\r\nSystems initializing...";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.ActiveBorder;
            this.ClientSize = new System.Drawing.Size(627, 248);
            this.Controls.Add(this.textBox1);
            this.Font = new System.Drawing.Font("Euro Caps", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.Location = new System.Drawing.Point(966, 1114);
            this.MinimumSize = new System.Drawing.Size(635, 283);
            this.Name = "Form1";
            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox textBox1;
    }
}

My questions are now more aimed:

1. Can I use this as an inline C# function?
2. If yes, how can I insert it into the predefined environment? I mean, into this:
Quote
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

public class VAInline
{
   public void main()
   {

      //This is where your code goes.  Note that the class and this function (main()) are required for this to work.

      //You also have access to the shared VoiceAttack proxy object VA, which is the same that you will find
      //used with the VoiceAttack plugin framework.  See the help documentation for more info.

      //VA.ExecuteCommand("myCommand");
      //VA.ParseTokens("The time is {TIME}");
      //VA.GetText("myTextVariable");
      //VA.SetDecimal("myDecimalVariable", 2.2);
      //you get the idea;)
   }
}

3. If I have a variable set in VA, like TXT:system, what is the syntax to display that in my text? I mean, within this somewhere:

Quote
this.textBox1.Text = "Welcome, Commander Brigetiol!\r\n\r\nSystems initializing...";

Thanks in advance!

Brigetiol



Brigetiol

  • Guest
Re: How to create a text window in c++ as an inline function?
« Reply #4 on: June 18, 2018, 05:02:45 AM »
Hi,

maybe these ones are important too... (I really should read a book about C#)

Quote
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Quote
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Application.OpenForms["Form1"].FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            Application.OpenForms["Form1"].MinimumSize = new System.Drawing.Size(635, 283);
            Application.OpenForms["Form1"].Location = new System.Drawing.Point(996, 1114);
            textBox1.SelectionStart = 0;
        }
    }
}

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: How to create a text window in c++ as an inline function?
« Reply #5 on: June 18, 2018, 07:22:06 AM »
You should go check out the Inline Functions section of the forum to get an idea for what VA inline functions look like (beyond the example text provided by VA). VA has a specific format that needs to be used to encapsulate the main, and as far as I know traditional methods for employing Windows Forms will not work as a result of it (thought I may be wrong there). Perhaps Pfeil or Gary have more to say on the subject.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4787
  • RTFM
Re: How to create a text window in c++ as an inline function?
« Reply #6 on: June 18, 2018, 11:33:49 AM »
Plugins can spawn winforms, I've not tried it in an inline function.

Do be careful with things like
Code: [Select]
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
as they will affect VoiceAttack as a whole(because inline functions and plugins run as part of VoiceAttack, essentially).

IIRC, using
Code: [Select]
Application.Run(new Form1());is problematic, in that it doesn't return until the form closes so you have to run it asynchronously(no "Wait for the inline function to finish before continuing", because the command would never continue).


If you're going to try any of this, back up your VoiceAttack profiles and config, just in case.

Brigetiol

  • Guest
Re: How to create a text window in c++ as an inline function?
« Reply #7 on: June 18, 2018, 12:05:15 PM »
Thanks Exergist and Pfeil for the tips!

Now I see, this is going to be more, than a few hours. I'll check the topic on the forum!

Best regards!

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: How to create a text window in c++ as an inline function?
« Reply #8 on: June 18, 2018, 02:38:25 PM »
I believe Gary showed interest in addition inline functionality to handle various kinds of VA events, like pressing the Stop Commands button or changing profiles. Events like these could provide a path to closing the form and returning.

Just remember if your code borks something up and VA hangs (especially when doing async stuff) just close VA (you'll probably want to avoid auto-running your profile at startup while you work on the function). :)

Brigetiol

  • Guest
Re: How to create a text window in c++ as an inline function?
« Reply #9 on: June 20, 2018, 05:05:46 AM »
Hi,

regarding my 'mental rampage' during the weekend, there is only one quote to describe it:

Quote
“The difference between stupidity and genius is that genius has its limits.” -Albert Einstein

...and I realized, that I forgot about my limits...

So I've restarted the project, using the assets and knowledge that I have (and knowing, what kind of knowledge I don't have).

-I turned on Log Quiet Mode.
-I have 10 rows in my VA window on the log screen, so when I want to write out something with Write a Value to Event Log, I just have to make sure, that all those 10 rows are written, so I'll have a clean screen, containing only my actual message. I use '.' to fill the empty rows, or I can use a txt variable containing only a SPACE to have a more clean look.

 
-With the app OnTopReplica, I can create a new borderless window, showing a defined area of any existing window, in this case the VA window's log area


-I made a command to turn on/off this 'fullscreen mode'

So, with this method, I can do, what I originally wanted to do :) . Ugly, overcomplicated, but it works (and I'm still within my limits)!

I'm already happy with this, but have some questions:

Can I change the Font for the Log window? (now I understand, that Inline functions are for thing like this)
Can I turn on/off the Quiet Log Mode from a command, or just manually, in the settings menu?

Thank you for your patience!

Brigetiol 
 

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: How to create a text window in c++ as an inline function?
« Reply #10 on: June 20, 2018, 08:16:13 AM »
How did you get all the text to be green in the native VA window?

Brigetiol

  • Guest
Re: How to create a text window in c++ as an inline function?
« Reply #11 on: June 20, 2018, 09:50:05 AM »