Splash class

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.
D.Bane
Posts: 78
Joined: Thu Jul 29, 2010 2:51 pm

Splash class

Post by D.Bane »

Hi to all again.

Happy holidays to all (even though they have passed for some and as I saw on forum, for some will only begin).

I am sorry for not having time to come sooner but here is the splash class that I had promised earlier.

This class could probably be better written, so if you find errors do tell me as well so I know where I made them. I wanted to create more effects but unfortunately am not able to find my VB splash form where I had them, so here are only the basic ones.

The file you would need to include in your project in order to use splash screen is the "splash.ec".
The file "form1.ec" and "MySplash.epj" serve only as an example of how it would look.

I hope that you like them.

Best Wishes to all,
D.Bane
Attachments
splash.ec
Here is the class and all the code needed for splash to be included in your projects
(10.58 KiB) Downloaded 4049 times
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: Splash class

Post by jerome »

Hi D.Bane!

Sorry for taking so long to reply...

As you know I am on holidays in Vietnam, and I was working hard on improving the eC Distributed Objects, used in my implementation of the Blokus game:

Source code @ GitHub

Win32 binaries

I will try to answer all your questions, in this Splash screen code and on the forums as well.

So first, Splash::OnRedraw

You ask: //delete bitm; //causes weird things..Should we not get it destroyed??

Well, it turns out that no, you don't need to destroy it. The goal of the BitmapResource class is to hold the Bitmap object for you and decide when to destroy / reload it (i.e. loading when first using it in a particular display driver, getting rid of it when no more window makes use of it in that display driver). And since BitmapResource bmpLogo { } is a member instance, it gets itself deleted automatically when the Splash object is gone.

I noticed also:

//for now
txtLogoSmCap.position.x = txtLogoCap.position.x + txtLogoCap.size.w;

It's best if any 'state modifying' code is left out of OnRedraw. The Ecere GUI model is that OnRedraw simply 'renders' the current state, and any state modification should be done outside...
It could be for example, in an input event, or in a timer's DelayExpired event...
In your case, perhaps you mean to put it on initialization. The best place is probably OnLoadGraphics, where the font would have been loaded.

Using multiple fonts in your OnRedraw method
The way to do this easily is with FontResource that manages the fonts for you, just like the BitmapResource. The alternative to FontResource/BitmapResource is to manually Load/Unload the fonts and bitmaps in OnLoadGraphics() and OnUnloadGraphics(). (Using Display::LoadFont and Bitmap::Load)

So you declare the font resources in your window this way:

Code: Select all

   FontResource bigFont { "Tahoma", 30, bold = true, window = this };
   FontResource smallFont { "Tahoma", 20, bold = true, window = this };
And then in your OnRedraw method you can do:

Code: Select all

         {
            char * s = TextLogoPrepare(true);
            int len = strlen(s), tw;
 
            surface.font = bigFont.font;
            // Compute the width in pixels of the text with this font in tw
            display.FontExtent(bigFont.font, s, len, &tw, null);
            surface.foreground = teal;
            surface.WriteText(4, 4, s, len);
 
            surface.font = smallFont.font;
            surface.WriteTextf(4 + tw, 18, TextLogoPrepare(false));
 
            surface.font = fontObject;
         }
OnLoadGraphics/OnUnloadGraphics
I just noticed you are doing AddResource/RemoveResource with bmpLogo.
When you do 'window = this' for the BitmapResource:

BitmapResource bmpLogo {fileName = ":SplashLogo.png", window = this;};

You do not need to manually Add/Remove resources (It's to save you from having to implement OnLoadGraphics/OnUnloadGraphics and do it for all bitmaps).
So in this case it is redundant...

TextLogoPrepare
You have CopyString() inside TextLogoPrepare (And only for the "E"?), but the way you use it, you do not require a new copy each time... So this is a memory leak. Setting the 'text' propery on a label (or other window) will make its own copy of the string. So return "E"; is right.

currentlyLoading property
The reason it would crash on a delete, is because you are passing in a string literal constant, which should not get deleted. What you can do, as is common practice, is make String properties copy the incoming string (deleting the previous one beforehand as you're doing is good, though the null check is superfluous with delete, and making sure to clean it on destruction). Example:

Code: Select all

   property String currentlyLoading
   {
      get { return currentlyLoading; }
      set
      {
         delete(currentlyLoading);
         currentlyLoading = CopyString(value);
      }
   }
   ~Splash()
   {
      delete currentlyLoading;
   }
I hope this helps, and that it covered everything. (moving on to your other forum questions)

Cheers!

Jerome
Attachments
splash.ec
My changed splash.ec
(10.98 KiB) Downloaded 4047 times
D.Bane
Posts: 78
Joined: Thu Jul 29, 2010 2:51 pm

Re: Splash class

Post by D.Bane »

Hi Jerome.

Thank you very much for the response with so many valuable comments.

I was looking for a way to use those fonts :) Now, I'll certainly have some more fun :)

Sorry about my late response as well :oops: , I was busy :ugeek: . As soon as I had time I wanted to check the tooltips and splash. I have updated the splash control (well only a part of it), but since I had little time I did not respond to you because of the errors I got. I thought that I messed something up, but I took another look today and I do not see what may be a problem.

Basically I added a variable: String textLogo; a property for same and updated the function to return textLogo[0] + textLogo[1->end]. But all that it did was going into an endless loop on PrintBuf();

I will attach the file so you can see what I had done. Basically it all starts at the String TextLogoPrepare(bool returnMain) function at line 355.

Is that related to the newest source with tooltips or am I missing something?

Again, thank you Jerome for the help and answers :)

All the best,
D.Bane.
Attachments
splash.ec
This file will not render, the file in first post does so download it if you are looking for newest version.
(11.78 KiB) Downloaded 4026 times
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: Splash class

Post by jerome »

Just to make sure you don't miss it, I've answered in this post
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: Splash class

Post by samsam598 »

Just found that the splash screen can be closed by closing on the taskbar icon if the splashing time is long enough.The taskbar icon shows up there even if the property showInTaskBar=false.

Another issue,recently find that those created forms (projects) times ago inside which those controls who has a hot key (AltO for example) will not pass during compiling time,it complained that

Code: Select all

 
form1.ec:17:33: error: unresolved identifier altD; expected ecere::gui::controls::ScrollBar
   form1.ec:17:33: error: unresolved identifier altD; expected ecere::gui::controls::ScrollBar
   form1.ec:15:4: error: couldn't determine type of altD                               
I have to re-assign the hot key in the IDE designer property window.

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

Re: Splash class

Post by jerome »

Hi Sam!

Sorry for the very late reply, I must have missed this post somehow!
Haven't seen you around in a while either, I hope you are well!

Those errors must be caused by the change of order of properties, and they are probably not set explicitly (i.e. hotKey = altD). Perhaps they follow 'text' which was made obsolete in favor of 'caption'.

As for the splash screen which shows up in the taskbar, was that on Windows or Linux? Perhaps settings 'master' to another form or setting interim = true might do it... I'd have to check with the project )

Regards,

Jerome
jonaspm
Posts: 49
Joined: Thu Apr 11, 2013 11:04 pm
Location: Mexico
Contact:

Re: Splash class

Post by jonaspm »

The taskbar icon shows up there even if the property showInTaskBar=false.
I also experience that under Windows 7
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Splash class

Post by jerome »

OK I did some quick testing and here's the clarification:

- The 'showInTaskBar' property defaults to 'false', and is useful for 'forcing' a window to show up in task bar, not to take it out of there
- The circumstances when a window will show up in a taskbar are quite complex, from Windows.

Here are some articles explaining them:
http://msdn.microsoft.com/en-us/library/aa969325.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 46371.aspx

From this Stack Overflow post ( http://stackoverflow.com/questions/8204 ... pwindow-do ):
There are some basic rules on which windows go into the taskbar. In short:

If the WS_EX_APPWINDOW extended style is set, then it will show (when visible).
If the window is a top-level unowned window, then it will show (when visible).
Otherwise it doesn't show.
In Ecere this translates to:

- By default, windows without a parent (top level window, confined only to the desktop) will show up in the taskbar unless they have a master (owner) and are either marked as modal (isModal = true) or interim (interim = true).
- To force a window to show up in the taskbar, set showInTaskBar to true.

To force a top-level, unowned window not to show up in the taskbar, you could use an invisible window as a master:

Code: Select all

import "ecere"
 
Window hidden { visible = false };
 
class HelloForm : Window
{
   text = "Not in the taskbar!";
   borderStyle = sizable;
   size = { 280, 100 };
   hasClose = true;
   master = hidden;
   interim = true;
 
   Label label
   {
      this, position = { 10, 10 }, font = { "Arial", 30 }, 
      text = "Hello, World!!"
   };
};
 
HelloForm hello { };
Regards,

Jerome
jonaspm
Posts: 49
Joined: Thu Apr 11, 2013 11:04 pm
Location: Mexico
Contact:

Re: Splash class

Post by jonaspm »

that's good to know, thanks a lot :D
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: Splash class

Post by samsam598 »

D.Bane wrote:Hi to all again.

...

The file you would need to include in your project in order to use splash screen is the "splash.ec".
The file "form1.ec" and "MySplash.epj" serve only as an example of how it would look.

I hope that you like them.

Best Wishes to all,
D.Bane
The test project file seem's broken.Mine old test project doesn't work for this Splash class,app crashed upon startup.
Post Reply