graphics: continue to change code to store some images as Texture

+ replace graf_pos and graf_pos_ref by Texture_ref
  + correct cCustomGraphics::copy_graphic
This commit is contained in:
Laurent alonso
2020-10-16 22:02:54 +02:00
committed by Celtic Minstrel
parent fcc2db7a5e
commit a407d61f4c
17 changed files with 387 additions and 362 deletions

View File

@@ -534,9 +534,9 @@ void set_up_terrain_buttons(bool reset) {
ter_from = ter_from_base;
pic = scenario.ter_types[i].picture;
if(pic >= 1000) {
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic % 1000);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, draw_rect);
Texture source_gworld;
std::tie(source_gworld, ter_from) = spec_scen_g.find_graphic(pic % 1000);
rect_draw_some_item(source_gworld, ter_from, mainPtr, draw_rect);
}
else if(pic < 960) {
pic = pic % 50;
@@ -571,55 +571,55 @@ void set_up_terrain_buttons(bool reset) {
pic %= 1000;
tiny_to.width() = tiny_to.width() / 2;
tiny_to.height() = tiny_to.height() / 2;
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
Texture source_gworld;
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
pic++;
tiny_to.offset(tiny_to.width(), 0);
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
pic++;
tiny_to.offset(-tiny_to.width(), tiny_to.height());
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
pic++;
tiny_to.offset(tiny_to.width(), 0);
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
} else if(pic >= 3000) {
pic %= 1000;
tiny_to.width() = tiny_to.width() / 2;
tiny_to.height() = tiny_to.height() / 2;
tiny_to.offset(tiny_to.width() / 2, 0);
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
Texture source_gworld;
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
pic++;
tiny_to.offset(0, tiny_to.height());
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
} else if(pic >= 2000) {
pic %= 1000;
tiny_to.width() = tiny_to.width() / 2;
tiny_to.height() = tiny_to.height() / 2;
tiny_to.offset(0, tiny_to.height() / 2);
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
Texture source_gworld;
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
pic++;
tiny_to.offset(tiny_to.width(), 0);
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
} else if(pic >= 1000) {
pic %= 1000;
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
Texture source_gworld;
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic);
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
} else {
auto pic_info = m_pic_index[pic];
pic = pic_info.i;
auto monst_gworld = [](pic_num_t sheet_num) {
return *ResMgr::graphics.get("monst" + std::to_string(1 + sheet_num));
return *ResMgr::textures.get("monst" + std::to_string(1 + sheet_num));
};
if(pic_info.x == 2 && pic_info.y == 2) {
tiny_to.width() = tiny_to.width() / 2;
@@ -669,9 +669,9 @@ void set_up_terrain_buttons(bool reset) {
tiny_to = draw_rect;
frame_rect(mainPtr, tiny_to, sf::Color::Black);
if(pic >= 1000) {
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic % 1000);
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
Texture source_gworld;
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic % 1000);
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
} else {
tiny_from = {0,0,18,18};
tiny_from.offset((pic % 10) * 18,(pic / 10) * 18);
@@ -992,7 +992,7 @@ void draw_terrain(){
void draw_monsts() {
short width,height,m_start_pic;
std::shared_ptr<const sf::Texture> from_gworld = nullptr;
Texture from_gworld;
rectangle source_rect;
location where_draw,store_loc;
@@ -1008,14 +1008,14 @@ void draw_monsts() {
if((where_draw.x == minmax(0,8,where_draw.x)) &&
(where_draw.y == minmax(0,8,where_draw.y)) &&
(scenario.scen_monsters[town->creatures[i].number].picture_num >= 1000)) {
graf_pos_ref(from_gworld, source_rect) = spec_scen_g.find_graphic((scenario.scen_monsters[town->creatures[i].number].picture_num + k) % 1000);
std::tie(from_gworld,source_rect) = spec_scen_g.find_graphic((scenario.scen_monsters[town->creatures[i].number].picture_num + k) % 1000);
store_loc.x += k % width;
store_loc.y += k / width;
}
else if(scenario.scen_monsters[town->creatures[i].number].picture_num < 1000) {
m_start_pic = m_pic_index[scenario.scen_monsters[town->creatures[i].number].picture_num].i + k;
int which_sheet = m_start_pic / 20;
from_gworld = &ResMgr::graphics.get("monst" + std::to_string(1 + which_sheet));
from_gworld = *ResMgr::textures.get("monst" + std::to_string(1 + which_sheet));
m_start_pic = m_start_pic % 20;
source_rect = calc_rect(2 * (m_start_pic / 10), m_start_pic % 10);
store_loc.x += k % width;
@@ -1035,7 +1035,7 @@ void draw_monsts() {
destrec.top = destrec.bottom - (source_rect.bottom - source_rect.top);
destrec.offset(TER_RECT_UL_X,TER_RECT_UL_Y);
rect_draw_some_item(*from_gworld, source_rect, mainPtr, destrec, sf::BlendAlpha);
rect_draw_some_item(from_gworld, source_rect, mainPtr, destrec, sf::BlendAlpha);
}
}
}
@@ -1075,11 +1075,11 @@ void draw_items() {
(where_draw.y >= 0) && (where_draw.y <= 8)) {
if(pic_num >= 1000) {
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(pic_num - 1000);
Texture source_gworld;
std::tie(source_gworld,source_rect)= spec_scen_g.find_graphic(pic_num - 1000);
dest_rect = calc_rect(where_draw.x,where_draw.y);
dest_rect.offset(8+TER_RECT_UL_X,8+TER_RECT_UL_Y);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, dest_rect, sf::BlendAlpha);
rect_draw_some_item(source_gworld, source_rect, mainPtr, dest_rect, sf::BlendAlpha);
}
else {
source_rect = get_item_template_rect(pic_num);
@@ -1111,7 +1111,7 @@ void draw_one_terrain_spot (short i,short j,ter_num_t terrain_to_draw) {
location where_draw;
rectangle source_rect;
short picture_wanted;
std::shared_ptr<const sf::Texture> source_gworld;
Texture source_gworld;
if(i < 0 || i > 8 || j < 0 || j > 8)
return;
@@ -1122,10 +1122,10 @@ void draw_one_terrain_spot (short i,short j,ter_num_t terrain_to_draw) {
where_draw.y = (char) j;
if(picture_wanted >= 1000 && spec_scen_g) {
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
}
else if(picture_wanted >= 960) {
source_gworld = &ResMgr::graphics.get("teranim");
source_gworld = *ResMgr::textures.get("teranim");
picture_wanted -= 960;
source_rect.left = 112 * (picture_wanted / 5);
source_rect.right = source_rect.left + 28;
@@ -1135,7 +1135,7 @@ void draw_one_terrain_spot (short i,short j,ter_num_t terrain_to_draw) {
else {
source_rect = get_template_rect(terrain_to_draw);
int which_sheet = picture_wanted / 50;
source_gworld = &ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet));
source_gworld = *ResMgr::textures.get("ter" + std::to_string(1 + which_sheet));
}
rectangle destrec;
@@ -1145,14 +1145,14 @@ void draw_one_terrain_spot (short i,short j,ter_num_t terrain_to_draw) {
destrec.bottom = destrec.top + BITMAP_HEIGHT;
destrec.offset(TER_RECT_UL_X,TER_RECT_UL_Y);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, destrec);
rect_draw_some_item(source_gworld, source_rect, mainPtr, destrec);
}
void draw_one_tiny_terrain_spot (short i,short j,ter_num_t terrain_to_draw,short size,bool road) {
rectangle dest_rect = {0,0,size,size},from_rect = {0,0,12,12};
short picture_wanted;
bool drawLargeIcon = false;
std::shared_ptr<const sf::Texture> source_gworld;
Texture source_gworld;
picture_wanted = scenario.ter_types[terrain_to_draw].map_pic;
if(picture_wanted == NO_PIC) {
@@ -1163,21 +1163,21 @@ void draw_one_tiny_terrain_spot (short i,short j,ter_num_t terrain_to_draw,short
dest_rect.offset(8 + TER_RECT_UL_X + size * i, 8 + TER_RECT_UL_Y + size * j);
if(drawLargeIcon) {
if(picture_wanted >= 1000) {
graf_pos_ref(source_gworld, from_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
std::tie(source_gworld,from_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
} else if(picture_wanted >= 960) {
source_gworld = &ResMgr::graphics.get("teranim");
source_gworld = *ResMgr::textures.get("teranim");
from_rect = calc_rect(4 * ((picture_wanted - 960) / 5),(picture_wanted - 960) % 5);
} else {
int which_sheet = picture_wanted / 50;
source_gworld = &ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet));
source_gworld = *ResMgr::textures.get("ter" + std::to_string(1 + which_sheet));
picture_wanted %= 50;
from_rect = calc_rect(picture_wanted % 10, picture_wanted / 10);
}
rect_draw_some_item(*source_gworld, from_rect, mainPtr, dest_rect);
rect_draw_some_item(source_gworld, from_rect, mainPtr, dest_rect);
} else {
if(picture_wanted >= 1000) {
std::shared_ptr<const sf::Texture> from_gw;
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
Texture from_gw;
std::tie(from_gw,from_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
from_rect.right = from_rect.left + 12;
from_rect.bottom = from_rect.top + 12;
picture_wanted /= 1000; picture_wanted--;
@@ -1279,9 +1279,9 @@ static void place_selected_terrain(ter_num_t ter, rectangle draw_rect) {
pic_num_t picture_wanted = scenario.ter_types[ter].picture;
rectangle source_rect;
if(picture_wanted >= 1000) {
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
rect_draw_some_item(*source_gworld, source_rect,mainPtr,draw_rect);
Texture source_gworld;
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
rect_draw_some_item(source_gworld, source_rect, mainPtr,draw_rect);
}
else if(picture_wanted >= 960) {
picture_wanted -= 960;
@@ -1395,55 +1395,55 @@ void place_location() {
picture_wanted %= 1000;
to_rect.width() = to_rect.width() / 2;
to_rect.height() = to_rect.height() / 2;
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
Texture source_gworld;
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
picture_wanted++;
to_rect.offset(to_rect.width(), 0);
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
picture_wanted++;
to_rect.offset(-to_rect.width(), to_rect.height());
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
picture_wanted++;
to_rect.offset(to_rect.width(), 0);
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
} else if(picture_wanted >= 3000) {
picture_wanted %= 1000;
to_rect.width() = to_rect.width() / 2;
to_rect.height() = to_rect.height() / 2;
to_rect.offset(to_rect.width() / 2, 0);
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
Texture source_gworld;
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
picture_wanted++;
to_rect.offset(0, to_rect.height());
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
} else if(picture_wanted >= 2000) {
picture_wanted %= 1000;
to_rect.width() = to_rect.width() / 2;
to_rect.height() = to_rect.height() / 2;
to_rect.offset(0, to_rect.height() / 2);
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
Texture source_gworld;
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
picture_wanted++;
to_rect.offset(to_rect.width(), 0);
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
} else if(picture_wanted >= 1000) {
picture_wanted %= 1000;
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
Texture source_gworld;
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted);
rect_draw_some_item(source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
} else {
auto pic_info = m_pic_index[picture_wanted];
picture_wanted = pic_info.i;
auto monst_gworld = [](pic_num_t sheet_num) {
return *ResMgr::graphics.get("monst" + std::to_string(1 + sheet_num));
return *ResMgr::textures.get("monst" + std::to_string(1 + sheet_num));
};
if(pic_info.x == 2 && pic_info.y == 2) {
to_rect.width() = to_rect.width() / 2;
@@ -1490,9 +1490,9 @@ void place_location() {
} else if(overall_mode == MODE_PLACE_ITEM || overall_mode == MODE_PLACE_SAME_ITEM) {
picture_wanted = scenario.scen_items[mode_count].graphic_num;
if(picture_wanted >= 1000) {
std::shared_ptr<const sf::Texture> source_gworld;
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
rect_draw_some_item(*source_gworld,source_rect,mainPtr,draw_rect,sf::BlendAlpha);
Texture source_gworld;
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
rect_draw_some_item(source_gworld,source_rect,mainPtr,draw_rect,sf::BlendAlpha);
} else if(picture_wanted < 55) {
source_rect = calc_rect(picture_wanted % 5,picture_wanted / 5);
rect_draw_some_item(*ResMgr::textures.get("objects"),source_rect,mainPtr,draw_rect,sf::BlendAlpha);