Sign in to follow this  
PGSCreativeDirector

the problem with coding?

Recommended Posts

Hello there i have been coding for about 7-8 months maybe more and well my issue here is the lack of simplified information on what i need in few cases like for instance ill look at the SDL tutorials or wikis and it will mostly just show the code and not explain much about it in alot of cases expecting that im an expert and all this but what if im learning as i go and need to understand not everything just alittle bit more then what SDL is providing now this is a problem and this doesn't happen in just SDL theres many cases where iv seen this such as WxWidgets it has all this documentation but doesn't really simplify it down to newcomers and that is a big deal that should be noted

on another note i have situation

Heres my problem

im trying to make a area of my window area clickable and then when clicked it does what i want it to do

now how do i do that in SDL Event and how did you figure it out because im one of those people who look at things and are not shore if its the right way or anything and need calarfications otherwise i worry that im doing it wrong

this is the page im looking at at the moment [url="http://www.libsdl.org/intro.en/usingevents.html"]http://www.libsdl.or...singevents.html[/url] i don't understand it :(
for example i dont understand how its used is it just like that and nothing else??

or is there something extra im missing i was thinking it had something to do with SDL Event unions so i made a typedef struct and have all these Uint variable declarations and i also Declared the Variables themself using what i presume is the SDL way of doing it like using Uint8 type and button and State and xy and then putting a object name SDL_MouseButtonEvent which i assume stores all those informations that you need to declare?? what?? do i need to create a Union? but i dont really get how it all works what is the required mindset to figure out this problem and the solution to the problem as well :(

im using OpenGL , SDL and C++

Share this post


Link to post
Share on other sites
Tutorials and especially documentation pages can't explain everything every time. They have to assume you know at least the basics. To learn the language (C, C++) I recommend you read a book or take a course. If you encounter something you don't understand you can look it up separately.

With SDL I find this [url=http://www.libsdl.org/cgi/docwiki.cgi/SDL_API]SDL Documentation[/url] useful to look things up. If you find a type or function you don't understand what it does, look it up before continue. [url=http://www.libsdl.org/cgi/docwiki.cgi/SDL_Event]SDL_Event[/url] is a type already defined by SDL.

In the page you have found there is an example how to handle SDL_MOUSEBUTTONDOWN events. Information about SDL_MOUSEBUTTONDOWN and SDL_MOUSEBUTTONUP events is stored in event.button which is of type [url=http://www.libsdl.org/cgi/docwiki.cgi/SDL_MouseButtonEvent]SDL_MouseButtonEvent[/url]. event.button.x and event.button.y are the coordinates of the click. Use that information to test if the click is inside the clickable area and if it is do what you want to do.

In case you didn't know about it, [url=http://lazyfoo.net/SDL_tutorials/index.php]Lazy Foo tutorials[/url] is a popular SDL tutorial. Lesson 9 describes mouse events but you should probably look through the previous lessons if you don't like surprises.

You should not be afraid of testing things on your own. You learn a lot by doing so. Don't be afraid of learning more than you need to know, knowledge is not heavy.

Share this post


Link to post
Share on other sites
so basically let me just get an example can't be arsed to write it all out at this point

[font="monospace"][size="2"]{[/size][/font][code] SDL_Event event; [color="#0000FF"]while[/color] ( SDL_PollEvent(&event) ) { [color="#0000FF"]switch[/color] (event.type) { [color="#0000FF"]case[/color] SDL_MOUSEMOTION: printf("[color="#000000"]Mouse moved by %d,%d to (%d,%d)\n[/color]", event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y); break; [color="#0000FF"]case[/color] SDL_MOUSEBUTTONDOWN: printf("[color="#000000"]Mouse button %d pressed at (%d,%d)\n[/color]", event.button.button, event.button.x, event.button.y); break; [color="#0000FF"]case[/color] SDL_QUIT: exit(0); } }}[/code]
I create an event using SDL_EVENT as like a type then when I've done that depending on how i want the event to work I then set it like poll or wait or directly then make shore i set it too event name that i used to attach SDL_EVENT type with also i setup the event type and make it whatever button i need then after that i put : and within it i put whatever code i want? after all that i use the break keyword and then its done

thats how i've figured it out is this correct? is there anything else that can be done with events that im missing with this statement please do tell me

Share this post


Link to post
Share on other sites
It's hard to understand what you are saying. Make a small program that handles mouse events and play around with it. See if it do what you expect it to do.

Share this post


Link to post
Share on other sites
{
SDL_Event event;

SDL_WaitEvent(&event);

switch (event.type) {
case SDL_MOUSEBUTTONUP:
fprintf (stdout,"randomwording");

if (fprintf == false);
{
fprintf(stdout,"Not Working");
}

break;
case SDL_QUIT:
exit(0);
}
}


this is the event i've made and it wont do, won't put any text into the stdout txt file ;(

I think i need to specify the actual button that will be pressed down?? how do i do that??

Share this post


Link to post
Share on other sites
wooot !!! the art of people who want me to do extra effort when i detest intensive effort ahh the joys :D i dont follow rules i break them aslong as no bad comes from it and this ant bad anuff because i know people can help ether way so there you go now can someone actually help me rather then giving me there thought of perception im hoping wooh gets back hes awesome at this stuff

im gunna get this answer otherwise ill be sitting there for hours struggling and i can pass this by asking forums ircs and reading in some cases

Share this post


Link to post
Share on other sites
+1 for rip-off and I would like to add that this is EXACTLY what makes coding so much fun: you have to find the answers to your problems, they are not offered to you on a silver plate. Sometimes you do it by looking at the docs, sometimes looking at the code, sometimes you just try every possible crazy thing that comes in your head to go around a problem.
If all the answers were already there in tutorials this would become such a boring job!

EDIT: nevermind.. wasted time

Share this post


Link to post
Share on other sites
If you want help with code, post a full program we can see.

For example:
[code]
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>

#include "SDL.h"

int main(int, const char **)
{
std::srand(static_cast<unsigned>(std::time(NULL)));

if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
std::cerr << "Failed to initialise SDL: " << SDL_GetError() << '\n';
return 1;
}

std::atexit(&SDL_Quit);

SDL_Surface *screen = SDL_SetVideoMode(600, 600, 0, SDL_SWSURFACE);
if(!screen)
{
std::cerr << "Failed to set video mode: " << SDL_GetError() << '\n';
return 1;
}

Uint32 colour = 0;
int x = 0;
int y = 0;

bool running = true;
while(running)
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
running = false;
}
else if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
{
running = false;
}
else if(event.type == SDL_MOUSEBUTTONDOWN)
{
x = event.button.x;
y = event.button.y;

if(event.button.button == 1)
{
colour = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00);
}
else if(event.button.button == 2)
{
colour = SDL_MapRGB(screen->format, 0x00, 0xff, 0x00);
}
else
{
colour = SDL_MapRGB(screen->format, 0x00, 0x00, 0xff);
}
}
}

SDL_FillRect(screen, NULL, 0);
SDL_Rect rect = {x, y,10, 10};
SDL_FillRect(screen, &rect, colour);
SDL_Flip(screen);
}

return 0;
}
[/code]

Share this post


Link to post
Share on other sites
MAN WHY DO I HAVE TO BE HERE SITTING TRYING TO FIGURE THIS OUT can't someone just say how to do this bloody hell!!! frick sake im sooo sick of reading books and tutorials and them not working or not been explained properly can not wait till i know how to do this stuff gunna do my own tutorials that will be simplfied !¬ the amount of crap people present is unbareablly stupidly driven by lazyiness in high quantitys! then you get people with there silly perceptive ideas describing it and always saying this and that or may say something different rather then sitting there screaming about how i did whateva figure it out and help me so i can learn from you and figure it out for myself when i do it on my own again because ill have a basis to work from and know what too do then

screw the rules there just to be annoying and require more effort that isn't really needed honestly


this is how i see this when i use a tool i expect that it actually make sense that it actually has a purpose and a benefit and also how to use it and work with it if i don't have any of those things then its poor in its present ability everyone can aggree on this

Share this post


Link to post
Share on other sites
The code you posted was incomplete. You still need to create a window that you can click on. The reason you get no output could be because you never flush stdout. Try putting fflush(stdout); after the fprintf. Fixing these things and you should get some output

rip-off posted a good example. Learn from it!

Share this post


Link to post
Share on other sites
? so for asking for simplified presentablity in the sdl tutorials means ill get banned??? and for the factor of which i expressed my emotion ???
and if this is about what i said it was a general truthfull point so i don't know why i should get banned for that?


so this hole factor is one sided opinionated standard ?

and i spoke good anuff that me and anyone i know could read that so i don't know how speaking more clearly will help its just a general semi detailed statement of wording? whats hard of that in which to understand

oh yea and about not wanting to read 5minutes worth of text i would do it if it meant helping someone so im sure others will just saying

do you want me to speak shakespeare old english maybe that might help ? :)

Share this post


Link to post
Share on other sites
If you have a problem with the presentation of a set of tutorials, you should email the author. Complaining to us about it won't change anything, we didn't write them. You are correct, many tutorials are awful.

You do realise that you complain about the laziness of tutorial writers who will not explain things properly, and yet excuse yourself from the very same thing when asked.

As for your code:
[code]
if (fprintf == false);
{
fprintf(stdout,"Not Working");
}
[/code]
Don't compare "fprintf" with false. fprintf is a function pointer, and non-zero. This comparison is always false. Also, you have a semicolon after the if condition, which terminates the if expression. Your code is equivalent to this:
[code]
// Does nothing
if (false) { ; }

// Unconditional
{
fprintf(stdout,"Not Working");
}
[/code]
There could be other errors in the surrounding code, this is why I asked you prepare an actual program that will demonstrate the errant behaviour.

Share this post


Link to post
Share on other sites
The OP's problem is he doesn't know how to program. He doesn't understand the very basics. And, he's trying to understand how SDL Events work with a moving mouse.

OP, go back to step 1. Start at "hello world" and go from there. If you don't have the patience to learn for yourself, we won't have the patience to try and help you.

Share this post


Link to post
Share on other sites
Hidden
[quote name='PGSCreativeDirector' timestamp='1317369973' post='4867500']
im trying to make a area of my window area clickable and then when clicked it does what i want it to do[/quote]
Welcome to the world of programming.


L. Spiro

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this