The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Year to fix

Last post 07-08-2008 6:15 PM by SpComb. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-07-2008 5:59 PM

    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 :P

    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;
    // OBSELETE CODE - DOES NOTHING!!!
    /*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 - bbox.top;
    break;
    }
  • 07-08-2008 8:24 AM In reply to

    Re: Year to fix

    Tarn Adams, is that you?
  • 07-08-2008 8:52 AM In reply to

    • Monkios
    • Not Ranked
    • Joined on 10-19-2006
    • Laval, Québec
    • Posts 39

    Re: Year to fix

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

    À cause de la Chartre de la Langue Française, toutes mes réponses doivent se faire en français.

    Ils peuvent également être faits à la fois en français et dans une autre langue pourvu que le français y figure de façon nettement prédominante.


    Because of the Charter of the French language, all my posts must be in French.

    They may also be both in French and in another language provided that French is markedly predominant.
    Filed under:
  • 07-08-2008 6:15 PM In reply to

    Re: Year to fix

    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.

    Filed under:
Page 1 of 1 (4 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems