Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <math.h>
- #include <fstream>
- #include <sstream>
- #include <vector>
- #include <tchar.h>
- using namespace std;
- static int Flag=0;
- static vector<int> AllPoints;
- LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
- TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");
- int Round(double x)
- {
- return (int)(x + 0.5);
- }
- void save(int x,int y)
- {
- AllPoints.push_back(x);
- AllPoints.push_back(y);
- }
- void Extract()
- {
- ofstream out;
- out.open("text.txt");
- for(int i = 0; i<AllPoints.size(); i+=2)
- out << AllPoints[i] << "," << AllPoints[i+1] << ",";
- out.close();
- }
- //CARTESIN
- void DrawLine1(HDC hdc, int x1, int y1, int x2, int y2, COLORREF c)
- {
- int dx=(x2-x1),dy=(y2-y1);
- if(abs(dx)>=abs(dy))
- {
- if(x1 > x2)
- {
- swap(x1,x2);
- swap(y1,y2);
- }
- double slope = (double)dy/dx;
- for(int x=x1; x<x2; x++)
- {
- double y = y1 + (x - x1)*slope;
- SetPixel(hdc, x, Round(y), c);
- save(x,Round(y));
- }
- }
- else
- {
- if(y1 > y2)
- {
- swap(x1,x2);
- swap(y1,y2);
- }
- double slope = (double)dx/dy;
- for(int y=y1; y<y2; y++)
- {
- double x = x1 + (y - y1)*slope;
- SetPixel(hdc, Round(x), y, c);
- save(Round(x),y);
- }
- }
- }
- void Draw8Points(HDC hdc, int x, int y, int xc,int yc, COLORREF c)
- {
- save(xc+x,yc+y);
- save(xc-x,yc+y);
- save(xc-x,yc-y);
- save(xc+x,yc-y);
- save(xc+y,yc+x);
- save(xc-y,yc+x);
- save(xc-y,yc-x);
- save(xc+y,yc-x);
- SetPixel(hdc, xc+x, yc+y, c);
- SetPixel(hdc, xc-x, yc+y, c);
- SetPixel(hdc, xc-x, yc-y, c);
- SetPixel(hdc, xc+x, yc-y, c);
- SetPixel(hdc, xc+y, yc+x, c);
- SetPixel(hdc, xc-y, yc+x, c);
- SetPixel(hdc, xc-y, yc-x, c);
- SetPixel(hdc, xc+y, yc-x, c);
- }
- //MIDPOINT CIRCLE
- void DrawCircle3(HDC hdc,int xc, int yc, int R, COLORREF c)
- {
- int x = R , y = 0;
- int d = 1 - R;
- Draw8Points(hdc,Round(x),Round(y),xc,yc,c);
- while(x > y)
- {
- if(x==0)
- cout<< x << " " << y << " " << d<<endl;
- int d1 = 2*y + 3;
- int d2 = 2*(y-x) + 5;
- if(d<0)
- {
- d+=d1;
- y++;
- }
- else
- {
- d+=d2;
- y++;
- x--;
- }
- Draw8Points(hdc,Round(x),Round(y),xc,yc,c);
- }
- }
- void Sorting(vector<int> &arr,string Nums)
- {
- stringstream ss(Nums);
- for (int i; ss >> i;) {
- arr.push_back(i);
- if (ss.peek() == ',')
- ss.ignore();
- }
- }
- void prev(HDC hdc,vector<int> numbers,COLORREF c)
- {
- for(int i = 0; i<numbers.size(); i+=2)
- {
- SetPixel(hdc,numbers[i],numbers[i+1],c);
- }
- }
- static int x1, y1,x2,y2,x,y,xc,yc;
- LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT mcode, WPARAM wp, LPARAM lp)
- {
- string line;
- vector<int> vect;
- ifstream in;
- HDC hdc;
- double R;
- switch (mcode)
- {
- case WM_LBUTTONDOWN:
- if(Flag == 0)
- {
- remove( "text.txt" );
- Flag = 1;
- }
- xc = LOWORD(lp);
- yc = HIWORD(lp);
- break;
- case WM_LBUTTONUP:
- if(Flag == 0)
- {
- remove( "text.txt" );
- Flag = 1;
- }
- x = LOWORD(lp);
- y = HIWORD(lp);
- hdc = GetDC(hWnd);
- R = Round(sqrt(pow(x-xc,2.0)+pow(y-yc,2.0)));
- DrawCircle3(hdc, xc, yc, R, RGB(255,255,255));
- ReleaseDC(hWnd, hdc);
- break;
- case WM_RBUTTONDOWN:
- if(Flag == 0)
- {
- remove( "text.txt" );
- Flag = 1;
- }
- xc = LOWORD(lp);
- yc = HIWORD(lp);
- break;
- case WM_RBUTTONUP:
- if(Flag == 0)
- {
- remove( "text.txt" );
- Flag = 1;
- }
- x = LOWORD(lp);
- y = HIWORD(lp);
- hdc = GetDC(hWnd);
- DrawLine1(hdc, xc, yc, x, y, RGB(255, 255, 255));
- ReleaseDC(hWnd, hdc);
- break;
- case WM_KEYDOWN:
- if ( wp == 'L' )
- {
- in.open("text.txt");
- getline(in, line);
- Sorting(vect, line);
- hdc = GetDC(hWnd);
- AllPoints = vect;
- prev(hdc,vect,RGB(255,255,255));
- in.close();
- }
- if ( wp == 'S' )
- {
- Extract();
- }
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, mcode, wp, lp);
- }
- return 0;
- }
- int WINAPI WinMain (HINSTANCE hThisInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpszArgument,
- int nCmdShow)
- {
- HWND hwnd; /* This is the handle for our window */
- MSG messages; /* Here messages to the application are saved */
- WNDCLASSEX wincl; /* Data structure for the windowclass */
- /* The Window structure */
- wincl.hInstance = hThisInstance;
- wincl.lpszClassName = szClassName;
- wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
- wincl.style = CS_DBLCLKS; /* Catch double-clicks */
- wincl.cbSize = sizeof (WNDCLASSEX);
- /* Use default icon and mouse-pointer */
- wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
- wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
- wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
- wincl.lpszMenuName = NULL; /* No menu */
- wincl.cbClsExtra = 0; /* No extra bytes after the window class */
- wincl.cbWndExtra = 0; /* structure or the window instance */
- /* Use Windows's default colour as the background of the window */
- wincl.hbrBackground = (HBRUSH) 10;
- /* Register the window class, and if it fails quit the program */
- if (!RegisterClassEx (&wincl))
- return 0;
- /* The class is registered, let's create the program*/
- hwnd = CreateWindowEx (
- 0, /* Extended possibilites for variation */
- szClassName, /* Classname */
- _T("Code::Blocks Template Windows App"), /* Title Text */
- WS_OVERLAPPEDWINDOW, /* default window */
- CW_USEDEFAULT, /* Windows decides the position */
- CW_USEDEFAULT, /* where the window ends up on the screen */
- 1000, /* The programs width */
- 600, /* and height in pixels */
- HWND_DESKTOP, /* The window is a child-window to desktop */
- NULL, /* No menu */
- hThisInstance, /* Program Instance handler */
- NULL /* No Window Creation data */
- );
- /* Make the window visible on the screen */
- ShowWindow (hwnd, nCmdShow);
- /* Run the message loop. It will run until GetMessage() returns 0 */
- while (GetMessage (&messages, NULL, 0, 0))
- {
- /* Translate virtual-key messages into character messages */
- TranslateMessage(&messages);
- /* Send message to WindowProcedure */
- DispatchMessage(&messages);
- }
- /* The program return-value is 0 - The value that PostQuitMessage() gave */
- return messages.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement