how to render an object on the screen using the mouse coordinate

Source: www.stackoverflow.com

My question is more about the for loops. I’ve been working on this all night but just can’t grasp how to do this. I slightly understand what this function is doing but what i wanna know is how to add the mouse_x and the mouse_y to the list so i can have my render function render the image to the screen. I’m still converting the render function to a dynamic array format so i can’t post that code just yet. can someone help me out here?

#define CAP 2       /* initial capacity for new struct */

struct blockhead_node{
    int x, y;
    int dx, dy;
    size_t size, capacity;
    int *data;
};

void add_blockhead_for_mouse(struct blockhead_node * blockhead_list, int v, double mx, double my) // double pointer because we can't modify the lost it self
{

    // account 4 mx and my
    //mx and my is a double for accuracy and rounding error could be a problem
    if (!blockhead_list->capacity || blockhead_list->size == blockhead_list->capacity) {
        size_t newsize;
        if (!blockhead_list->capacity)                   /* new stuct, set size = CAP */
            newsize = CAP;
        else if (blockhead_list->size == blockhead_list->capacity)    /* otherwise double size */
            newsize = blockhead_list->capacity * 2;
        /* alway realloc with a temporary pointer */
        void *temp = realloc (blockhead_list->data, newsize * sizeof *blockhead_list->data);
        if (!temp) {     /* validate reallocation */
            perror ("realloc_b->data");
            return 0;   /* return failure */
        }
        blockhead_list->data = temp;          /* assign new block of memory to data */
        blockhead_list->capacity = newsize;  /* set capacity to newsize */
    }

    blockhead_list->data[blockhead_list->size++] = v;     /* set data value to v */

    for (int c = 0; c >= blockhead_list; c++)
    {
        reallc(blockhead_list->size[0] + 1 = blockkhead_list->data; //adding memory
        blockhead_list[0][-1] = mx; //add a bkhd to the end of the list

    }
    for (int q = 0; q >= blockhead_list; q++)
    {
        reallc(blockhead_list->size[1] + 1 = blockkhead_list->data; //adding memory
        blockhead_list->size[1][-1] = my; //add a blockhead to the end of the list

    }


    if((blockhead_list)->x + (blockhead_list)->size > screen_width)
    {
        (blockhead_list)->x = screen_width - (blockhead_list)->size;
    }
    if((blockhead_list)->y + (blockhead_list)->size > screen_height)
    {
        (blockhead_list)->y = screen_height - (blockhead_list)->size;
    }

    return 1;   /* return success */


}

Read More Here, go to stackoverflow Author of this News
Author: Jason West

Leave a Reply

Your email address will not be published. Required fields are marked *