Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: mouse coord out until resize by any amount  (Read 16368 times)

0 Members and 2 Guests are viewing this topic.

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« on: June 25, 2008, 02:13:40 am »
hi, i tried to simplify my code as much as possible and extract exactly where my problem is occuring, so the code below if copied and pasted wil compile, i have just included the neccessary pieces from multiple files where i have found a problem,

the problem, i set my window as a desktop_mode, then i draw a 2dpanel at the bottom of the viewport that overlays the 3d viewport, if the mouse cursor is over the black 'drag-line' and left mouse is held down, the panel can be resized/dragged up and down,

there could be a problem in my code, but from tests i am guessing something else, if i load the program up and without resizing i try to drag the panel, it misses the mark by about 20px, as soon as i resize by any amount it behaves as it should, the code shouldn't be wrong as i have used it before, but i might be wrong,please check for me,you can just copy paste code....

sorry if it is a bit long but i have tried to preserve exactly how i use it,not usually in one file though

Code: [Select]

#include <SFML/Window.h>
#include<SFML/System.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct GUI{

   int high, wide;
}GUI;


GUI *mygui;
int init_gui_panel(int w, int h, GUI *gui);
void guidraw();

sfEvent Event;
sfWindow* mywin;

enum   actions {DRAGS, NONE};

static int action = NONE;



void guidraw(){

      glColor3f(0.1,0.1,0.1);
     glBegin(GL_QUADS);
        glVertex2i(mygui->wide, (mygui->high-5));
        glVertex2i(0,(mygui->high-5));
        glVertex2i(0, mygui->high);
        glVertex2i(mygui->wide, mygui->high);

     glColor3f(0.7,0.7,0.7);
        glVertex2i(mygui->wide, 0);
        glVertex2i(0,0);
        glVertex2i(0, (mygui->high-5));
        glVertex2i(mygui->wide, (mygui->high-5));
        glEnd();

}






int init_gui_panel(int w, int h, GUI *gui){

    //this function should encapsulate more than this later!!

   gui->high = (h/4);
   gui->wide = w;

   return gui;

}


int main(){

    sfWindow* mywin;
    sfWindowSettings Settings = {24,8,4};
    mywin = sfWindow_Create(sfVideoMode_GetDesktopMode(), "Quirk", sfResize | sfClose, Settings);


    GUI initgui;
    mygui = init_gui_panel(sfWindow_GetWidth(mywin), sfWindow_GetHeight(mywin),&initgui);

while(sfWindow_IsOpened(mywin)){
const sfInput* input = sfWindow_GetInput(mywin);

     if(sfWindow_GetEvent(mywin, &Event)){

             switch(Event.Type)
             {
                 case sfEvtClosed:
                      sfWindow_Close(mywin);
                 break;

                 case sfEvtMouseButtonPressed:
                    switch(Event.MouseButton.Button){

                        case sfButtonLeft:
                        if( (sfInput_GetMouseY(input) > sfWindow_GetHeight(mywin)-mygui->high)  &&     (  sfInput_GetMouseY(input) < sfWindow_GetHeight(mywin)-mygui->high+5)  ){

                            action=DRAGS;
                        }
                        break;
                    }
                 break;


                 case sfEvtMouseButtonReleased:
                    if( Event.MouseButton.Button == sfButtonLeft)
                        {
                        action = NONE;
                        }
                 break;

                 case sfEvtMouseMoved:

                      switch(action){
                       case DRAGS:
                            mygui->high = (sfWindow_GetHeight(mywin)-(Event.MouseMove.Y));

                            if( ((sfWindow_GetHeight(mywin)-Event.MouseMove.Y) > (sfWindow_GetHeight(mywin)-30)) )
                            {
                            mygui->high = (sfWindow_GetHeight(mywin)-30);
                            }

                            if( Event.MouseMove.Y > (sfWindow_GetHeight(mywin)-30))
                            {
                            mygui->high = 30;
                            }
                            break;
                      }
                 break;

             }
     }

     sfWindow_SetActive(mywin, 1);

     glClearColor(0.5,0.5,0.5,1.0);
     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );


     //3d
     float aspect;
        aspect = ((float)sfWindow_GetWidth(mywin))/((float)sfWindow_GetHeight(mywin));
        glViewport(0,0,sfWindow_GetWidth(mywin), sfWindow_GetHeight(mywin));
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
        gluPerspective(45.0, aspect, 0.1, 200.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();





     //2d
     glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
        gluOrtho2D(0, sfWindow_GetWidth(mywin), 0, sfWindow_GetHeight(mywin));
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

    guidraw();



     sfWindow_Display(mywin);

 }




    return 0;
}






help appreciated

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #1 on: June 25, 2008, 10:22:17 am »
ok, no reply??mmm....maybe i shouldnt have pasted all that code, well i am not asking it to be fixed if it is wrong on my part. but later today i will try post an even simpler example of what i mean,


oh and by resize i mean resize the window,
if i load the window with getdesktop and i try adjust the panel (that i draw in opengl) it wont work, if i just adjust the window size by even 1px i can now adjust the panel by click-and-hold on it's drag-line...

this is on windowsxp, sfml 1.3, i am going to test it on 1.2 and check if it does same thing..

but as i say i have used this code before....except for the getdesktopmode part.

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #2 on: June 25, 2008, 01:59:43 pm »
ok after double checking this,

if instead of
Code: [Select]

    sfWindow* mywin;    
    sfWindowSettings Settings = {24,8,4};
    mywin = sfWindow_Create(sfVideoMode_GetDesktopMode(), "Quirk", sfResize | sfClose, Settings);


i use say,

Code: [Select]

    sfWindow* mywin;
    sfVideoMode Mode = {800, 600, 32};
    sfWindowSettings Settings = {24,8,4};
    mywin = sfWindow_Create(Mode, "Quirk", sfResize | sfClose, Settings);


then my mouse input records just fine without having to resize the window,


which leads me to ask, is there something wrong how i am calling sfVideoMode_GetDesktopMode()?? or is it something else??

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
mouse coord out until resize by any amount
« Reply #3 on: June 25, 2008, 02:33:34 pm »
I can't see any relation between the video mode and the inputs, I'll try this code and see if I can reproduce the problem.
Laurent Gomila - SFML developer

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #4 on: June 25, 2008, 03:03:44 pm »
cool thanks, sorry for the hassle, if you notice anything blatantly wrong in my code just let me know, i don't need a full solution, maybe just a tip,

i don't think this should matter, but i build in code::blocks...

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #5 on: June 25, 2008, 08:21:42 pm »
earlier you said you don't see relation between video mode and input, i think there might be,you know this but just to recap

mouse-y starts at top=(0)

opengl-y starts at bottom=(0)

if i draw a simple line across the screen in opengl using orthographic 192px  from bottom,

and i everytime i click mouse on the line and print out -> window-height,  mouse-ypos (from top),   line-height(from bottom),

these are results:

open as desktop mode, no resize just one click on line,
window height  768
mouse y from top 556
line height from bottom  192
windowheight  minus  mousey gives 212 (20px out  - possibly taskbar)


open as desktop mode, maximize,  just one click on line,
window height  708
mouse y from top 508
line height from bottom  192
windowheight  minus  mousey gives 202 (10px out ?)

open as desktop mode, drag windows left edge slightly inward,  just one click on line,
window height  742
mouse y from top 548 (-edit:550)
line height from bottom  192
windowheight  minus  mousey gives 192 -----CORRECT



open as 800X600, no resize,  just one click on line,
window height  600
mouse y from top 408
line height from bottom  192
windowheight  minus  mousey gives 192 -----CORRECT


have you tried this?

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #6 on: June 26, 2008, 11:07:48 am »
hi,

i dont know if you had time to look at this, if you did could you pls inform me if you encountered same thing.
it is not a serious issue for me at the moment in any case,

later

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
mouse coord out until resize by any amount
« Reply #7 on: June 26, 2008, 11:16:54 am »
Yes of course, I'll check this as soon as possible and let you know if I can find something ;)
Laurent Gomila - SFML developer

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #8 on: June 26, 2008, 08:00:05 pm »
hi,

i had a look through the svn and downloaded some of the source for window and video, i think i am going to have to download the c++ source, and i am going to see if i can try help debug this - or at least find out if it is a code bug or my display or something, at least to teach myself a bit more about what is going on behind the scenes,  
I had a look at the msdn DEVMODE docs, and will start from there and then go through the window creation, even if i dont come up with a solution I will definitely gain from trying, later.....

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #9 on: June 27, 2008, 12:40:48 am »
ok i got a build workspace up and running, can compile the c++ and c libs, i am going to try check this out,

i have been thinkin though, i understand that you use dmPelsHeight to detect the height of the screen, is this connect in anyway to anything else,

would it not be possible to use GetSystemMetrics( SM_CYFULLSCREEN ), but i am not actually sure if that is where the problem lies in any case but it is where i am first going to start.

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #10 on: June 27, 2008, 01:13:19 am »
i just want to ask a quick question,

this is the first time i am trying something like this so kinda in the deep end here,

if i want to make changes that are reflected in the csfml libs,

i first make changes to the c++ source, compile those libs,

and then compile the c libs, correct?

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #11 on: June 27, 2008, 02:25:23 am »
okay i managed to get things going and want to discuss,

i changed return value of getdesktopmode to this:

   
Code: [Select]

 return VideoMode(GetSystemMetrics( SM_CXFULLSCREEN ), GetSystemMetrics( SM_CYFULLSCREEN ), Win32Mode.dmBitsPerPel);


what this does is give the correct input from mouse, however the screenposition is now 20px lower.

I think dmPelsHeight was getting stuck somewhere on my system, and don't know exactly why, I was guessing my display drivers or monitor (HP 7540) doesnt agree with the DEVMODE stuff

i am going to try SM_CYSCREEN, as SM_CYFULLSCREEN, takes into account the bottom taskbar on windows, I think this will resolve the issue, but not sure how it affects videomode, although I pretty sure nothing bad will come of it.

vurentjie

  • Newbie
  • *
  • Posts: 31
    • View Profile
mouse coord out until resize by any amount
« Reply #12 on: June 27, 2008, 02:32:51 am »
i tried CYSCREEN instead, now this is exactly where mouse input becomes 20px out, as the screen size is perfectly set as a fullscreen desktop but mouse input is out by 20px (repeating myself here)....which means i am wrong about the DEVMODE stuff, that is all fine, the problem possibly lies either in the positioning on the screen, or in the actual input capture, not quite sure, going to go check that out now.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
mouse coord out until resize by any amount
« Reply #13 on: June 27, 2008, 02:58:59 am »
Hey, thanks a lot for trying to solve it by yourself :)

I'm sorry I don't have much time to help you right now, but I'll try to check it this week-end.

Let me know if you find more :)
Laurent Gomila - SFML developer

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
mouse coord out until resize by any amount
« Reply #14 on: June 27, 2008, 03:29:52 am »
You could try getting the dimensions of the viewport rather than the window. I have no clue if this'll give you the results you want, but it's worth a try.