Newer
Older
Import / research / match3 / windowing.h
@John John on 29 Dec 2020 993 bytes bulk import from macbookpro checkouts
//  C/C++ API for Mac OS X Windowing - windowing.h
//  Created by John Ryland (jryland@xiaofrog.com), 29/10/2017
//  Copyright (c) 2017 InvertedLogic
//  All rights reserved.
#pragma once
#include <stdint.h>
#include "canvas.h"

class Application
{
public:
  Application();
  int run();
  virtual void onStart() = 0;
};

class Window
{
public:
  Window() { buffer.w = buffer.h = 0; }
  ~Window();
  void create(int w, int h);
  int getWidth() { return buffer.w; }
  int getHeight() { return buffer.h; }
  virtual void onDraw(int x1, int y1, int x2, int y2) = 0;
  virtual void onResize(int w, int h);
  virtual void onMouseEvent(int x, int y, int buttons) {}
  virtual void onTimerEvent() {}
  void refresh();
  void flush();
protected:
  void* window;
  void* view;
  Image buffer;
};

class CanvasWindow : public Window
{
public:
  CanvasWindow();
  void onDraw(int x1, int y1, int x2, int y2);
  void setFrameRate(int a_fps);
  bool drawn;
  uint32_t delay;
protected:
  Canvas canvas;
};