/* ImageSourceImpl.h - WinRT image wrapper used to render the maps into brushes.
* Copyright (C) 2014 Paulo Pinto
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/

#ifndef IMAGESOURCEIMPL_H
#define IMAGESOURCEIMPL_H

#pragma once

#include "pch.h"

namespace ImageSourceImplementation
{
	public ref class ImageSourceImpl sealed : Windows::UI::Xaml::Media::Imaging::SurfaceImageSource
    {
    public:
		ImageSourceImpl(int pixelWidth, int pixelHeight, bool isOpaque);

        void BeginDraw(Windows::Foundation::Rect updateRect);
        void BeginDraw()    { BeginDraw(Windows::Foundation::Rect(0, 0, (float)m_width, (float)m_height)); }
        void EndDraw();

        void Clear(Windows::UI::Color color);
        void FillSolidRect(Windows::UI::Color color, Windows::Foundation::Rect rect);
		void DrawLine(Windows::UI::Color color, float x0, float yo, float x1, float y1);

		int Width() { return m_width; }
		int Height() { return m_height; }

    private protected:
        void OnSuspending(Platform::Object ^sender, Windows::ApplicationModel::SuspendingEventArgs ^e);
        void CreateDeviceResources();

        // DirectX devices
        Microsoft::WRL::ComPtr<ID3D11Device>                m_d3dDevice;
        Microsoft::WRL::ComPtr<ID2D1Device>                 m_d2dDevice;
        Microsoft::WRL::ComPtr<ID2D1DeviceContext>          m_d2dContext;

        int                                                 m_width;
        int                                                 m_height;
    };
}

#endif /* IMAGESOURCEIMPL_H */