hey, im making a pseudo win xp gui system. all going fine so far, but when i drag the window all of the gadgets seem to be out of place :S the source will be uploaded soon, but does anyone have any ideas on why this is?
acid2
acid2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; I was a fond user of the BlitzUI library but when it came to customizing it ; ; so I could have rollouts I got a problem and was to lazy to fix it :P the ; ; 'polarGUI' is the result: and I hope its going to be quite nice! ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; 1) Call SetupUI("my program", 800, 600). This sets the graphics mode and ; ; also makes polarGUI ready for use. ; ; ; ; 2) Create your application ; ; ; ; 4) Open a while loop and call UpdateGUI() This updates everything, and ; ; also draws it. ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; global fntTitle, fntButton, fntGadgetB global createMode$ = "Window" type Application field MX%, MY% ; The MouseX() and Mousey() field Title$ ; Used with AppTitle field pointNormal field mouseState field active.window, overWin.window end type type Window field X%, Y%, W%, H% field Caption$ field flagClose%, flagMin%, flagCenter%, flagLock%, flagTop% field image% field dragX%, dragY%, dragging% field closed field FXY field winImage ;<- Used to display the entire window (not yet implented) end type type Button field x%, y%, w%, h%, enabled%, visible% field caption$ field owner.window, rollOwner.xprollitem, tabOwner.tabPage end type type Radio field x%, y%, checked%, visible% field caption$, desc$ field toggleId% field owner.window, rollowner.xprollitem end type type Shape field x%, y%, w%, h% field shType% field owner.window field r, g, b field image end type type XpRollout field x%, y%, w%, h%, offset% field owner.window end type type xpRollitem field x%, y%, w%, h%, caption$ field owner.window, rollout.xpRollout field open% end type type Tab field x%, y%, w%, h%, offset% field owner.window end type type TabPage field x%, w%, caption$ field owner.window, owntab.tab field open% end type global EventWindow$ global EventWidget$ global EventMenu$ global EventHandle dim GuiImages(15) ;None resized elements include "images.bb" Function Window(x% = 0, y% = 0, width% = 100, h% = 50, Caption$ = "-", Image = 0, alwaysTop%=0, close% = 1, min% = 1, cent% = 0, lock% = 0) w.Window = new Window w\x = x w\y = y w\w = width w\h = h w\fxy = 29 w\caption = caption w\flagClose = close w\flagMin = min w\flagCenter = cent w\flagLock = lock if image w\image = copyimage(image) endif insert w before first window return handle( w ) End Function Function UpdateGUI() app.application = first application UpdateWindows() UpdateMouse() temp.window = app\active for temp2.window = each window if temp2\flagTop then insert temp2 before first window next app\mx = mousex() app\my = mousey() app\active = temp drawimage app\pointNormal, app\mx, app\my End Function function UpdateWindows() app.application = first application ;Z-Order w.window = last window while w <> null if mouseover(w\x, w\y, w\w, w\h) app\overWin = w endif w = before w wend if app\mouseState = 1 if app\overWin <> null insert app\Overwin before first window app\active = first window endif endif w.window = last window while w <> null if w\closed = false ;Draw The Borders restore xpSideL for i = 0 to 2 setcolourdata() line w\x+i, w\y+6, w\x+i, w\y+w\h-1 next restore xpSideR for i = 0 to 2 setcolourdata() line w\x+w\w-2+i, w\y+6, w\x+w\w-2+i, w\y+w\h-1 next restore xpSideB for i = 0 to 2 setcolourdata() line w\x, w\y+w\h-2+i, w\x+w\w, w\y+w\h-2+i next ;Title Bar restore xpTitle for i = 0 to 28 SetColourData() line w\x+7, w\y+i, w\x+w\w-6, w\y+i next ;Fine Tunings :) drawimage GuiImages(5), w\x, w\y+w\h-2 drawimage GuiImages(6), w\x+w\w-2, w\y+w\h-2 drawimage GuiImages(3), w\x, w\y drawimage GuiImages(4), w\x+w\w-6, w\y restore winTl for y = 0 to 28 for x = 0 to 6 setcolourdata() if not (colorred() = 255 and colorblue() = 255 and colorgreen() = 0) plot w\x+x, w\y+y endif next next restore winTr for y = 0 to 28 for x = 0 to 5 setcolourdata() if not (colorred() = 255 and colorblue() = 255 and colorgreen() = 0) plot w\x+w\w-6+x, w\y+y endif next next color 239, 235, 222 rect w\x+3, w\y + 29, w\w - 5, w\h - 31 ;Close if w\flagClose app.application = first application if MouseOver(w\x+w\w-27, w\y+5, 19, 19) if app\mouseState = 2 drawimage GuiImages(2), w\x+w\w-26, w\y+6 elseif mousestate = 3 w\closed = true EventWindow = "closed" EventHandle = handle ( w ) else drawimage GuiImages(1), w\x+w\w-26, w\y+6 endif else drawimage GuiImages(0), w\x+w\w-26, w\y+6 endif endif ;Minamize ;Attempt of dragging :P if w\flagLock <> true if app\mouseState = 1 if w = first window if Mouseover(w\x, w\y, w\w, 29) and mouseover(w\x+w\w-27, w\y+5, 21, 21) = false w\dragX = mousex() - w\x w\dragY = mousey() - w\y w\dragging = true insert w before first window endif endif endif if w\dragging and app\mouseState = 2 w\x = mousex() - w\dragX w\y = mousey() - w\dragY elseif app\mouseState = 0 and w\dragging = true w\dragging = false endif endif ;Title setfont fntTitle if w\image if imagewidth(w\image) <= 16 if imageheight(w\image) <= 16 drawimage w\image, w\x+6, w\y+8 color 8, 24, 132: text w\x+9+imagewidth(w\image), w\y+9, w\Caption color 255, 255, 255: text w\x+8+imagewidth(w\image), w\y+8, w\Caption else showsimple = true endif else showsimple = true endif else showSimple = true endif if showSimple color 8, 24, 132: text w\x+8, w\y+9, w\Caption color 255, 255, 255: text w\x+7, w\y+8, w\Caption endif endif updateXpRollouts(w) updatetabs(w) updatebuttons(w) updateshapes(w) updateRadio(w) w = before w wend End function function UpdateButtons(w.window) app.application = first application for b.button = each button if b\owner = w x = b\owner\x + 4 + b\x ;Root x y = b\owner\y + b\owner\fxy + b\y ;Root y if b\rollOwner <> null x = b\owner\x + 4 + b\rollOwner\rollout\x + 12 + b\x y = b\owner\y + b\owner\fxy + b\rollOwner\rollout\y + b\rollOwner\y + b\y if b\rollOwner\open then b\visible = true else b\visible = false viewport b\owner\x + 4 + b\rollOwner\rollout\x, b\owner\y + b\owner\fxy + b\rollOwner\rollout\y, b\rollOwner\rollout\w, b\rollOwner\rollout\h endif if b\tabOwner <> Null x = b\owner\x + 4 + b\tabOwner\ownTab\x + 1 + b\x y = b\owner\y + b\owner\fxy + b\tabOwner\ownTab\y + 30 + b\y if b\tabOwner\open then b\visible = true else b\visible = false endif if b\visible ;Drawing if b\enabled ;Indent color 231, 227, 214 RoundRect x-1, y-1, b\w+2, b\h+2 color 255, 251, 247 roundrect x, y, b\w+1, b\h+1 endif ;Border if b\enabled color 0, 60, 115 else color 206, 199, 189 endif roundrect x, y, b\w, b\h ;Inside color 247, 247, 239 rect x+1, y+1, b\w-2, b\h-2 if b\enabled ;Highlights color 238, 235, 231: line x+1, y+b\h-4, x+b\w-2, y+b\h-4 color 231, 227, 214: line x+1, y+b\h-3, x+b\w-2, y+b\h-3 color 218, 215, 197: line x+1, y+b\h-2, x+b\w-2, y+b\h-2 if app\active = b\owner offset = 0 if mouseover(x, y, b\w, b\h) if app\MouseState = 0 color 255, 243, 206: rect x+1, y+1, b\w-2, 1 ;Top color 255, 217, 137 starty = y+1 height = ceil(b\h/2)-2 rect x+1, starty, b\w-2, height color 254, 193, 81 starty = starty + height height = ceil(b\h/2)-2 rect x+1, starty, b\w-2, height color 243, 165, 25: rect x+1, y+b\h-4, b\w-2, 3 ;Base ;The inside color 238, 235, 231: line x+3, y+b\h-4, x+b\w-4, y+b\h-4 color 247, 243, 239: rect x+3, y+3, b\w-6, b\h-7 elseif app\MouseState = 1 or app\MouseState = 2 color 209, 180, 131: rect x+1, y+1, b\w-2, b\h-2 color 231, 216, 190: rect x+3, y+3, b\w-4, b\h-4 color 221, 204, 170: rect x+3, y+3, b\w-6, b\h-6 elseif app\MouseState = 3 EventWidget = Handle ( b ) endif endif endif endif if b\enabled then color 0, 0, 0 else color 165, 162, 148 setfont fntButton text x+(b\w/2)+offset, y+(b\h/2)+offset, b\caption, true, true endif endif viewport 0, 0, graphicswidth(), graphicsheight() next end function Function RoundRect(x, y, w, h, radius = 1) Rect x, y+radius, w, h-(radius*2) Rect x+radius, y, w-(radius*2), h If radius > 1 Oval x, y, radius*2, radius*2 Oval (x+w)-(radius*2), y, radius*2, radius*2 Oval x, (y+h)-(radius*2), radius*2, radius*2 Oval (x+w)-(radius*2), (y+h)-(radius*2), radius*2, radius*2 EndIf End Function function Shape(shtype%, x, y, w, h, r = 0, g = 0, b = 0, image = 0) s.shape = new shape s\x = x s\y = y s\w = w s\h = h s\r = r s\g = b s\b = g if image s\image = copyimage(image) endif s\owner = first window s\shType = shType end function Function UpdateShapes(w.window) for s.shape = each shape if s\owner = w select s\shType case 1 color 165, 162, 148: line s\x+s\owner\x+4, s\y+s\owner\y+s\owner\fxy, s\x+s\owner\x+s\w-4, s\y+s\owner\y+s\owner\fxy color 255, 251, 247: line s\x+s\owner\x+4, s\y+s\owner\y+s\owner\fxy+1, s\x+s\owner\x+s\w-4, s\y+s\owner\y+s\owner\fxy+1 case 2 color s\r, s\g, s\b: rect s\x+s\owner\x+4, s\y+s\owner\y+s\owner\fxy, s\w-6, s\h case 3 drawimage s\image, s\x+s\owner\x+4, s\y+s\owner\y+s\owner\fxy end select endif next end function Function Radio(x%, y%, id%, Caption$, Desc$ = "", Checked% = false) r.radio = new radio r\x = x r\y = y r\toggleid = id r\caption = caption r\desc = desc r\checked = false r\owner = first window if createMode = "xpRollitem" then r\rollOwner = first xprollitem if checked for r.radio = each radio if r\owner = first window if r\toggleId = id r\checked = false endif endif next r\checked = true endif r\visible = true insert r before first radio return handle ( r ) end function Function UpdateRadio(w.window) app.application = first application for r.radio = each radio if r\owner = w x = r\owner\x + 4 + r\x ;Root x y = r\owner\y + r\owner\fxy + r\y ;Root y if r\rollOwner <> null x = r\owner\x + 4 + r\rollOwner\rollout\x + 12 + r\x y = r\owner\y + r\owner\fxy + r\rollOwner\rollout\y + r\rollOwner\y + r\y if r\rollOwner\open = false then r\visible = false else r\visible = true ;Set the viewport (we're in a rollout :) ) viewport r\owner\x + 4 + r\rollOwner\rollout\x, r\owner\y + r\owner\fxy + r\rollOwner\rollout\y, r\rollOwner\rollout\w, r\rollOwner\rollout\h endif if r\visible ;Drawing drawimage GuiImages(16), x, y if mouseover(x, y, 13, 13) if app\active = r\owner if app\mouseState = 1 or app\Mousestate = 2 for temp.radio = each radio if temp\toggleId = r\toggleId then temp\checked = false next r\checked = true drawimage GuiImages(17), x+5, y+5 elseif app\mousestate = 3 or app\mousestate = 0 if r\checked = true drawimage GuiImages(18), x+4, y+4 endif endif endif else if r\checked drawimage GuiImages(17), x+4, y+4 endif endif ;Labels color 0, 0, 0 if r\desc <> "" setfont fntGadgetB text x+22, y+1, r\caption setfont fntButton text x+22, y+15, r\desc else setfont fntButton text x+22, y+1, r\caption endif ENDIF endif viewport 0, 0, graphicswidth(), graphicsheight() next end function Function XpRollout(x, y, w, h) r.xpRollout = new xprollout r\x = x r\y = y r\w = w r\h = h r\owner = first window insert r before first xprollout return handle ( r ) end function function XpRollItem(Caption$, h) page.xpRollitem = new xpRollitem page\h = h page\caption = caption page\owner = first window page\rollout = first xpRollout createMode = "xpRollitem" insert page before first xpRollitem return handle ( page ) end function function UpdateXpRollouts(w.window) app.application = first application for rollout.xpRollout = each XpRollout if rollout\owner = w ;Scroll bars ;Top if MouseOver(rollout\owner\x+4+rollout\x+rollout\w, rollout\owner\y+rollout\owner\fxy+rollout\y, 13, 14) if app\mouseState = 2 drawimage GuiImages(21), rollout\owner\x+4+rollout\x+rollout\w, rollout\owner\y+rollout\owner\fxy+rollout\y rollout\offset = rollout\offset + 5 if rollout\offset > 0 then rollout\offset = 0 else drawimage GuiImages(20), rollout\owner\x+4+rollout\x+rollout\w, rollout\owner\y+rollout\owner\fxy+rollout\y endif else drawimage GuiImages(19), rollout\owner\x+4+rollout\x+rollout\w, rollout\owner\y+rollout\owner\fxy+rollout\y endif ;Base if MouseOver(rollout\owner\x+4+rollout\x+rollout\w, rollout\owner\y+rollout\owner\fxy+rollout\y+rollout\h-14, 13, 14) if app\mouseState = 2 drawimage GuiImages(27), rollout\owner\x+4+rollout\x+rollout\w, rollout\owner\y+rollout\owner\fxy+rollout\y+rollout\h-14 rollout\offset = rollout\offset - 5 else drawimage GuiImages(26), rollout\owner\x+4+rollout\x+rollout\w, rollout\owner\y+rollout\owner\fxy+rollout\y+rollout\h-14 endif else drawimage GuiImages(25), rollout\owner\x+4+rollout\x+rollout\w, rollout\owner\y+rollout\owner\fxy+rollout\y+rollout\h-14 endif viewport rollout\owner\x+4+rollout\x, rollout\owner\y+rollout\owner\fxy+rollout\y, rollout\w, rollout\h color 164, 158, 228 rect rollout\owner\x+4+rollout\x, rollout\owner\y+rollout\owner\fxy+rollout\y, rollout\w, rollout\h UpdateXpRollitems(rollout) viewport 0, 0, graphicswidth(), graphicsheight() endif next end function function UpdateXpRollitems(rollout.xprollout) rollitem.xprollitem = last xprollitem app.application = last application x = rollout\owner\x+14+rollout\x y = rollout\y+rollout\owner\y+rollout\owner\fxy+10+rollout\offset w = rollout\w-20 while rollitem <> null if rollitem\rollout = rollout if mouseover(x, y, w, 25) if app\mouseState = 1 and app\active = rollitem\owner rollitem\open = not rollitem\open endif endif if rollitem\caption = "See also" then color 0, 0, 0: text 200, 200, "See also y: " + y color 7, 76, 184 roundrect x, y, w, 25, 2 rect x, y + 3, w, 22 setfont fntGadgetB color 255, 255, 255 text x+5, y+7, rollitem\caption if rollitem\open color 255, 255, 255 rect x, y+25, w, rollitem\h Gradientrect(x+1, y+25, w-2, rollitem\h-1, 255, 255, 255, 173, 188, 228) y = y + rollitem\h + 10 + 25 else y = y + 25 + 10 endif endif rollitem = before rollitem wend ;Update the 'y' positions. rollitem.xprollitem = last xprollitem y = 35 while rollitem <> null if rollitem\rollout = rollout rollitem\y = y + rollout\offset y = y + 35 if rollitem\open then y = y + rollitem\h endif rollitem = before rollitem wend end function Function CloseXpRollitem() createMode = "window" end function Function Tab(x, y, w, h) t.tab = new tab t\x = x t\y = y t\w = w t\h = h t\owner = first window createMode = "tab" insert t before first tab return handle ( t ) end function function TabPage(caption$) t.tabpage = new tabpage t\caption = caption t\w = w if t\w = 0 setfont fntButton t\w = (fontwidth()*len(t\caption)) / 3 endif t\ownTab = first tab t\owner = first window for temp.tabpage= each tabpage if temp\ownTab = first tab temp\open = false endif next t\open = true insert t before first tabpage return handle ( t ) end function function UpdateTabs(w.window) app.application = first application for t.tab = each tab if t\owner = w color 150, 151, 143 rect t\x+t\owner\x+4, t\y+t\owner\y+t\owner\fxy+21, t\w, t\h-42 color 255, 255, 255 rect t\x+t\owner\x+4+1, t\y+t\owner\y+t\owner\fxy+22, t\w-2, t\h-44 updatetabpages(t) endif next end function function UpdateTabPages(owntab.tab) app.application = first application ;Update the 'x' positions. temp.tabpage = last tabPage x = 0 while temp <> null if temp\ownTab = ownTab temp\x = x x = x + 2 + temp\w endif temp = before temp wend for t.tabPage = each tabpage if t\ownTab = owntab x = ownTab\x + ownTab\owner\x + 4 + t\x y = ownTab\y + ownTab\owner\y + ownTab\owner\fxy if t\open color 150, 151, 143 roundrect (x, y, t\w, 21, 2) line x, y+2, x, y+21 line x+t\w-1, y+1, x+t\w-1, y+21 color 255, 255, 255 roundrect (x+1, y+1, t\w-2, 20) color 243, 165, 25 line x+2, y+1, x+t\w-2, y+1 color 255, 243, 206 line x+1, y+2, x+t\w-1, y+2 color 255, 255, 255 rect x+1, y+3, t\w-2, 30 setfont fntButton color 0, 0, 0 text x+(t\w/2), y+10, t\caption, true, true else color 150, 151, 143 line x + 1, y+2, x + t\w-1, y+2 line x, y+3, x, y+21 line x + t\w-1 + 1, y+3, x + t\w-1 + 1, y+21 color 247, 247, 239 rect x+1, y+4, t\w-2, 14 color 238, 235, 231 line x+1, y+21-3, x+t\w-2, y+21-3 color 231, 227, 214 line x+1, y+21-2, x+t\w-2, y+21-2 color 218, 215, 197 line x+1, y+21-1, x+t\w-2, y+21-1 setfont fntButton color 0, 0, 0 text x+(t\w/2), y+11, t\caption, true, true endif if app\active = owntab\owner if mouseover(x, y, t\w, 21) if app\mouseState = 1 for temp.tabpage= each tabpage if temp\ownTab = ownTab temp\open = false endif next t\open = true endif endif endif endif next end function