Created
July 30, 2018 14:14
-
-
Save long-long-float/79aa7406dc0d73f9879ed94b057c242a to your computer and use it in GitHub Desktop.
AzPainter(Linux)で色の数値入力を16進数でも出来るようにするパッチ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/mlib/src/mStr.c b/mlib/src/mStr.c | |
index b8426a6..12930c2 100644 | |
--- a/mlib/src/mStr.c | |
+++ b/mlib/src/mStr.c | |
@@ -882,7 +882,7 @@ void mStrAppendText(mStr *str,const char *text) | |
if(text) | |
{ | |
len = strlen(text); | |
- | |
+ | |
if(mStrResize(str, str->len + len)) | |
{ | |
memcpy(str->buf + str->len, text, len + 1); | |
@@ -1174,6 +1174,41 @@ int mStrToIntArray_range(mStr *str,int *dst,int maxnum,char ch,int min,int max) | |
return num; | |
} | |
+int hex2int(char ch) | |
+{ | |
+ char table[] = "0123456789abcdef"; | |
+ int i; | |
+ for (i = 0; i < 16; i++) { | |
+ if (table[i] == ch) return i; | |
+ } | |
+ return -1; | |
+} | |
+ | |
+/** 16進数の文字列が持つ複数数値を長さ3の配列で取得 | |
+ * | |
+ * @return 変換が成功した場合1 */ | |
+ | |
+int mHexStrToIntArray(mStr *str,int *dst) | |
+{ | |
+ int i, dst_i = 0; | |
+ const int str_len = 1 + 2 * 3; | |
+ char *buf = str->buf; | |
+ | |
+ if (buf[0] != '#') return 0; | |
+ if (str->len != str_len) return 0; | |
+ | |
+ for (i = 1; i < str_len; i += 2) { | |
+ int high = hex2int(tolower(buf[i])), | |
+ low = hex2int(tolower(buf[i + 1])); | |
+ | |
+ if (high < 0 || low < 0) return 0; | |
+ | |
+ dst[(i - 1) / 2] = high * 16 + low; | |
+ } | |
+ | |
+ return 1; | |
+} | |
+ | |
/** 文字を置き換え */ | |
void mStrReplaceChar(mStr *str,char ch,char chnew) | |
diff --git a/src/widget/DockColor_tab.c b/src/widget/DockColor_tab.c | |
index 08d99ab..e5163c7 100644 | |
--- a/src/widget/DockColor_tab.c | |
+++ b/src/widget/DockColor_tab.c | |
@@ -150,18 +150,29 @@ static void _rgb_input(_tabct_barcomm *p) | |
&str, MSYSDLG_INPUTTEXT_F_NOEMPTY)) | |
return; | |
- mStrToIntArray_range(&str, c, 3, 0, 0, 255); | |
+ int success = 0; | |
+ | |
+ // hex | |
+ if(str.buf[0] == '#') { | |
+ success = mHexStrToIntArray(&str, c); | |
+ } | |
+ // decimal | |
+ else { | |
+ success = mStrToIntArray_range(&str, c, 3, 0, 0, 255) == 3; | |
+ } | |
mStrFree(&str); | |
//セット | |
+ if (success) { | |
+ for(i = 0; i < 3; i++) | |
+ ValueBar_setPos(p->bar[i], c[i]); | |
- for(i = 0; i < 3; i++) | |
- ValueBar_setPos(p->bar[i], c[i]); | |
+ drawColor_setDrawColor(M_RGB(c[0], c[1], c[2])); | |
+ } | |
- drawColor_setDrawColor(M_RGB(c[0], c[1], c[2])); | |
- | |
mWidgetAppendEvent_notify(MWIDGET_NOTIFYWIDGET_RAW, M_WIDGET(p), 0, _NOTIFY_PARAM_RGB, 0); | |
+ | |
} | |
/** イベント */ | |
diff --git a/translation/en b/translation/en | |
index 97eaaf0..20dae03 100644 | |
--- a/translation/en | |
+++ b/translation/en | |
@@ -270,7 +270,7 @@ | |
[1002] | |
0=input value | |
-1=RGB value\n(text except of number is treated as a separate mark)\nexample:255,0,128 | |
+1=RGB value\n(text except of number is treated as a separate mark)\nexample:255,0,128\nor hex value\nexample: #ff0080 | |
100=set painting color as mask color(&S) [left click] | |
+=add painting color to mask color(&A) | |
diff --git a/translation/ja b/translation/ja | |
index 1a3fd44..b9dddf5 100644 | |
--- a/translation/ja | |
+++ b/translation/ja | |
@@ -271,7 +271,7 @@ | |
[1002] | |
0=数値入力 | |
-1=RGB値 (数字以外の文字で区切る) 例:255,0,128 | |
+1=RGB値 (数字以外の文字で区切る) 例:255,0,128\nまたは16進文字列 例:#ff0080 | |
100=描画色をマスク色にセット(&S) [左クリック] | |
+=描画色をマスク色に追加(&A) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment