Page 1 of 1
FAT32 and Window Manager?
Posted: Thu May 17, 2007 11:36 pm
by pcmattman
I have good news, and bad news.
The good news is, I have finally finished my FAT32 'fread' function. It works perefectly (including with multiple-cluster files). It's up on CVS for those who need help with it.
The bad news is, I have a question.
With my window manager, ATM on every time it's 'Repaint' function is called it does this (function names aren't the same as my code):
- Clears the screen to the desktop color
- Calls Window_Repaint for each window, this then calls Window_Repaint for each child window et al. There are no child windows yet.
- It then returns to the function that called it, which draws the cursor (last, so always on top)
Unfortunately, this is really slow, and doesn't work well. If I leave out calling Window_Repaint after the first (needs_repaint = 0, so doesn't need to repaint anymore) then the window disappears!
If I leave out clearing the screen, the mouse cursor replicates itself hundreds of times over the path of its travel.
Any ideas as to how to do this?
Posted: Fri May 18, 2007 2:41 am
by jnc100
There are very few times you need to repaint the whole screen.
The usual method to deal with mouse movements is to save the area of the screen where the mouse is moving to, then when the cursor moves again, just restore that little bit. You then just need some logic to update the "under cursor" area if that particular bit of screen is refreshed.
Regards,
John.
Posted: Fri May 18, 2007 3:36 am
by pcmattman
OK, so I basically, whenever I'm about to draw the cursor, save the data beneath it, then when the cursor is moved I blit the old data to the screen where the cursor was then do the same process again?
That sounds pretty simple. I'll give it a go.
BTW: The rest of my OS is GPL, but I'm putting the FAT32 code up as Public Domain for all who are interested.
Edit: I've implemented it, and it's incredibly slow! No more unecessary repaints, though. I think I'm going to have to only blit the old bitmap when the mouse moves, instead of all the time...
Edit 2: OK, done. I now have a fast mouse cursor! Obviously I must avoid as much bitmap blitting as possible! Thanks everyone!
Posted: Sat May 19, 2007 10:25 pm
by AndrewAPrice
Allocate each window some memory - say a 200x200 window has 200x200x4 bytes (Windows allocates the desktop's resolution for each program). Don't continually clear this bitmap and redraw it unless something has changed in the window (even then, it could be easier to draw over the top of the old area rather than clearing the entire window and redrawing everything). When you go to refresh the screen (which you should only do if the contents of one of the windows has changed) then you can clear the screen, draw the desktop's bimap, then each window's bitmap (starting from the furtherest away), then the mouse poiner, and flip the screen buffer.
You could try drawing child windows within it's parent window to speed up this process. The method I mentioned could be optimised making every window a child of the desktop, and only redraw the area under the cursor from the desktop's bitmap when the cursor moves.
Posted: Sat May 19, 2007 10:52 pm
by pcmattman
Good ideas, thanks for the input.
Now I just have to get my window manager working properly. I'm going to have to rewrite it, it isn't working well. Or maybe I just need a better malloc.
Posted: Mon May 21, 2007 2:15 pm
by JJeronimo
I've never implemented windowing painting functions, but I have an idea that should work for mouse as well as for applications.
Programs write to buffers where there is only one window (on each buffer), and everything else is marked as alpha 100%. When you want to update the video memory, this buffers will work as layers.
This allows you to update only certain areas of your desktop, by providing a repaint function that takes the coordinates of a rectangle as parameters.
If a windows is moved, then you only need to repaint everything that is under the old window position, without counting that window's layer, and then do the same thing for the new window location (perhaps only for that window and the ones in front of it, unless you want some type of alpha blending)...
If you want to move the mouse, you only need to recalculate the image that should be under the old cursor position, and then redraw the cursor on the new position.
JJ
Posted: Mon May 26, 2008 7:09 am
by thepowersgang
try having a flag that is set when a window is invalidated (a message/event is handled) and only redraw it if that flag is satisfied.
**ignores the noob in the previous post***
Posted: Mon May 26, 2008 8:31 am
by jal
pcmattman wrote:Good ideas, thanks for the input.
I'm a bit disappointed in you for not coming up with something as simple as the 'safe area beneath cursor' stuff, it's basic software sprite handling :). As for rewriting your stuff, there was a recent thread (didn't you comment in that too?) that discussed the need for repaint vs. back buffers. The outcome is that most here think it is useful (and almost obligatory nowadays) to store or window data in a seperate buffer, and blit the buffer (or parts of it) to the screen. If you ever get to 3D acceleration, you'll need this as well.
JAL
Posted: Mon May 26, 2008 3:55 pm
by Combuster
thepowersgang wrote:**ignores the noob in the previous post***
Removed for violating the majority of forum rules.
Posted: Mon May 26, 2008 4:00 pm
by lukem95
jal wrote:pcmattman wrote:Good ideas, thanks for the input.
I'm a bit disappointed in you for not coming up with something as simple as the 'safe area beneath cursor' stuff, it's basic software sprite handling
. As for rewriting your stuff, there was a recent thread (didn't you comment in that too?) that discussed the need for repaint vs. back buffers. The outcome is that most here think it is useful (and almost obligatory nowadays) to store or window data in a seperate buffer, and blit the buffer (or parts of it) to the screen. If you ever get to 3D acceleration, you'll need this as well.
JAL
http://www.osdev.org/phpBB2/viewtopic.php?t=16634
that was my thread, there was a whole tonne of useful information there. its worth a read. It's also worth wiki'ing, i'll look for a place to shove the link now.
Posted: Mon May 26, 2008 5:21 pm
by pcmattman
Is there any reason everyone here is commenting on a thread that's now just over a year old?
Sure, it got bumped by the noob, but that doesn't mean we continue the discussion!
Posted: Tue May 27, 2008 12:38 am
by jal
pcmattman wrote:Is there any reason everyone here is commenting on a thread that's now just over a year old?
Sure, it got bumped by the noob, but that doesn't mean we continue the discussion! :D
Ah, that explains :). I never look at the date, just assume it's recent. Stupid me.
JAL
Posted: Tue May 27, 2008 5:20 am
by lukem95
jal wrote:pcmattman wrote:Is there any reason everyone here is commenting on a thread that's now just over a year old?
Sure, it got bumped by the noob, but that doesn't mean we continue the discussion!
Ah, that explains
. I never look at the date, just assume it's recent. Stupid me.
JAL
ditto