PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

interface oddity in 2.01

I find it odd that CreateFont now has a background color flag in its parameters. Is this any different than the SetColorKey that is normally used on the actual surface?

For example:
Code:

Font.CreateSurface(...);
Font.SetColorKey(TRANSPARENTCOLOR);
Font.CreateFont(0, TRANSPARENTCOLOR, ...);


Prior to v2 line 2 in the above matched all other surface initialization, in that I was creating the surface and then set its color key if needed. I assume line 2 is no longer needed for a font? Does it have an effect if I use 0 in the parameter and continue using SetColorKey?


As an aside, a design comment on the library and how I see it evolving. I would prefer a simpler interface local to each method than a complex parameter list and a simpler class interface. In other words less parameters and more overloaded methods or plain old different methods. What I am finding is for *many* cases 2-4 parameters are 0 (or null, which in C++ is the same thing). This is very error prone IMO, much like the Windows API which sucks in any design consideration. Not to mention more difficult to remember.


I dislike writing user-mode wrappers, but its beginning to become needed. Here is an example of the sort of thing I would do:
Code:

HRESULT Blt(
RECT* pDestRect,
CGapiSurface* pSrcSurface, RECT* pSrcRect,
DWORD dwFlags);
HRESULT BltFx(
RECT* pDestRect,
CGapiSurface* pSrcSurface, RECT* pSrcRect,
DWORD dwFlags, GDBLTFX* pGDBltFx);

[/code]
Hi,

CreateFont will now use the color passed as background color to call SetColorKey. If you pass a black color, CreateFont will use that to set a black color key. The change was done after watching several students have their font creation fail since they forgot to set the color key manually.

It would be interesting to have a discussion on your suggestions. There are several experienced developers on this board. What do you all think?

//Johan
Well, technically there is a performance penalty for additional parameters beyond the first four. So there's a small reason to simplify the function calling.

http://forums.pocketmatrix.com/viewtopic.php?t=10293

Dan East
I think each of us could come up with a "better" way of doing things. While user suggestions are important I think a line has to be drawn somewhere.

Personally I don't have a problems with flags. I prefer having a few flags to look over instead of 10 overloaded functions for the same blit routine. The flags/structure is a nice way of adding options to a call without changing it too much. Like the new options in DrawText().

It might be more error prone, but a for() also is. Put a semicolon at the end of the for() line, and you'll spend the next two hours searching for a killer bug. There are dozens of tiny details that must be taken care of when programming. Specifying flags is not the worst.

If someone cannot grasp how GapiDraw works, the tutorials or documentation are at fault. Create objects, set display, blit and flip. Repeat.

A complete reorganization of the library will do no one any good. New features and optimizations will. What we do is not supposed to be easy for us, but for our users/clients.

I killed one of my best selling shareware product by trying to entertain every user suggestions. I don't want this to happen to GapiDraw, it's far too valuable.

--Eric

PS: Sorry, but I had to vent some steam!

SBL: If you need more beginner tutorials, please let me know. I'll be more than happy to write some.
efortier wrote:
It might be more error prone, but a for() also is. Put a semicolon at the end of the for() line, and you'll spend the next two hours searching for a killer bug. There are dozens of tiny details that must be taken care of when programming. Specifying flags is not the worst.


There are things that are minimal skills, like the semicolon. Sure, many beginners get stuck with these bugs many times, but you learn the hard way and you then can avoid them in the future. I for one do not recall having an error of this sort in ages, the largest bulk of programmers are above this minimum competancy so any change to correct this problem would just annoy most of us. There may be solutions that make everyone happy, but thats a language issue not what I was talking about above.


Same relevant points to parameters. One there is a reasonable speed consideration when there are more than 4 32 bit. Two, default parameters in C++.


Since the original post I decided I would just write a wrapper, and in fact leave the blit effects up to an object. Which has also been an error prone section and creates a lot of noise in my code. You may like the parameters and flags, but to me it violates information hiding. My surface should care wether its key colored, or alpha blended. And in fact I could set this once and then not worry about it.
This also solves another problem I've had with this methodology (struct passing), all of those auto declared structs, C99 can't come quick enough.


And finally, I disagree, parameters *are* the worse problem. Back in the day, they were an awful problem, and then prototyping and type checking entered the world and it was better. You can still taste that old world when there are many of the same type in a method, and when you have to cast. The later is mostly just an W32API abomination, where you have to cast around all the time, completely defeating any error prevention type checking offered.

Some would say pointers are the worst, but I never trust pointers whereas I tend to trust parameters since there is some checking being done for me.