» »

[C++] izris v [x,y]

[C++] izris v [x,y]

DuleKrtola ::

Delam aplikacijo v Visual studio. Rad bi imel eno polje, kjer se bo izrisovala točka v ravnini.
Našel sem to:
http://codecutter.org/tools/koolplot/
Rabiš še graphics.h ki pa je menda stara zadeva, še iz 16bitnih časov (žal nisem bookmarkal foruma, kjer so debatiral o tem, niti nisem potem probal zadeve). Druga stvar, ki sem jo našel, je ProEssentials. AFAICS je tole overkill za to kar js rabim.

Kaj bi bla najlažja rešitev?

DuleKrtola ::

najdu še tole:
http://www.advsofteng.com/download.html
mislim da bo kr uredu

DuleKrtola ::

Sm najdu še en tutorial, to bi mogl zadoščat:
http://www.functionx.com/vcnet/gdi+/cha...
Zadeva se skompajla, ampak dobim samo črn ekran, nobenih krogov. Moral bi pa začet migat ob pritsku tipke
form1.h
#pragma once


namespace circleChase {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Timer^  timer1;
	protected: 
	private: System::ComponentModel::IContainer^  components;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma 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>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
			this->SuspendLayout();
			// 
			// timer1
			// 
			this->timer1->Enabled = true;
			this->timer1->Interval = 50;
			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackColor = System::Drawing::Color::Black;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form1::Form1_KeyPress);
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void Form1_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {
			 }
	private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
			 }
	};
}

MrBrdo ::

jumo: ta koda zgleda skor ko C# če nebi blo pragma bi že mislu... :)

no v vsakem primeru a maš mogoče varianto naredit v C#, je dost lažje (en picturebox daš gor, rišeš v onpaint pa je)? recimo če maš neke podatke bi jih lahko exportal v neko datoteko ali kaj takega...
ali pa recimo narediš tisto kar imaš v C++ kot dll in to pokličeš v C# potem pa tiste podatke narišeš, ki jih recimo vrne tista funkcija... ker v C++ je kar pain delat take stvari razen mogoče s kakšnim wrapperjem (v GTK recimo je še kar vzdržno).
MrBrdo

Senitel ::

DuleKrtola ::

Senitel, tnx za link, bom počekiral.

MrBrdo, tud to je varjanta ja. Sicer je pa GUI bolj optional za mojo aplikacijo, se bom kasneje še s tem ukvarjal ...

c0dehunter ::

C# je majka za takele stvari.
Lahko se pa tudi zajebavaš z C++ MFC.
I do not agree with what you have to say,
but I'll defend to the death your right to say it.

Senitel ::

Zakaj za vraga bi rabil MFC za to?

c0dehunter ::

Senitel, imaš prav. Temo sem na hitro preletel in sem mislil da se rabi kaj več kot le izris..
I do not agree with what you have to say,
but I'll defend to the death your right to say it.

DuleKrtola ::

zdele mam spet mal več cajta, sem se še enkrat lotil tega.
Najdu sem tale example:
#pragma once


namespace graf2 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Timer^  timer1;
	protected: 
	private: System::ComponentModel::IContainer^  components;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma 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>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
			this->SuspendLayout();
			
			this->timer1->Enabled = true;
			this->timer1->Interval = 50;
			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::On_paint);
			
			this->ResumeLayout(false);
			
		}
#pragma endregion
	private: System::Void On_paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  pe) {
			 Graphics^ g = pe->Graphics; 
			   g->Clear(Color::White); 
			   Rectangle rect = Form::ClientRectangle;
			   Rectangle smallRect; 
			   //smallRect.X = rect.X + rect.Width / 2; 
			   smallRect.X = rect.X; 
			   smallRect.Y = rect.Y + rect.Height / 2; 
			   smallRect.Width = rect.Width / 10; 
			   smallRect.Height = rect.Height / 10; 
			   Pen^ redPen = gcnew Pen(Color::Red); 
			   redPen->Width = 4; 
			   g->DrawLine(redPen, 0, 0, rect.Width, rect.Height);
			   Pen^ bluePen = gcnew Pen(Color::Blue); 
			   bluePen->Width = 1; 
			   g->DrawArc( bluePen, smallRect, 20, 360 );
			   
			 }
	private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  pe) {
	
	
			 }
	};
}


Program izriše eno daljico in krožnico v System::Void On_paint().
Kako bi izrisoval te objekte v System::Void timer1_Tick (želim animacijo)? Če napišem:
	private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  pe) {
			Graphics^ g = pe->Graphics; 
			g->DrawArc( bluePen, smallRect, 20, 360 );
	
			 }

dobim error:
Error 1 error C2039: 'Graphics' : is not a member of 'System::EventArgs'

Zgodovina sprememb…

MrBrdo ::

ne delat animacije na tak način... naredi raje v onpaint, glede na nek parameter (recimo nek array točk, ki ga lahko iz drugih metod spreminjaš).
v timerju pa reči PaintBox1->Repaint() al Invalidate() al nekaj takega (ne vem točno na pamet).
se pravi v timerju spremeniš neko spremenljivko potem pa rečeš repaint in se nato izriše nova slika. pri tem moraš tudi malo merkat oz. met v glavi da se onpaint lahko tudi sam sproži (tako da moraš pazit da kakšna od tistih spremenljivk takrat ni v neveljavnem stanju oz. da v tem primeru onpaint nič ne izriše ali kaj takega).
pa še da ne boš imel flicker (slika utripa) potem lahko pogooglaš double buffering c# paintbox ali pa namesto da rišeš direktno po paintboxu (e->graphics) rišeš na Bitmap in potem v enem šusu narišeš ta bitmap na tisti graphics. to rabiš predvsem če boš imel kakšne hitrejše "animacije".
obstaja pa z razlogom OpenGL in DirectX tako da če želiš kakšne uber animacije delat potem si raje tisto malo poglej.
MrBrdo

Zgodovina sprememb…

  • spremenilo: MrBrdo ()

DuleKrtola ::

Tole z grafiko v form-u sem rešil, zdej imam pa novo vprašanje. V console application izračunavam neke spremenljivke, ki bi jih rad izrisoval v tejle ravnini v Formu.
Kako najlažje povežem aplikaciji? Rad bi obdržal console app, če ni druge varjante bom pa kodo prenesel v project s formami.

DuleKrtola ::

Da malo specificiram vprašanje. AFAICS imam 3 varjante:

1. - prenesem kodo iz projekta console app v form app. S tem se trenutno ubadam, bolj ali manj neuspešno. Uporabljam namreč en .lib fajl, ki bere data iz bluetootha ...
Podatke z BTja pobiram s 100Hz in bi jih tudi izrisoval z enako frekvenco

2. - obratno od prejšnje varjante. Zgooglal sem, da se da pognat form iz console app, ampak je nerodno in ni priporočljivo

3. - kličem grafični fajl s argumenti (grafika.exe -int a,b,c ... ) - ni glih optimalna rešitev

Idealno bi bilo (najmanj dela), če bi lah imel 2 ločena .exe fajla, skompajlana iz različnih projektov, eden bi drugemu posredoval spremenljivke (cca 10 byteov vsakih 10ms). To gre? Najmanj šlampasta varjanta je prva, ampak očitno nimam dost znanja za to

DuleKrtola ::

Quick question

A je kaka razlika med linkerjem za console app in form app?
Tale console app, ki ga poskušam predelat v form, uporablja neko eksterno knjižnico - imam ext.lib, ext.c, ext.h. V console app sem samo includal header in dodal .lib v additional dependencies, tu pa tale postopek ne dela. Kaka ideja?


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

C# Pomoč

Oddelek: Programiranje
131315 (1140) jizzer
»

Spremljanje dogajanja na ekranu

Oddelek: Programiranje
81148 (1007) boss-tech
»

C# okna in podokna

Oddelek: Programiranje
111561 (1155) FlashM
»

[c#]4 v vrsto - padanje krogov

Oddelek: Programiranje
81907 (1739) VASkO
»

[c#] enostavna Igrca -> poraba procesorja 95%

Oddelek: Programiranje
192089 (1453) elKaktus

Več podobnih tem