Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Y-pos example for Peter Wang

This thread is locked; no one can reply to it. rss feed Print
Y-pos example for Peter Wang
AvG1938
Member #14,944
February 2013

A couple of weeks ago you asked for an example of the deviating y-mousepos.
The thread is closed now.
Running Win 8, MSVC2010Express and Allegro-508

Here is the adapted code to show the difference in y-pos.

First a pixel is drawn on 1000, 500.
Pointing and pressing LMB gives 1000, 490.

Dizzy Egg
Member #10,824
March 2009
avatar

Hello, I'm probably wrong, but I've compiled and ran your code and the only thing I can think of is that your mouse pointer doesn't click at (0,0).

Can you add code that draws a pixel using mouse.x/mouse.y, and prints out mouse.x/mouse.y at the same time? Don't use the mouse cursor, just draw a pixel at the mouse.x/mouse.y instead and then read what it says when you hover over your white pixel at 1000/500.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

bamccaig
Member #7,536
July 2006
avatar

Protip: You can embed code directly in the forum with <code></code> tags. That is preferred to an attachment because it allows people to view the code without downloading, saving, and opening a file (OK, if the code is 30 files, or 10 MB in size, then attaching is probably better, but you get the point).

Peter Wang
Member #23
April 2000

Your screen is being rescaled. You ask for a 1920x1080 pixel window, presumably on a 1920x1080 monitor, but the Windows taskbar takes up some space so your window is scaled down. You can see this more clearly with this version of the example, that I hacked up. Some of the horizontal lines are blurry due to the scaling.

You can use ALLEGRO_FULLSCREEN or ALLEGRO_FULLSCREEN_WINDOW, or translate from the unscaled mouse coordinates to match the rescaled screen coordinates.

AvG1938
Member #14,944
February 2013

Bamccaig,
I noticed of course the fact that my code was not looking the way other code-entries are showing in this forum and I was wondering how to fix that.
Maybe you mean with your entry " tags." the same but I do NOT understand it.
Some more details would be helpfull.

Vanneto
Member #8,643
May 2007

Simple, for example:

<code>
#include <allegro.h>

int main (int argc, char *argv[])
{

    return 0;
}
</code>

would look like:

#include <allegro.h>

int main (int argc, char *argv[])
{

    return 0;
}

If I paste your code between

<code></code>

tags it would look like below.

#SelectExpand
1#include <allegro5\allegro.h> 2#include <allegro5\allegro_image.h> 3#include <allegro5\allegro_native_dialog.h> 4#include <allegro5\allegro_ttf.h> 5#include <allegro5\allegro_primitives.h> 6 7#define screenWidth 1920 8#define screenheight 1080 9ALLEGRO_DISPLAY *display = NULL; 10 11bool klaar = false; 12 13int init_addons() //just a collection of needed things at start. 14{ 15 al_init_font_addon(); 16 al_init_ttf_addon(); 17 al_init_image_addon(); 18 al_init_primitives_addon(); 19 return 0; 20} 21 22int mouseinside(int x1, int y1, int x2, int y2) // in this case it returns the mouse-pos. 23{ 24 ALLEGRO_MOUSE_STATE state; 25 al_get_mouse_state(&state); 26 if (state.x > x1 && state.x < x2 && state.y > y1 && state.y < y2) 27 return 1; 28 else 29 return 0; 30} 31 32 33 34 35 36int main() 37{ 38 ALLEGRO_DISPLAY *display = NULL; 39 ALLEGRO_EVENT_QUEUE *evqu2 = NULL; 40 41 int *mouse_x = NULL; 42 int *mouse_y = NULL; 43 44 init_addons(); 45 46 if(!al_init()) 47 { 48 al_show_native_message_box(NULL, NULL, NULL, "failed to initialize allegro!", NULL, NULL); 49 return -1; 50 } 51 52 display = al_create_display(screenWidth, screenheight); 53 if(!display) 54 { 55 al_show_native_message_box(NULL, NULL, NULL, "failed to initialize display!", NULL, NULL); 56 return -1; 57 } 58 59 ALLEGRO_FONT *font1 = al_load_font("C:\\WINDOWS\\fonts\\kartika.ttf", 18, 0); 60 ALLEGRO_FONT *font2 = al_load_font("C:\\WINDOWS\\fonts\\kartika.ttf", 36, 0); 61 62 al_set_target_backbuffer(display); 63 64 al_clear_to_color(al_map_rgb(55, 5, 55)); 65 al_put_pixel(1000, 500, al_map_rgb(255, 255, 0)); 66 al_flip_display(); 67 al_install_keyboard(); 68 al_install_mouse(); 69 70 evqu2 = al_create_event_queue(); 71 72 al_register_event_source(evqu2, al_get_mouse_event_source()); 73 74 while(!klaar) 75 { 76 ALLEGRO_EVENT ev2; 77 al_wait_for_event(evqu2, &ev2); 78 79 if(ev2.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) 80 { 81 if(ev2.mouse.button & 1) 82 { 83 84 if (mouseinside(0, 0, 1920, 1080)) 85 { 86 al_draw_filled_rectangle(800, 440, 860, 550, al_map_rgb(50, 255, 0)); 87 al_draw_textf(font1, al_map_rgb(25, 25, 0), 810, 460, 0, "%d", ev2.mouse.x); 88 al_draw_textf(font1, al_map_rgb(25, 25, 0), 810, 500, 0, "%d", ev2.mouse.y); 89 al_flip_display(); 90 klaar = 1; 91 } 92 } 93 } 94 } 95 96 97 al_rest(5); 98 al_destroy_event_queue(evqu2); 99 return 0; 100}

In capitalist America bank robs you.

AvG1938
Member #14,944
February 2013

So here is the entry of the formatted text.

#include <allegro5\allegro.h>
#include <allegro5\allegro_image.h>
#include <allegro5\allegro_native_dialog.h>
#include <allegro5\allegro_ttf.h>
#include <allegro5\allegro_primitives.h>

Edit: OK, got it now. Do NOT use the dropbox.

LennyLen
Member #5,313
December 2004
avatar

Did you read Peter's reply where he told you what's wrong with your code?

AvG1938
Member #14,944
February 2013

Yes, I read his replay and did some trials.
I used the line he commented out, but no result.

I understand however what Peter means.
Whatever I try, the bottom-bar stays visible, and the y-deviation is still there.

BTW: Is editing of own post not possible in this forum?
Is replying 2 times also not possible?

Raidho36
Member #14,628
October 2012
avatar

Replying two times in a row automatically glues posts together.

Edit button is to the right from post date label.

Also, now that this is mentioned, Allegro shouldn't force window size so that it's smaller than requested, resulting in distortions. User should have no problem with requesting 100000x20000 px window. One doesn't with plain WinAPI and GTK+.

AvG1938
Member #14,944
February 2013

Thanks Raidho,
Due to your answer I could edit my "format"-entry and show that even I can do it.

The y-deviation answer is puzzling me. Does it mean that my code is not wrong?
Is using a smaller screenheight the answer for the moment. ( I need for my future program at least a height of 960 pix). I will try if using a height of 960 solves
the problem, so I can go on)

Raidho36
Member #14,628
October 2012
avatar

That's simply an oddities in Allegro design. You can find them every now and then. If you want to run a windowed application, then you shouldn't make window so big that it won't fit most of the desktops, make it 640x480 and the users will then adjust the sizes on their own.

Go to: