Alright, I've put together this little test. Question: Why is the green polygon showing up on the second form?
Originally, I had an error producing a polygon on a canvas on a second form, but I haven't reproduced it yet.
Main file
Code: Select all
EnableExplicit
Global wMain, wSecond
Enumeration
#m1
EndEnumeration
Structure Point
x.D
y.D
EndStructure
Structure PolygonEntry
ColorRed.D
ColorGreen.D
ColorBlue.D
Fill.L
List PolygonPoint.Point()
EndStructure
Global MainForm.I, SecondForm.l
Declare WidgetExposeHandler(*a,*b)
Global NewList Polygon.PolygonEntry()
Global NewList PolygonPoint.Point()
IncludeFile "/home/ken/PureBasic/polygon.Shardik" ;This file hasn't changed from first test. Use the same one.
IncludeFile "/home/ken/PureBasic/Second.form"
Procedure Load_data()
Define i.I
For i = 1 To 5
AddElement(PolygonPoint())
Read.D PolygonPoint()\x
Read.D PolygonPoint()\y
Next i
EndProcedure
Load_data()
DataSection
; -- Pentagon
Data.D 0, 0
Data.D 150, 0
Data.D 175, 75
Data.D 150, 200
Data.D 50, 125
EndDataSection
; ----- Display window and define expose handler
Procedure OpenMain()
wMain = OpenWindow(#PB_Any, 270, 100, 500, 500, "Polygon demo", #PB_Window_SizeGadget)
SetWindowColor(wMain, 0)
MainForm = g_list_nth_data_(gtk_container_get_children_(gtk_bin_get_child_(WindowID(wMain))), 0)
g_signal_connect_data_(MainForm, "expose-event", @WidgetExposeHandler(), 0, 0, #G_CONNECT_AFTER)
CreatePolygon(PolygonPoint(), 250, 200, RGB(254, 255, 0), #True) ; THIS SHOULD BE YELLOW, NOT GREEN.
WidgetExposeHandler(MainForm, 0)
CreateMenu(#PB_Any, WindowID(wMain))
MenuTitle("Open")
MenuItem(#m1, "2nd form")
EndProcedure
Procedure wMain_Events(event)
Select event
Case #PB_Event_CloseWindow
End
Case #PB_Event_Menu
Select EventMenu()
Case #m1
OpenSecondForm()
EndSelect
EndSelect
EndProcedure
OpenMain()
Repeat : wMain_Events(WaitWindowEvent()) : ForEver
Second file: "Second.form"
Code: Select all
Procedure wSecond_Events(event)
Select event
Case #PB_Event_CloseWindow
End
Case #PB_Event_Menu
Select EventMenu()
Case #m1
CreatePolygon(PolygonPoint(), 200, 150, RGB(255, 254, 0), #True) ; THIS SHOULD BE YELLOW, NOT RED.
WidgetExposeHandler(SecondForm, 0)
EndSelect
EndSelect
EndProcedure
Procedure OpenSecondForm()
wSecond = OpenWindow(#PB_Any, 350, 150, 500, 500, "Second Form", #PB_Window_SizeGadget)
SetWindowColor(wSecond, 0)
SecondForm = g_list_nth_data_(gtk_container_get_children_(gtk_bin_get_child_(WindowID(wSecond))), 0)
g_signal_connect_data_(SecondForm, "expose-event", @WidgetExposeHandler(), 0, 0, #G_CONNECT_AFTER)
CreateMenu(#PB_Any, WindowID(wSecond))
MenuTitle("Test")
MenuItem(#m1, "Do_test")
Repeat : wSecond_Events(WaitWindowEvent()) : ForEver
EndProcedure
Third file is same as first test.
Code: Select all
ImportC ""
gdk_cairo_create(*Drawable.GdkDrawable)
EndImport
ImportC "-lcairo"
cairo_close_path(*CairoContext)
cairo_destroy(*CairoContext)
cairo_fill(*CairoContext)
cairo_line_to(*CairoContext, x.D, y.D)
cairo_set_line_width(*CairoContext, LineWidth.D)
cairo_set_source_rgb(*CairoContext, Red.D, Green.D, Blue.D)
cairo_stroke(*CairoContext)
EndImport
Procedure CreatePolygon(List PolygonPoint.Point(), x.D, y.D, Color.L, Fill.L)
Shared Polygon.PolygonEntry()
Protected ColorPart.L
Protected i.I
AddElement(Polygon())
ForEach PolygonPoint()
AddElement(Polygon()\PolygonPoint())
Polygon()\PolygonPoint()\x = x + PolygonPoint()\x
Polygon()\PolygonPoint()\y = y + PolygonPoint()\y
Next
ColorPart = (Color & $FF) / 255
Polygon()\ColorRed = ColorPart
ColorPart = ((Color >> 8) & $FF) / 255
Polygon()\ColorGreen = ColorPart
ColorPart = ((Color >> 16) & $FF) / 255
Polygon()\ColorBlue = ColorPart
Polygon()\Fill = Fill
EndProcedure
Procedure DrawPolygons(*Widget.GtkWidget)
Shared Polygon.PolygonEntry()
Protected CairoContext.I = gdk_cairo_create(*Widget\window)
ForEach Polygon()
If Polygon()\Fill
ForEach Polygon()\PolygonPoint()
cairo_line_to(CairoContext, Polygon()\PolygonPoint()\x, Polygon()\PolygonPoint()\y)
Next
cairo_close_path(CairoContext)
cairo_set_source_rgb(CairoContext, Polygon()\ColorRed, Polygon()\ColorGreen, Polygon()\ColorBlue)
cairo_fill(CairoContext)
Else
cairo_set_line_width(CairoContext, 1)
cairo_set_source_rgb(CairoContext, Polygon()\ColorRed, Polygon()\ColorGreen, Polygon()\ColorBlue)
ForEach Polygon()\PolygonPoint()
cairo_line_to(CairoContext, Polygon()\PolygonPoint()\x, Polygon()\PolygonPoint()\y)
Next
cairo_close_path(CairoContext)
cairo_stroke(CairoContext)
EndIf
Next
cairo_destroy(CairoContext)
EndProcedure
ProcedureC WidgetExposeHandler(*Widget.GtkWidget, *Event.GdkEventExpose)
DrawPolygons(*Widget.GtkWidget)
EndProcedure