Win32max Demo (20k)
Community Forums/Showcase/Win32max Demo (20k)
| ||
This isn't releasing anything as such, it is just a small little demo. I'll take down the exe if needed though. http://skn3.acsv.net/junk/win32max_example1.zip (20k) ![]() This demonstrates the Extended button lib I have been writting, using my module interface. Still to do, are bitmaps, and that is about it. If oyu are interested, the code for the Extended button class is shown below. It shows how gadgets can now be fully designed in a modular form. Allowing the user to extend the module, by including some extra .bmx files. "TButtonEx.bmx" '--- styles --------------------------------- Const CBSdefault:Int = 2048 Const CBSmultiline:Int = 4096 Const CBSflat:Int = 8192 Const CBStextleft:Int = 16384 Const CBStextright:Int = 32768 Const CBStexttop:Int = 65536 Const CBStextbottom:Int = 131072 Const BEXcolorDefault = 0 Const BEXcolorCustom = 1 Const BEXcolorGradient = 2 Const BEXgradientVertical = 0 Const BEXgradientHorizontal = 1 '--- type --------------------------------- TButtonEx.list = CreateList() Type TButtonEx Extends TGadget Global list:Tlist 'drawing modes Field colormode'0 normal button, 1 color button, 2 gradient button Field bitmapmode'0 normal button, 1 bitmap & text, 2 bitmap only Field gradientmode'0 vertical, 1 horizontal 'drawing properties Field facergb1 Field facergb2 Field lightrgb Field darkrgb Field shadowrgb Field textrgb 'drawing states Field disabledstate Field pushedstate Field focusstate 'system functions Function FromHwnd:TButtonEx(Hwnd:Int) 'finds TGadget instance from hwnd If TButtonEx.list = Null Return Null For Local gadget:TButtonEx = EachIn TButtonEx.list If gadget.Hwnd = Hwnd Return gadget Next Return Null End Function Function Brain:Int(gadgethandle:Object,parenthandle:Object,hwnd:Int,msgid:Int,wparam:Int,lparam:Int,returnvalue:Int Var) Local gadget:TButtonEx = TButtonEx(gadgethandle) Local parent:TButtonEx = TButtonEx(parenthandle) Select msgid Case WM_LBUTTONDBLCLK 'convert double click into single click ApiPostMessage(hwnd,WM_LBUTTONDOWN,Byte Ptr(wParam),Byte Ptr(lParam)) returnvalue = 0 Return True Case WM_DRAWITEM 'button state has changed gadget.pushedstate = win32max.drawitem.itemstate & ODS_SELECTED gadget.disabledstate = win32max.drawitem.itemstate & ODS_DISABLED gadget.focusstate = win32max.drawitem.itemstate & ODS_FOCUS gadget.Render() returnvalue = 1 Return True Case WM_MOUSEMOVE 'Print "MOVE!" 'mouse has moved over button Case WM_PAINT 'button needs refreshing gadget.Render() ApiValidateRect(gadget.hwnd,Null) returnvalue = 1 Return True End Select End Function Function Callback() Select eventid Case WM_LBUTTONUP If Not ApiPtInRect(eventgadget.Rect(),eventx,eventy) Return True eventdata = 1 eventid = GEmouseup eventx = lparamX(eventlparam) eventy = lparamY(eventlparam) End Select End Function Function MakeApiStyle:Int(style:Int) Local base:Int = 0 base = BS_OWNERDRAW Return base End Function Function MakeApiStyleEx:Int(style:Int) Local base:Int = 0 Return base End Function 'system methods Method Render() 'global object used to render all TButtonEx's Global paint:TGadgetPaint = TGadgetPaint.Create() 'setup TGadgetPaint paint.SetOwner(Self) paint.BeginPaint() 'create gdi objects Local rect:TRect = New Trect rect.GetGadget(Self) Select colormode Case 0 'normal button paint.DrawButton(text,rect.x,rect.y,rect.width,rect.height,pushedstate,disabledstate,focusstate) Case 1,2 'color button Local penlight:Int = CreatePen(lightrgb) Local pendark:Int = CreatePen(darkrgb) Local penshadow:Int = CreatePen(shadowrgb) 'face Select colormode Case 1 Local brushface:Int = CreateBrush(facergb1) paint.SelectBrush(brushface) paint.DrawRect(rect.x,rect.y,rect.width,rect.height) paint.DeleteBrush(brushface) Case 2 'check for skip gradient fill If facergb1 = facergb2 Local brushface:Int = CreateBrush(facergb1) paint.SelectBrush(brushface) paint.DrawRect(rect.x,rect.y,rect.width,rect.height) paint.DeleteBrush(brushface) Else paint.DrawGradientRect(rect.x,rect.y,rect.width,rect.height,facergb1,facergb2,gradientmode) End If End Select 'border push/not pushed If pushedstate 'light paint.SelectPen(penlight) paint.DrawLine(rect.Left,rect.bottom-1,rect.Right+1,rect.bottom-1) paint.DrawLine(rect.Right,rect.top,rect.Right,rect.bottom-1) 'dark paint.SelectPen(pendark) paint.DrawLine(rect.Left+1,rect.top+1,rect.Right-1,rect.top+1) paint.DrawLine(rect.Left+1,rect.top+2,rect.Left+1,rect.bottom-1) 'shadow paint.SelectPen(penshadow) paint.DrawLine(rect.Left,rect.top,rect.Right,rect.top) paint.DrawLine(rect.Left,rect.top+1,rect.Left,rect.bottom) Else 'light paint.SelectPen(penlight) paint.DrawLine(rect.Left,rect.top,rect.Right,rect.top) paint.DrawLine(rect.Left,rect.top+1,rect.Left,rect.bottom) 'dark paint.SelectPen(pendark) paint.DrawLine(rect.Left+1,rect.bottom-2,rect.Right,rect.bottom-2) paint.DrawLine(rect.Right-1,rect.top+1,rect.Right-1,rect.bottom-2) 'shadow paint.SelectPen(penshadow) paint.DrawLine(rect.Left,rect.bottom-1,rect.Right+1,rect.bottom-1) paint.DrawLine(rect.Right,rect.top,rect.Right,rect.bottom-1) End If 'text rect.Shrink(3) paint.SetBackgroundTransparent() If disabledstate Local oldrgb:Int = paint.SetTextColor(lightrgb) If pushedstate paint.DrawTextRect(rect.x+2,rect.y+2,rect.width,rect.height,text,DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_WORDBREAK) paint.SetTextColor(darkrgb) paint.DrawTextRect(rect.x+1,rect.y+1,rect.width,rect.height,text,DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_WORDBREAK) paint.SetTextColor(oldrgb) Else paint.DrawTextRect(rect.x+1,rect.y+1,rect.width,rect.height,text,DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_WORDBREAK) paint.SetTextColor(darkrgb) paint.DrawTextRect(rect.x,rect.y,rect.width,rect.height,text,DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_WORDBREAK) paint.SetTextColor(oldrgb) End If Else Local oldrgb:Int = paint.SetTextColor(textrgb) If pushedstate paint.DrawTextRect(rect.x+1,rect.y+1,rect.width,rect.height,text,DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_WORDBREAK) Else paint.DrawTextRect(rect.x,rect.y,rect.width,rect.height,text,DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_WORDBREAK) End If paint.SetTextColor(oldrgb) End If 'focus rect If focusstate paint.DrawFocusRect(rect.x,rect.y,rect.width,rect.height) 'remove objects paint.DeletePen(penlight) paint.DeletePen(pendark) paint.DeletePen(penshadow) End Select 'end patining paint.EndPaint() End Method Method New() link = TButtonEx.list.AddLast(Self) End Method 'user methods Method SetFaceColor(rgb1:Int,rgb2:Int=0) If facergb1 <> rgb1 Or facergb2 <> rgb2 facergb1 = rgb1 facergb2 = rgb2 Redraw() End If End Method Method SetBorderColor(light:Int,dark:Int,shadow:Int) If light <> lightrgb Or dark <> darkrgb Or shadow <> shadowrgb lightrgb = light darkrgb = dark shadowrgb = shadow If colormode <> BEXcolorDefault Redraw() End If End Method Method SetColorMode(mode:Int) If mode <> colormode colormode = mode Redraw() End If End Method Method SetGradientDirection(direction:Int) If direction <> gradientmode gradientmode = direction If colormode = BEXcolorGradient Redraw() End If End Method End Type '--- functions --------------------------------- Function CreateButtonEx:TButtonEx(title:String,x:Int,y:Int,width:Int,height:Int,parent:Object,style:Int=0) 'create button Local gadget:TButtonEx = New TButtonEx gadget.MakeGadget(gadget,title,x,y,width,height,"Button",parent,WS_CHILD | TGadget.MakeApiStyle(style) | TButtonEx.MakeApiStyle(style),TGadget.MakeApiStyleEx(style) | TButtonEx.MakeApiStyleEx(style)) 'set button default colors gadget.facergb1 = SysColor(COLOR_BTNFACE) gadget.facergb2 = ChangeRgbBrightness(gadget.facergb1,1.13) gadget.lightrgb = SysColor(COLOR_3DHILIGHT) gadget.darkrgb = SysColor(COLOR_3DSHADOW) gadget.shadowrgb = SysColor(COLOR_3DDKSHADOW) gadget.textrgb = SysColor(COLOR_BTNTEXT) 'create button brain gadget.AddBrain(TButtonEx.Brain,WM_LBUTTONDBLCLK) gadget.AddBrain(TButtonEx.Brain,WM_DRAWITEM) gadget.AddBrain(TButtonEx.Brain,WM_PAINT) gadget.AddBrain(TButtonEx.Brain,WM_MOUSEMOVE) 'create button events gadget.AddEvent(TButtonEx.Callback,WM_LBUTTONUP) 'return button Return gadget End Function |
| ||
Sweet! |
| ||
Nice one ! Will we able to build also shaped buttons ? For example, a rounded button, or a 'triangle-ish' one ? Sergio. |
| ||
Probably not with the built in button class, but you could easily modify the painting routine to do whatever you want. |