473,396 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GUI design

Hi
Here is my current design:

In the drawing function, i declared an array : PIXEL[1024][768], the
drawing function will keep drawing every pixel in the array to the
screen.

There are many kind of component in my GUI library, all of them have an
OnPaint() method. The drawing function will pass a pointer to each
component like OnPaint(Pixel+(x+y*768)), then component draw whatever
they like to that array.

Is it good?

thanks
from Peter (cm****@hotmail.com)

Sep 29 '06 #1
12 1994
hk**********@hotmail.com wrote:
Hi
Here is my current design:

In the drawing function, i declared an array : PIXEL[1024][768],
Right in *that* function? And you're gonna allocate such a huge array every
time that function is called? Are you serious?
the
drawing function will keep drawing every pixel in the array to the
screen.
I'm a bit confused. Why should it not draw directly to the screen then? I'm
asking this because it seems like you first allocate the buffer, draw in it
the entire element and then copy out of this buffer only a fraction of the
buffer (very likely a fraction of the element if it's obscured by something)
to the screen. I wouldn't like drawing into the buffer pixels that won't be
displayed.
There are many kind of component in my GUI library, all of them have
an OnPaint() method. The drawing function will pass a pointer to each
component like OnPaint(Pixel+(x+y*768)),
I'm not sure how to interpret "Pixel+(x+y*768)".
then component draw whatever
they like to that array.

Is it good?
First of all, what you have outlined is too little. Like it's been
mentioned, you must deal with clipping, so, in the design there must also be
a place for computation of what's visible and what's not. Second, unless you
refine it, it's gonna be bloody slow. I should've probably provided an
option in my windowing demo that would redraw everything from back to front
without any clipping whatsoever. That would probably show the difference in
performance and visual quality and you'd not have such a question. :)

Alex

Sep 29 '06 #2
In the drawing function, i declared an array : PIXEL[1024][768], the
drawing function will keep drawing every pixel in the array to the
screen.
You should make that:
class Screen
{
Screen(int w, int h);
~Screen();
void Put(int x, int y, PIXEL p);
PIXEL* m_pScreen;
int m_w, m_h;
};

Screen::Screen(int w, int h)
{
m_pScreen = new PXIEL[w*h];
m_w = w; m_h = h;
}

Screen::~Screen()
{
delete[]m_pScreen;
}

void Screen::Put(int x, int y, PIXEL p)
{
if(x<0 || x>=m_w) return;
if(y<0 || y>=m_h) return;
m_pScreen[x+y*m_w] = p;
}

This way you have a dynamic memory allocation (1024x768 is quite a
thing for static memory). Also you can have several screens with
different resolutions. The Put function will only put pixels that are
visible (not crashing your program if you access pixel (-1,-1).

Well, it's just a thought.
-Gernot


Sep 29 '06 #3
Gernot Frisch wrote:
....
Screen::Screen(int w, int h)
{
m_pScreen = new PXIEL[w*h];
m_w = w; m_h = h;
}
The negative arguments are allowed in the above code but obviously not
welcome.

Alex

Sep 29 '06 #4

"Alexei A. Frounze" <al*****@chat.ruschrieb im Newsbeitrag
news:Z8******************************@comcast.com. ..
Gernot Frisch wrote:
...
>Screen::Screen(int w, int h)
{
m_pScreen = new PXIEL[w*h];
m_w = w; m_h = h;
}

The negative arguments are allowed in the above code but obviously
not welcome.
Doh!
Sep 29 '06 #5

Alexei A. Frounze 寫道:
hk**********@hotmail.com wrote:
Hi
Here is my current design:

In the drawing function, i declared an array : PIXEL[1024][768],

Right in *that* function? And you're gonna allocate such a huge array every
time that function is called? Are you serious?
the
drawing function will keep drawing every pixel in the array to the
screen.

I'm a bit confused. Why should it not draw directly to the screen then? I'm
asking this because it seems like you first allocate the buffer, draw in it
the entire element and then copy out of this buffer only a fraction of the
buffer (very likely a fraction of the element if it's obscured by something)
to the screen. I wouldn't like drawing into the buffer pixels that won't be
displayed.
If i do that, i can do some "whole screen" effect. In mac, when you
press F11, it transparent the whole screen.

>
There are many kind of component in my GUI library, all of them have
an OnPaint() method. The drawing function will pass a pointer to each
component like OnPaint(Pixel+(x+y*768)),

I'm not sure how to interpret "Pixel+(x+y*768)".
then component draw whatever
they like to that array.

Is it good?

First of all, what you have outlined is too little. Like it's been
mentioned, you must deal with clipping, so, in the design there must alsobe
a place for computation of what's visible and what's not. Second, unless you
refine it, it's gonna be bloody slow. I should've probably provided an
option in my windowing demo that would redraw everything from back to front
without any clipping whatsoever. That would probably show the difference in
performance and visual quality and you'd not have such a question. :)

Alex

My basic idea is, os keep a pixel array, the display card driver keep
putting every pixel to the screen. At the same time, the os graphic
engine also modify the pixel array, for example, when there is a new
window comes or you closed a window.

Dan

Sep 29 '06 #6
hk**********@hotmail.com wrote:
Hi
Here is my current design:

In the drawing function, i declared an array : PIXEL[1024][768], the
drawing function will keep drawing every pixel in the array to the
screen.

There are many kind of component in my GUI library, all of them have an
OnPaint() method. The drawing function will pass a pointer to each
component like OnPaint(Pixel+(x+y*768)), then component draw whatever
they like to that array.

Is it good?

thanks
from Peter (cm****@hotmail.com)
Peter,

your method will work, but it will, as others have said, be very slow.
the method would be fine for something like a microcontroller, where
processing power is limited, but for a PC, where you expect speed, this
would be incredibly slow.

By looping around your putpixel() routine, you are repeatedly redrawing
pixels which have not changed, rather than concentrating on those that
have.

Think about it this way; Every high level drawing function MUST be
designed to check whether the thing being drawn is totally inside the
window, totally outside it, or partway in and partway outside. it can
then crop off the bits that would otherwise be outside the drawing area,
(or more importantly, outside your array of pixels!) This makes high
level functions slow. It is therefore important to avoid simple
functions like putpixel(), which only place a single pixel once the
checks are done, in preference for bitblit() which does the same tests,
but then puts perhaps 10000 pixels.

What you could do is this:

Each high level drawing function is given a pointer to your
pixel_buffer, and access to two x,y coordinates, the top_left, and
bottom_right points. These are initialised to impossible values
(top_left set to the bottom right of the screen and vice-versa.) Each
drawing function then checks to see if the thing it has to draw is
inside the valid range of pixels (in other words, on the screen) and
draws what it can to your pixel_buffer. It then updates the top_left and
bottom_right values to the extremes of a box containing the object. Each
drawing function can expand the region, but not shrink it. When all of
your functions have finished, the two points define a box containing all
the parts of the screen that need to be updated. You then bitblit() only
this rectangle to the screen.

Obviously, this process can be made asynchronous, by interrupting the
drawing process and bitblitting what has changed so far, then
continuing, but this is more complex.

Hope this helps

matt
Sep 29 '06 #7
Matt wrote:
....
your method will work, but it will, as others have said, be very slow.
the method would be fine for something like a microcontroller, where
processing power is limited, but for a PC, where you expect speed,
this would be incredibly slow.
On a microcontroller it would just ... be even slower than on a PC.
Microcontrollers themselves are usually much slower than a PC's CPU. As you
say, the key is whether what happens is the same as what's expected.
However, if I want a device to respond to an event or interrupt quickly and
meet the deadlines no matter what, a PC, even if it's 10 or 50 times faster
than those microcontrollers or dedicated CPUs, isn't the right choice,
because neither its firmware nor OS guarantee anything, yet you have little
control over the two. You don't know what's in the BIOS and on the
motherboard and you don't know what's installed under the OS and what other
devices are attached and how all that worsens the latency.

Alex

Sep 30 '06 #8
Alexei A. Frounze wrote:
Matt wrote:
...
>your method will work, but it will, as others have said, be very slow.
the method would be fine for something like a microcontroller, where
processing power is limited, but for a PC, where you expect speed,
this would be incredibly slow.

On a microcontroller it would just ... be even slower than on a PC.
Microcontrollers themselves are usually much slower than a PC's CPU. As
you say, the key is whether what happens is the same as what's expected.
However, if I want a device to respond to an event or interrupt quickly
and meet the deadlines no matter what, a PC, even if it's 10 or 50 times
faster than those microcontrollers or dedicated CPUs, isn't the right
choice, because neither its firmware nor OS guarantee anything, yet you
have little control over the two. You don't know what's in the BIOS and
on the motherboard and you don't know what's installed under the OS and
what other devices are attached and how all that worsens the latency.

Alex
Alex, I agree that on a micro controller the code would run even slower.
However, from years of experience programming them, I know that the main
issues with a microcontroller are often a) the simplicity of the code,
as code space is limited, and b) latency. The latency, being longer by
the nature of the slow speed, is better to be consistent. Because of
this, a simple interrupt driven routine that loops through all of the
pixels and draws one at a time would work better than one that tried to
bitblit.

As a general method for drawing to the screen on a PC, it is going to
run hundreds of times slower, due to all the overheads.

The good thing about microcontrollers, as you say, is that nothing
happens that you do not know about, so you can be certain that your code
will always respond in a known period.

Matt
Sep 30 '06 #9
In the drawing function, i declared an array : PIXEL[1024][768], the

Pixel is not the lowest-level primitive for GUI, BitBlt is :-)

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
ma***@storagecraft.com
http://www.storagecraft.com

Sep 30 '06 #10
I'm a bit confused. Why should it not draw directly to the screen then? I'm
asking this because it seems like you first allocate the buffer, draw in it
the entire element and then copy out of this buffer only a fraction of the
buffer (very likely a fraction of the element if it's obscured by something)
to the screen.
I think Vista's Desktop Composition works this way.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
ma***@storagecraft.com
http://www.storagecraft.com

Sep 30 '06 #11
Maxim S. Shatskih wrote:
>I'm a bit confused. Why should it not draw directly to the screen
then? I'm asking this because it seems like you first allocate the
buffer, draw in it the entire element and then copy out of this
buffer only a fraction of the buffer (very likely a fraction of the
element if it's obscured by something) to the screen.

I think Vista's Desktop Composition works this way.
IMO, an OS that's not a memory/power hog, must be able to do direct drawing
with transparency off and provide the transparency as an option. I don't
know exactly how this whole transparency thing works in Vista, but this
shouldn't be complicated -- the OS should still let the application know
when it's time to redraw and what and the OS may have an optional buffer on
behalf of each window for the transparency. The key is that it should be
designed to and work w/o such a buffer in the first place but allow for it.

Alex

Oct 1 '06 #12
Alexei A. Frounze wrote:
Maxim S. Shatskih wrote:
>>I'm a bit confused. Why should it not draw directly to the screen
then? I'm asking this because it seems like you first allocate the
buffer, draw in it the entire element and then copy out of this
buffer only a fraction of the buffer (very likely a fraction of the
element if it's obscured by something) to the screen.

I think Vista's Desktop Composition works this way.

IMO, an OS that's not a memory/power hog, must be able to do direct
drawing with transparency off and provide the transparency as an option.
I don't know exactly how this whole transparency thing works in Vista,
but this shouldn't be complicated -- the OS should still let the
application know when it's time to redraw and what and the OS may have
an optional buffer on behalf of each window for the transparency. The
key is that it should be designed to and work w/o such a buffer in the
first place but allow for it.
vista essentally knows two completly different ways to get things on screen:
- "classic way" (aero basic, windows classic, ...): every app draws it's
stuff when it's asked to do so
- "dwm way" (aero glass): every app draws something whenever it wants.
the graphics is stored in main memory & graphics memory. the whole
screen is redrawn whenever something changes, but the applications
obviously aren't required to redraw the window contents. that mean's it
uses more gpu and less cpu power. and you can make use of all the fancy
3d-capabilities of your gpu.

regards,
simon

--

http://valhalla.iru.ch/

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Oct 1 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: adb | last post by:
I came up with a replication configuration that is basically the result of all the restrictions of replication as well as the restrictions of allowable software on work PC's and I was curious if...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
0
by: Edward Diener | last post by:
In Borland's VCL it was possible to divide a component into design time and run time DLLs. The design time DLL would only be necessary when the programmer was setting a component's properties or...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
2
by: Paul Cheetham | last post by:
Hi, I have moved an application from VS2003 to VS2005, and I am now unable to view most of my forms in the designer. The majority of the forms in my project are derived from class PACForm,...
1
by: Nogusta123 | last post by:
Hi, I have had a lot of problems getting web pages, master pages and content pages to render in VS2005 design view the same as they would in Internet Explorer. I did a lot of looking on the...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
19
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
10
by: vital | last post by:
Hi, I am designing the middle tier of a project. It has 6 classes and microsoft application data access block. The six classes are DBServices, Logger, ProjectServices ... etc. and all these...
4
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.