Exemplo n.º 1
0
Arquivo: axGrid.cpp Projeto: EQ4/axLib
void axGrid::OnPaint()
{
	axGC* gc = GetGC();
	axRect rect(GetRect());
	axRect rect0(axPoint(0, 0), rect.size);

	gc->SetColor(_info.normal, 1.0);
	gc->DrawRectangle(rect0);

	gc->SetColor(_info.contour, 1.0);

	int y = 0;
	glLineWidth(1.0);
	for(int j = 0; j <= _dimension.y; j++)
	{
		int y = (double(j) / _dimension.y) * rect.size.y;
		gc->DrawLine(axPoint(0, y), axPoint(rect.size.x, y));
	}

	int x = 0;
	for(int i = 0; i <= _dimension.x; i++)
	{
		int x = (double(i) / _dimension.x) * rect.size.x;
		gc->DrawLine(axPoint(x, 0), axPoint(x, rect.size.y));
	}

	axSize element_size(1.0 / _dimension.x * rect.size.x - 1, 
						1.0 / _dimension.y * rect.size.y - 1);
	for(int j = 0;j < _dimension.y; j++)
	{
		for(int i = 0; i < _dimension.x; i++)
		{
			if(_gridElements[j][i].on)
			{
				gc->SetColor(_gridElements[j][i].color);

				axSize elem_size(floor((double(i+1)/ _dimension.x * rect.size.x)) - 
								 floor((double(i) / _dimension.x * rect.size.x)) - 1,
								1.0 / _dimension.y * rect.size.y - 1);
				gc->DrawRectangle(axRect(_gridElements[j][i].position, elem_size));
			}
		}
	}



	//_selectedElement
	gc->SetColor(axColor(0.0, 0.0, 1.0));
	//glLineWidth(4.0);
	gc->DrawRectangleContour(axRect(GetPositionOfElement(_selectedElement), element_size), 2);

	// glLineWidth(1.0);

	// gc->DrawCircle(axPoint(50, 50), 10, 500);

}
int main()
{
    List myList;
    int exit, val, pos;
    char command;


        myList = CreateList();

        exit = FALSE;

        while (!exit)
        {
               fflush(stdin);
               printf("\nEnter command \n\ni)nitialize \nn)ew element \nd)elete element \nf)ind element \np)osition of element \nh)ead of list \nt)ail of list \ns)orted insert \ne)xit\n\nCOMMAND: ");
               scanf("%c", &command);
               fflush(stdin);

                  switch(command)
                  {
                         case 'i':
                                MakeEmptyList(myList);
                                break;
                         case 'n':
                                printf("enter value: ");
                                scanf("%d", &val);
                                printf("enter position: ");
                                scanf("%d", &pos);
                                InsertList(myList, pos, val);
                                break;
                         case 'd':
                                printf("enter value: ");
                                scanf("%d", &val);
                                DeleteList(myList, val);
                                break;
                         case 'p':
                                printf("enter value: ");
                                scanf("%d", &val);
                                pos = GetPositionOfElement(myList, val);
                                if (pos > 0)
                                    printf("element %d at position %d\n", val, pos);
                                break;
                         case 'f':
                                printf("enter position: ");
                                scanf("%d", &pos);
                                val = GetElementAtPosition(myList, pos);
                                if (val >= 0)
                                    printf("element at position %d is %d\n", pos, val);
                                break;
                          case 'h':
                                val = HeadOfList(myList);
                                if (val != -1)
                                       printf("front element is %d\n", val);
                                break;
                          case 't':
                                val = TailOfList(myList);
                                if (val != -1)
                                       printf("rear element is %d\n", val);
                                break;
                         case 'e':
                                exit = TRUE;
                                break;

                         case 's':

                              printf("enter value: ");
                              scanf("%d", &val);
                              sortedInsert (myList, val);

                              break;
                         default:
                                 printf("command not recognized\n");
                                 break;
                  }
                  DisplayList(myList);

        }

        printf("\n\n");
        system("PAUSE");
        return 0;
}