GUI

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
alberich
Posts: 9
Joined: Mon Dec 08, 2008 5:09 pm

GUI

Post 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!!
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: GUI

Post 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
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
alberich
Posts: 9
Joined: Mon Dec 08, 2008 5:09 pm

Re: GUI

Post 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!
CodeCat
Member
Member
Posts: 158
Joined: Tue Sep 23, 2008 1:45 pm
Location: Eindhoven, Netherlands

Re: GUI

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: GUI

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: GUI

Post 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
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
alberich
Posts: 9
Joined: Mon Dec 08, 2008 5:09 pm

Re: GUI

Post 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!!
CodeCat
Member
Member
Posts: 158
Joined: Tue Sep 23, 2008 1:45 pm
Location: Eindhoven, Netherlands

Re: GUI

Post 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. ;)
LoseThos
Member
Member
Posts: 112
Joined: Tue Oct 30, 2007 6:41 pm
Location: Las Vegas, NV USA
Contact:

Re: GUI

Post 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.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: GUI

Post 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:
"Programmers are tools for converting caffeine into code."
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Re: GUI

Post 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
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: GUI

Post 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
tantrikwizard
Member
Member
Posts: 153
Joined: Sun Jan 07, 2007 9:40 am
Contact:

Re: GUI

Post 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
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: GUI

Post by quanganht »

Is there any way to use VESA without returning to Unreal mode?
"Programmers are tools for converting caffeine into code."
k0ksz
Posts: 8
Joined: Fri Dec 05, 2008 4:03 am

Re: GUI

Post 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
Post Reply