Main Site Documentation

How to draw anything on a Pyxis2 form?


#1

Hello,

I’m only a beginner on Fez Cobra and NetMF and, after a fast progression, I was stopped by adding a GUI to my application.

So, I started discovering and using Pyxis2 and a few hours later, my app was using a form to display labels, textboxes, buttons and pictureboxes (thanks for the examples).

Now I want to display something on top of this form using the NetMF bitmap functions.

using a bitmap declaration

static Bitmap lcd=new Bitmap(lcd_w,lcd_h);

some instructions like

lcd.DrawTextInRect(text,x,y,w,h,align,color,font);

and a lcd.Flush to draw.

It works but it seems that Pyxis2 redisplay periodically (?) the form content, erasing what I have displayed on the screen.

Is there a way (I imagine it is possible…) to display what I want on the screen (like a chart)?
May be I can use directly the bitmap object used by the desktop or the form to avoid my operations be erased?

Thank you skewworks for your contribution with Pyxis2! I really like it. :slight_smile:


#2

We will need a little bit more information on what you trying to do. Full source code will help as well.


#3

ok, the code looks like this:

namespace Skewworks.Pyxis.Apps.th
{
	public class th
	{
			private static Pyxis2Controller _controller;
			private static desktop _desktop;
			const string STR_APP_TITLE="title";
			private static int lcd_w=SystemMetrics.ScreenWidth;
			private static int lcd_h=SystemMetrics.ScreenHeight;
			private static Bitmap lcd=new Bitmap(lcd_w,lcd_h);
			private static int desk_w=0;
			private static int desk_h=0;
			private static int date_area_w=70;
			private static Font luc09n_fnt=Resources.GetFont(Resources.FontResources.lucidagrande09n);
		
		//----------------------------------------
		public static AppStartup PyxisApp(ref Pyxis2Controller controller)
		{
			AppStartup _app=new AppStartup();

			_controller=controller;
			_desktop=_controller.Desktop;
			desk_w=_controller.Desktop.Width;
			desk_h=_controller.Desktop.Height;

			// Finalizing
			_app.title="th 003";
			_app.description=STR_APP_TITLE;
			_app.company="---";
			_app.copyright="---";
			
			_app.menus=MBar_Create();

			home();

			return _app;
		}
		
		//----------------------------------------
		static void home()
		{	
			home_form=new form(_controller);
			home_form.background=ColorUtility.ColorFromRGB(0xcc,0xcc,0xcc);
			
			label title_lbl=new label(_controller,STR_APP_TITLE,4,4);
			title_lbl.font=luc09b_fnt;
			title_lbl.autosize=true;
			home_form.addChild(title_lbl);
			
			picturebox th_mon_btn=new picturebox(_controller,Resources.GetBitmap(Resources.BitmapResources.th_mon),desk_w-40,desk_h-40-20,32,32);
			th_mon_btn.borderstyle=BorderStyle.BorderNone;
			th_mon_btn.scalemode=ScaleMode.Normal;
			th_mon_btn.tapEvent+=new OnTap(th_mon_btn_evt);
			home_form.addChild(th_mon_btn);
			
			_desktop.children.Add(home_form);
			
			// my problem : the following lines
			// will be displayed on the screen then erased just after
			tm_now=DateTime.Now;
			int posx=lcd_w-date_area_w;
			int posy=50;
			int w=date_area_w;
			int h=30;
			lcd.DrawTextInRect(tm_now.ToString("d MMM yyyy"),posx,posy,w,h,Bitmap.DT_AlignmentRight,Colors.Black,luc09n_fnt)
			lcd.Flush(posx,posy,w,h);
			
		}
	}
}

#4

I don’t know Pyxis architecture,but in general you have 2 options:

  1. don’t use bitmap. Add a text control or whatever is available on Pyxis.

  2. If you really want to use bitmap put it into picturebox and add that picture box to the container that has all your ui elements. Anytime you want to change the image just modify the bitmap as you do.

Remember that in the current example you just flashed the bitmap once in home() method which was called once. To make it stick you need it to be part of a control that is on the screen or make it part of the some sort of OnPaint equivalent of your main window.

I will look at Pyxis API later and might be able to provide more info that is close to the Pyxis wolrd.

Cheers,
V


#5

Yes, that’s true and but I want to to display a dynamic graphic, some kind of temperature chart where data are provided by four probes. Using a picturebox to handle that chart could not be as fast as needed.


#6

Cugel,

Sorry it took so long to get back to you I was just told about this post. I wrote Pyxis. It’s still in beta so I’ll keep your issues in mind. For now your best bet is the PictureBox. You can assign your image to it and assure it isn’t over written.

Pyxis refreshes the screen based on user action only. So if you click a button or menu or such to cause it to do a refresh it will overwrite what you have. But assigning the BMP to a picturebox will prevent this.

For example:


picturebox pb1 = new picturebox(controller, x, y, etc);

[all your code]

pb1.image = myBitmap;

The next beta is in the works and will be released soon with support for programs in their own AppDomains and more. So if there’s anything you’d like to see now is the time to let me know :slight_smile:


#7

@ Cugel how fast do you need the update to be? If you assign the image to a picturebox and call it’s render method it should be pretty fast. Also the next beta (due out soon) renders significantly faster.


#8

ok, I found Pyxis2 little bit slow and I’m happy the next beta will speed up things. I will use it as soon as it will be released.

Do you know if it is possible to get the touchscreen to be used without any window?
We can draw graphic primitives on the screen with bitmaps and do plenty basic things (for another project, I need no more than just bitmaps) but I could not find any example for using the touch screen without any window, just the basic, the pen coordinates for a click or something like that. The sort of things we could do with the megapalm.


#9

Yes you can get the touch screen to work without a Window or WPF. It’s a bit more involved that way but you’ll be able to see how it works with the next release of Pyxis. Basically you need to set up an EventListener and perform a few casts to change the supplied message into what you need and raise your events from there.


#10

yes, I finally found an old example, but very interesting, with the EggBasket example. It’s an old project with old hardware references compiled with NetMF 3.0.