Esempio n. 1
0
void handleMouseDrag()
{
  if (drag_state == 0)
  {
    pwque = getDraggedWindowQueue();
    if (pwque)
    {
      drag_state = 1;
      if (pwque != lastWindow && pwque != &windowLine[0])
        reorderQueue(pwque);
    }
    else
      drag_state = 2;
  }
  else
  if (drag_state == 1)
  {
    switchuvm(pwque->proc);
    counter = (counter + 1) % 20;
    if (counter == 0)
      isdraw = 1;
    else
      isdraw = 0;
    moveWindow(pwque->window, mouse_info.x_position, mouse_info.y_position, down_pos_x, down_pos_y, isdraw);
  }
  if (proc == 0)
    switchkvm();
  else
    switchuvm(proc);
}
Esempio n. 2
0
File: Graph.c Progetto: dejarc/Graph
/*to calculate the shortest paths to all cities from a givern vertex
@param mySource the name of the starting city, prints error message if
not present
*/
void shortestPath(char *mySource) {
    int index;
    int source_present = FALSE;
    queue myQueue = createQueue();
    for(index = 0; index < myGraph->num_vertexes; index++) {
        if(strcmp(mySource, myGraph->allVertexes[index]->name) == 0) {
            myGraph->allVertexes[index]->cost = 0;
            strcpy(myGraph->allVertexes[index]->cheap_source, myGraph->allVertexes[index]->name);
            source_present = TRUE;
        }
        addToQueue(myQueue, createNode(myGraph->allVertexes[index]));
    }
    if(!source_present) {
        printf("\nThat city doesn't exist!");
        return;
    }
    while(!isEmpty(myQueue)) {
        node temp = pop(myQueue);
        if(temp->myVertex->cost == INT_MAX)
            break;
        for(index = 0; index < temp->myVertex->num_edges; index++) {
            if(temp->myVertex->myEdges[index]->cost + temp->myVertex->cost < temp->myVertex->myEdges[index]->destination->cost) {
                temp->myVertex->myEdges[index]->destination->cost = temp->myVertex->myEdges[index]->cost + temp->myVertex->cost;
                strcpy(temp->myVertex->myEdges[index]->destination->cheap_source, temp->myVertex->name);
                reorderQueue(myQueue, temp->myVertex->myEdges[index]->destination);
            }
        }
        free(temp);
    }
    for(index = 0; index < myGraph->num_vertexes; index++) {
        printf("\nthe cheapest path to %s is %d from %s", myGraph->allVertexes[index]->name, myGraph->allVertexes[index]->cost,
               myGraph->allVertexes[index]->cheap_source);
    }
    free(myQueue);
}
Esempio n. 3
0
void handleLeftClick()
{
  WindowQueue *pwindowQueue;
  Widget *pwidget;

  pwindowQueue = getClickedWindowQueue();
  if (pwindowQueue)
  {
    if (pwindowQueue != lastWindow && pwindowQueue == &windowLine[0])
    {
      if (proc == 0)
        switchkvm();
      else
        switchuvm(proc);
      return;
    }
    if (pwindowQueue != lastWindow  && pwindowQueue != &windowLine[0])
    {
      focusDismiss();
      reorderQueue(pwindowQueue);
      switchuvm(pwindowQueue->proc);
    }
    pwidget = getClickedWidget(pwindowQueue->window);
    if (pwidget)
    {
      switch (pwidget->type)
      {
      case button:
        focusDismiss();
        switchuvm(pwindowQueue->proc);
        pwidget->context.button->onLeftClickHandler.triggered = 1;
        break;
      case imageView:
        focusDismiss();
        switchuvm(pwindowQueue->proc);
        pwidget->context.imageView->onLeftClickHandler.triggered = 1;
        break;
      case iconView:
        focusIconView(pwidget->context.iconView);
        break;
      default:
        focusDismiss();
        switchuvm(pwindowQueue->proc);
        break;
      }
    }
    else
    {
        focusDismiss();
        switchuvm(pwindowQueue->proc);
    }
  }
  if (proc == 0)
    switchkvm();
  else
    switchuvm(proc);
}
Esempio n. 4
0
File: Graph.c Progetto: dejarc/Graph
/*calculates the shortest distance between a source and destination city using
djikstra's shortest path algorithm and a priority queue.
@param source_name the name of the starting city
@param destination_name the name of the destination city
*/
void shortestPathBetweenPriorityQueue(char* source_name, char* destination_name) {
    queue myQueue = createQueue();
    vertex sourceVertex = NULL;
    int index;
    int destination_exists = FALSE;
    for(index = 0; index < myGraph->num_vertexes; index++) {
        if(strcmp(myGraph->allVertexes[index]->name, source_name) == 0) {
            myGraph->allVertexes[index]->cost = 0;
            sourceVertex = myGraph->allVertexes[index];
        }
        if(strcmp(myGraph->allVertexes[index]->name, destination_name) == 0)
            destination_exists = TRUE;
        addToQueue(myQueue, createNode(myGraph->allVertexes[index]));
    }
    if(sourceVertex == NULL || !destination_exists) {
        printf("\none of the cities doesn't exist!");
        return;
    }
    while(!isEmpty(myQueue)) {
        node temp = pop(myQueue);
        if(temp->myVertex->cost == INT_MAX)//no connection exists break out of the loop
            break;
        if(strcmp(temp->myVertex->name, destination_name) == 0) {//destination has been found, break
            sourceVertex = temp->myVertex;
            free(temp);
            break;
        }
        for(index = 0; index < temp->myVertex->num_edges; index++) {
            //if the cost has been decreased reset the cost, copy the new cheap source, and reorder the queue storing the nodes
            if(temp->myVertex->myEdges[index]->cost + temp->myVertex->cost < temp->myVertex->myEdges[index]->destination->cost) {
                temp->myVertex->myEdges[index]->destination->cost = temp->myVertex->myEdges[index]->cost + temp->myVertex->cost;
                strcpy(temp->myVertex->myEdges[index]->destination->cheap_source, temp->myVertex->name);
                reorderQueue(myQueue, temp->myVertex->myEdges[index]->destination);
            }
        }
        free(temp);
    }
    if(strcmp(sourceVertex->name, destination_name) == 0) {
        printf("\nthe cheapest cost to get to %s is %d miles", sourceVertex->name, sourceVertex->cost);
        queue myStack = createQueue();
        push(myStack, createNode(sourceVertex));
        while(strcmp(sourceVertex->name,source_name) != 0) {//used to back trace the path in the map
            for(index = 0; index < myGraph->num_vertexes; index++) {
                if(strcmp(sourceVertex->cheap_source, myGraph->allVertexes[index]->name) == 0) {
                    sourceVertex = myGraph->allVertexes[index];
                    break;
                }
            }
            push(myStack, createNode(sourceVertex));
        }
        node temp = pop(myStack);
        int edge_length = temp->myVertex->cost;
        printf("\nfrom %s with a cost of %d", temp->myVertex->name, edge_length);
        free(temp);
        while(!isEmpty(myStack)) {
            node myTop = pop(myStack);
            edge_length = myTop->myVertex->cost - edge_length;
            printf("\nto %s with cost of %d", myTop->myVertex->name, edge_length);
            edge_length = myTop->myVertex->cost;
            free(myTop);
        }
        free(myStack);
    } else {
        printf("\nno connection exists between the two points");
    }
    free(myQueue);
}