コード例 #1
0
ファイル: main.py プロジェクト: williamfou/Dindo-Bot
	def bind_game_window(self, window_xid):
		self.debug('Bind game window (id: %d)' % window_xid, DebugLevel.Low)
		self.game_window = tools.get_game_window(window_xid)
		if self.game_window:
			bot_width, bot_height = self.get_size()
			bot_decoration_height = self.get_titlebar().get_allocated_height()
			screen_width, screen_height = tools.get_screen_size()
			game_window_left_margin = 1
			game_window_decoration_height = self.settings['Game']['WindowDecorationHeight'] if self.settings['Game']['UseCustomWindowDecorationHeight'] else tools.get_game_window_decoration_height(window_xid)
			game_window_width = screen_width - bot_width - game_window_left_margin
			game_window_height = bot_height if self.settings['Game']['UseCustomWindowDecorationHeight'] else bot_height + bot_decoration_height - game_window_decoration_height
			if game_window_width > 900:
				game_window_width = 900
			bot_x_position = screen_width / 2 - (bot_width + game_window_width) / 2
			bot_y_position = screen_height / 2 - bot_height / 2
			game_window_x_position = bot_x_position + bot_width + game_window_left_margin
			game_window_y_position = bot_y_position + game_window_decoration_height
			# save game window location
			self.game_window_location = (int(game_window_x_position), int(game_window_y_position), int(game_window_width), int(game_window_height))
			# move bot & game window
			self.move(bot_x_position, bot_y_position)
			self.move_resize_game_window(self.game_window_location)
			# enable/disable widgets
			self.refresh_button.hide()
			self.unbind_button.show()
			self.game_window_combo.set_sensitive(False)
			self.take_screenshot_button.set_sensitive(True)
コード例 #2
0
	def wait_for_click(self, callback, game_location=None):
		# wait for click
		tools.wait_for_mouse_event('left_down')
		# get mouse position & screen size
		x, y = tools.get_mouse_position()
		width, height = tools.get_screen_size()
		# get pixel color
		color = tools.get_pixel_color(x, y)
		# adjust location to game window
		if game_location is not None:
			# get game area location
			game_x, game_y, game_width, game_height = game_location
			#print('x: %d, y: %d, game_x: %d, game_y: %d, game_width: %d, game_height: %d' % (x, y, game_x, game_y, game_width, game_height))
			# scale to game area
			if tools.position_is_inside_bounds(x, y, game_x, game_y, game_width, game_height):
				# position is inside game area, so we fit x & y to it
				x = x - game_x
				y = y - game_y
				width = game_width
				height = game_height
		# execute callback
		GObject.idle_add(callback, (x, y, width, height, color))