I wasted a lot of time trying to get CEGUI to work.
I thought the ideal would be to do it in pb via sprites, independently of the 3d engine
I found my old code.
Code: Select all
EnableExplicit
Procedure drawimagex(id1,x1,y1,dx1,dy1,x2,y2,dx2=-1,dy2=-1)
Protected n
If dx2=-1:dx2=dx1:EndIf
If dy2=-1:dy2=dy1:EndIf
n=GrabImage(id1,-1,x1,y1,dx1,dy1)
DrawImage(ImageID(n),x2,y2,dx2,dy2)
FreeImage(n)
EndProcedure
Procedure cadre(n,dx,dy)
DrawImagex(n,0,0,8,8,0,0)
DrawImagex(n,8,0,8,8,dx-8,0)
DrawImagex(n,0,8,8,8,0,dy-8)
DrawImagex(n,8,8,8,8,dx-8,dy-8)
DrawImagex(n,8,0,1,8,8,0,dx-16)
DrawImagex(n,8,8,1,8,8,dy-8,dx-16)
DrawImagex(n,0,8,8,1,0,8,8,dy-16)
DrawImagex(n,8,8,8,1,dx-8,8,8,dy-16)
DrawImagex(n,8,8,1,1,8,8,dx-16,dy-16)
EndProcedure
;Macro titre(x,y,txt,posx=0,posy=0)
;EndMacro
;===============================================================
#PB_Window_Transparent=1<<3
Structure Selement
n.i
type.b
cont.s
iscont.b
Map Glist.s()
x.w
y.w
dx.w
dy.w
xo.w
yo.w
EndStructure
Structure Sevent
n.i
ev.i
EndStructure
Global NewMap lselement.Selement()
Global NewList lSevent.Sevent()
Global Dim SCont.s(256), w3dConti
Global smouse, Son, SeventG,SeventT
Global wsalpha=255
Global Dim wsbord(20)
Enumeration
#mouse
#Window
#WindowTitle
#Raised ; button / combo / ...
#Sunken ; Edit ...
#Flat ; Image ...
EndEnumeration
Procedure Sdessine(type,n,dx,dy)
StartDrawing(SpriteOutput(n))
DrawingMode(#PB_2DDrawing_AllChannels )
Select type
Case 0 ; window
cadre(wsbord(#Window),dx,dy)
Case 1 ;button / combo / ...
cadre(wsbord(#Raised),dx,dy)
EndSelect
;DrawText(1,1,Str(n))
StopDrawing()
EndProcedure
Procedure w3dInfo(na,n,type.b,x.w,y.w,dx.w,dy.w,iscontainer.b=0)
Protected el.Selement, eid,teid.s
With el
If n=-1:\n=na:Else:\n=n:EndIf
\x=x: \dx=dx
\y=y: \dy=dy
teid=Str(n)
\iscont=iscontainer
If iscontainer=-1
w3dConti=0
Else
lselement(SCont(w3dConti))\Glist(teid)=teid
EndIf
\cont=SCont(w3dConti)
lselement(teid)=el
If iscontainer:w3dConti+1:SCont(w3dConti)=teid :EndIf
ProcedureReturn \n
EndWith
EndProcedure
Procedure creerSelement(n,type.b,flag,x,y,dx,dy,iscontainer.b=0)
Protected na
dx+16
dy+16
x-8
y-8
na=CreateSprite(n,dx,dy,#PB_Sprite_AlphaBlending)
n=w3dInfo(na,n,type,x,y,dx,dy,iscontainer)
Sdessine(type,n,dx,dy)
ProcedureReturn n
EndProcedure
Procedure Sinit()
Protected n,rc,rc2
;graphics of the different types of frames (here I do them manually, but you can load 16x16 images (32x32 for the mouse)
;mouse
wsbord(#mouse)=CreateSprite(-1,32,32,#PB_Sprite_AlphaBlending)
n=CreateImage(-1,32,32,32,#PB_Image_Transparent )
StartVectorDrawing(ImageVectorOutput(n));:TranslateCoordinates(0.5,0.5)
AddPathSegments("M 0 0 L 16 16 L 0 24 Z")
VectorSourceColor($ff000000)
FillPath(#PB_Path_Preserve)
VectorSourceColor($ffffffff)
StrokePath(2)
StopVectorDrawing()
StartDrawing(SpriteOutput(wsbord(#mouse)))
DrawingMode(#PB_2DDrawing_AllChannels)
DrawImage(ImageID(n),0,0)
StopDrawing()
;border
rc=6
Macro cadre(wsid,c1,c2,c3,pos)
wsid=CreateImage(-1,16,16,32,#PB_Image_Transparent )
StartVectorDrawing(ImageVectorOutput(wsid));:TranslateCoordinates(0.5,0.5)
AddPathCircle(8,8,rc)
VectorSourceCircularGradient(8,8,rc+0, -pos*rc/2, -pos*rc/2)
VectorSourceGradientColor(c1, 0.0)
VectorSourceGradientColor(c2, 0.5)
VectorSourceGradientColor(c3, 1.0)
FillPath()
StopVectorDrawing()
EndMacro
cadre(wsbord(#Window ),RGBA(255, 255, 255, 255),RGBA(128,128,200, 255),RGBA(64, 64, 64, 255),1)
cadre(wsbord(#WindowTitle),RGBA(255, 255, 255, 255),RGBA(128,128,255, 255),RGBA(64, 64, 255, 255),1)
cadre(wsbord(#Raised ),RGBA(255, 255, 255, 255),RGBA(192,192,100, 255),RGBA(128,128,128, 255),1)
cadre(wsbord(#Sunken ),RGBA(255, 255, 255, 255),RGBA(255,255,255, 255),RGBA(192,192,192, 255),1)
cadre(wsbord(#Flat ),RGBA(255, 255, 255, 255),RGBA(255,255,255, 255),RGBA(192,192,192, 255),1)
EndProcedure
Procedure Saff()
Static mx,my, ambg,ambd, mbd,mbg,clicg,clicd
Protected c.Selement, x,y, sp, onc,onn,onx,ony
; mx=WindowMouseX(0)
; my=WindowMouseY(0)
; clicg=Bool(EventType()=#PB_Event_LeftClick)
; clicd=Bool(WindowEvent()=#PB_Event_RightClick)
;ReleaseMouse(0)
ExamineMouse()
mx=MouseX()
my=MouseY()
ambg=mbg:mbg=MouseButton(1):clicg=Bool(Not(ambg) And (mbg))
ambd=mbd:mbd=MouseButton(2):clicd=Bool(Not(ambd) And (mbd))
son=-1
onc=-1
ForEach lselement()
With lselement()
;Debug "n="+\n +" cont="+\cont
If \cont>"":PushMapPosition(lselement()):c=lselement(\cont):PopMapPosition(lselement()):EndIf
x=c\x+\x
y=c\y+\y
If (mx>=x And mx<=x+\dx) And (my>=y And my<=y+\dy):son= \n:onc=\iscont:onn=\n:onx=x:ony=y:EndIf
DisplayTransparentSprite(\n,x,y,wsalpha)
EndWith
Next
;survol
If onc>=0:DisplayTransparentSprite(onn,onx,ony,64,$ff0000):EndIf
;clic gauche
If clicg:SeventG=son:SeventT=#PB_EventType_LeftClick:EndIf
;clic droit
If clicd:SeventG=son:SeventT=#PB_EventType_RightClick:EndIf
DisplayTransparentSprite(wsbord(#mouse),mx,my)
EndProcedure
Procedure sEventGadget()
Protected ev=SeventG
SeventG=-1
ProcedureReturn ev
EndProcedure
Procedure sEventType()
Protected ev=SeventT
SeventT=-1
ProcedureReturn ev
EndProcedure
;===============================================================
Procedure SOpenWindow(n,x,y,dx,dy,Title.s="",flag=0)
;If flag & #PB_Window3D_Borderless::EndIf
Protected l,h
creerSelement(n,0,flag,x,y,dx,dy,-1)
StartDrawing(SpriteOutput(n))
DrawingMode(#PB_2DDrawing_Transparent)
l=TextWidth(Title)
h=TextHeight(Title)
DrawText((dx-l)/2+8,8,Title)
StopDrawing()
EndProcedure
Procedure SButtonGadget(n, X, Y, dx,dy, txt.s,flag=0)
Protected l,h
n=creerSelement(n,1,flag,x+8,y+8,dx,dy)
StartDrawing(SpriteOutput(n))
DrawingMode(#PB_2DDrawing_Transparent)
l=TextWidth(txt)
h=TextHeight(txt)
DrawText((dx-l)/2+8,(dy-h)/2+8,txt)
StopDrawing()
EndProcedure
Procedure SImageGadget(n, X, Y, dx,dy, ID,flag=0)
Protected l,h
n=creerSelement(n,1,flag,x+8,y+8,dx,dy)
StartDrawing(SpriteOutput(n))
DrawImage(id,8,8)
StopDrawing()
EndProcedure
;===============================================================
Procedure scene3d()
CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,0,-2):CameraLookAt(0,0,0,0)
CreateLight(0,$ffffff, 10000, 10000, 0000)
CreateCube(0,1)
CreateEntity(0,MeshID(0),#PB_Material_None)
EndProcedure
Define gadget,test3d=1
If test3d:InitEngine3D():EndIf
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0, 0, 0, 512, 400, "[Escape] to quit", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 512, 400, 0, 0, 0)
If test3d:scene3d():EndIf
Sinit()
CreateImage(0,50,50,32,#PB_Image_Transparent )
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Outlined )
Box(0,0,50,50,$aaffaa)
StopDrawing()
SOpenWindow(1,50 ,20 ,200,150,"window 1")
SImageGadget(10,10,30,80,80,ImageID(0))
SOpenWindow(2,150,150,200,120,"window 2",#PB_Window_BorderLess)
SButtonGadget(20,10,30,100,20,"btn")
SButtonGadget(21,10,60,100,20,"btn")
SButtonGadget(22,10,90,100,20,"btn")
Repeat
WindowEvent()
ExamineKeyboard()
If test3d
RotateEntity(0,0.1,0.2,0.3,#PB_Relative)
RenderWorld()
EndIf
gadget=SeventGadget()
If gadget>-1
Debug "gadget:"+gadget+ " sEventType:"+sEventType()
EndIf
ClearScreen($888888)
Saff()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)