

fnc_drawMap = {
	with uiNamespace do {
		if(!isNull (findDisplay 12) && !nou_maphandleradded) then {
			_height = 15;
			_width = 15;
			_idc = 11001;
			_mapPos = ctrlPosition ((findDisplay 12) displayCtrl 51);
			_bg = (findDisplay 12) ctrlCreate ["RscText", 6533];
			_bg ctrlSetBackgroundColor [1,1,1,1];
			_bg ctrlSetPosition _mapPos;
			_bg ctrlCommit 0;
			
			if(!isNil "nou_tiles") then {
				{
					{
						ctrlDelete _x;
					} forEach _x;
				
				} forEach nou_tiles;
			};
			
			nou_tiles = [];
			for "_y" from 0 to _height-1 do {
				nou_tiles pushBack [];
				for "_x" from 0 to _width-1 do {
					(nou_tiles select _y) set[_x, ((findDisplay 12) ctrlCreate ["RscPicture", _idc])];
					_idc = _idc + 1;
				};
			};
			
		
		
			nou_maphandleradded = true;
			
			
			((findDisplay 12) displayCtrl 51) ctrlShow false;
			((findDisplay 12) displayCtrl 51) ctrlCommit 0;
			
			((findDisplay 12) displayCtrl 51) ctrlCommit 0;
			
			nou_map = (findDisplay 12) ctrlCreate ["NouTestMap", 51];
			nou_map ctrlSetPosition _mapPos;
			nou_map ctrlCommit 0;
			nou_map ctrlAddEventHandler ["Draw",{ _this call fnc_drawMapActual; }];
		};
	};
};

fnc_drawMapActual = {
	with uiNamespace do {
		_map = nou_map;
		
		// ((findDisplay 12) displayCtrl 51) ctrlSetPosition [0,0,0,0];
		// ((findDisplay 12) displayCtrl 51) ctrlCommit 0;
		
		_mouseOver = _disp displayCtrl 1016;
		_mouseOver ctrlSetTextColor [0,0,0,0];
		_pos1 = _map ctrlMapWorldToScreen [2048,0,0];
		_pos2 = _map ctrlMapWorldToScreen [0,2048,0];
		
		_width = (_pos1 select 0)-(_pos2 select 0);
		_height = (_pos1 select 1)-(_pos2 select 1);
		
		_mapWidth = 15;
		_mapHeight = 15;
		_scale = (ctrlMapScale _map);
		_size = 512;
		if(_scale < 0.6) then {
			if(_scale > 0.17) then {
				_size = 1024;
			} else {
				_size = 2048;
			};
		};
		_size = 2048;
		
		for "_y" from 0 to _mapHeight-1 do {
			for "_x" from 0 to _mapWidth-1 do {
				_tile = (nou_tiles select _y) select _x;
				_tilePos = [(_pos2 select 0)+(_width*_x), (_pos2 select 1)-(_height*_y), _width, _height];
				_tile ctrlSetPosition _tilePos;
				_tile ctrlSetText format["altis_%1_%2_%3_ca.paa", _x, _y, _size];
				_tile ctrlCommit 0;
			};
		};
		
		_mapSize = (ceil ((4096*7.5)/1000));
		_mapSizeM = (4096*7.5);
		// player sideChat format["_mapSize: %1", _mapSize];
		// _map drawLine [[0,0,0], [1000,1000,0], [1,1,0,1]];
		
		_pos2 = [0, _mapSizeM];
		_pos1 = [-8000, 0];
		_width = (_pos2 select 0)-(_pos1 select 0);
		_height = (_pos2 select 1)-(_pos1 select 1);
		
		
		_map drawRectangle [[(_pos1 select 0)+(_width/2), (_pos1 select 1)+(_height/2)], (_width/2), (_height/2), 0, [1,1,1,1], "#(argb,8,8,3)color(1,1,1,1)"];
		
		
		_pos2 = [_mapSizeM+8000, 0];
		_pos1 = [-8000, -8000];
		_width = (_pos2 select 0)-(_pos1 select 0);
		_height = (_pos2 select 1)-(_pos1 select 1);
		
		
		_map drawRectangle [[(_pos1 select 0)+(_width/2), (_pos1 select 1)+(_height/2)], (_width/2), (_height/2), 0, [1,1,1,1], "#(argb,8,8,3)color(1,1,1,1)"];
		
		
		_pos2 = [_mapSizeM, 0];
		_pos1 = [_mapSizeM+8000, _mapSizeM];
		_width = (_pos2 select 0)-(_pos1 select 0);
		_height = (_pos2 select 1)-(_pos1 select 1);
		
		
		_map drawRectangle [[(_pos1 select 0)+(_width/2), (_pos1 select 1)+(_height/2)], (_width/2), (_height/2), 0, [1,1,1,1], "#(argb,8,8,3)color(1,1,1,1)"];
		
		_pos2 = [-8000, _mapSizeM];
		_pos1 = [_mapSizeM+8000, _mapSizeM+8000];
		_width = (_pos2 select 0)-(_pos1 select 0);
		_height = (_pos2 select 1)-(_pos1 select 1);
		
		
		_map drawRectangle [[(_pos1 select 0)+(_width/2), (_pos1 select 1)+(_height/2)], (_width/2), (_height/2), 0, [1,1,1,1], "#(argb,8,8,3)color(1,1,1,1)"];

		for "_y" from 0 to _mapSize-1 do {
			_map drawLine [[0, 1000*_y, 0], [_mapSizeM, 1000*_y, 0], [0,0,0,1]];
			// _map draw
		};
		for "_x" from 0 to _mapSize-1 do {
			// _map drawIcon ["", [1,0,0,1], [1000*_x, -100, 0], 100, 100, 0, "FFF", 0, 1, "TahomaB", "center"];
			_map drawLine [[1000*_x, 0, 0], [1000*_x, _mapSizeM, 0], [0,0,0,1]];
		};
	};
};