Skip to content

Commit

Permalink
Implement color preview (via CallTip), issue #659.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed May 29, 2023
1 parent b946043 commit 9492cf8
Show file tree
Hide file tree
Showing 18 changed files with 307 additions and 97 deletions.
9 changes: 8 additions & 1 deletion locale/de/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ BEGIN
MENUITEM "Show Line &Endings\tCtrl+Shift+9", IDM_VIEW_SHOWEOLS
MENUITEM "Show Wrap S&ymbols\tCtrl+Shift+0", IDM_VIEW_WORDWRAPSYMBOLS
MENUITEM "Un&icode Control Character", IDM_VIEW_UNICODE_CONTROL_CHAR
//MENUITEM "S&how CallTips", IDM_VIEW_SHOWCALLTIPS
MENUITEM SEPARATOR
MENUITEM "&Visual Brace Matching\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES
MENUITEM "Highlight Current &Block", IDM_VIEW_HIGHLIGHTCURRENT_BLOCK
Expand All @@ -447,6 +446,14 @@ BEGIN
MENUITEM "Match &Whole Word Only", IDM_VIEW_MARKOCCURRENCES_WORD
MENUITEM "Bookmark &Matched Line", IDM_VIEW_MARKOCCURRENCES_BOOKMARK
END
POPUP "Show CallTi&p"
BEGIN
MENUITEM "&Off", IDM_VIEW_SHOWCALLTIP_OFF
MENUITEM "&RGBA Color", IDM_VIEW_SHOWCALLTIP_RGBA
MENUITEM "AR&GB Color", IDM_VIEW_SHOWCALLTIP_ARGB
MENUITEM "&BGRA Color", IDM_VIEW_SHOWCALLTIP_BGRA
MENUITEM "&ABGR Color", IDM_VIEW_SHOWCALLTIP_ABGR
END
MENUITEM SEPARATOR
MENUITEM "Line &Numbers\tCtrl+Shift+N", IDM_VIEW_LINENUMBERS
MENUITEM "Bookmark &Margin\tCtrl+Shift+M", IDM_VIEW_MARGIN
Expand Down
9 changes: 8 additions & 1 deletion locale/fr-FR/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ BEGIN
MENUITEM "Afficher les fin de lignes\tCtrl+Shift+9", IDM_VIEW_SHOWEOLS
MENUITEM "Afficher la marque de retour à la ligne automatique\tCtrl+Shift+0", IDM_VIEW_WORDWRAPSYMBOLS
MENUITEM "Afficher les caractères de contrôle unicode", IDM_VIEW_UNICODE_CONTROL_CHAR
//MENUITEM "Afficher les astuces de call", IDM_VIEW_SHOWCALLTIPS
MENUITEM SEPARATOR
MENUITEM "Visualisation de la paranthèse fermante\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES
MENUITEM "Surligner la ligne courante", IDM_VIEW_HIGHLIGHTCURRENT_BLOCK
Expand All @@ -447,6 +446,14 @@ BEGIN
MENUITEM "Mot correspondant seulement", IDM_VIEW_MARKOCCURRENCES_WORD
MENUITEM "Marque-page ligne correspondante", IDM_VIEW_MARKOCCURRENCES_BOOKMARK
END
POPUP "Show CallTi&p"
BEGIN
MENUITEM "&Off", IDM_VIEW_SHOWCALLTIP_OFF
MENUITEM "&RGBA Color", IDM_VIEW_SHOWCALLTIP_RGBA
MENUITEM "AR&GB Color", IDM_VIEW_SHOWCALLTIP_ARGB
MENUITEM "&BGRA Color", IDM_VIEW_SHOWCALLTIP_BGRA
MENUITEM "&ABGR Color", IDM_VIEW_SHOWCALLTIP_ABGR
END
MENUITEM SEPARATOR
MENUITEM "Voir les numéros de ligne\tCtrl+Shift+N", IDM_VIEW_LINENUMBERS
MENUITEM "Voir la marge de signets\tCtrl+Shift+M", IDM_VIEW_MARGIN
Expand Down
9 changes: 8 additions & 1 deletion locale/it/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ BEGIN
MENUITEM "Mostra te&rminazioni di linea\tCtrl+Shift+9", IDM_VIEW_SHOWEOLS
MENUITEM "Mostra sim&boli a capo\tCtrl+Shift+0", IDM_VIEW_WORDWRAPSYMBOLS
MENUITEM "Carattere di controllo &Unicode", IDM_VIEW_UNICODE_CONTROL_CHAR
//MENUITEM "S&how CallTips", IDM_VIEW_SHOWCALLTIPS
MENUITEM SEPARATOR
MENUITEM "Corrispondenza &visiva delle parentesi\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES
MENUITEM "&Evidenzia blocco corrente", IDM_VIEW_HIGHLIGHTCURRENT_BLOCK
Expand All @@ -447,6 +446,14 @@ BEGIN
MENUITEM "Segna solo &parola intera", IDM_VIEW_MARKOCCURRENCES_WORD
MENUITEM "&Segnalibro e linea abbinata", IDM_VIEW_MARKOCCURRENCES_BOOKMARK
END
POPUP "Show CallTi&p"
BEGIN
MENUITEM "&Off", IDM_VIEW_SHOWCALLTIP_OFF
MENUITEM "&RGBA Color", IDM_VIEW_SHOWCALLTIP_RGBA
MENUITEM "AR&GB Color", IDM_VIEW_SHOWCALLTIP_ARGB
MENUITEM "&BGRA Color", IDM_VIEW_SHOWCALLTIP_BGRA
MENUITEM "&ABGR Color", IDM_VIEW_SHOWCALLTIP_ABGR
END
MENUITEM SEPARATOR
MENUITEM "&Numeri linee\tCtrl+Shift+N", IDM_VIEW_LINENUMBERS
MENUITEM "Mar&gine segnalibri\tCtrl+Shift+M", IDM_VIEW_MARGIN
Expand Down
9 changes: 8 additions & 1 deletion locale/ja/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ BEGIN
MENUITEM "改行コード(&E)\tCtrl+Shift+9", IDM_VIEW_SHOWEOLS
MENUITEM "折り返し記号(&Y)\tCtrl+Shift+0", IDM_VIEW_WORDWRAPSYMBOLS
MENUITEM "Unicode制御文字(&I)", IDM_VIEW_UNICODE_CONTROL_CHAR
//MENUITEM "コールチップ(&H)", IDM_VIEW_SHOWCALLTIPS
MENUITEM SEPARATOR
MENUITEM "対応括弧を強調表示(&V)\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES
MENUITEM "現在のブロックを強調(&B)", IDM_VIEW_HIGHLIGHTCURRENT_BLOCK
Expand All @@ -447,6 +446,14 @@ BEGIN
MENUITEM "単語単位で一致(&W)", IDM_VIEW_MARKOCCURRENCES_WORD
MENUITEM "一致行にしおり(&M)", IDM_VIEW_MARKOCCURRENCES_BOOKMARK
END
POPUP "Show CallTi&p"
BEGIN
MENUITEM "&Off", IDM_VIEW_SHOWCALLTIP_OFF
MENUITEM "&RGBA Color", IDM_VIEW_SHOWCALLTIP_RGBA
MENUITEM "AR&GB Color", IDM_VIEW_SHOWCALLTIP_ARGB
MENUITEM "&BGRA Color", IDM_VIEW_SHOWCALLTIP_BGRA
MENUITEM "&ABGR Color", IDM_VIEW_SHOWCALLTIP_ABGR
END
MENUITEM SEPARATOR
MENUITEM "行番号(&N)\tCtrl+Shift+N", IDM_VIEW_LINENUMBERS
MENUITEM "行番号/しおりの余白(&M)\tCtrl+Shift+M", IDM_VIEW_MARGIN
Expand Down
9 changes: 8 additions & 1 deletion locale/ko/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ BEGIN
MENUITEM "줄 끝 표시(&E)\tCtrl+Shift+9", IDM_VIEW_SHOWEOLS
MENUITEM "줄바꿈 기호 표시(&Y)\tCtrl+Shift+0", IDM_VIEW_WORDWRAPSYMBOLS
MENUITEM "유니코드 제어 문자(&I)", IDM_VIEW_UNICODE_CONTROL_CHAR
//MENUITEM "호출팁 표시(&H)", IDM_VIEW_SHOWCALLTIPS
MENUITEM SEPARATOR
MENUITEM "시각적 괄호 일치(&V)\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES
MENUITEM "현재 블록 강조(&B)", IDM_VIEW_HIGHLIGHTCURRENT_BLOCK
Expand All @@ -447,6 +446,14 @@ BEGIN
MENUITEM "전체 단어만 일치(&W)", IDM_VIEW_MARKOCCURRENCES_WORD
MENUITEM "책갈피 일치 줄(&M)", IDM_VIEW_MARKOCCURRENCES_BOOKMARK
END
POPUP "Show CallTi&p"
BEGIN
MENUITEM "&Off", IDM_VIEW_SHOWCALLTIP_OFF
MENUITEM "&RGBA Color", IDM_VIEW_SHOWCALLTIP_RGBA
MENUITEM "AR&GB Color", IDM_VIEW_SHOWCALLTIP_ARGB
MENUITEM "&BGRA Color", IDM_VIEW_SHOWCALLTIP_BGRA
MENUITEM "&ABGR Color", IDM_VIEW_SHOWCALLTIP_ABGR
END
MENUITEM SEPARATOR
MENUITEM "줄 번호(&N)\tCtrl+Shift+N", IDM_VIEW_LINENUMBERS
MENUITEM "책갈피 여백(&M)\tCtrl+Shift+M", IDM_VIEW_MARGIN
Expand Down
9 changes: 8 additions & 1 deletion locale/pt-BR/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ BEGIN
MENUITEM "Show Line &Endings\tCtrl+Shift+9", IDM_VIEW_SHOWEOLS
MENUITEM "Show Wrap S&ymbols\tCtrl+Shift+0", IDM_VIEW_WORDWRAPSYMBOLS
MENUITEM "Un&icode Control Character", IDM_VIEW_UNICODE_CONTROL_CHAR
//MENUITEM "S&how CallTips", IDM_VIEW_SHOWCALLTIPS
MENUITEM SEPARATOR
MENUITEM "&Visual Brace Matching\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES
MENUITEM "Highlight Current &Block", IDM_VIEW_HIGHLIGHTCURRENT_BLOCK
Expand All @@ -447,6 +446,14 @@ BEGIN
MENUITEM "Match &Whole Word Only", IDM_VIEW_MARKOCCURRENCES_WORD
MENUITEM "Bookmark &Matched Line", IDM_VIEW_MARKOCCURRENCES_BOOKMARK
END
POPUP "Show CallTi&p"
BEGIN
MENUITEM "&Off", IDM_VIEW_SHOWCALLTIP_OFF
MENUITEM "&RGBA Color", IDM_VIEW_SHOWCALLTIP_RGBA
MENUITEM "AR&GB Color", IDM_VIEW_SHOWCALLTIP_ARGB
MENUITEM "&BGRA Color", IDM_VIEW_SHOWCALLTIP_BGRA
MENUITEM "&ABGR Color", IDM_VIEW_SHOWCALLTIP_ABGR
END
MENUITEM SEPARATOR
MENUITEM "Line &Numbers\tCtrl+Shift+N", IDM_VIEW_LINENUMBERS
MENUITEM "Bookmark &Margin\tCtrl+Shift+M", IDM_VIEW_MARGIN
Expand Down
9 changes: 8 additions & 1 deletion locale/zh-Hans/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ BEGIN
MENUITEM "显示换行符(&E)\tCtrl+Shift+9", IDM_VIEW_SHOWEOLS
MENUITEM "显示换行标记(&Y)\tCtrl+Shift+0", IDM_VIEW_WORDWRAPSYMBOLS
MENUITEM "显示 Unicode 控制字符(&I)", IDM_VIEW_UNICODE_CONTROL_CHAR
//MENUITEM "S&how CallTips", IDM_VIEW_SHOWCALLTIPS
MENUITEM SEPARATOR
MENUITEM "凸显配对括号(&V)\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES
MENUITEM "高亮当前代码块(&B)", IDM_VIEW_HIGHLIGHTCURRENT_BLOCK
Expand All @@ -447,6 +446,14 @@ BEGIN
MENUITEM "只匹配完整单词(&W)", IDM_VIEW_MARKOCCURRENCES_WORD
MENUITEM "为匹配的行添加书签(&M)", IDM_VIEW_MARKOCCURRENCES_BOOKMARK
END
POPUP "显示提示(&P)"
BEGIN
MENUITEM "不显示(&O)", IDM_VIEW_SHOWCALLTIP_OFF
MENUITEM "RGBA 颜色(&R)", IDM_VIEW_SHOWCALLTIP_RGBA
MENUITEM "ARGB 颜色(&G)", IDM_VIEW_SHOWCALLTIP_ARGB
MENUITEM "BGRA 颜色(&B)", IDM_VIEW_SHOWCALLTIP_BGRA
MENUITEM "ABGR 颜色(&A)", IDM_VIEW_SHOWCALLTIP_ABGR
END
MENUITEM SEPARATOR
MENUITEM "行号(&N)\tCtrl+Shift+N", IDM_VIEW_LINENUMBERS
MENUITEM "书签边界(&M)\tCtrl+Shift+M", IDM_VIEW_MARGIN
Expand Down
9 changes: 8 additions & 1 deletion locale/zh-Hant/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ BEGIN
MENUITEM "顯示換行子(&E)\tCtrl+Shift+9", IDM_VIEW_SHOWEOLS
MENUITEM "顯示軟換行子(&Y)\tCtrl+Shift+0", IDM_VIEW_WORDWRAPSYMBOLS
MENUITEM "Un&icode 控制字符", IDM_VIEW_UNICODE_CONTROL_CHAR
//MENUITEM "S&how CallTips", IDM_VIEW_SHOWCALLTIPS
MENUITEM SEPARATOR
MENUITEM "可視括弧符合(&V)\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES
MENUITEM "高亮目前片段(&B)", IDM_VIEW_HIGHLIGHTCURRENT_BLOCK
Expand All @@ -447,6 +446,14 @@ BEGIN
MENUITEM "只符合完整單詞(&W)", IDM_VIEW_MARKOCCURRENCES_WORD
MENUITEM "為匹配的行添加書簽(&M)", IDM_VIEW_MARKOCCURRENCES_BOOKMARK
END
POPUP "顯示提示(&P)"
BEGIN
MENUITEM "不显示(&O)", IDM_VIEW_SHOWCALLTIP_OFF
MENUITEM "RGBA 顏色(&R)", IDM_VIEW_SHOWCALLTIP_RGBA
MENUITEM "ARGB 顏色(&G)", IDM_VIEW_SHOWCALLTIP_ARGB
MENUITEM "BGRA 顏色(&B)", IDM_VIEW_SHOWCALLTIP_BGRA
MENUITEM "ABGR 顏色(&A)", IDM_VIEW_SHOWCALLTIP_ABGR
END
MENUITEM SEPARATOR
MENUITEM "行號(&N)\tCtrl+Shift+N", IDM_VIEW_LINENUMBERS
MENUITEM "書籤邊界(&M)\tCtrl+Shift+M", IDM_VIEW_MARGIN
Expand Down
10 changes: 10 additions & 0 deletions scintilla/include/GraphicUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// color RGB hex: #RRGGBB => 0x00RRGGBB
// RGBA hex: #RRGGBBAA
// ARGB hex: #AARRGGBB
// BGRA hex: #BBGGRRAA
// ABGR hex: #AABBGGRR

static inline uint32_t ColorFromRGBQuad(uint32_t quad) NP2_noexcept {
return rotr8(bswap32(quad));
Expand All @@ -33,6 +35,10 @@ static inline uint32_t ColorFromARGBHex(uint32_t hex) NP2_noexcept {
return rotr8(bswap32(hex));
}

static inline uint32_t ColorFromBGRAHex(uint32_t hex) NP2_noexcept {
return rotl8(hex);
}

static inline uint32_t ColorToRGBQuad(uint32_t color) NP2_noexcept {
return rotr8(bswap32(color));
}
Expand All @@ -49,6 +55,10 @@ static inline uint32_t ColorToARGBHex(uint32_t color) NP2_noexcept {
return rotr8(bswap32(color));
}

static inline uint32_t ColorToBGRAHex(uint32_t hex) NP2_noexcept {
return rotl8(hex);
}

// see https://docs.microsoft.com/en-us/windows/win32/uxguide/vis-icons#size-requirements
// we can process 4 pixels at a time for all our bitmap (even after DPI scaling).

Expand Down
10 changes: 5 additions & 5 deletions scintilla/src/ScintillaBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1051,28 +1051,28 @@ sptr_t ScintillaBase::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::CallTipSetBack:
ct.colourBG = ColourRGBA::FromIpRGB(SPtrFromUPtr(wParam));
vs.styles[StyleCallTip].back = ct.colourBG;
InvalidateStyleRedraw();
//InvalidateStyleRedraw();
break;

case Message::CallTipSetFore:
ct.colourUnSel = ColourRGBA::FromIpRGB(SPtrFromUPtr(wParam));
vs.styles[StyleCallTip].fore = ct.colourUnSel;
InvalidateStyleRedraw();
//InvalidateStyleRedraw();
break;

case Message::CallTipSetForeHlt:
ct.colourSel = ColourRGBA::FromIpRGB(SPtrFromUPtr(wParam));
InvalidateStyleRedraw();
//InvalidateStyleRedraw();
break;

case Message::CallTipUseStyle:
ct.SetTabSize(static_cast<int>(std::lround(wParam * vs.aveCharWidth)));
InvalidateStyleRedraw();
//InvalidateStyleRedraw();
break;

case Message::CallTipSetPosition:
ct.SetPosition(wParam != 0);
InvalidateStyleRedraw();
//InvalidateStyleRedraw();
break;

#if SCI_EnablePopupMenu
Expand Down
28 changes: 27 additions & 1 deletion src/Edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,33 @@ void EditAutoIndent(void);
void EditToggleCommentLine(void);
void EditToggleCommentBlock(void);
void EditInsertScriptShebangLine(void);
void EditShowCallTips(Sci_Position position);

typedef enum CallTipType {
CallTipType_None,
CallTipType_Notification,
CallTipType_ColorHex,
} CallTipType;

typedef enum ShowCallTip {
ShowCallTip_None,
ShowCallTip_ColorRGBA,
ShowCallTip_ColorARGB,
ShowCallTip_ColorBGRA,
ShowCallTip_ColorABGR,
} ShowCallTip;

struct CallTipInfo {
ShowCallTip showCallTip;
CallTipType type;
Sci_Position startPos;
Sci_Position endPos;
Sci_Position hexStart;
COLORREF currentColor;
//COLORREF backColor;
//COLORREF foreColor;
};
void EditShowCallTip(Sci_Position position);
void EditClickCallTip(HWND hwnd);

#define NCP_DEFAULT 1
#define NCP_UTF8 2
Expand Down
24 changes: 3 additions & 21 deletions src/EditAutoC.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ static void AutoC_AddKeyword(struct WordList *pWList, int iCurrentStyle) {
// embedded script
LPCEDITLEXER pLex = NULL;
if (iLexer == SCLEX_HTML || iLexer == SCLEX_PHPSCRIPT) {
const int block = GetCurrentHtmlTextBlockEx(iLexer, iCurrentStyle);
const HtmlTextBlock block = GetCurrentHtmlTextBlockEx(iLexer, iCurrentStyle);
switch (block) {
case HtmlTextBlock_JavaScript:
pLex = &lexJavaScript;
Expand Down Expand Up @@ -2361,7 +2361,7 @@ void EditToggleCommentLine(void) {
case NP2LEX_HTML:
case NP2LEX_PHP:
case NP2LEX_XML: {
const int block = GetCurrentHtmlTextBlock(pLexCurrent->iLexer);
const HtmlTextBlock block = GetCurrentHtmlTextBlock(pLexCurrent->iLexer);
switch (block) {
case HtmlTextBlock_VBScript:
EditToggleLineComments(L"'", false);
Expand Down Expand Up @@ -2548,7 +2548,7 @@ void EditToggleCommentBlock(void) {
case NP2LEX_HTML:
case NP2LEX_PHP:
case NP2LEX_XML: {
const int block = GetCurrentHtmlTextBlock(pLexCurrent->iLexer);
const HtmlTextBlock block = GetCurrentHtmlTextBlock(pLexCurrent->iLexer);
switch (block) {
case HtmlTextBlock_Tag:
EditEncloseSelection(L"<!--", L"-->");
Expand Down Expand Up @@ -2781,24 +2781,6 @@ void EditInsertScriptShebangLine(void) {
SciCall_ReplaceSel(line);
}

void EditShowCallTips(Sci_Position position) {
const Sci_Line iLine = SciCall_LineFromPosition(position);
const Sci_Position iDocLen = SciCall_GetLineLength(iLine);
char *pLine = (char *)NP2HeapAlloc(iDocLen + 1);
SciCall_GetLine(iLine, pLine);
StrTrimA(pLine, " \t\r\n");
char *text = (char *)NP2HeapAlloc(iDocLen + 1 + 128);
#if defined(_WIN64)
sprintf(text, "ShowCallTips(%" PRId64 ", %" PRId64 ", %" PRId64 ")\n\n\002%s", iLine + 1, position, iDocLen, pLine);
#else
sprintf(text, "ShowCallTips(%d, %d, %d)\n\n\002%s", (int)(iLine + 1), (int)position, (int)iDocLen, pLine);
#endif
SciCall_CallTipUseStyle(fvCurFile.iTabWidth);
SciCall_CallTipShow(position, text);
NP2HeapFree(pLine);
NP2HeapFree(text);
}

void InitAutoCompletionCache(LPCEDITLEXER pLex) {
np2_LexKeyword = NULL;
memset(CharacterPrefixMask, 0, sizeof(CharacterPrefixMask));
Expand Down
6 changes: 6 additions & 0 deletions src/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ NP2_inline int ToLowerA(int ch) {
return (ch >= 'A' && ch <= 'Z') ? (ch - 'A' + 'a') : ch;
}

NP2_inline bool IsHexDigit(int ch) {
return (ch >= '0' && ch <= '9')
|| (ch >= 'A' && ch <= 'F')
|| (ch >= 'a' && ch <= 'f');
}

NP2_inline int GetHexDigit(int ch) {
unsigned int diff = ch - '0';
if (diff < 10) {
Expand Down
Loading

0 comments on commit 9492cf8

Please sign in to comment.