color.class
字号:
program setintensity
args fint
if 0`.`c(curscm)'.system.naturally_white' {
colormult_nw `.rgb' `fint'
}
else {
colormult_nb `.rgb' `fint'
}
.rgb = "`r(color)'"
end
/* -------------------------------------------------------------------------*/
/*
Set this color to the appropriate GDI color registers
*/
program define setgdi
syntax [, Line Text Shade Background Foreground ]
local toset `line'`text'`shade'`background'`foreground'
if "`toset'" == "" {
local toset `._type.setting'
}
if "`.stylename'" == "none" {
if ("`toset'" == "shade" | "`toset'" == "foreground" | ///
"`toset'" == "background") gdi shadepattern = none
else if ("`toset'" == "line") gdi linedash = 0
exit
}
if "`toset'" != "foregound" { /* typical case */
gdi linedash = // just in case
gdi `toset'rgb = `.rgb'
exit
}
/* set all but those
* containing "ground" */
forvalues i = 0/`._type.codes.arrnels' {
if index("`_type.codes[`i']'", "ground") == 0) {
gdi `_type.codes[`i']'rgb = `.rgb'
}
}
end
/* -------------------------------------------------------------------------*/
/*
Set this color to the appropriate GDI color register and reset the pen
*/
program define setgdifull
syntax [, Line Text Shade Background Foreground ]
.setgdi `0'
local toset `line'`text'`shade'`background'`foreground'
if "`toset'" == "" {
local toset `._type.setting'
}
if "`toset'" == "line" | "`toset'" == "foreground" {
gdi penchange
}
if "`toset'" == "shade" | "`toset'" == "foreground" {
gdi shadechange
}
if "`toset'" == "text" | "`toset'" == "foreground" {
gdi textchange
}
end
/* -------------------------------------------------------------------------*/
program define add_colorname
end
/* -------------------------------------------------------------------------*/
/* Usage: _rgb2hsv h_mac s_mac v_mac : */
program define _rgb2hsv
args hmac smac vmac colon
tokenize `.rgb'
args r g b
local r = 0`r' / 255
local g = 0`g' / 255
local b = 0`b' / 255
local max = max(`r', `g', `b')
local min = min(`r', `g', `b')
local v = `max'
local s = (`max' - `min') / `max'
local dif = `max' - `min'
if `s' != 0 {
if `r' == `max' {
local h = (`g' - `b') / `dif'
}
if `g' == `max' {
local h = 2 + (`b' - `r') / `dif'
}
if `b' == `max' {
local h = 4 + (`r' - `g') / `dif'
}
local h = `h' * 60
if `h' < 0 {
local h = `h' + 360
}
}
else local h = .
c_local `hmac' = `h'
c_local `smac' = `s'
c_local `vmac' = string(`v', "%6.2f")
end
program define _hsv2rgb
args h s v
if `s' == 0 & `h' == . {
local r = int(`v' * 255)
local g = int(`v' * 255)
local b = int(`v' * 255)
.rgb = "`r' `g' `b'"
exit /* EXIT */
}
if `h' == 360 {
local h = 0
}
local h = `h' / 60
local i = int(`h')
local f = `h' - `i'
local p = `v' * (1 - `s')
local q = `v' * (1 - (`s' * `f'))
local t = `v' * (1 - (`s' * (1 - `f')))
if `i' == 0 {
local r = int(`v' * 255)
local g = int(`t' * 255)
local b = int(`p' * 255)
}
if `i' == 1 {
local r = int(`q' * 255)
local g = int(`v' * 255)
local b = int(`p' * 255)
}
if `i' == 2 {
local r = int(`p' * 255)
local g = int(`v' * 255)
local b = int(`t' * 255)
}
if `i' == 3 {
local r = int(`p' * 255)
local g = int(`q' * 255)
local b = int(`v' * 255)
}
if `i' == 4 {
local r = int(`t' * 255)
local g = int(`p' * 255)
local b = int(`v' * 255)
}
if `i' == 5 {
local r = int(`v' * 255)
local g = int(`p' * 255)
local b = int(`q' * 255)
}
.rgb = "`r' `g' `b'"
end
/* -------------------------------------------------------------------------*/
/*
Places and manages dialog box for color.
Interacts with globals and subprograms in object.cls
*/
program define dialog_box
.popifcontains .dialog_box
syntax [, All Classmv Instancemv Dynamicmv Redraw Apply Name(string) ]
if "`all'`class'" != "" {
.Super.dialog_box `0'
exit
}
global T_Name `name' /* just easier */
global T_SubNm `._restname'
global T_TopNm `._topname $T_Name'
global T_is_style = 1
if ! 0`.hasstyles' {
._populate_stylenames
}
local ctrlsize `.dbstyle.ctrlsize' /* control sizes */
local txtsize `.dbstyle.txtsize'
local ysize `.dbstyle.ysize'
local x0 = 3 * `.dbstyle.xgap'
local y = 0
local xtxt = `x0' + `ctrlsize' + `.dbstyle.xgap'
/* place own style editor */
global T_percol 0
._place_controls_from x y ymax : ownstyle `x0' `y' 1000 `offset'
local y = `y' + `ysize' + 3 * `.dbstyle.yspace'
tokenize `.rgb' /* fetch rgb and v */
args Red Green Blue
._rgb2hsv unused unused hsv_val
local hsv_val = 100 * `hsv_val'
global T_txt_rgb RGB values
window control static T_txt_rgb `=`.dbstyle.xgap'' `y' /*
*/ `=`xtxt'+`txtsize'+`.dbstyle.xgap'' /*
*/ `=`y'+1*`ysize'+2*`.dbstyle.yspace'' blackframe
window control static T_txt_rgb `=`x'+3*`.dbstyle.xgap'' /*
*/ `=int(`y'-`ysize'/3)' `txtsize' /*
*/ `ysize'
local y = `y' + 2*`.dbstyle.yspace'
/* place controls */
foreach color in Red Green Blue {
global T_txt_`color' `color'
window control static T_txt_`color' `xtxt' `y' `txtsize' `ysize'
global T_v_`color' ``color''
global T_hv_`color' ``color''
window control edit `x0' `y' `ctrlsize' `ysize' T_v_`color'
local y = `y' + `ysize' + `.dbstyle.yspace'
}
local y = `y' + `ysize' + `.dbstyle.yspace'
global T_txt_intensity Intensity
window control static T_txt_intensity `xtxt' `y' `txtsize' `ysize'
global T_v_intensity `hsv_val'
global T_hv_intensity `hsv_val'
window control edit `x0' `y' `ctrlsize' `ysize' T_v_intensity
/* OK, cancel, apply */
local y = `y' + 2*`.dbstyle.yspace'
if "`apply'" != "" {
global T_curobj `.objkey'
}
._place_ok_cancel y : `.dbstyle.xspace' `y' "`apply'" /* object.cls */
/* show the db */
local xsz = `xtxt' + `txtsize' + 3 * `.dbstyle.xgap' + 15
local ysz = `y' + `ysize' + 2 * `.dbstyle.yspace'
capture noisily window dialog "color" . . `xsz' `ysz'
local rc = _rc
/* --------------- process the results -------------------------- */
if `rc' == 3098 { /* cancelled */
/* possibly reset and redraw */
local rgb_was "`.rgb'"
.rgb = "${T_hv_Red} ${T_hv_Green} ${T_hv_Blue}"
if "$T_drawobj" != "" & "`.rgb'" != "`rgb_was'" {
.${T_drawobj}.drawgraph
global T_changed 0
}
._style_cleanup
exit
}
._post_all
if "$T_drawobj" != "" & $T_changed {
.${T_drawobj}.drawgraph
global T_changed 0
}
/* run a sub-view dialog box if
* requested */
local xpnd = `rc'-3000-$T_is_style
if `xpnd' == 0 & $T_is_style {
._copy_style_db
}
._style_cleanup
end
/* -------------------------------------------------------------------------*/
program define _post_all
if ! `._set_changed' {
exit
}
._post_style /* handle edits to own style, etc */
if ! 0$T_changed_p1 {
exit
}
foreach color in Red Green Blue {
if 0${T_v_`color'} != ${T_hv_`color'} {
local rgb_chg 1
global T_v_`color' = max(0, min(255, ${T_v_`color'}))
}
}
if 0`rgb_chg' {
.setrgb $T_v_Red $T_v_Green $T_v_Blue
_gm_log $T_Name.setrgb $T_v_Red $T_v_Green $T_v_Blue
}
if 0$T_v_intensity != $T_hv_intensity {
global T_v_intensity = max(0, min(100, $T_v_intensity))
.setvalue $T_v_intensity
_gm_log $T_Name.setvalue $T_v_intensity
}
end
/* Silly, needed only because color dialog box uses names rather than numbers
for the globals holdin the control results.
*/
program define _set_changed
global T_changed 0
global T_changed_p1 0
if `"${T_v1}"' != `"${T_hv1}"' {
global T_changed 1
}
foreach j in Red Green Blue intensity {
if ${T_v_`j'} != ${T_hv_`j'} {
global T_changed 1
global T_changed_p1 1
continue, break
}
}
class exit = $T_changed
end
// ---------------------------------------------------------------------------
program _unabbrev
local 0 `", `0'"'
syntax [ , FG BG FOREGROUND BACKGROUND * ]
local opt `fg' `bg' `foregound' `backgroud'
if "`opt'" == "" {
class exit `"`options'"'
}
if "`fg'`foreground'" != "" {
class exit `"`.`c(curscm)'.style `.classname' scheme foreground'"'
}
class exit `"`.`c(curscm)'.style `.classname' scheme background'"'
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -