注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

[原创]沉默蜂版颜色选择器(二)  

2014-10-12 19:30:21|  分类: B.图形 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
下面是类模块MyColorPicker

#Region 代码说明

'版本:2014-10-12
'设计:沉默蜂(QQ793136625)
'博客:http://silentbees.blog.163.com

#End Region


'Class module
Sub Class_Globals

Private mModule As Object
Private mEventName As String
'pnlColor是颜色选择器,pnlBottom放置底部按钮,pnlShadow阴影
Private pnlColor, pnlBottom,pnlShadow As Panel
' Dim lblTitle As Label
Private sbTransparency As SeekBar
Private sbRed As SeekBar
Private sbGreen As SeekBar
Private sbBlue As SeekBar
Dim lblT,lblR,lblG,lblB As Label
Dim btnApplyColor, btnOKColor ,btnCancelColor  As Button
End Sub


'初始化颜色选择器
'初始化后的颜色盘是隐藏的
'IsEisenableApply - 是否需要禁用应用按钮
'ShadowColor - 颜色选择器阴影区的颜色
'SerColor - 初始颜色
Sub Initialize(Activity As Activity, Module As Object, EventName As String,IsEisenableApply As Boolean,ShadowColor As Int,SerColor As Int)

mModule = Module
mEventName = EventName
#Region 面板
'最底部的阴影区域,这个颜色选择器上的所有控件全放置在这个面板上
'面板Visible属性决定这个颜色选择器的显示隐藏
pnlShadow.Initialize("pnlColor")
pnlShadow.Visible = False
pnlShadow.Color=ShadowColor
' pnlShadow.Color=Colors.ARGB(70,50,50,50)
Activity.AddView(pnlShadow, 0, 0, 100%x , 100%y)
'在这个面板上放置颜色盘,屏幕中间显示,高度为270dip,宽度为100%x
pnlColor.Initialize("pnlColor")
' pnlColor.Visible = False
pnlShadow.AddView(pnlColor, 0, (100%y - 270dip)/2, 100%x, 270dip)
'pnlBottom面板是在颜色盘下方用来放置按钮的,高度为70dip
pnlBottom.Initialize("")
pnlColor.AddView(pnlBottom, 0, pnlColor.Height - 70dip, pnlColor.Width, 70dip)
#End Region
#Region 颜色滑块
'透明度标签
lblT.Initialize("")
lblT.Text = "透明"
lblT.TextColor = Colors.Black
lblT.TextSize = 5dip
pnlColor.AddView(lblT, 10dip, 11dip, 80dip, 25dip)
'透明度滑块
sbTransparency.Initialize("sbColor")
sbTransparency.Max = 255
sbTransparency.Tag="sbTransparency"
pnlColor.AddView(sbTransparency, 90dip, 10dip, 100%x-100dip, 31dip)

'红色标签
lblR.Initialize("")
lblR.Text = "红色"
lblR.TextColor = Colors.Black
lblR.TextSize = 5dip
pnlColor.AddView(lblR, 10dip, 61dip, 80dip, 25dip)
'红色滑块
sbRed.Initialize("sbColor")
sbRed.Max = 255
sbRed.Tag="sbRed"
pnlColor.AddView(sbRed, 90dip, 60dip, 100%x-100dip, 31dip)


'绿色标签
lblG.Initialize("")
lblG.Text = "绿色"
lblG.TextColor = Colors.Black
lblG.TextSize = 5dip
pnlColor.AddView(lblG, 10dip, 111dip, 80dip, 25dip)
'绿色滑块
sbGreen.Initialize("sbColor")
sbGreen.Max = 255
sbGreen.Tag="sbGreen"
pnlColor.AddView(sbGreen, 90dip, 110dip, 100%x-100dip, 31dip)

'蓝色标签
lblB.Initialize("")
lblB.Text = "蓝色"
lblB.TextColor = Colors.Black
lblB.TextSize =5dip
pnlColor.AddView(lblB, 10dip, 161dip, 80dip, 25dip)
'蓝色滑块
sbBlue.Initialize("sbColor")
sbBlue.Max = 255
sbBlue.Tag="sbBlue"
pnlColor.AddView(sbBlue, 90dip, 160dip, 100%x-100dip, 31dip)

#End Region



#Region 确定取消应用按钮
    '最右边的按钮
btnApplyColor.Initialize("btnApplyColor")
btnApplyColor.Text = "应用"
pnlBottom.AddView(btnApplyColor, pnlBottom.Width - 90dip, 10dip, 80dip, 50dip)
   

'中间按钮
btnCancelColor.Initialize("btnCancelColor")
btnCancelColor.Text = "取消"
pnlBottom.AddView(btnCancelColor, btnApplyColor.Left-10dip-80dip, 10dip, 80dip, 50dip)
   '最左边按钮
btnOKColor.Initialize("btnOKColor")
btnOKColor.Text = "确定"
pnlBottom.AddView(btnOKColor, btnCancelColor.Left-10dip-80dip, 10dip, 80dip, 50dip)
#End Region


'是否需要禁用应用按钮
btnApplyColor.Enabled=IsEisenableApply
 
ParseColor(SerColor)
 
' sbTransparency.Value=255
' sbRed.Value=255
'    sbGreen.Value=255
' sbBlue.Value=255
 
End Sub

'分解一个颜色值
'参考http://www.basic4ppc.com/android/forum/threads/colorpalette.32483/ 
Public Sub ParseColor(clr As Int)

'将一个颜色值通内部处理后返回一个包含透明度的颜色值
'Public Sub ParseColor(clr As Int) As Int()

sbTransparency.Value=Bit.UnsignedShiftRight(Bit.AND(clr, 0xff000000), 24) ' alfa透明度
sbRed.Value=Bit.UnsignedShiftRight(Bit.AND(clr, 0xff0000), 16)   ' R红色
    sbGreen.Value=Bit.UnsignedShiftRight(Bit.AND(clr, 0xff00), 8)      ' G绿色
sbBlue.Value=Bit.AND(clr, 0xff)  ' B蓝色
' Dim res(4) As Int
' res(0) = Bit.UnsignedShiftRight(Bit.AND(clr, 0xff000000), 24) ' alfa透明度
' res(1) = Bit.UnsignedShiftRight(Bit.AND(clr, 0xff0000), 16)   ' R红色
' res(2) = Bit.UnsignedShiftRight(Bit.AND(clr, 0xff00), 8)      ' G绿色
' res(3) = Bit.AND(clr, 0xff)  ' B蓝色
' Return res


End Sub






'获取颜色盘当前是否为可视
Public Sub  GetVisible  As Boolean
Return pnlShadow.Visible
End Sub

'控制显示颜色选择器可视与隐藏
Public Sub  SetShow(show As Boolean)
pnlShadow.Visible = show  
End Sub


'滑块发生变化时,颜色也随之发生变化
Private  Sub sbColor_ValueChanged(Value As Int, UserChanged As Boolean)

pnlColor.Color = Colors.ARGB( sbTransparency.Value, sbRed.Value, sbGreen.Value, sbBlue.Value)
pnlBottom.Color = Colors.ARGB(255, sbRed.Value, sbGreen.Value, sbBlue.Value)
' pnlColor.Invalidate
Dim  vSb As SeekBar =Sender
Select vSb.Tag
Case "sbTransparency"
lblT.Text="透明:" &sbTransparency.Value
Case  "sbRed"
lblR.Text="红色:" &sbRed.Value
Case "sbGreen"
lblG.Text="绿色:" &sbGreen.Value
Case  "sbBlue"
lblB.Text="蓝色:" &sbBlue.Value
End Select
End Sub

'点击应用按钮
Sub btnApplyColor_Click

CallSub2(mModule,mEventName & "_btnApplyColor",Colors.ARGB(sbTransparency.Value, sbRed.Value, sbGreen.Value, sbBlue.Value))
End Sub

'点击取消按钮
Sub btnCancelColor_Click
SetShow(False)
End Sub

'点击确定按钮
Sub btnOKColor_Click
CallSub2(mModule,mEventName & "_btnOKColor",Colors.ARGB(sbTransparency.Value, sbRed.Value, sbGreen.Value, sbBlue.Value))
SetShow(False)
End Sub

  评论这张
 
阅读(198)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017