//bk 背景贴图 import gdi; import com.picture; import util.metaProperty; namespace win.ui.ctrl; class bk{ ctor(parent,tParam){ if(tParam.bkImage){ this.bitmap = ..com.picture.loadBitmap(tParam.bkImage) } this.text = tParam.text; //@AIFIX if(!tParam.left && !tParam.top && tParam.dl && tParam.dr && tParam.dt && !tParam.db){ var rc = parent._defClientRect; if(rc){ if( tParam.right && (rc.width == tParam.right+1) ){ if(tParam.bottom && tParam.bottom < (rc.height * 0.5) ){ tParam.right = rc.width } } } } this.rect = ::RECT(); this.paddingRight = tParam.paddingRight : 0; this.paddingBottom = tParam.paddingBottom : 0; this.paddingLeft = tParam.paddingLeft : 0; this.paddingTop = tParam.paddingTop : 0; this.onlyDirectDrawBackground = true;//禁止创建窗口 this.align = tParam.align : "center"; this.valign = tParam.valign : "center"; }; onDirectDrawBackground = function(hdc){ if(owner.$hidden) return ; var rc = this.rect; if( (this.bgcolor!==null) && (this.linearGradient== null) ){ ..gdi.fillRect(hdc,this.bgcolor,rc); } if(owner[["(background)"]]){ if(!this.repeat || this.repeat =="expand"){ ..gdi.drawBitmap(hdc,owner[["(background)"]],rc,this.bkTop:0,this.bkRight:0,this.bkBottom:0,this.bkLeft:0); } else { ..gdi.drawBitmap(hdc,owner[["(background)"]],rc); } } var rcContent = rc.copy(); rcContent.right = rcContent.right - this.paddingRight; rcContent.bottom = rcContent.bottom - this.paddingBottom; rcContent.left = rcContent.left + this.paddingLeft; rcContent.top = rcContent.top + this.paddingTop; if(this.forecolor!==null){ if(this.linearGradient!== null && this.bgcolor !== null ){ if(this.linearGradient>=0){ ..gdi.fillGradient(hdc,rc,this.bgcolor,this.forecolor,this.linearGradient?1:0) } } else { ..gdi.fillRect(hdc,this.forecolor,rcContent); } } if(this.onDrawBackground)this.onDrawBackground(hdc,rc); if(this.text && this.font){ var flags = 0x20/*_DT_SINGLELINE*/; if( this.align =="center"){ flags = flags | 1/*_DT_CENTER*/; } elseif( this.align =="right"){ flags = flags | 2/*_DT_RIGHT*/; } if( this.valign =="center"){ flags = flags | 4/*_DT_VCENTER*/ ; } elseif( this.valign =="bottom"){ flags = flags | 8/*_DT_BOTTOM*/; } if( this.drawTextFlags ) flags = flags | this.drawTextFlags; if(this.color!==null){ var preClr = ::SetTextColor(hdc,this.color); ..gdi.drawText(hdc,this.font,this.text,rc,flags); ::SetTextColor(hdc,preClr); } else { ..gdi.drawText(hdc,this.font,this.text,rc,flags); } } }; setPos = function(x,y,cx,cy){ this.rect.setPos(x,y,cx,cy); }; getPos = function(){ return this.rect.getPos(); }; redraw = function(){ owner[["_parentForm"]].redrawBackground(owner.rect); }; setBitmap = function(bmp){ if(owner[["(background)"]]){ ::DeleteObject(owner[["(background)"]]); owner[["(background)"]] = null; } owner[["(background)"]] = bmp; }; setFont = function(f){ if(type(f) != "table" ) error("参数错误@1",2) f = ::LOGFONT(f); if(f[["h"]] && !f[["point"]] && !f[["noScale"]]){ var yScale = owner[["dpiScaleY"]]; if(yScale && yScale>1){ f[["h"]] = f[["h"]] * yScale; } } this.font = f; }; getFont = function(noScale){ var f = ::LOGFONT(this.font); if(!noScale){ var yScale = owner[["dpiScaleY"]]; if(yScale && yScale>1) f[["h"]] = f[["h"]] / yScale; } else f.noScale = true; return f; }; enableDpiScaling = function(scaleX,scaleY){ if( scaleX === false ){ return; } if(!( scaleX && scaleY ) ) { return; } if( !owner[["dpiScaleX"]] ) { owner[["dpiScaleX"]] = 1; owner[["dpiScaleY"]] = 1; } var origScaleX,origScaleY = owner[["dpiScaleX"]],owner[["dpiScaleY"]]; owner[["dpiScaleX"]] = scaleX; owner[["dpiScaleY"]] = scaleY; var font = this.font; if( font ){ font.h = ( font.h / origScaleY ) * scaleY; } }; _onDestroy = function(){ if(this.bitmap){ ::DeleteObject(this.bitmap); this.bitmap = null; } }; @_metaProperty; } bk._metaProperty = ..util.metaProperty( background = { _get = function () { return owner[["(background)"]]; } _set = function (v) { if(owner[["(background)"]] ){ ::DeleteObject(owner[["(background)"]]); owner[["(background)"]] = null; } if(type(v)==="number"){ owner.bgcolor = v; } else{ owner[["(background)"]] = ..com.picture.loadBitmap(v) } } }; foreground = { _get = function () { return owner.forecolor; } _set = function (v) { owner.forecolor = v; } }; show = function(v){ owner.$hidden = (v===null || !v); owner.redraw(); }; hide = { _get = function(ownerCall){ if(ownerCall) return function() {owner.$hidden = true;owner.redraw();}; return owner.$hidden; } _set = function(v){ owner.$hidden = v; owner.redraw(); } }; close = function(){ owner[["_parentForm"]].remove(owner); owner._onDestroy(); owner.redraw(); }; ) /**intellisense() win.ui.ctrl.bk() = 无窗口控件,仅用于背景贴图,不建议用于频繁刷新绘图\n!winuictrlbk. end intellisense**/ /**intellisense(!winuictrlbk) redraw() = 刷新,会导致背景窗口重建背景图缓存\n不建议频繁调用 setBitmap(__) = 参数指定位图句柄,重设背景位图\n控件负责销毁位图句柄 background = 参数指定图像路径,重设背景图像,\n仅支持 gif,jpg 等,不支持png,\npng 贴图请改用 bkplus 控件 forecolor = 前景色,RGB 格式数值 bgcolor = 背景色,RGB 格式数值 linearGradient = 线程渐变方向,0为水平方向,其他数值为垂直方向渐变 getPos() = 返回 `x,y,cx,cy` 等 4 个值。\n`x,y`为控件坐标,`cx,cy` 为控件宽、高。 setPos(.(x,y,cx,cw) = 修改控件的 x,y 坐标与宽(cx),高(cw)。\n所有参数可选,不指定的参数则保持原值。\n对于 bk,bkplus 控件此函数不负责重绘。 onDrawBackground = @.onDrawBackground(hdc,rc){ /*背景绘图以后触发此回调,\nhdc为当前绘图设备句柄,rc为控件位置*/ } show() = 显示窗口。\n参数 @1 为 false 时隐藏窗口。 hide = 当前控件是否隐藏\n\n以 `.` 前导的 `.hide()` 作为成员函数被调用时,\n作用等价于将 hide 属性设为 null 。 close() = 移除控件。 end intellisense**/