|
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. Here is the adapted code to show the difference in y-pos. First a pixel is drawn on 1000, 500. |
Dizzy Egg
Member #10,824
March 2009
|
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.
---------------------------------------------------- |
bamccaig
Member #7,536
July 2006
|
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). -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
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, |
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. 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
|
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 understand however what Peter means. BTW: Is editing of own post not possible in this forum? |
Raidho36
Member #14,628
October 2012
|
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, The y-deviation answer is puzzling me. Does it mean that my code is not wrong? |
Raidho36
Member #14,628
October 2012
|
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. |
|