📄 viewport.h
字号:
/*
This file is part of SWAIN (http://sourceforge.net/projects/swain).
Copyright (C) 2006 Daniel Lindstr鰉 and Daniel Nilsson
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
// Forward declaration of classes defined in this file, must be before includes.
class ViewPort;
#include "coords.h"
#include "Canvas.h"
#include "Bitmap.h"
// How the zoom depends on the size of the window
#define ZOOMFACTOR (max(width,height))
// Convert from float to pixel coordinates (z = zoom, o = offset/pan, f = float coord)
#define F2P(z,o,f) ((int)( ((f)-(o)) * ((z)*ZOOMFACTOR) ))
// Convert from pixel to float coordinates (z = zoom, o = offset/pan, p = pixel coord)
#define P2F(z,o,p) ((float)((p) / ((z)*ZOOMFACTOR) + (o)))
class ViewPort {
private:
HWND my_hwnd;
HDC screen;
HDC backbuf;
int width, height;
float zoom;
float overzoom;
FPOINT pan;
HBITMAP backbuf_bitmap;
Canvas *canvas;
HPEN pen_standard;
int f2x(float f) { return F2P(zoom, pan.x, f); };
int f2y(float f) { return F2P(zoom, pan.y, f); };
float x2f(int x) { return P2F(zoom, pan.x, x); };
float y2f(int y) { return P2F(zoom, pan.y, y); };
void createBackbuffer(void);
void destroyBackbuffer(void);
public:
ViewPort(HWND hwnd);
~ViewPort(void);
void screenResized(void);
void flip(void);
void flip(FRECT *frect);
void clearRect(FRECT *rect);
void drawPolyLine(FPOINT *points, int count);
void drawPolyLine(FPOINT *points, int count, COLORREF color);
void drawRectangle(float left, float top, float right, float bottom, COLORREF color, int style);
void drawPolygon(FPOINT *points, int count);
void drawBitmap(Bitmap *bitmap, FRECT *dest, RECT *source);
void mouseDown(POINT *p);
void mouseUp(POINT *p);
void mouseDragged(POINT *p);
void redraw(void);
void redraw(RECT *rect);
void invalidate(FRECT *frect);
void invalidate(void);
void alignRect(FRECT *frect);
void expandBoundsHack(FRECT *frect);
void setZoomPan(float z, FPOINT *p);
float getZoom(void);
void getPan(FPOINT *p);
float getMaxZoom(void);
float getMinZoom(void);
void setOverzoom(float f);
void drawDot(int x, int y);
void setCanvas(Canvas *canvas);
void getBounds(FRECT *rect);
void setBounds(FRECT *rect);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -