X, Y co-ordinate system under OS/2

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

X, Y co-ordinate system under OS/2

Graeme Geldenhuys-2
Hi,

I'm porting an OS/2 application to Linux & Windows.  From what I can
see in the code, it looks like co-ordinates (0,0) is in the bottom
left corner of the screen. Whereas Windows and Linux, co-ordinates
(0,0) is in the Top Left of the screen.

Is my assumption correct?  If so, DAMN! This is going to cause a lot
of work. :-/


Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: X, Y co-ordinate system under OS/2

Tomas Hajny
On Wed, October 7, 2009 16:31, Graeme Geldenhuys wrote:


Hi,

> I'm porting an OS/2 application to Linux & Windows.  From what I can
> see in the code, it looks like co-ordinates (0,0) is in the bottom
> left corner of the screen. Whereas Windows and Linux, co-ordinates
> (0,0) is in the Top Left of the screen.
>
> Is my assumption correct?  If so, DAMN! This is going to cause a lot
> of work. :-/

Yes, this is the case as far as I know (I haven't done any GUI programming
under OS/2 myself, but I know that this has always been one of the main
porting obstacles between Win32 and OS/2 at least).

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: X, Y co-ordinate system under OS/2

Graeme Geldenhuys-2
2009/10/7 Tomas Hajny <[hidden email]>:
>
> Yes, this is the case as far as I know (I haven't done any GUI programming
> under OS/2 myself, but I know that this has always been one of the main
> porting obstacles between Win32 and OS/2 at least).

I suppose I can see the merits for using each of the co-ordinate systems.

Windows & Linux:  Follows the path of how memory is laid out in the
graphics hardware.

OS/2: Follows the path of mathematics.


Either way, I have found numerous errors in my port due to this
"unknown by me" issue.  :-/


--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: X, Y co-ordinate system under OS/2

Paul Nicholls
In reply to this post by Graeme Geldenhuys-2
----- Original Message -----
From: "Graeme Geldenhuys" <[hidden email]>
To: "FPC-Pascal users discussions" <[hidden email]>
Sent: Thursday, October 08, 2009 1:31 AM
Subject: [fpc-pascal] X, Y co-ordinate system under OS/2


> Hi,
>
> I'm porting an OS/2 application to Linux & Windows.  From what I can
> see in the code, it looks like co-ordinates (0,0) is in the bottom
> left corner of the screen. Whereas Windows and Linux, co-ordinates
> (0,0) is in the Top Left of the screen.
>
> Is my assumption correct?  If so, DAMN! This is going to cause a lot
> of work. :-/
>
>
> Regards,
>  - Graeme -

Hi Graeme, I know this is a oldish post, but I had some thoughts on this
just today :)

I'm making a simple GUI system for a game, and I needed to have screen
origin independant input coordinates for the GUI (simpler to think about
when using), and can be used in different world coordinate systems.

So, I have this in my GUI class:

properties
----------
FOriginX : Integer;  // is the screen's top-left coordinate in final 'world'
coordiantes
FOriginY : Integer;
FDownDir : Integer;  // is either +1, or -1 (+1 for world y coordinates
increasing downwards, and -1 for increasing upwards

methods
---------
Function  TIMGUI.ScreenToWorldX(Const sx : Integer) : Integer;
Begin
    Result := FOriginX + sx;
End;
{..............................................................................}

{..............................................................................}
Function  TIMGUI.ScreenToWorldY(Const sy : Integer) : Integer;
Begin
    Result := FOriginY + sy * FDownDir;
End;

with the GUI screen, I assume that the top left is 0,0 and the bottom right
is (width,height) just like in windows.

Now if I want to draw a button, I just do this:

(x,y)
    +-------+
    |       |
    |       |
    +-------+
            (x+w,y+h)

Procedure FIMGUI.DrawRadioButton(x,y,w,h : Integer; text : AnsiString);
Begin
    mx := x + h Div 2;
    my := y + h Div 2;
    r  := h Div 2;

    x1 := ScreenToWorldX(mx-r);
    y1 := ScreenToWorldY(my-r);

    x2 := ScreenToWorldX(mx+r);
    y2 := ScreenToWorldY(my+r);
{...}
        // radio button background
        DrawRoundedRect(x1,y1,
                        x2,y2,
                        0,r,cLineWidth,
                        FBackgroundColor.r,
                        FBackgroundColor.g,
                        FBackgroundColor.b,
                        FBackgroundColor.a,
                        True,5);

        // radio button border
        DrawRoundedRect(x1,y1,
                        x2,y2,
                        0,r,cLineWidth,
                        FBorderColor.r,
                        FBorderColor.g,
                        FBorderColor.b,
                        FBorderColor.a,
                        False,5);

        r := Trunc(r * 0.65);

        x1 := ScreenToWorldX(mx-r);
        y1 := ScreenToWorldY(my-r);

        x2 := ScreenToWorldX(mx+r);
        y2 := ScreenToWorldY(my+r);

        // radio button active dot
        If active Then
            DrawRoundedRect(x1,y1,
                            x2,y2,
                            0,r,cLineWidth,
                            FBorderColor.r,
                            FBorderColor.g,
                            FBorderColor.b,
                            FBorderColor.a,
                            True,5);

        If text = ''  Then Exit;
        If font = Nil Then Exit;

        FontH := font.MaxHeight;
        FontX := ScreenToWorldX(x+h+4);
        FontY := ScreenToWorldY(my - FontH Div 2);

        glEnable(GL_TEXTURE_2D);
        If FUIState.HotItem = id Then
            glColor4fv(@FHotColor)
        Else
            glColor4fv(@FFontColor);
        font.Draw(FontX,FontY,text,0);
{...}
End;

I hope this helps?

cheers,
Paul

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: X, Y co-ordinate system under OS/2

Graeme Geldenhuys-2
2009/10/29 Paul Nicholls <[hidden email]>:
>
> I hope this helps?

A little bit late, as I have done most of the drawing conversion
already. But your post is still handy if I ever wanted to support OS/2
in fpGUI. A clever solution. I'll file your post for future reference
- thanks.


--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: X, Y co-ordinate system under OS/2

Bugzilla from juha.manninen@phnet.fi
In reply to this post by Paul Nicholls
Hi,

> I'm making a simple GUI system for a game, and I needed to have screen
> origin independant input coordinates for the GUI (simpler to think about
> when using), and can be used in different world coordinate systems.

If done right, the code doing coordinate conversion should be in library
Canvas class, not in application code.
It is supposed to be portable, right...

It can also be optimized with conditional compilation. The conversion is
needed only when compiling for OS/2 and so other systems wouldn't get even the
small performance hit the conversion causes.

Regards,
Juha Manninen
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: X, Y co-ordinate system under OS/2

Graeme Geldenhuys-2
On 29/10/2009, Juha Manninen <[hidden email]> wrote:
>
> If done right, the code doing coordinate conversion should be in library
>  Canvas class, not in application code.

That's how I would have implemented in it fpGUI as well. The higher
level code uses x, y as normal. The drawing backend code does
conversions if needed.

That's how I handle differences between Windows GDI API and XLib API.

--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: X, Y co-ordinate system under OS/2

Paul Nicholls
----- Original Message -----
From: "Graeme Geldenhuys" <[hidden email]>
To: "FPC-Pascal users discussions" <[hidden email]>
Sent: Thursday, October 29, 2009 7:51 PM
Subject: Re: [fpc-pascal] X, Y co-ordinate system under OS/2


> On 29/10/2009, Juha Manninen <[hidden email]> wrote:
>>
>> If done right, the code doing coordinate conversion should be in library
>>  Canvas class, not in application code.
>
> That's how I would have implemented in it fpGUI as well. The higher
> level code uses x, y as normal. The drawing backend code does
> conversions if needed.
>
> That's how I handle differences between Windows GDI API and XLib API.
>
> --
> Regards,
>  - Graeme -

Very good points, and I completely agree :)
I was only doing a quick "hack" so I could get something working in a short
time ;)

BTW, I found these very interesting articles about IMGUI (Immediate Mode
GUI) systems (which I am using in my game):

http://www.johno.se/book/imgui.html
http://sol.gfxile.net/imgui/index.html

and a forum about IMGUs
http://www.mollyrocket.com/forums/viewforum.php?f=10

Perhaps this might help someone, except maybe Graeme "fpGUI" Geldenhuys LOL!
;P

cheers,
Paul

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal