Example #1
0
void kernel_main( const multiboot& /*multiboot_structure*/, typ::uint32_t mboot_magic ) {
  if( multiboot_magic != mboot_magic ) {
    screen << color_t( color::red, color::white )
      << "Error: No Multiboot Bootloader Found ( Err_NMBF )";
    return;
  }
  screen << color_t( color::white, color::black );
  screen.clear();
  screen << "Welcome OSDeveloper";
  screen.endl();  
  gdt::init_gdt();
  typ::size_t a = 27;
  screen << a;
  return;
}
Example #2
0
std::vector<color_t> palette(const color_range& cr)
{
	std::vector<color_t> temp, res;
	std::unordered_set<color_t> clist;

	// Use blue to make master set of possible colors
	for(int i = 255; i != 0; i--) {
		const int j = 255 - i;

		temp.emplace_back(static_cast<uint8_t>(0), static_cast<uint8_t>(0), static_cast<uint8_t>(i));
		temp.emplace_back(static_cast<uint8_t>(j), static_cast<uint8_t>(j), static_cast<uint8_t>(255));
	}

	// Use recolor function to generate list of possible colors.
	// Could use a special function, would be more efficient, but harder to maintain.
	color_range_map cmap = recolor_range(cr, temp);
	for(const auto& cm : cmap) {
		clist.insert(cm.second);
	}

	res.push_back(cmap[{0,0,255}]);

	for(const auto& cs : clist) {
		if(cs != res[0] && !cs.null() && cs != color_t(255, 255, 255)) {
			res.push_back(cs);
		}
	}

	return res;
}
Example #3
0
void import_styles::set_border_color(
    border_direction_t dir, color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue)
{
    border_attrs_t* p = get_border_attrs(m_cur_border, dir);
    if (p)
        p->border_color = color_t(alpha, red, green, blue);
}
Example #4
0
static inline bool valid_total_colors(cube_t *cube) {
    lyrnum_t layers = cube->layers;
    for (lyrnum_t i = 0; i < (layers - 1) / 2 + 1; i++) {
        lyrnum_t total = (layers - i * 2) * 4 - 4;
        total = (total == 0 ? 1 : total);
        lyrnum_t count[TOTAL_COLORS];
        for (color_t j = 0; j < TOTAL_COLORS; j++) {
            count[j] = total;
        }

        if (total == 1) {
            lyrnum_t center = pow(layers, 2);
            for (color_t j = 0; j < TOTAL_COLORS; j++) {
                count[cube->faces[j][center]]--;
            }
        } else {
            for (color_t j = 0; j < TOTAL_COLORS; j++) {
                color_t (*face)[layers] = (color_t (*)[layers]) cube->faces[j];
                for (lyrnum_t k = i, k_c = layers - 1 - i; k < layers - 1 - i; k++, k_c--) {
                    count[face[i][k]]--;
                    count[face[k][layers - 1 - i]]--;
                    count[face[layers - 1 - i][k_c]]--;
                    count[face[k_c][i]]--;
                }
            }
        }

        for (color_t j = 0; j < TOTAL_COLORS; j++) {
            if (count[j] != 0)
                return false;
        }
    }

    return true;
}
Example #5
0
void format_run::reset()
{
    pos = 0;
    size = 0;
    font.clear();
    font_size = 0;
    bold = false;
    italic = false;
    color = color_t();
}
Example #6
0
color_range_map recolor_range(const color_range& new_range, const std::vector<color_t>& old_rgb)
{
	color_range_map map_rgb;

	const uint16_t new_red   = new_range.mid().r;
	const uint16_t new_green = new_range.mid().g;
	const uint16_t new_blue  = new_range.mid().b;

	const uint16_t max_red   = new_range.max().r;
	const uint16_t max_green = new_range.max().g;
	const uint16_t max_blue  = new_range.max().b;

	const uint16_t min_red   = new_range.min().r;
	const uint16_t min_green = new_range.min().g;
	const uint16_t min_blue  = new_range.min().b;

	// Map first color in vector to exact new color
	const color_t temp_rgb = old_rgb.empty() ? color_t() : old_rgb[0];

	const uint16_t reference_avg = (temp_rgb.r + temp_rgb.g + temp_rgb.b) / 3;

	for(const auto& old_c : old_rgb) {
		const uint16_t old_avg = (old_c.r + old_c.g + old_c.b) / 3;

		// Calculate new color
		uint32_t new_r = 0, new_g = 0, new_b = 0;

		if(reference_avg && old_avg <= reference_avg) {
			float old_ratio = static_cast<float>(old_avg) / reference_avg;

			new_r = static_cast<uint32_t>(old_ratio * new_red   + (1 - old_ratio) * min_red);
			new_g = static_cast<uint32_t>(old_ratio * new_green + (1 - old_ratio) * min_green);
			new_b = static_cast<uint32_t>(old_ratio * new_blue  + (1 - old_ratio) * min_blue);
		} else if(reference_avg != 255) {
			float old_ratio = (255.0f - static_cast<float>(old_avg)) / (255.0f - reference_avg);

			new_r = static_cast<uint32_t>(old_ratio * new_red   + (1 - old_ratio) * max_red);
			new_g = static_cast<uint32_t>(old_ratio * new_green + (1 - old_ratio) * max_green);
			new_b = static_cast<uint32_t>(old_ratio * new_blue  + (1 - old_ratio) * max_blue);
		} else {
			// Should never get here.
			// Would imply old_avg > reference_avg = 255
			assert(false);
		}

		new_r = std::min<uint32_t>(new_r, 255);
		new_g = std::min<uint32_t>(new_g, 255);
		new_b = std::min<uint32_t>(new_b, 255);

		map_rgb[old_c] = {static_cast<uint8_t>(new_r), static_cast<uint8_t>(new_g), static_cast<uint8_t>(new_b)};
	}

	return map_rgb;
}
Example #7
0
void fill_t::find_min_max(point_t p,int& YMin, int& YMax, int& XMin, int& XMax,float width,float height){
	//std::cout<<"Min max\n";
	std::queue <point_t> fmmQueue;
	fmmQueue.push(p);
	float pointx = p.getX();
	float pointy = p.getY();
	
	color_t c=colorArray[(int)pointx][(int)pointy];
    color_t pixels;
    
     while(!fmmQueue.empty()){
		p=fmmQueue.front();
		pointx=p.getX();
		pointy=p.getY();
		fmmQueue.pop();
		//Added Canvas size check
		if(pointx>=width || pointy>=height || pointx<0 || pointy<0)
			continue;
		
		pixels = colorArray[(int)pointx][(int)pointy];
		//glReadPixels(pointx,pointy,1.0,1.0,GL_RGB,GL_FLOAT,pixels);
		
		if( (pixels.getR()==c.getR()) && (pixels.getG()==c.getG()) && (pixels.getB()==c.getB()) )
		{
			if(pointy<YMin){
				YMin=pointy;
			}
			if(pointy>YMax){
				YMax=pointy;
			}
			
			if(pointx<XMin){
				XMin=pointx;
			}
			if(pointx>XMax){
				XMax=pointx;
			}
			p.draw(pen_t(color_t(0.5,0.5,0.5),1));
			//std::cout<<" let me pass!!! I am the point "<<pointx<<" and "<<pointy<<std::endl;
			fmmQueue.push(point_t(pointx+1,pointy));
			fmmQueue.push(point_t(pointx,pointy+1));
			fmmQueue.push(point_t(pointx-1,pointy));
			fmmQueue.push(point_t(pointx,pointy-1));
			// fmmQueue.push(point_t(pointx+1,pointy+1));
			// fmmQueue.push(point_t(pointx-1,pointy-1));
			// fmmQueue.push(point_t(pointx+1,pointy-1));
			// fmmQueue.push(point_t(pointx-1,pointy+1));
		}
	}
}
Example #8
0
void the_end(CVideo &video, std::string text, unsigned int duration)
{
	//
	// Some sane defaults.
	//
	if(text.empty())
		text = _("The End");
	if(!duration)
		duration = 3500;

	SDL_Rect area = screen_area();
	sdl::fill_rect(video.getSurface(),&area,0);

	video.flip();

	const size_t font_size = font::SIZE_XLARGE;

	area = font::text_area(text,font_size);
	area.x = screen_area().w/2 - area.w/2;
	area.y = screen_area().h/2 - area.h/2;

	for(size_t n = 0; n < 255; n += 5) {
		if(n)
			sdl::fill_rect(video.getSurface(),&area,0);

		const color_t col = color_t(uint8_t(n), uint8_t(n), uint8_t(n), uint8_t(n));
		font::draw_text(&video,area,font_size,col,text,area.x,area.y);

		events::pump();
		events::raise_process_event();
		events::raise_draw_event();
		video.flip();
		CVideo::delay(10);
	}

	//
	// Delay after the end of fading.
	// Rounded to multiples of 10.
	//
	unsigned int count = duration/10;
	while(count) {
		events::pump();
		events::raise_process_event();
		events::raise_draw_event();
		video.flip();
		CVideo::delay(10);
		--count;
	}
}
    void asdf_multiplat_t::render() {
        renderer->pre_render();

        {
            spritebatch->begin();
            ASSERT(!CheckGLError(), "gl error after begin");
            main_view->render(glm::vec3(0, 0, 0), glm::mat3(), color_t(1.0f));
            ASSERT(!CheckGLError(), "GL error after main_view->render() ");
            spritebatch->end();
        }

        glUseProgram(0);

        if (render_debug_views)
            render_debug();

        ASSERT(specific, "app.specific not assigned");
        specific->render();

        renderer->post_render();
    }
Example #10
0
namespace editor
{

    const color_t selection_overlay_color = color_t(1.0, 1.0, 1.0, 0.5f);


    //TODO: move this into an asdf_multiplat header
    constexpr bool is_sdl_keyboard_event(SDL_Event* event)
    {
        return event->type == SDL_KEYDOWN
            || event->type == SDL_KEYUP
            || event->type == SDL_TEXTEDITING
            || event->type == SDL_TEXTINPUT
            // || event->type == SDL_KEYMAPCHANGED  /// Does not compile on travis (it might be using an old version of SDL? docs say this requires SDL 2.0.4)
            ;
    }
    //--


    editor_t::editor_t()
    : hexmap_t()
    , action_stack(*this)
    , object_selection(*this)
    {}

    void editor_t::init()
    {
        hexmap_t::init();

        input = make_unique<input_handler_t>(*this);
        app.mouse_state.thing = input.get();
    }

    void editor_t::render()
    {
        hexmap_t::render();

        for(auto const& sel_obj_ind : object_selection.object_indices)
        {
            auto const& sel_obj = map_data.objects[sel_obj_ind];

            auto& spritebatch = rendered_map->spritebatch;
            auto const& shader = rendered_map->shader;
            spritebatch.begin(shader->view_matrix, shader->projection_matrix);

            auto const& pixel_texture = Content.textures["pixel"];
            auto const& obj_size_px = rendered_map->ojects_atlas->atlas_entries[sel_obj.id].size_px;
            auto scale = vec2(obj_size_px) / pixel_texture->get_size(); //scale overlay texture to match object texture size
            auto sprite_scale = scale * sel_obj.scale / glm::vec2(px_per_unit);

            spritebatch.draw(pixel_texture, sel_obj.position, selection_overlay_color, sprite_scale, sel_obj.rotation);

            spritebatch.end();
        }
    }

    void editor_t::save_action()
    {
        map_data.save_to_file("test_save.hxm");
        LOG("map saved");
    }

    void editor_t::load_action()
    {
        map_data.load_from_file("test_save.hxm");
        LOG("map loaded");
    }

    bool editor_t::undo()
    {
        if(action_stack.can_undo())
        {
            action_stack.undo();
            return true;
        }

        return false;
    }

    bool editor_t::redo()
    {
        if(action_stack.can_redo())
        {
            action_stack.redo();
            return true;
        }

        return false;
    }

    void editor_t::on_event(SDL_Event* event)
    {
        // I eventually want to remove this in place of my own keyboard
        // abstraction so I can get rid of handling sdl events here
        if(is_sdl_keyboard_event(event))
        {
            if(event->key.type == SDL_KEYDOWN)
                input->on_key_down(event->key.keysym);
        }    
    }


    void editor_t::set_tool(editor_t::tool_type_e const& new_tool)
    {
        switch(current_tool)
        {
            case select:
            {
                object_selection.clear_selection();
                break;
            }
            case terrain_paint:
            {
                paint_terrain_end();
                break;
            }
            case place_objects:
            {
                break;
            }
            case place_splines:
            {
                break;
            }
        };

        current_tool = new_tool;

        LOG("current tool: %s", tool_type_strings[current_tool]);
    }


    /// Selection
    bool editor_t::select_object(size_t object_index)
    {
        ASSERT(object_index != size_t(-1), "");
        LOG("selected object: %zu", object_index);
        return object_selection.add_object_index(object_index);
    }

    bool editor_t::deselect_object(size_t object_index)
    {
        ASSERT(object_index != size_t(-1), "");
        LOG("deselected object: %zu", object_index);
        return object_selection.remove_object_index(object_index);
    }

    void editor_t::deselect_all()
    {
        object_selection.clear_selection();
    }

    bool editor_t::select_object_at(glm::vec2 position)
    {
        size_t ind = map_data.object_index_at(position);

        if(ind != size_t(-1))
        {
            select_object(ind);
            return true;
        }

        return false;
    }

    bool editor_t::is_object_selected(size_t obj_index) const
    {
        return object_selection.object_indices.count(obj_index);
    }


    /// Terrain
    void editor_t::paint_terrain_start()
    {
        painted_terrain_coords.clear();
    }

    /// If the coord is inside the map, track the old tile_id of that cell
    /// and then paint it with the editor's current_tile_id
    bool editor_t::paint_terrain_at_coord(glm::ivec2 coord)
    {
        if(map_data.hex_grid.is_in_bounds(coord))
        {
            auto& cell = map_data.hex_grid.cell_at(coord);
            painted_terrain_coords.insert({coord, cell.tile_id});
            cell.tile_id = current_tile_id;
            return true;
        }

        return false;
    }

    void editor_t::paint_terrain_end()
    {
        if(!painted_terrain_coords.empty())
        {
            action_stack.push(make_unique<paint_tiles_action_t>
                ( map_data.hex_grid
                , std::move(painted_terrain_coords)
                , current_tile_id
                )
            );

            painted_terrain_coords.clear(); //pretty sure its empty anyway due to std::move
        }
    }


    /// Map Objects
    void editor_t::place_object(glm::vec2 position)
    {
        auto const& atlas_entries = rendered_map->ojects_atlas->atlas_entries;
        ASSERT(current_object_id < atlas_entries.size(), "object ID does not exist in atlas");
        auto const& atlas_entry = atlas_entries[current_object_id];
        glm::vec2 size = glm::vec2(atlas_entry.size_px) * units_per_px;

        data::map_object_t obj{current_object_id, position, size, glm::vec4(1), glm::vec2(1,1), 0.0f};

        action_stack.push_and_execute(make_unique<add_map_object_action_t>(map_data, std::move(obj)));
    }



    void editor_t::cancel_action()
    {
        switch(current_tool)
        {
            case select:
            {
                deselect_all();
                break;
            }
            case terrain_paint:
            {
                break;
            }
            case place_objects:
            {
                break;
            }
            case place_splines:
            {
                break;
            }
            default: break;
        };
    }

    object_selection_t::object_selection_t(editor_t& _e)
    : editor(_e)
    {
    }

    bool object_selection_t::add_object_index(size_t obj_ind)
    {
        auto x = object_indices.insert(obj_ind);
        recalc_bounds();

        //second value of pair returned by insert is a bool that is true
        //if the insertion took place
        return x.second;
    }

    bool object_selection_t::remove_object_index(size_t obj_ind)
    {
        // not 100% sure if it erases the object at this position, or with this key
        // I think it's with the key
        auto n = object_indices.erase(obj_ind);
        recalc_bounds();

        return n > 0;
    }

    void object_selection_t::clear_selection()
    {
        object_indices.clear();
        recalc_bounds();
    }

    void object_selection_t::recalc_bounds()
    {
        upper_bound = vec2(numeric_limits<float>::min());
        lower_bound = vec2(numeric_limits<float>::max());

        for(auto const& obj_ind : object_indices)
        {
            auto const& obj = editor.map_data.objects[obj_ind];

            upper_bound.x = std::max(upper_bound.x, obj.position.x + obj.size_d2.x);
            upper_bound.y = std::max(upper_bound.y, obj.position.y + obj.size_d2.y);

            lower_bound.x = std::min(lower_bound.x, obj.position.x - obj.size_d2.x);
            lower_bound.y = std::min(lower_bound.y, obj.position.y - obj.size_d2.y);
        }
    }

}
Example #11
0
void import_shared_strings::set_segment_font_color(
    color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue)
{
    m_cur_format.color = color_t(alpha, red, green, blue);
}
Example #12
0
		virtual color_t get_clear_color() const { return color_t(); }
Example #13
0
void color_t::reset()
{
    *this = color_t();
}
Example #14
0
void import_styles::set_fill_bg_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue)
{
    m_cur_fill.bg_color = color_t(alpha, red, green, blue);
}
Example #15
0
void import_styles::set_font_underline_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue)
{
    m_cur_font.underline_color = color_t(alpha, red, green, blue);
}
Example #16
0
		color_t gradientUp() {
			return color_t (red*255.0+(1.0-red)*102.0 , 
							green*255.0+(1.0-green)*102.0 , 
							blue*255.0+(1.0-blue)*102.0 ) ;
		}
Example #17
0
		color_t gradientDown() {
			return color_t (red*153 , green*153 , blue*153 ) ;
		}