PowerBuilder Aquarium Fish Get From PowerBuilder Code Examples
Source Code
m_fish from menu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | forward global type m_fish from menu end type type fish$ from menu within m_fish end type type m_start from menu within fish$ end type type m_stop from menu within fish$ end type type m_-1 from menu within fish$ end type type m_configureaquarium from menu within fish$ end type type m_- from menu within fish$ end type type m_close from menu within fish$ end type type fish$ from menu within m_fish m_start m_start m_stop m_stop m_-1 m_-1 m_configureaquarium m_configureaquarium m_- m_- m_close m_close end type end forward shared variables end variables global type m_fish from menu fish$ fish$ end type global m_fish m_fish type variables w_fish iw_parent_win end variables on m_fish.create m_fish=this this.fish$=create fish$ this.Item[]={this.fish$} end on on m_fish.destroy destroy(this.fish$) end on type fish$ from menu within m_fish m_start m_start m_stop m_stop m_-1 m_-1 m_configureaquarium m_configureaquarium m_- m_- m_close m_close end type on selected;iw_parent_win = parentwindow end on on fish$.create this.Text="&Fish" this.m_start=create m_start this.m_stop=create m_stop this.m_-1=create m_-1 this.m_configureaquarium=create m_configureaquarium this.m_-=create m_- this.m_close=create m_close this.Item[]={this.m_start, & this.m_stop, & this.m_-1, & this.m_configureaquarium, & this.m_-, & this.m_close} end on on fish$.destroy destroy(this.m_start) destroy(this.m_stop) destroy(this.m_-1) destroy(this.m_configureaquarium) destroy(this.m_-) destroy(this.m_close) end on type m_start from menu within fish$ end type event clicked;//Clicked script for m_start w_fish w_Parent w_Parent = ParentWindow Timer(w_Parent.idb_Interval, w_Parent) end event on m_start.create this.Text="&Start" end on type m_stop from menu within fish$ end type event clicked;//Clicked script for m_stop Timer(0, ParentWindow) end event on m_stop.create this.Text="S&top" end on on m_stop.destroy end on type m_-1 from menu within fish$ end type on m_-1.create this.Text="-" end on type m_configureaquarium from menu within fish$ end type event clicked;OpenWithParm(w_fish_config, ParentWindow) end event on m_configureaquarium.create this.Text="&Configure Aquarium..." end on on m_configureaquarium.destroy end on type m_- from menu within fish$ end type on m_-.create this.Text="-" end on type m_close from menu within fish$ end type on clicked;//Clicked script for m_close Close(ParentWindow) end on on m_close.create this.Text="&Close" this.Microhelp="Close window" end on |
w_fish from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | forward global type w_fish from window end type type p_4 from picture within w_fish end type type p_5 from picture within w_fish end type type p_3 from picture within w_fish end type type p_2 from picture within w_fish end type type p_1 from picture within w_fish end type type s_fish from structure within w_fish end type end forward type s_fish from structure picture p_pict integer i_pos integer i_dist boolean b_right boolean b_visible end type shared variables end variables global type w_fish from window integer y = 4 integer width = 2071 integer height = 1908 boolean titlebar = true string title = "Aquarium Fish" string menuname = "m_fish" boolean controlmenu = true boolean resizable = true windowtype windowtype = popup! long backcolor = 8388608 p_4 p_4 p_5 p_5 p_3 p_3 p_2 p_2 p_1 p_1 end type global w_fish w_fish type variables Public: Double idb_Interval = 0.075 Integer ii_Delta = 0 Private: /* Object Structure references must be declared as private */ s_fish istr_Fish[5] end variables forward prototypes public function integer of_addremovefish (readonly integer ai_index, readonly boolean ab_visible) public function integer of_getfishvisible (readonly integer ai_index) public function integer wf_center () end prototypes public function integer of_addremovefish (readonly integer ai_index, readonly boolean ab_visible);istr_Fish[ai_index].b_Visible = ab_visible istr_Fish[ai_index].p_pict.Visible = ab_visible Return 1 end function public function integer of_getfishvisible (readonly integer ai_index);If istr_fish[ai_index].b_visible Then return 0 Else return 1 End If end function public function integer wf_center ();//*-----------------------------------------------------------------*/ //* f_Center: Center the window //*-----------------------------------------------------------------*/ int li_screenheight, li_screenwidth, li_rc, li_x=1, li_y=1 environment lenv_obj /* Check for a window association with this object */ If IsNull ( this ) Or Not IsValid ( this ) Then Return -1 /* Get environment */ If GetEnvironment ( lenv_obj ) = -1 Then Return -1 /* Determine current screen resolution and validate */ li_screenheight = PixelsToUnits ( lenv_obj.ScreenHeight, YPixelsToUnits! ) li_screenwidth = PixelsToUnits ( lenv_obj.ScreenWidth, XPixelsToUnits! ) If Not ( li_screenheight > 0 ) Or Not ( li_screenwidth > 0 ) Then Return -1 /* Get center points */ If li_screenwidth > this.Width Then li_x = ( li_screenwidth / 2 ) - ( this.Width / 2 ) End If If li_screenheight > this.Height Then li_y = ( li_screenheight / 2 ) - ( this.Height / 2 ) End If /* Center window */ li_rc = this.Move ( li_x, li_y ) If li_rc <> 1 Then Return -1 Return 1 end function event timer;//Timer script for w_fish // Loop thru the 5 fish, changing each fish's position. // At boundary conditions, change bitmap to left (fish?l) // or right (fish?r) fish as appropriate. Integer li_Cnt, li_Dist For li_Cnt = 1 To 5 If istr_Fish[li_Cnt].b_visible = False & And istr_Fish[li_Cnt].p_pict.Visible = True Then istr_Fish[li_Cnt].p_pict.Visible = False This.SetRedraw ( True ) Continue End If If (istr_Fish[li_Cnt].i_Dist + ii_Delta) > 16 Then li_Dist = 16 ElseIf (istr_Fish[li_Cnt].i_Dist + ii_Delta) < 2 Then li_Dist = 2 Else li_Dist = istr_Fish[li_Cnt].i_Dist + ii_Delta End If If istr_Fish[li_Cnt].b_Right Then istr_Fish[li_Cnt].i_Pos = istr_Fish[li_Cnt].i_Pos + li_Dist istr_Fish[li_Cnt].p_pict.Draw(istr_Fish[li_Cnt].i_Pos, istr_Fish[li_Cnt].p_pict.Y) If ((istr_Fish[li_Cnt].i_Pos + istr_Fish[li_Cnt].p_pict.Width) > This.Width) And & istr_Fish[li_Cnt].b_visible Then // At right edge of screen, turn fish istr_Fish[li_Cnt].p_pict.PictureName = "fish" + String(li_Cnt) + "l.bmp" istr_Fish[li_Cnt].b_Right = False If istr_Fish[li_Cnt].i_Pos > This.Width Then // Fish is past right edge of window, move it back istr_Fish[li_Cnt].i_Pos = This.Width End If End If Else istr_Fish[li_Cnt].i_Pos = istr_Fish[li_Cnt].i_Pos - li_Dist istr_Fish[li_Cnt].p_pict.Draw(istr_Fish[li_Cnt].i_Pos, istr_Fish[li_Cnt].p_pict.Y) If istr_Fish[li_Cnt].i_Pos < 0 And istr_Fish[li_Cnt].b_visible Then // At left edge of screen, turn fish istr_Fish[li_Cnt].p_pict.PictureName = "fish" + String(li_Cnt) + "r.bmp" istr_Fish[li_Cnt].b_Right = True If (istr_Fish[li_Cnt].i_Pos + istr_Fish[li_Cnt].p_pict.Width) < 0 Then // Fish is past left edge of window, move it back istr_Fish[li_Cnt].i_Pos = 0 - istr_Fish[li_Cnt].p_pict.Width End If End If End If Next end event event open;wf_Center() //Open script for w_fish Integer li_Cnt // Initialize picture array to the five pictures of fish, visible to // the right of the visible window. To see these, expand the window to // the right. istr_Fish[1].p_Pict = p_1 istr_Fish[2].p_Pict = p_2 istr_Fish[3].p_Pict = p_3 istr_Fish[4].p_Pict = p_4 istr_Fish[5].p_Pict = p_5 // Randomize the fish speed and move them // off the left side of the screen. Randomize(0) For li_Cnt = 1 To 5 istr_Fish[li_Cnt].i_Dist = Rand(9) + 3 If li_Cnt > 1 Then If istr_Fish[li_Cnt].i_Dist = istr_Fish[li_Cnt - 1].i_Dist Then istr_Fish[li_Cnt].i_Dist = istr_Fish[li_Cnt].i_Dist + 2 End If End If istr_Fish[li_Cnt].p_Pict.X = -732 istr_Fish[li_Cnt].i_Pos = istr_Fish[li_Cnt].p_Pict.X istr_Fish[li_Cnt].b_Right = True istr_Fish[li_Cnt].b_Visible = True Next // Start them swimming. Timer(idb_Interval) end event on w_fish.create if this.MenuName = "m_fish" then this.MenuID = create m_fish this.p_4=create p_4 this.p_5=create p_5 this.p_3=create p_3 this.p_2=create p_2 this.p_1=create p_1 this.Control[]={this.p_4,& this.p_5,& this.p_3,& this.p_2,& this.p_1} end on on w_fish.destroy if IsValid(MenuID) then destroy(MenuID) destroy(this.p_4) destroy(this.p_5) destroy(this.p_3) destroy(this.p_2) destroy(this.p_1) end on event close;//Close script for w_fish If IsValid(w_fish_config) Then Close(w_fish_config) End If end event type p_4 from picture within w_fish integer x = 2030 integer y = 988 integer width = 731 integer height = 484 boolean originalsize = true string picturename = "fish4r.bmp" end type type p_5 from picture within w_fish integer x = 2030 integer y = 1436 integer width = 731 integer height = 484 boolean originalsize = true string picturename = "fish5r.bmp" end type type p_3 from picture within w_fish integer x = 2030 integer y = 620 integer width = 731 integer height = 484 boolean originalsize = true string picturename = "fish3r.bmp" end type type p_2 from picture within w_fish integer x = 2030 integer y = 268 integer width = 731 integer height = 484 boolean originalsize = true string picturename = "fish2r.bmp" end type type p_1 from picture within w_fish integer x = 2030 integer width = 731 integer height = 484 boolean originalsize = true string picturename = "fish1r.bmp" end type |
w_fish_config from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | forward global type w_fish_config from window end type type st_speed from statictext within w_fish_config end type type lv_1 from listview within w_fish_config end type type st_2 from statictext within w_fish_config end type type cb_close from commandbutton within w_fish_config end type type hsb_speed from hscrollbar within w_fish_config end type type st_4 from statictext within w_fish_config end type type st_1 from statictext within w_fish_config end type type s_fish from structure within w_fish_config end type end forward type s_fish from structure picture p_pict integer i_pos integer i_dist boolean b_right boolean b_visible end type global type w_fish_config from window integer x = 2098 integer y = 20 integer width = 841 integer height = 1404 boolean titlebar = true string title = "Configure Aquarium" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 81838264 toolbaralignment toolbaralignment = alignatleft! st_speed st_speed lv_1 lv_1 st_2 st_2 cb_close cb_close hsb_speed hsb_speed st_4 st_4 st_1 st_1 end type global w_fish_config w_fish_config type variables w_fish w_aquarium end variables forward prototypes public subroutine of_change_speed (integer ai_position) public function integer wf_center () end prototypes public subroutine of_change_speed (integer ai_position);// Function to change the speed of the fish. ai_Position = ai_Position - 4 Choose Case ai_Position Case -4, -3 st_speed.Text = "Drifting" Case -2 To -1 st_speed.Text = "Pokey" Case 0 st_speed.Text = "Normal" Case 1, 2 st_speed.Text = "Zippy" Case 3, 4 st_speed.Text = "Flying" End Choose w_aquarium.ii_Delta = ai_Position * 2 end subroutine public function integer wf_center ();//*-----------------------------------------------------------------*/ //* f_Center: Center the window //*-----------------------------------------------------------------*/ int li_screenheight, li_screenwidth, li_rc, li_x=1, li_y=1 environment lenv_obj /* Check for a window association with this object */ If IsNull ( this ) Or Not IsValid ( this ) Then Return -1 /* Get environment */ If GetEnvironment ( lenv_obj ) = -1 Then Return -1 /* Determine current screen resolution and validate */ li_screenheight = PixelsToUnits ( lenv_obj.ScreenHeight, YPixelsToUnits! ) li_screenwidth = PixelsToUnits ( lenv_obj.ScreenWidth, XPixelsToUnits! ) If Not ( li_screenheight > 0 ) Or Not ( li_screenwidth > 0 ) Then Return -1 /* Get center points */ If li_screenwidth > this.Width Then li_x = ( li_screenwidth / 2 ) - ( this.Width / 2 ) End If If li_screenheight > this.Height Then li_y = ( li_screenheight / 2 ) - ( this.Height / 2 ) End If /* Center window */ li_rc = this.Move ( li_x, li_y ) If li_rc <> 1 Then Return -1 Return 1 end function on w_fish_config.create this.st_speed=create st_speed this.lv_1=create lv_1 this.st_2=create st_2 this.cb_close=create cb_close this.hsb_speed=create hsb_speed this.st_4=create st_4 this.st_1=create st_1 this.Control[]={this.st_speed,& this.lv_1,& this.st_2,& this.cb_close,& this.hsb_speed,& this.st_4,& this.st_1} end on on w_fish_config.destroy destroy(this.st_speed) destroy(this.lv_1) destroy(this.st_2) destroy(this.cb_close) destroy(this.hsb_speed) destroy(this.st_4) destroy(this.st_1) end on event open;wf_center() Integer li_1, li_2, li_3, li_4, li_5, li_Overlay, li_Position ListViewItem llvi_Item w_aquarium = Message.PowerObjectParm // Add the fish pictures to the ListView lv_1.SmallPictureWidth = 57 lv_1.SmallPictureHeight = 39 li_1 = lv_1.AddSmallPicture("fish1r.bmp") li_2 = lv_1.AddSmallPicture("fish2r.bmp") li_3 = lv_1.AddSmallPicture("fish3r.bmp") li_4 = lv_1.AddSmallPicture("fish4r.bmp") li_5 = lv_1.AddSmallPicture("fish5r.bmp") li_Overlay = lv_1.AddSmallPicture("NotFound!") lv_1.SetOverlayPicture(1, li_Overlay) lv_1.AddColumn("fish", Left!, 700) llvi_Item.Label = "Clownfish" llvi_Item.PictureIndex = li_1 llvi_Item.OverlayPictureIndex = w_aquarium.of_GetFishVisible ( li_1 ) lv_1.AddItem ( llvi_Item ) llvi_Item.Label = "Clown Triggerfish" llvi_Item.PictureIndex = li_2 llvi_Item.OverlayPictureIndex = w_aquarium.of_GetFishVisible ( li_2 ) lv_1.AddItem ( llvi_Item ) llvi_Item.Label = "Emperor Anglefish" llvi_Item.PictureIndex = li_3 llvi_Item.OverlayPictureIndex = w_aquarium.of_GetFishVisible ( li_3 ) lv_1.AddItem ( llvi_Item ) llvi_Item.Label = "Moorish Idol" llvi_Item.PictureIndex = li_4 llvi_Item.OverlayPictureIndex = w_aquarium.of_GetFishVisible ( li_4 ) lv_1.AddItem ( llvi_Item ) llvi_Item.Label = "Palette Tang" llvi_Item.PictureIndex = li_5 llvi_Item.OverlayPictureIndex = w_aquarium.of_GetFishVisible ( li_5 ) lv_1.AddItem ( llvi_Item ) li_Position = ( w_aquarium.ii_Delta / 2 ) Choose Case li_Position Case -4, -3 st_speed.Text = "Drifting" Case -2 To -1 st_speed.Text = "Pokey" Case 0 st_speed.Text = "Normal" Case 1, 2 st_speed.Text = "Zippy" Case 3, 4 st_speed.Text = "Flying" End Choose hsb_speed.Position = li_Position + 4 end event type st_speed from statictext within w_fish_config integer x = 439 integer y = 1000 integer width = 265 integer height = 64 integer textsize = -8 integer weight = 400 fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" long textcolor = 41943040 long backcolor = 75530304 boolean enabled = false string text = "Normal" long bordercolor = 8388608 boolean focusrectangle = false end type type lv_1 from listview within w_fish_config integer x = 37 integer y = 148 integer width = 722 integer height = 828 integer taborder = 10 integer textsize = -8 integer weight = 400 fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" long textcolor = 16777215 long backcolor = 8388608 borderstyle borderstyle = stylelowered! boolean buttonheader = false boolean showheader = false boolean scrolling = false listviewview view = listviewreport! integer largepicturewidth = 32 integer largepictureheight = 32 long largepicturemaskcolor = 553648127 integer smallpicturewidth = 16 integer smallpictureheight = 16 long smallpicturemaskcolor = 12632256 long statepicturemaskcolor = 536870912 end type event doubleclicked;// Remove or add a fish to/from the aquarium ListViewItem llvi_Item If index <=0 Then Return If GetItem(index, llvi_Item) = -1 Then Return If llvi_Item.OverlayPictureIndex = 0 Then llvi_Item.OverlayPictureIndex = 1 // Remove the fish from the aquarium w_aquarium.of_AddRemoveFish ( index, False ) Else llvi_Item.OverlayPictureIndex = 0 // Add the fish back to the aquarium w_aquarium.of_AddRemoveFish ( index, True ) End If llvi_Item.Selected = False SetItem(index, llvi_Item) end event type st_2 from statictext within w_fish_config integer x = 37 integer y = 76 integer width = 425 integer height = 64 integer textsize = -8 integer weight = 400 fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" long textcolor = 41943040 long backcolor = 75530304 boolean enabled = false string text = "include/exclude it:" long bordercolor = 8388608 boolean focusrectangle = false end type type cb_close from commandbutton within w_fish_config integer x = 279 integer y = 1172 integer width = 215 integer height = 84 integer taborder = 20 integer textsize = -8 integer weight = 400 fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" string text = "Close" end type event clicked;Close(Parent) end event type hsb_speed from hscrollbar within w_fish_config integer x = 37 integer y = 1064 integer width = 722 integer height = 52 integer maxposition = 8 integer position = 4 end type event moved;of_change_speed(position) end event event lineleft;If This.Position > 0 Then This.Position = This.Position - 1 End If of_change_speed(This.Position) end event event lineright;If This.Position < 8 Then This.Position = This.Position + 1 End If of_change_speed(This.Position) end event event pageright;If This.Position < 7 Then This.Position = This.Position + 2 End If of_change_speed(This.Position) end event event pageleft;If This.Position > 1 Then This.Position = This.Position - 2 End If of_change_speed(This.Position) end event type st_4 from statictext within w_fish_config integer x = 37 integer y = 1000 integer width = 416 integer height = 64 integer textsize = -8 integer weight = 400 fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" long textcolor = 41943040 long backcolor = 75530304 boolean enabled = false string text = "Swimming Speed:" long bordercolor = 8388608 boolean focusrectangle = false end type type st_1 from statictext within w_fish_config integer x = 37 integer y = 20 integer width = 498 integer height = 64 integer textsize = -8 integer weight = 400 fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" long textcolor = 41943040 long backcolor = 75530304 boolean enabled = false string text = "Double-click a fish to" long bordercolor = 8388608 boolean focusrectangle = false end type |
Find Projects On Github click here
Good Luck!