def __on_mousemove(user, event):
    new_mouse_over_map = not pf.mouse_over_ui() and not pf.mouse_over_minimap()

    global mouse_over_map
    if new_mouse_over_map != mouse_over_map:
        if new_mouse_over_map:
            pf.global_event(EVENT_MOUSE_ENTERED_MAP, None)
        else:
            pf.global_event(EVENT_MOUSE_EXITED_MAP, None)
        mouse_over_map = new_mouse_over_map
    def __paint_selection(self):

        if pf.mouse_over_ui():
            return

        if pf.mouse_over_minimap():
            return

        global_r = self.selected_tile[0][
            0] * pf.TILES_PER_CHUNK_HEIGHT + self.selected_tile[1][0]
        global_c = self.selected_tile[0][
            1] * pf.TILES_PER_CHUNK_WIDTH + self.selected_tile[1][1]

        for r in range(-(self.view.brush_size_idx),
                       (self.view.brush_size_idx) + 1):
            for c in range(-(self.view.brush_size_idx),
                           (self.view.brush_size_idx) + 1):

                if self.view.blend_textures:
                    bm = pf.BLEND_MODE_BLUR
                else:
                    bm = pf.BLEND_MODE_NOBLEND

                tile_coords = globals.active_map.relative_tile_coords(
                    global_r, global_c, r, c)
                if tile_coords is not None:

                    top_mat = globals.active_map.materials[
                        self.view.selected_mat_idx]
                    side_mat = globals.active_map.materials[
                        self.view.selected_side_mat_idx]

                    if self.view.brush_type_idx == 0:
                        globals.active_map.update_tile_mat(
                            tile_coords, top_mat, bm, self.view.blend_normals)
                    elif self.view.brush_type_idx == 1:
                        center_height = self.view.heights[
                            self.view.selected_height_idx]
                        globals.active_map.update_tile(tile_coords,
                                                       center_height,
                                                       pf.TILETYPE_FLAT,
                                                       side_mat, 0, bm,
                                                       self.view.blend_normals)

        if (self.view.brush_type_idx == 1 and self.view.edges_type_idx == 1):
            self.__paint_smooth_border(self.view.brush_size_idx + 1, 'down')
            self.__paint_smooth_border(self.view.brush_size_idx + 1, 'up')
            self.__update_objects_for_height_change()
    def __paint_selection(self):

        if pf.mouse_over_ui():
            return

        if pf.mouse_over_minimap():
            return

        global_r = self.selected_tile[0][
            0] * pf.TILES_PER_CHUNK_HEIGHT + self.selected_tile[1][0]
        global_c = self.selected_tile[0][
            1] * pf.TILES_PER_CHUNK_WIDTH + self.selected_tile[1][1]

        for r in range(-((self.view.brush_size_idx + 1) // 2),
                       ((self.view.brush_size_idx + 1) // 2) + 1):
            for c in range(-((self.view.brush_size_idx + 1) // 2),
                           ((self.view.brush_size_idx + 1) // 2) + 1):

                tile_coords = globals.active_map.relative_tile_coords(
                    global_r, global_c, r, c)
                if tile_coords is not None:

                    if self.view.brush_type_idx == 0:
                        globals.active_map.update_tile_mat(
                            tile_coords, TerrainTabVC.MATERIALS_LIST[
                                self.view.selected_mat_idx])
                    elif self.view.brush_type_idx == 1:
                        center_height = self.view.heights[
                            self.view.selected_height_idx]
                        globals.active_map.update_tile(
                            tile_coords,
                            center_height,
                            newtype=map.TILETYPE_FLAT)

        if self.view.edges_type_idx == 1:
            self.__paint_smooth_border(self.view.brush_size_idx + 1, 'down')
            self.__paint_smooth_border(self.view.brush_size_idx + 1, 'up')
            self.__update_objects_for_height_change()
def install():
    global mouse_over_map
    mouse_over_map = not pf.mouse_over_ui() and not pf.mouse_over_minimap()
    pf.register_event_handler(pf.SDL_MOUSEMOTION, __on_mousemove, None)