void DrawPaintPanel()
    {
        var activeBrush = editorData.activeBrush;

        if (Ready && (activeBrush == null || activeBrush.Empty))
        {
            editorData.InitBrushes(tileMap.spriteCollection);
        }

        // Draw layer selector
        if (tileMap.data.NumLayers > 1)
        {
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true));
            GUILayout.Label("Layers", EditorStyles.toolbarButton);  GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            DrawLayersPanel(false);
            EditorGUILayout.Space();
            GUILayout.EndVertical();
        }

        // Brush properties
        string[] toolBarButtonNames = System.Enum.GetNames(typeof(tk2dTileMapEditorBrush.PaintMode));
        editorData.activeBrush.paintMode = (tk2dTileMapEditorBrush.PaintMode)InlineToolbar("Paint mode", (int)editorData.activeBrush.paintMode, toolBarButtonNames);

        // Draw palette
        editorData.showPalette = EditorGUILayout.Foldout(editorData.showPalette, "Palette");
        if (editorData.showPalette)
        {
            // brush name
            string selectionDesc = "";
            if (activeBrush.tiles.Length == 1 && activeBrush.tiles[0].spriteId >= 0)
            {
                selectionDesc = SpriteCollection.spriteDefinitions[activeBrush.tiles[0].spriteId].name;
            }
            GUILayout.Label(selectionDesc);

            // palette
            Rect  rect         = brushRenderer.DrawBrush(tileMap, editorData.paletteBrush, editorData.brushDisplayScale, true, editorData.paletteTilesPerRow);
            float displayScale = brushRenderer.LastScale;

            Rect tileSize = new Rect(0, 0, brushRenderer.TileSizePixels.width * displayScale, brushRenderer.TileSizePixels.height * displayScale);
            guiBrushBuilder.HandleGUI(rect, tileSize, editorData.paletteTilesPerRow, tileMap.spriteCollection, activeBrush);
            EditorGUILayout.Separator();
        }
        EditorGUILayout.Separator();

        // Draw brush
        editorData.showBrush = EditorGUILayout.Foldout(editorData.showBrush, "Brush");
        if (editorData.showBrush)
        {
            brushRenderer.DrawBrush(tileMap, editorData.activeBrush, editorData.brushDisplayScale, false, editorData.paletteTilesPerRow);
            EditorGUILayout.Separator();
        }
    }
	void DrawPaintPanel()
	{
		var activeBrush = editorData.activeBrush;
		
		if (Ready && (activeBrush == null || activeBrush.Empty))
		{
			editorData.InitBrushes(tileMap.SpriteCollectionInst);
		}
		
		// Draw layer selector
		if (tileMap.data.NumLayers > 1)
		{
			GUILayout.BeginVertical();
			GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true));
			GUILayout.Label("Layers", EditorStyles.toolbarButton);	GUILayout.FlexibleSpace();	
			GUILayout.EndHorizontal();
			DrawLayersPanel(false);
			EditorGUILayout.Space();
			GUILayout.EndVertical();
		}

#if TK2D_TILEMAP_EXPERIMENTAL
		DrawLoadSaveBrushSection(activeBrush);
#endif

		// Draw palette
		if (!showLoadSection && !showSaveSection)
		{
			editorData.showPalette = EditorGUILayout.Foldout(editorData.showPalette, "Palette");
			if (editorData.showPalette)
			{
				// brush name
				string selectionDesc = "";
				if (activeBrush.tiles.Length == 1) {
					int tile = tk2dRuntime.TileMap.BuilderUtil.GetTileFromRawTile(activeBrush.tiles[0].spriteId);
					if (tile >= 0 && tile < SpriteCollection.spriteDefinitions.Length)
						selectionDesc = SpriteCollection.spriteDefinitions[tile].name;
				}
				GUILayout.Label(selectionDesc);
			
				
				Rect innerRect = brushRenderer.GetBrushViewRect(editorData.paletteBrush, editorData.paletteTilesPerRow);
				paletteScrollPos = BeginHScrollView(paletteScrollPos, GUILayout.MinHeight(innerRect.height * editorData.brushDisplayScale + 32.0f));
				innerRect.width *= editorData.brushDisplayScale;
				innerRect.height *= editorData.brushDisplayScale;
				tk2dGrid.Draw(innerRect);

				// palette
				Rect rect = brushRenderer.DrawBrush(tileMap, editorData.paletteBrush, editorData.brushDisplayScale, true, editorData.paletteTilesPerRow);
				float displayScale = brushRenderer.LastScale;
				
				Rect tileSize = new Rect(0, 0, brushRenderer.TileSizePixels.width * displayScale, brushRenderer.TileSizePixels.height * displayScale);
				guiBrushBuilder.HandleGUI(rect, tileSize, editorData.paletteTilesPerRow, tileMap.SpriteCollectionInst, activeBrush);
				EditorGUILayout.Separator();

				EndHScrollView();
			}
			EditorGUILayout.Separator();
		}

		// Draw brush
		if (!showLoadSection)
		{
			editorData.showBrush = EditorGUILayout.Foldout(editorData.showBrush, "Brush");
			if (editorData.showBrush)
			{
				GUILayout.BeginHorizontal();
				EditorGUILayout.PrefixLabel("Cursor Tile Opacity");
				tk2dTileMapToolbar.workBrushOpacity = EditorGUILayout.Slider(tk2dTileMapToolbar.workBrushOpacity, 0.0f, 1.0f);
				GUILayout.EndHorizontal();

				Rect innerRect = brushRenderer.GetBrushViewRect(editorData.activeBrush, editorData.paletteTilesPerRow);
				activeBrushScrollPos = BeginHScrollView(activeBrushScrollPos, GUILayout.MinHeight(innerRect.height * editorData.brushDisplayScale + 32.0f));
				innerRect.width *= editorData.brushDisplayScale;
				innerRect.height *= editorData.brushDisplayScale;
				tk2dGrid.Draw(innerRect);
				brushRenderer.DrawBrush(tileMap, editorData.activeBrush, editorData.brushDisplayScale, false, editorData.paletteTilesPerRow);
				EndHScrollView();
				EditorGUILayout.Separator();
			}
		}
	}