Properly have main window own all dialogs, pass hDC to Node.Draw().

master
Anthony Zhang 2012-07-02 21:19:39 -04:00
parent b0e4485119
commit c20f83768d
11 changed files with 71 additions and 82 deletions

View File

@ -1,6 +1,5 @@
#NoEnv
;wip: pass hDC to Node.Draw()
;wip: multiple simultaneous viewports with independent views
;wip: undo/redo
;wip: component count in status bar - nodes used in selection, in total, as well as info such as hovered node class and state
@ -110,6 +109,7 @@ class Nodes
}
FileNew:
Gui, Main:+OwnDialogs
If FileModified
{
MsgBox, 35, Confirm, Save current schematic?
@ -128,6 +128,7 @@ ResizeWindow(Width,Height)
Return
FileOpen:
Gui, Main:+OwnDialogs
If FileModified
{
MsgBox, 35, Confirm, Save current schematic?
@ -179,6 +180,7 @@ SetModified(False)
Return
FileSave:
Gui, Main:+OwnDialogs
If (CurrentFile = "<Untitled>")
{
Gosub, FileSaveAs
@ -188,15 +190,13 @@ FileDelete, %CurrentFile%
Value := FileVersion . "`n" . Viewport.X . " " . Viewport.Y . " " . Viewport.W . " " . Viewport.H . "`n" . Serialize(Grid)
FileAppend, %Value%, %CurrentFile%
If ErrorLevel
{
Gui, Main:+OwnDialogs
MsgBox, 16, Error, Could not save file as "%CurrentFile%".
}
SetModified(False)
Else
SetModified(False)
Return
FileSaveAs:
Gui, Main:+OwnDialogs
FileSelectFile, FileName, S48,, Save mesecon schematic, Mesecon Schematic (*.mesecon)
If ErrorLevel
Return
@ -206,10 +206,12 @@ Gosub, FileSave
Return
FileImport:
Gui, Main:+OwnDialogs
;wip
Return
FileExport:
Gui, Main:+OwnDialogs
FileSelectFile, FileName, S48,, Save worldedit schematic, WorldEdit Schematic (*.we)
If ErrorLevel
Return
@ -242,9 +244,8 @@ Return
AboutGuiEscape:
AboutGuiClose:
Gui, About:Destroy
Gui, Main:-Disabled
Gui, Main:Show
Gui, About:Destroy
Return
MainGuiClose:
@ -282,7 +283,7 @@ CurrentTool.Class.Select()
Return
Draw:
Draw(Grid,Width,Height,Viewport)
Draw(hDC,hMemoryDC,Grid,Width,Height,Viewport)
Return
SetModified(Value)
@ -499,9 +500,8 @@ UninitializeViewport(hWindow)
throw Exception("Could not release window device context.")
}
Draw(Grid,Width,Height,Viewport)
Draw(hDC,hMemoryDC,Grid,Width,Height,Viewport)
{
global hDC, hMemoryDC
static hPen := DllCall("CreatePen","Int",0,"Int",0,"UInt",0x888888,"UPtr") ;PS_SOLID
;clear the bitmap
@ -547,7 +547,7 @@ Draw(Grid,Width,Height,Viewport)
Loop, % Ceil(Viewport.H) + 1
{
If Grid[IndexX,IndexY1]
Grid[IndexX,IndexY1].Draw(BlockX,BlockY1,BlockW,BlockH)
Grid[IndexX,IndexY1].Draw(hMemoryDC,BlockX,BlockY1,BlockW,BlockH)
IndexY1 ++, BlockY1 += BlockH
}
IndexX ++, BlockX += BlockW

View File

@ -10,7 +10,7 @@ class Basis
}
Draw(X,Y,W,H)
Draw(hDC,X,Y,W,H)
{
}

View File

@ -35,18 +35,17 @@ class BlinkyPlant extends Nodes.Power
this.base.BlinkyPlantArray.Remove(&this,"")
}
Draw(X,Y,W,H)
Draw(hDC,X,Y,W,H)
{
global hMemoryDC
hBrush := this.State ? this.base.hOnBrush : this.base.hOffBrush
hOriginalPen := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",this.base.hPen,"UPtr") ;select the pen
hOriginalBrush := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hBrush,"UPtr") ;select the brush
hOriginalPen := DllCall("SelectObject","UPtr",hDC,"UPtr",this.base.hPen,"UPtr") ;select the pen
hOriginalBrush := DllCall("SelectObject","UPtr",hDC,"UPtr",hBrush,"UPtr") ;select the brush
;draw the power plant
DllCall("Ellipse","UPtr",hMemoryDC,"Int",Round(X + (W * 0.1)),"Int",Round(Y + (H * 0.1)),"Int",Round(X + (W * 0.9)),"Int",Round(Y + (H * 0.9)))
DllCall("Ellipse","UPtr",hDC,"Int",Round(X + (W * 0.1)),"Int",Round(Y + (H * 0.1)),"Int",Round(X + (W * 0.9)),"Int",Round(Y + (H * 0.9)))
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalPen,"UPtr") ;deselect the pen
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalBrush,"UPtr") ;deselect the brush
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalPen,"UPtr") ;deselect the pen
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalBrush,"UPtr") ;deselect the brush
}
}

View File

@ -28,12 +28,10 @@ class Inverter extends Nodes.Power
base.__New(IndexX,IndexY)
}
Draw(X,Y,W,H)
Draw(hDC,X,Y,W,H)
{
global hMemoryDC
hOriginalPen := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",this.base.hPen,"UPtr") ;select the pen
hOriginalBrush := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",this.base.hBrush,"UPtr") ;select the brush
hOriginalPen := DllCall("SelectObject","UPtr",hDC,"UPtr",this.base.hPen,"UPtr") ;select the pen
hOriginalBrush := DllCall("SelectObject","UPtr",hDC,"UPtr",this.base.hBrush,"UPtr") ;select the brush
Vertices := 3
VarSetCapacity(Points,8 * Vertices)
@ -42,27 +40,27 @@ class Inverter extends Nodes.Power
NumPut(Round(X),Points,0,"Int"), NumPut(Round(Y + (H * 0.3)),Points,4,"Int")
NumPut(Round(X),Points,8,"Int"), NumPut(Round(Y + (H * 0.7)),Points,12,"Int")
NumPut(Round(X + (W * 0.3)),Points,16,"Int"), NumPut(Round(Y + (H * 0.5)),Points,20,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
;draw right arrow
NumPut(Round(X + W),Points,0,"Int")
NumPut(Round(X + W),Points,8,"Int")
NumPut(Round(X + (W * 0.7)),Points,16,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
;draw top arrow
NumPut(Round(X + (W * 0.3)),Points,0,"Int"), NumPut(Round(Y),Points,4,"Int")
NumPut(Round(X + (W * 0.7)),Points,8,"Int"), NumPut(Round(Y),Points,12,"Int")
NumPut(Round(X + (W * 0.5)),Points,16,"Int"), NumPut(Round(Y + (H * 0.3)),Points,20,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
;draw bottom arrow
NumPut(Round(Y + H),Points,4,"Int")
NumPut(Round(Y + H),Points,12,"Int")
NumPut(Round(Y + (H * 0.7)),Points,20,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalPen,"UPtr") ;deselect the pen
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalBrush,"UPtr") ;deselect the brush
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalPen,"UPtr") ;deselect the pen
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalBrush,"UPtr") ;deselect the brush
}
}

View File

@ -141,9 +141,9 @@ class Mesecon extends Nodes.Basis
Bottom.ModifyState(Amount,OpenList)
}
Draw(X,Y,W,H)
Draw(hDC,X,Y,W,H)
{
global hMemoryDC, Grid
global Grid
;obtain neighbor nodes
Left := Grid[this.IndexX - 1,this.IndexY], Left := Left.Send || Left.Receive
@ -165,19 +165,19 @@ class Mesecon extends Nodes.Basis
NumPut(Round(X + W),Rectangle,8,"Int")
Else
NumPut(Round(X + (W * 0.6)),Rectangle,8,"Int")
DllCall("FillRect","UPtr",hMemoryDC,"UPtr",&Rectangle,"UPtr",hBrush)
DllCall("FillRect","UPtr",hDC,"UPtr",&Rectangle,"UPtr",hBrush)
}
Else If Right ;right but not left neighbor
{
NumPut(Round(X + (W * 0.4)),Rectangle,0,"Int")
NumPut(Round(X + W),Rectangle,8,"Int")
DllCall("FillRect","UPtr",hMemoryDC,"UPtr",&Rectangle,"UPtr",hBrush)
DllCall("FillRect","UPtr",hDC,"UPtr",&Rectangle,"UPtr",hBrush)
}
Else If !(Top || Bottom) ;no neighbors
{
NumPut(Round(X + (W * 0.4)),Rectangle,0,"Int")
NumPut(Round(X + (W * 0.6)),Rectangle,8,"Int")
DllCall("FillRect","UPtr",hMemoryDC,"UPtr",&Rectangle,"UPtr",hBrush)
DllCall("FillRect","UPtr",hDC,"UPtr",&Rectangle,"UPtr",hBrush)
}
;draw vertical bar
@ -190,13 +190,13 @@ class Mesecon extends Nodes.Basis
NumPut(Round(Y + H),Rectangle,12,"Int")
Else
NumPut(Round(Y + (H * 0.6)),Rectangle,12,"Int")
DllCall("FillRect","UPtr",hMemoryDC,"UPtr",&Rectangle,"UPtr",hBrush)
DllCall("FillRect","UPtr",hDC,"UPtr",&Rectangle,"UPtr",hBrush)
}
Else If Bottom
{
NumPut(Round(Y + (H * 0.4)),Rectangle,12,"Int")
NumPut(Round(Y + H),Rectangle,12,"Int")
DllCall("FillRect","UPtr",hMemoryDC,"UPtr",&Rectangle,"UPtr",hBrush)
DllCall("FillRect","UPtr",hDC,"UPtr",&Rectangle,"UPtr",hBrush)
}
}
}

View File

@ -5,9 +5,8 @@ class Meselamp extends Nodes.Load
static hOffBrush := DllCall("CreateSolidBrush","UInt",0x777777,"UPtr")
static hOnBrush := DllCall("CreateSolidBrush","UInt",0xFFFFFF,"UPtr")
Draw(X,Y,W,H)
Draw(hDC,X,Y,W,H)
{
global hMemoryDC
hBrush := this.State ? this.base.hOnBrush : this.base.hOffBrush ;select the brush
VarSetCapacity(Rectangle,16)
@ -17,6 +16,6 @@ class Meselamp extends Nodes.Load
NumPut(Round(Y + (H * 0.3)),Rectangle,4,"Int")
NumPut(Round(X + (W * 0.9)),Rectangle,8,"Int")
NumPut(Round(Y + (H * 0.7)),Rectangle,12,"Int")
DllCall("FillRect","UPtr",hMemoryDC,"UPtr",&Rectangle,"UPtr",hBrush)
DllCall("FillRect","UPtr",hDC,"UPtr",&Rectangle,"UPtr",hBrush)
}
}

View File

@ -56,11 +56,10 @@ class Plug extends Nodes.Load
}
}
Draw(X,Y,W,H)
Draw(hDC,X,Y,W,H)
{
global hMemoryDC
hOriginalPen := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",this.base.hPen,"UPtr") ;select the pen
hOriginalBrush := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",this.base.hBrush,"UPtr") ;select the brush
hOriginalPen := DllCall("SelectObject","UPtr",hDC,"UPtr",this.base.hPen,"UPtr") ;select the pen
hOriginalBrush := DllCall("SelectObject","UPtr",hDC,"UPtr",this.base.hBrush,"UPtr") ;select the brush
Vertices := 3
VarSetCapacity(Points,8 * Vertices)
@ -69,27 +68,27 @@ class Plug extends Nodes.Load
NumPut(Round(X),Points,0,"Int"), NumPut(Round(Y + (H * 0.5)),Points,4,"Int")
NumPut(Round(X + (W * 0.3)),Points,8,"Int"), NumPut(Round(Y + (H * 0.3)),Points,12,"Int")
NumPut(Round(X + (W * 0.3)),Points,16,"Int"), NumPut(Round(Y + (H * 0.7)),Points,20,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
;draw right arrow
NumPut(Round(X + W),Points,0,"Int")
NumPut(Round(X + (W * 0.7)),Points,8,"Int")
NumPut(Round(X + (W * 0.7)),Points,16,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
;draw top arrow
NumPut(Round(X + (W * 0.5)),Points,0,"Int"), NumPut(Round(Y),Points,4,"Int")
NumPut(Round(X + (W * 0.3)),Points,8,"Int"), NumPut(Round(Y + (H * 0.3)),Points,12,"Int")
NumPut(Round(X + (W * 0.7)),Points,16,"Int"), NumPut(Round(Y + (H * 0.3)),Points,20,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
;draw bottom arrow
NumPut(Round(Y + H),Points,4,"Int")
NumPut(Round(Y + (H * 0.7)),Points,12,"Int")
NumPut(Round(Y + (H * 0.7)),Points,20,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalPen,"UPtr") ;deselect the pen
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalBrush,"UPtr") ;deselect the brush
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalPen,"UPtr") ;deselect the pen
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalBrush,"UPtr") ;deselect the brush
}
}

View File

@ -11,17 +11,16 @@ class PowerPlant extends Nodes.Power
base.__New(IndexX,IndexY)
}
Draw(X,Y,W,H)
Draw(hDC,X,Y,W,H)
{
global hMemoryDC
hOriginalPen := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",this.base.hPen,"UPtr") ;select the pen
hOriginalBrush := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",this.base.hBrush,"UPtr") ;select the brush
hOriginalPen := DllCall("SelectObject","UPtr",hDC,"UPtr",this.base.hPen,"UPtr") ;select the pen
hOriginalBrush := DllCall("SelectObject","UPtr",hDC,"UPtr",this.base.hBrush,"UPtr") ;select the brush
;draw the power plant
DllCall("Ellipse","UPtr",hMemoryDC,"Int",Round(X + (W * 0.1)),"Int",Round(Y + (H * 0.1)),"Int",Round(X + (W * 0.9)),"Int",Round(Y + (H * 0.9)))
DllCall("Ellipse","UPtr",hDC,"Int",Round(X + (W * 0.1)),"Int",Round(Y + (H * 0.1)),"Int",Round(X + (W * 0.9)),"Int",Round(Y + (H * 0.9)))
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalPen,"UPtr") ;deselect the pen
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalBrush,"UPtr") ;deselect the brush
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalPen,"UPtr") ;deselect the pen
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalBrush,"UPtr") ;deselect the brush
}
Serialize()

View File

@ -37,9 +37,8 @@ class Sign extends Nodes.Basis
Return
}
Draw(X,Y,W,H)
Draw(hDC,X,Y,W,H)
{
global hMemoryDC
static hFont := 0, PreviousH := -1
VarSetCapacity(Rectangle,16)
@ -49,7 +48,7 @@ class Sign extends Nodes.Basis
NumPut(Round(Y + (H * 0.2)),Rectangle,4,"Int")
NumPut(Round(X + (W * 0.9)),Rectangle,8,"Int")
NumPut(Round(Y + (H * 0.7)),Rectangle,12,"Int")
DllCall("FillRect","UPtr",hMemoryDC,"UPtr",&Rectangle,"UPtr",this.base.hBrush)
DllCall("FillRect","UPtr",hDC,"UPtr",&Rectangle,"UPtr",this.base.hBrush)
;set up text properties
If (H != PreviousH)
@ -73,20 +72,20 @@ class Sign extends Nodes.Basis
,"Str","Arial" ;typeface name
,"UPtr")
}
DllCall("SetTextColor","UPtr",hMemoryDC,"UInt",0xFFFFFF)
DllCall("SetBkMode","UPtr",hMemoryDC,"Int",1) ;TRANSPARENT
DllCall("SetTextAlign","UPtr",hMemoryDC,"UInt",6) ;TA_CENTER | TA_TOP: align text to the center and the top
DllCall("SetTextColor","UPtr",hDC,"UInt",0xFFFFFF)
DllCall("SetBkMode","UPtr",hDC,"Int",1) ;TRANSPARENT
DllCall("SetTextAlign","UPtr",hDC,"UInt",6) ;TA_CENTER | TA_TOP: align text to the center and the top
;draw text
hOriginalFont := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hFont,"UPtr")
hOriginalFont := DllCall("SelectObject","UPtr",hDC,"UPtr",hFont,"UPtr")
PositionX := X + (W * 0.5), PositionY := Y + (H * 0.25)
Text := this.Text
Loop, Parse, Text, `n
{
DllCall("TextOut","UPtr",hMemoryDC,"Int",Round(PositionX),"Int",Round(PositionY),"Str",A_LoopField,"Int",StrLen(A_LoopField))
DllCall("TextOut","UPtr",hDC,"Int",Round(PositionX),"Int",Round(PositionY),"Str",A_LoopField,"Int",StrLen(A_LoopField))
PositionY += H * 0.2
}
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalFont,"UPtr")
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalFont,"UPtr")
}
Serialize()

View File

@ -28,12 +28,10 @@ class Socket extends Nodes.Power
base.__New(IndexX,IndexY)
}
Draw(X,Y,W,H)
Draw(hDC,X,Y,W,H)
{
global hMemoryDC
hOriginalPen := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",this.base.hPen,"UPtr") ;select the pen
hOriginalBrush := DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",this.base.hBrush,"UPtr") ;select the brush
hOriginalPen := DllCall("SelectObject","UPtr",hDC,"UPtr",this.base.hPen,"UPtr") ;select the pen
hOriginalBrush := DllCall("SelectObject","UPtr",hDC,"UPtr",this.base.hBrush,"UPtr") ;select the brush
Vertices := 3
VarSetCapacity(Points,8 * Vertices)
@ -42,27 +40,27 @@ class Socket extends Nodes.Power
NumPut(Round(X),Points,0,"Int"), NumPut(Round(Y + (H * 0.3)),Points,4,"Int")
NumPut(Round(X),Points,8,"Int"), NumPut(Round(Y + (H * 0.7)),Points,12,"Int")
NumPut(Round(X + (W * 0.3)),Points,16,"Int"), NumPut(Round(Y + (H * 0.5)),Points,20,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
;draw right arrow
NumPut(Round(X + W),Points,0,"Int")
NumPut(Round(X + W),Points,8,"Int")
NumPut(Round(X + (W * 0.7)),Points,16,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
;draw top arrow
NumPut(Round(X + (W * 0.3)),Points,0,"Int"), NumPut(Round(Y),Points,4,"Int")
NumPut(Round(X + (W * 0.7)),Points,8,"Int"), NumPut(Round(Y),Points,12,"Int")
NumPut(Round(X + (W * 0.5)),Points,16,"Int"), NumPut(Round(Y + (H * 0.3)),Points,20,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
;draw bottom arrow
NumPut(Round(Y + H),Points,4,"Int")
NumPut(Round(Y + H),Points,12,"Int")
NumPut(Round(Y + (H * 0.7)),Points,20,"Int")
DllCall("Polygon","UPtr",hMemoryDC,"UPtr",&Points,"Int",Vertices)
DllCall("Polygon","UPtr",hDC,"UPtr",&Points,"Int",Vertices)
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalPen,"UPtr") ;deselect the pen
DllCall("SelectObject","UPtr",hMemoryDC,"UPtr",hOriginalBrush,"UPtr") ;deselect the brush
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalPen,"UPtr") ;deselect the pen
DllCall("SelectObject","UPtr",hDC,"UPtr",hOriginalBrush,"UPtr") ;deselect the brush
}
}

View File

@ -8,10 +8,8 @@ class Solid extends Nodes.Basis
this.Receive := False
}
Draw(X,Y,W,H)
Draw(hDC,X,Y,W,H)
{
global hMemoryDC
VarSetCapacity(Rectangle,16)
;draw rectangle
@ -19,7 +17,7 @@ class Solid extends Nodes.Basis
NumPut(Round(Y + (H * 0.1)),Rectangle,4,"Int")
NumPut(Round(X + (W * 0.9)),Rectangle,8,"Int")
NumPut(Round(Y + (H * 0.9)),Rectangle,12,"Int")
DllCall("FillRect","UPtr",hMemoryDC,"UPtr",&Rectangle,"UPtr",this.base.hBrush)
DllCall("FillRect","UPtr",hDC,"UPtr",&Rectangle,"UPtr",this.base.hBrush)
}
Serialize()