PageRenderTime 31ms CodeModel.GetById 14ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/win/scaffold/view.d

http://github.com/wilkie/djehuty
D | 152 lines | 94 code | 43 blank | 15 comment | 3 complexity | 054ac9078e313a0198724ab776ed898a MD5 | raw file
  1/*
  2 * view.d
  3 *
  4 * This file implements the Scaffold for platform specific View
  5 * operations in Windows.
  6 *
  7 * Author: Dave Wilkinson
  8 *
  9 */
 10
 11module scaffold.view;
 12
 13import platform.win.common;
 14import platform.win.main;
 15
 16import Gdiplus = binding.win32.gdiplus;
 17
 18import platform.vars.view;
 19import platform.vars.window;
 20
 21import gui.window;
 22
 23import graphics.view;
 24import graphics.graphics;
 25import graphics.bitmap;
 26
 27import core.string;
 28import core.main;
 29import core.definitions;
 30
 31import data.queue;
 32
 33import io.console;
 34
 35// views
 36void ViewCreate(View view, ViewPlatformVars*viewVars) {
 37//	Gdiplus.GdipCreateBitmapFromScan0(view.width(), view.height(), 0, Gdiplus.PixelFormat32bppARGB, null, &viewVars.image);
 38	//viewVars.rt = Gdiplus.Rect(0, 0, view.width, view.height);
 39	//Gdiplus.GdipGetImageGraphicsContext(viewVars.image, &viewVars.g);
 40//	Gdiplus.GdipGetDC(viewVars.g, &viewVars.dc);
 41	viewVars.clipRegions = new _clipList();
 42
 43	viewVars.length = (view.width() * view.height()) * 4;
 44
 45	Gdiplus.GdipCreateBitmapFromScan0(view.width(), view.height(), 0, Gdiplus.PixelFormat32bppARGB, null, &viewVars.image);
 46	viewVars.rt = Gdiplus.Rect(0, 0, view.width, view.height);
 47	Gdiplus.GdipGetImageGraphicsContext(viewVars.image, &viewVars.g);
 48}
 49
 50void ViewDestroy(ref View view, ViewPlatformVars*viewVars) {
 51	DeleteDC(viewVars.dc);
 52	Gdiplus.GdipDeleteGraphics(viewVars.g);
 53}
 54
 55void ViewCreateDIB(ref Bitmap view, ViewPlatformVars*viewVars) {
 56	viewVars.clipRegions = new _clipList();
 57
 58	viewVars.length = (view.width() * view.height()) * 4;
 59
 60	Gdiplus.GdipCreateBitmapFromScan0(view.width(), view.height(), 0, Gdiplus.PixelFormat32bppARGB, null, &viewVars.image);
 61	viewVars.rt = Gdiplus.Rect(0, 0, view.width, view.height);
 62	Gdiplus.GdipGetImageGraphicsContext(viewVars.image, &viewVars.g);
 63	Gdiplus.GdipGetDC(viewVars.g, &viewVars.dc);
 64}
 65
 66void ViewCreateForWindow(ref WindowView view, ViewPlatformVars*viewVars, ref Window window, WindowPlatformVars* windowVars) {
 67	//will set _inited to true:
 68	HDC dc;
 69
 70	dc = GetDC(null);
 71
 72	viewVars.clipRegions = new _clipList();
 73
 74	viewVars.dc = CreateCompatibleDC(dc);
 75
 76	HBITMAP bmp = CreateCompatibleBitmap(dc, view.width(), view.height());
 77
 78	ReleaseDC(null, dc);
 79
 80	SelectObject(viewVars.dc, bmp);
 81
 82	DeleteObject(bmp);
 83
 84    Gdiplus.GdipCreateFromHDC(viewVars.dc, &viewVars.g);
 85}
 86
 87void ViewResizeForWindow(ref WindowView view, ViewPlatformVars*viewVars, ref Window window, WindowPlatformVars* windowVars) {
 88}
 89
 90void ViewResize(ref View view, ViewPlatformVars*viewVars) {
 91	Console.putln("view resize");
 92	HDC dc;
 93
 94	dc = GetDC(null);
 95
 96	HBITMAP bmp;
 97
 98	if (cast(Bitmap)view !is null) {
 99		BITMAPINFO bi;
100
101		bi.bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
102		bi.bmiHeader.biWidth = view.width();
103		bi.bmiHeader.biHeight = -view.height();
104		bi.bmiHeader.biPlanes = 1;
105		bi.bmiHeader.biBitCount = 32;
106
107		bmp = CreateDIBSection(dc, &bi, DIB_RGB_COLORS, &viewVars.bits, null, 0);
108	}
109	else {
110		bmp = CreateCompatibleBitmap(dc, view.width(), view.height());
111	}
112
113	ReleaseDC(null, dc);
114
115	SelectObject(viewVars.dc, bmp);
116
117	DeleteObject(bmp);
118	Console.putln("view done");
119}
120
121void* ViewGetBytes(ViewPlatformVars*viewVars, ref ulong length) {
122    Gdiplus.GdipBitmapLockBits(viewVars.image, &viewVars.rt, Gdiplus.ImageLockMode.ImageLockModeReadWrite, Gdiplus.PixelFormat32bppARGB, &viewVars.bdata);
123
124	length = viewVars.length;
125	return cast(void*)viewVars.bdata.Scan0;
126}
127
128void* ViewGetBytes(ViewPlatformVars*viewVars) {
129    Gdiplus.GdipBitmapLockBits(viewVars.image, &viewVars.rt, Gdiplus.ImageLockMode.ImageLockModeReadWrite, Gdiplus.PixelFormat32bppARGB, &viewVars.bdata);
130
131	return cast(void*)viewVars.bdata.Scan0;
132}
133
134void ViewUnlockBytes(ViewPlatformVars* viewVars) {
135	Gdiplus.GdipBitmapUnlockBits(viewVars.image, &viewVars.bdata);
136}
137
138uint ViewRGBAToInt32(ref bool _forcenopremultiply, ViewPlatformVars*_pfvars, ref uint r, ref uint g, ref uint b, ref uint a) {
139	if (!_forcenopremultiply) {
140		float anew = a;
141		anew /= cast(float)0xFF;
142
143		r = cast(ubyte)(anew * cast(float)r);
144		g = cast(ubyte)(anew * cast(float)g);
145		b = cast(ubyte)(anew * cast(float)b);
146	}
147	return (r << 16) | (g << 8) | (b) | (a << 24);
148}
149
150uint ViewRGBAToInt32(ViewPlatformVars*_pfvars, ref uint r, ref uint g, ref uint b) {
151	return (r << 16) | (g << 8) | (b) | 0xFF000000;
152}