Code Snippet03--SplashWindow(Timer driven)

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Code Snippet03--SplashWindow(Timer driven)

Post by samsam598 »

Purpose:Showing a startup screen before the main window shows.A label shows the seconds elapsed from 5 to 1,when it counts to 1,the splash window will close and the main window will get shown.In the future version a reall cool picture will be used instead of plain text message.

Known Issue:Ideally the main windows should get shown after the splash windows destroyed,but right at this moment I don't know how to make it,so in this version the main windows is visible also when the splash window get shown at program startup.I just make the size of the splash windows bigger than the main window to hide this issue.Will fix it in the future version.

main.ec

Code: Select all

 
import "ecere"
import "splash"
 
class Form1 : Window
{
   text = "Form1";
   background = activeBorder;
   borderStyle = sizable;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   size = { 328, 192 };
   anchor = { horz = -239, vert = -205 };
   nativeDecorations = true;
 
 
   Label label1 { this, text = "程序主界面", foreground = green, font = { "Tahoma", 26, bold = true }, size = { 284, 61 }, position = { 16, 24 } };
   Button btnExit
   {
      this, text = "(X)退出", altX, size = { 74, 21 }, position = { 216, 112 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         Destroy(0);
         return true;
      }
   };
   Button btnShowInfo
   {
      this, text = "(S)显示信息", altS, position = { 56, 112 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         MessageBox {text="test",contents="Test splash windows";}.Modal();
         return true;
      }
   };
}
/*  
class App:GuiApplication
{  
   bool Init()
   {
 
       splash.Create(); 
       mainForm.Create(); 
 
 
       return true;
   }
}
*/
Splash splash {master=mainForm};   
Form1 mainForm {visible=false;};               
 
splash.ec

Code: Select all

 
 import "ecere"
class Splash : Window
{
   int i;
   i=5;
   text = "Form2";
   background = activeBorder;
   size = {800, 600 };
   anchor = { horz = -56, vert = -88 };
   isModal=true;
   Label label1 { this, text = "闪屏测试", foreground = teal, font = { "Tahoma", 26, bold = true }, size = { 284, 37 }, position = { 248, 216 } };
   Label label2 { this, text = "Are you ready?", foreground = teal, font = { "Tahoma", 26, bold = true }, size = {300, 45 }, position = { 248, 264 } };
   Label label3 { this, text = "5", foreground = teal, font = { "Tahoma", 80, bold = true }, size = {300, 200}, position = { 350, 320 } };
    Timer timer
   {
      userData = this, started = true, delay = 1;
 
      bool DelayExpired()
      {
 
         char msg[2];
         sprintf(msg,"%d",--i);
 
         label3.text=msg;
         Update(null);
 
         if(i==0) this.Destroy(0);
         return true;
      }
       void OnDestroy(void)
       {
          master.visible=true;
       } 
   };      
 
}             
 
Last edited by samsam598 on Wed Sep 07, 2011 7:49 pm, edited 7 times in total.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Code Snippet03--SplashWindow(ver1)

Post by jerome »

Sam,

1. Your 'App' class isn't working because it should be inheriting from 'GuiApplication', not GUIApplication, note the character case. I will double check, I might have made that mistake in my first post explaining this to you.

It doesn't seem to matter though which Window gets created first, for whatever reason Windows always decides to draw the form on top first and then draw the splash on top. So the whole Init() and the Create() doesn't seem to make any difference.

2. To get the behavior that you probably want, I saw you set 'isModal = true' in the splash, which is good, but for it to work you need to set its 'master' to be 'mainForm':

Code: Select all

Form1 mainForm {};
Splash splash { master = mainForm };
3. I see you tried to set nativeDecorations to true on a Button, native decorations are only supported for root (top level) windows, for title bars / system buttons, not for controls. We support skinning the controls however, but it's a bit of work at the moment. You could take a look at the sample in sdk/samples/guiAndGfx/skinning. Hopefully you can live with the default skin :D

4. By the way when you post code on the forums, you can make it syntax highlighted by using:
[ code=eC ] [ /code ] (without the spaces of course).
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: Code Snippet03--SplashWindow(ver1)

Post by samsam598 »

Hi Jerome,

I've made the modifications based on your guideline.
1.I tested both GuiAppliation and GUIApplication but it seems both work.Don't know why.
2.Revised.
3.Sorry that's an accident. :oops:
4.Got it.
It doesn't seem to matter though which Window gets created first, for whatever reason Windows always decides to draw the form on top first and then draw the splash on top. So the whole Init() and the Create() doesn't seem to make any difference.
Sorry don't quite understand the point.Could you please further clarify?

Appreciated.

Sam
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Code Snippet03--SplashWindow(ver1)

Post by jerome »

1.I tested both GuiAppliation and GUIApplication but it seems both work.Don't know why.
As you're saying, I was just saying the same thing. It doesn't make a difference in terms of how the windows show up. The 'master' and 'isModal' properties control which window will go on top.

But if you put a MessageBox or a PrintLn or a breakpoint in your App::Init() function, you will see that it never gets executed if you use ':GUIApplication', but it will if you use ':GuiApplication'. If you don't have other needs for Init() or GuiApplication, you can take out the whole 'App : GuiApplication' class definition.
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: Code Snippet03--SplashWindow(ver1)

Post by samsam598 »

Got it!
D.Bane
Posts: 78
Joined: Thu Jul 29, 2010 2:51 pm

Re: Code Snippet03--SplashWindow(Timer driven)

Post by D.Bane »

Hi to all :)

Long time since I had time to come here :oops:

Sam, I tried to get my applications to ecere and had some encounters with splash screen as well.

I would change few things in your code to make it seem activating in the order you want it.

in main.ec add this to call of your main window class:

Code: Select all

Form1 mainForm {visible = false;};
and than in splash.ec add this:

Code: Select all

 
   void OnDestroy()
   {
      master.visible = true;
   }
 
Now it seems to be created when your splash screen is destroyed.

Hope it helps you.

D.Bane
No army is to big, if the heart is beating strong.
There's no bad luck, it's just easier to blame someone else.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Code Snippet03--SplashWindow(Timer driven)

Post by jerome »

Hey D.Bane! long time indeed! :D

You're right you can see the windows popping up in that order if you set visible = false...
But with the fix I proposed above (isModal / master) you can have both windows displayed at the same time, but the proper one on top. Depends on what you want to do of course.

Do you have some time to play with Ecere lately? :)
We are now using git and on github!
You can keep up with the latest version of the SDK with a simple pull ! :P

Take care,

Jerome
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: Code Snippet03--SplashWindow(Timer driven)

Post by samsam598 »

D.Bane wrote:Hi to all :)

Long time since I had time to come here :oops:

Sam, I tried to get my applications to ecere and had some encounters with splash screen as well.

I would change few things in your code to make it seem activating in the order you want it.

in main.ec add this to call of your main window class:

Code: Select all

Form1 mainForm {visible = false;};
and than in splash.ec add this:

Code: Select all

 
   void OnDestroy()
   {
      master.visible = true;
   }
 
Now it seems to be created when your splash screen is destroyed.

Hope it helps you.

D.Bane
Thank you D.Bane!It really helps and the result is exactly what I want.Already updated the example.
D.Bane
Posts: 78
Joined: Thu Jul 29, 2010 2:51 pm

Re: Code Snippet03--SplashWindow(Timer driven)

Post by D.Bane »

Hi.

It is nice to be helpful :) and I am glad that it worked as you want it.

The Jerome's way is great for splash screens like in Photoshop, where you have main window shown but not active for usage and you can see the splash screen. This is also good to make some effects around the window by using the main window behind it (a picture in it, etc...) I personally like the ones where you have splash screen and after that you have your main window show if everything loads/checks, etc.

I still have not figured out how to make the transparency of it decrease/increase as well :)

Jerome, yes I had time to play with Ecere :) and from all the things that I got across on the internet, this is by far the best one. I have great time troubling myself with ecere and finding how to do make its power work for me properly :ugeek:

I need to do make install on the source code when I get it from Git right?

Oh yes, I did not forget about you all, I just have very little time to come on forums..When I have time I try to buzz trough them as much as possible.

So when I have more time, expect some questions :)

Best regards,
D.Bane.
No army is to big, if the heart is beating strong.
There's no bad luck, it's just easier to blame someone else.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Code Snippet03--SplashWindow(Timer driven)

Post by jerome »

D.Bane, Yes first you do 'make', and then 'make install' if that succeeds (That will install it under C:\Program Files\Ecere SDK , you need an elevated command prompt on Vista/7 to do that -- it HAS to say Administrator at the top, you need to right click the cmd.exe icon and do 'Run as administrator').

Transparency -- I think that would be possible, but you'd need to set the 'alphaBlend' property of your Window to true, and it might not be fully working under Linux right now (that is, windows that are translucent with the rest of the desktop, like in the ColorSpheres and HiraganaCube sample).

Could be tricky to do with an image / ramping opacity ... 'opacity' applies only to the 'background' color I believe. It would be interested to get a sample going :D

I'm looking forward to your questions! As you might have noticed, Sam has been asking a lot of good questions lately, so you might even find some answers there!

Cheers,

Jerome
Post Reply