Page 1 of 2

GUI

Posted: Mon Dec 08, 2008 5:15 pm
by alberich
Hi!

I'm new on this forum, and it's good to know there's so many people sharing interests :)

I've got a gui-newbie question: which is the best way to draw mouse pointer on screen? and then handle de moving of this pointer across all the windows/background?

Is there somewhere i can find information about a basic gui design?

thanks!!

Re: GUI

Posted: Mon Dec 08, 2008 5:25 pm
by M-Saunders
Hi,

First, see: http://wiki.osdev.org/Beginner_Mistakes#GUI_Design

I don't know if you've already written an OS, but if not, a GUI is a long way off. There's a huge amount of work to be done before you can start working on a GUI. To move a mouse pointer you need to interface with the hardware (eg a PS/2 or USB mouse) and video RAM. You will have to consider whether you want to use plain VGA (640x480x16) video mode, or VESA, or something else. So you'd need a lot of in-depth hardware knowledge.

Of course, if you have a fantastic idea for a GUI, great! But if you're new to OS development, you'll find it orders of magnitude easier to implement it as, say, a Unix X window manager than writing an OS to support your GUI. Good luck!

M

Re: GUI

Posted: Mon Dec 08, 2008 5:36 pm
by alberich
wow!

thanks for the quick reply!!

Yes, i've got an OS. It's a simple os, but for the moment i got: MM+pagging, monolitic kernel, and some other few thing. I'm able to move mouse pointer ( for the moment just ps2 mouse ), and i'm now able to query to VBE for modes, set/get modes, and ask for the best mode tha fits in a given screen resolution.

Next to this i think is to print some background ( which i have a very rude just for test ) and move a mouse pointer across it.

For the moment what i do is to keep 2 buffers: one for the mouse pointer and other with the same size as mouse pointer, that contains the previous "picture" before i print the mouse. But i don't know how to use 2d acceleration for example or if this is the best way to do that.

any help?

thanks once again!

Re: GUI

Posted: Mon Dec 08, 2008 5:42 pm
by CodeCat
I believe there is hardware support for mouse drawing, but I'm not really sure how it works. Might be worth looking into.

Re: GUI

Posted: Mon Dec 08, 2008 6:13 pm
by Combuster
In text mode, there is a VGA hardware cursor. In graphics modes, it depends on the video card, and VESA won't give it to you. So you'll have to (re)draw the cursor manually.
Hardware acceleration forces you to write a driver for each card as well.

The approach to have a copy of the area under the mouse is not uncommon - you only need to be careful when you are writing to the surface when the mouse is there. If you only do doublebuffering then you can just overwrite the screen (which erases the cursor) and then draw the cursor back over it, otherwise you might want to temporarily hide the mouse when you're drawing near it.

Re: GUI

Posted: Mon Dec 08, 2008 7:05 pm
by Troy Martin
This is my idea, just redraw the screen at the speed of 15 fps, doing the mouse cursor every five frames.

EDIT: It's probably a crappy idea. /flameguard

Re: GUI

Posted: Tue Dec 09, 2008 5:04 am
by alberich
Combuster wrote:In text mode, there is a VGA hardware cursor. In graphics modes, it depends on the video card, and VESA won't give it to you. So you'll have to (re)draw the cursor manually.
Hardware acceleration forces you to write a driver for each card as well.
Is there any info about this?
Combuster wrote:The approach to have a copy of the area under the mouse is not uncommon - you only need to be careful when you are writing to the surface when the mouse is there. If you only do doublebuffering then you can just overwrite the screen (which erases the cursor) and then draw the cursor back over it, otherwise you might want to temporarily hide the mouse when you're drawing near it.
But i'm not shure if this is a good way to redraw mouse, maybe is just a very simple way to do it. And yes, for the moment i'm only using double buffer.

Can you point me to anywhere like a "disign a helo world GUI"? to see the basic about to move a window? Becouse i don't want to keep the same strategy to redraw windows as the one used by the mouse.

thanks!!

Re: GUI

Posted: Tue Dec 09, 2008 5:40 am
by CodeCat
Troy Martin wrote:This is my idea, just redraw the screen at the speed of 15 fps, doing the mouse cursor every five frames.

EDIT: It's probably a crappy idea. /flameguard
Why redraw each time? It wastes a lot of resources when the mouse is sitting there doing nothing.

Instead, keep a mouse-less version of the screen buffer in memory, either the full buffer or like alberich said only an area the size of the cursor (usually 32x32). Then you only update the screen when the mouse moves, and you only update those regions that were affected by the mouse movement. I.e. for each mouse movement event, you redraw a 32x32 square from the saved in-memory screenbuffer or the 32x32 saved screen area to erase the mouse at its previous location, and then blit the cursor onto the screen at the new location. It's not really going to get more efficient than this. ;)

Re: GUI

Posted: Tue Dec 09, 2008 5:52 am
by LoseThos
You can alway XOR the mouse cursor shape with the screen memory and XOR it again before moving it. See if you like the way it looks.

I decided to keep things simple and redraw the whole screen each refresh. At 60 Hz, it uses 5% of my CPU with 640x480x16 color.

If you go to a different graphics mode, you probably can't get away with it.

Re: GUI

Posted: Tue Dec 09, 2008 8:00 am
by quanganht
M-Saunders wrote:To move a mouse pointer you need to interface with the hardware (eg a PS/2 or USB mouse) and video RAM. You will have to consider whether you want to use plain VGA (640x480x16) video mode, or VESA, or something else. So you'd need a lot of in-depth hardware knowledge.
I'm newbie too, but I think you had better make something like HAL, with video driver. So that your drawing functions don't have to depend on video hardware and video mode :wink:

Re: GUI

Posted: Tue Dec 09, 2008 9:39 am
by lukem95
just have a bit that you check (using your mouse driver - you can use the ISR for now) each time the mouse moves, then update it through a system clock or generic graphics driver

Re: GUI

Posted: Tue Dec 09, 2008 11:08 am
by Dex
For a basic GUI, you need to copy the background 32x32 (where the mouse is to be drawn over ) from the main back-buffer to a mouse buffer, redraw the old mouse buffer back to screen (direct to the screen) and than draw the mouse pointer to the new place (also directly to the screen).
When anything changes in the windows you need to update the back-buffer and redraw it to screen, plus you call a differant mouse function that does not redraw the old mouse buffer.
This will give a good response mouse movement.
This is the method i use, for a windowing type GUI in my OS.

Image

Re: GUI

Posted: Tue Dec 09, 2008 6:33 pm
by tantrikwizard
alberich wrote:...which is the best way to draw mouse pointer on screen? ...
the best way is always going to be a point of discussion, in the long run it will depend on your implementation. There are some ideas on the WIKI:
http://wiki.osdev.org/Drawing_In_Protected_Mode
http://wiki.osdev.org/GUI
http://osdever.net/tutorials/GUI_tut.php

Re: GUI

Posted: Wed Dec 10, 2008 4:13 am
by quanganht
Is there any way to use VESA without returning to Unreal mode?

Re: GUI

Posted: Wed Dec 10, 2008 4:16 am
by k0ksz
quanganht wrote:Is there any way to use VESA without returning to Unreal mode?
I think you have at least two options:
- use virtual 8086 mode
- write a real mode emulator

k0ksz