#ifndef __LISACANVASH__
#define __LISACANVASH__
#include <wx/wx.h>

#include "LisaConfigFrame.h"
#include "LisaConfig.h"

enum
{
    VIDEO_UNCORRECTED,
    VIDEO_CORRECTED,
    VIDEO_ENHANCED,
};

class LisaCanvas: public wxScrolledWindow
{
    public:
        // constructors
        LisaCanvas(wxWindow *parent);
        ~LisaCanvas();
        
        // External interface for others to control the emulation
        void SetThrottleSpeed(int hertz);
        int  GetThrottleSpeed();
        void SetRawKeyboard(bool raw);
        bool IsRawKeyboard();        
        void SetSkinOn(bool skin);
        bool IsSkinOn();
        void SetPowerOn(bool power);
        bool IsPowerOn();
        void SetPaused(bool paused);
        bool IsPaused();
        void SetVideoMode(int mode);
        int  GetVideoMode();
        
        void InsertFloppy(const wxString& floppy);
        bool IsFloppyPresent();
        
        // GUI event handlers
        void OnPaint(wxPaintEvent &event);
        void OnSize(wxSizeEvent &event);
        void OnMouseEvent(wxMouseEvent &event);
        void OnKeyDown(wxKeyEvent& event);
        void OnKeyUp(wxKeyEvent& event);
        void OnChar(wxKeyEvent& event);
        
        void OnFloppyTimer(wxTimerEvent &event);
        void OnPowerTimer(wxTimerEvent &event);
        void OnEmulationTimer(wxTimerEvent &event);
    
    private:
        void RefreshVirtualRect(int x, int y, int width, int height);
        void BlitVirtualRect(wxDC* src, int x, int y, int width, int height);
        void FixupScrollbars(void);
        
        void SkinLoad(void);
        void SkinDispose(void);
        void CreateCursor(void);
        void InitVideo(void);
        
        void DoSetSkinOn(bool skin, bool update_parent);
        
        void UpdateContrast(void);
        void UpdateVideo(void);
        void UpdateVideoUncorrected(void);
        void UpdateVideoCorrected(void);
        void UpdateVideoEnhanced(void);

        void StartEmulation(void);
        void StopEmulation(void);
        void RunEmulationFor(int cycles);
        void SendKeyEvent(int keycode, int keydir);
        
        void EjectFloppy(void);
        
        wxBitmap* m_lisa_bmp;
        wxBitmap* m_floppy0_bmp;
        wxBitmap* m_floppy1_bmp;
        wxBitmap* m_floppy2_bmp;
        wxBitmap* m_floppy3_bmp;
        wxBitmap* m_floppyN_bmp;
        wxBitmap* m_poweron_bmp;
        wxBitmap* m_video_bmp;
        wxBitmap* m_video_byte_bmp;
        
        wxMemoryDC* m_lisa_dc;
        wxMemoryDC* m_floppy0_dc;
        wxMemoryDC* m_floppy1_dc;
        wxMemoryDC* m_floppy2_dc;
        wxMemoryDC* m_floppy3_dc;
        wxMemoryDC* m_floppyN_dc;
        wxMemoryDC* m_poweron_dc;
        wxMemoryDC* m_video_dc;
        wxMemoryDC* m_video_byte_dc;

        wxCursor* m_dot_cursor;

        int m_throttle_speed;

        bool m_skin;
        bool m_power;
        bool m_paused;
        bool m_raw_keyboard;

        wxTimer* m_floppy_timer;
        wxTimer* m_power_timer;
        wxTimer* m_emulation_timer;

        int m_floppy, m_targ_floppy;
        int m_power_step, m_targ_power;
        
        char *m_floppy_to_insert;
        
        int m_video_mode;
        unsigned char *m_vram;
        /* Need to redraw the video DC based on contents of VRAM */
        int m_redraw_video_dc;
        /* The bounding rect of the video DC that changed since last update */
        int m_dirty_x_min;
        int m_dirty_x_max;
        int m_dirty_y_min;
        int m_dirty_y_max;
        wxColor* m_black;
        wxColor* m_med_grey;
        wxColor* m_white;

        /* This might be better handled by the app/frame, not us */
        LisaConfigFrame* m_lisa_configframe;
        LisaConfig* m_lisa_config;
        wxFileConfig* m_file_config;
        
        DECLARE_EVENT_TABLE()
};
#endif