Skip to content

Commit

Permalink
split NATIVE MODE into two projects
Browse files Browse the repository at this point in the history
  • Loading branch information
fungaren committed Jan 4, 2020
1 parent f2d4595 commit 1a2212f
Show file tree
Hide file tree
Showing 22 changed files with 3,068 additions and 1,286 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ endif()
set(MYNOTEPAD_VERSION_MAJOR 1)
set(MYNOTEPAD_VERSION_MINOR 0.5)

option(USE_NATIVE_EDIT_BOX "Use native or custom implemented edit control" ON)
#option(USE_NATIVE_EDIT_BOX "Use native or custom implemented edit control" ON)

configure_file(
"${PROJECT_SOURCE_DIR}/inc/config.h.in"
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Use `cmake -D<VAR>=<VALUE>` to change any option.
| Option | Default | Description |
| - | - | - |
| `CMAKE_BUILD_TYPE` | Debug | Build Type for Unix (Release / Debug) |
| `USE_NATIVE_EDIT_BOX` | ON | Use native or custom implemented edit control |

## Known bugs

Expand Down
4 changes: 4 additions & 0 deletions gen1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vs/
Release/
Debug/
x64/
138 changes: 138 additions & 0 deletions gen1/GDIUtilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#pragma once
#include <cstdint>
#include <string>

struct COLOR {
DWORD c;
COLOR(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0) :
c(a<<24|b<<16|g<<8|r) { }
COLOR(DWORD c) :c(c) {}
operator DWORD() {return c;}
};

class GDIUtil
{
public:
static void fill(HDC hdc, COLOR color, int left, int top, int width, int height) {
if (width == 0 || height == 0)
return;
RECT rc = { left, top, left + width, top + height };
SetBkColor(hdc, color);
ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
}

static void line(HDC hdc, COLOR color, int x1, int y1, int x2, int y2)
{
_ASSERT(x1 != x2 || y1 != y2);
HPEN hp = CreatePen(BS_SOLID, 1, color);
HGDIOBJ ho = SelectObject(hdc, hp);
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
SelectObject(hdc, ho);
DeleteObject(hp);
}
};

class MemDC {
HDC hdc;
HDC compatibleDC;
HBITMAP bmp;
HBITMAP oldBmp;

public:

MemDC(HDC hdc, int width, int height) :hdc(hdc) {
compatibleDC = CreateCompatibleDC(NULL);

bmp = CreateCompatibleBitmap(hdc, width, height);
oldBmp = (HBITMAP)SelectObject(compatibleDC, bmp);
}

operator HDC() const { return compatibleDC; }

~MemDC() {
SelectObject(compatibleDC, oldBmp);
DeleteObject(oldBmp);
DeleteObject(bmp);
DeleteDC(compatibleDC);
}
};

struct CharStyle
{
uint8_t bold : 1;
uint8_t itatic : 1;
uint8_t underline : 1;
uint8_t reserved : 5;
};

const CharStyle default_style = { 0 };

class Font {
HFONT hf;
HGDIOBJ ho;
HDC hdc;
const unsigned int format = DT_NOPREFIX | DT_WORDBREAK | DT_EDITCONTROL | DT_NOCLIP | DT_HIDEPREFIX;

public:
COLOR color;
CharStyle style;

Font(int size, LPCTSTR fontname, COLOR color = 0x00000000, CharStyle style = default_style)
:color(color),
style(style)
{
hf = CreateFont(size, 0, 0, 0, style.bold ? 700 : 400, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_SWISS, fontname);
}

Font& bind(HDC hdc) {
this->hdc = hdc;
ho = SelectObject(hdc, hf);
return *this;
}

void unbind() {
SelectObject(hdc, ho);
}

//// calc expected height for specific text width
//int calcHeight(const std::wstring& str, int width)
//{
// RECT rc = { 0,0,width,0 };
// DrawTextW(hdc, str.c_str(), str.length(), &rc, format | DT_CALCRECT);
// return rc.bottom - rc.top;
//}

//Font& drawText(const std::wstring& str, int left, int top, int width, int height) {
// RECT rc = { left, top, left + width, top + height };

// SetBkMode(hdc, TRANSPARENT);
// SetTextColor(hdc, color);

// DrawTextW(hdc, str.c_str(), str.length(), &rc, format);
// return *this;
//}

// Print a line without '\n'
Font& printLine(const std::wstring& str, int left, int top) {
_ASSERT(str.find(L'\n') == std::string::npos);

SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, color);

std::wstring temp;
for (wchar_t c : str)
if (c != L'\t')
temp += c;
else
temp += L" ";

TextOutW(hdc, left, top, temp.c_str(), temp.length());
return *this;
}

~Font() {
DeleteObject(hf);
}
};
31 changes: 31 additions & 0 deletions gen1/MarkdownParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
#include "lex_parse.h"
#include <sstream>
#include <regex>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#ifdef _DEBUG
#define SHOW_PARSING_TIME
#endif
void parse_markdown(std::wstring& str)
{
//std::wregex regex_table_align(L"^([:\\s]?-+[:\\s]?\\|?)+$");
//bool re = std::regex_match(str, regex_table_align);
//int j = 5;
#ifdef SHOW_PARSING_TIME
clock_t begin = clock();
#endif

std::wostringstream wos;

auto scanned = scanner(str);
parse_fromlex(wos, std::begin(scanned), std::end(scanned));

#ifdef SHOW_PARSING_TIME
clock_t end = clock();
double t = double(end - begin) / CLOCKS_PER_SEC;
wos << L"<br><p>用时:" << std::setprecision(2) << t << L" s</p>";
#endif // SHOW_PARSING_TIME
str = wos.str();
}
Binary file added gen1/MyNotePad.aps
Binary file not shown.
Binary file added gen1/MyNotePad.rc
Binary file not shown.
28 changes: 28 additions & 0 deletions gen1/MyNotePad.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyNotePad", "MyNotePad.vcxproj", "{69CA1588-7FCD-436F-9507-ABEB8A6F636D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Debug|x64.ActiveCfg = Debug|x64
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Debug|x64.Build.0 = Debug|x64
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Debug|x86.ActiveCfg = Debug|Win32
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Debug|x86.Build.0 = Debug|Win32
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Release|x64.ActiveCfg = Release|x64
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Release|x64.Build.0 = Release|x64
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Release|x86.ActiveCfg = Release|Win32
{69CA1588-7FCD-436F-9507-ABEB8A6F636D}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading

0 comments on commit 1a2212f

Please sign in to comment.