Year to fix

  • Just wanted to share this code snippet for everyone to laugh at that is from a project i had been working on for about 6years. I take full responsibility for it considering it was entirely coded by me as a pet project 😛

    Please bear in mind that when i originally wrote this i had zero formal training in any programming language and was completely self taught.

     The first two comment lines are not dated, and i believe were originally added in 2002.

    		// Please DO NOT ask me HOW this works.. i don't know... it just does....
    // That'll teach me for not putting comments in when i had the chance.
    // Thursday, 29 May 2003 8:09:02 PM -- Had another look at the code... still can't figure out how it works.....
    // Saturday, 15 May 2004 8:00:00 PM -- Changed window.cpp to use Direct3D
    // Saturday, 15 May 2004 9:13:00 PM -- Had another look. FIGURED IT OUT!!
    // difx and dify are the distance of the mouse from the top left of the box (origin)
    // The mouse must be kept this distance at all times when it is first clicked on the title bar.
    // And so we ensure we move it by taking the distance off the current mouse position and
    // setting the box the current mouse minus the difference.
    // The two variables savedmx and savedmy just allow the function to figure out
    // if the mouse has moved from the last call, used to optimize speed.
    // Saturday, 15 May 2004 9:26:00 PM -- HAH!! I just realized the code is crap and i took out a whole chunk
    // and now it works perfectly
    case W_MOUSEMOVE:
    if (mousedown)
    // Move the window to follow the mouse
    int newx = x - difx;
    int newy = y - dify;
    /*if (savedmx != x) // Moved mouse to the right or left
    difx = x - difx;
    newx = difx;
    if (savedmy != y) // Moved mouse up or down
    dify = y - dify;
    newy = dify;

    windowMove(newx, newy); // Window is moving!
    savedmx = x;
    savedmy = y;
    //difx = x - bbox.left;
    //dify = y -;

  • Tarn Adams, is that you?

  • It happens all the time when I code on beer ... 

  • Handling pixel co-ordinates and complicated-shared-state-n:m-producer-consumer-thread-mutexes/events are both things that really shouldn't, but apparently often are, solved using trial-and-error.

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.