本文整理汇总了C++中surface类的典型用法代码示例。如果您正苦于以下问题:C++ surface类的具体用法?C++ surface怎么用?C++ surface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了surface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: if
void Renderer::render(surface& surf, Plateau& plateau) {
surf.fill(color::black());
back.blit(surf,100,0);
int blanc=0;
int noir=0;
for(size_t i=0;i<plateau.pions.size();i++) {
for(size_t j=0;j<plateau.pions[i].size();j++) {
if(plateau.pions[i][j]==Pion::black()) {
black.blit(surf,100+((int)i*60),(int)j*60);
noir++;
} else if(plateau.pions[i][j]==Pion::white()) {
white.blit(surf,100+((int)i*60),(int)j*60);
blanc++;
}
}
}
if(plateau.gameFinished()) {
string aff = "Joueur: "
+lexical_cast<string>(blanc)+" Ordinateur: "
+lexical_cast<string>(noir);
surface text = thefont.render_shaded(aff,color::cyan(),color::grey());
text.blit(surf,(surf.get_width()/2)-(text.get_width()/2)
,(surf.get_height()/2)-(text.get_height()/2));
}
surf.flip();
}
开发者ID:nicolas-van,项目名称:codeyong,代码行数:29,代码来源:Renderer.cpp
示例2:
bool menu::imgsel_style::load_image(const std::string &img_sub)
{
std::string path = img_base_ + "-" + img_sub + ".png";
const surface image = image::get_image(path);
img_map_[img_sub] = image;
return(!image.null());
}
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:7,代码来源:menu_style.cpp
示例3: set_text
void textbox::append_text(const std::string& text, bool auto_scroll, const SDL_Color& color)
{
if(text_image_.get() == NULL) {
set_text(text, color);
return;
}
//disallow adding multi-line text to a single-line text box
if(wrap_ == false && std::find_if(text.begin(),text.end(),utils::isnewline) != text.end()) {
return;
}
const bool is_at_bottom = get_position() == get_max_position();
const wide_string& wtext = utils::string_to_wstring(text);
const surface new_text = add_text_line(wtext, color);
const surface new_surface = create_compatible_surface(text_image_,std::max<size_t>(text_image_->w,new_text->w),text_image_->h+new_text->h);
SDL_SetAlpha(new_text.get(),0,0);
SDL_SetAlpha(text_image_.get(),0,0);
SDL_BlitSurface(text_image_,NULL,new_surface,NULL);
SDL_Rect target = {0,text_image_->h,new_text->w,new_text->h};
SDL_BlitSurface(new_text,NULL,new_surface,&target);
text_image_.assign(new_surface);
text_.resize(text_.size() + wtext.size());
std::copy(wtext.begin(),wtext.end(),text_.end()-wtext.size());
set_dirty(true);
update_text_cache(false);
if(auto_scroll && is_at_bottom) scroll_to_bottom();
handle_text_changed(text_);
}
开发者ID:Yossarian,项目名称:WesnothAddonServer,代码行数:34,代码来源:textbox.cpp
示例4: draw_item
void item_palette::draw_item(const overlay& item, surface& image, std::stringstream& tooltip_text)
{
std::stringstream filename;
filename << item.image;
if(item.image.empty()) {
filename << item.halo;
}
image = image::get_image(filename.str());
if(image == nullptr) {
tooltip_text << "IMAGE NOT FOUND\n";
ERR_ED << "image for item type: '" << filename.str() << "' not found" << std::endl;
image = image::get_image(game_config::images::missing);
if(image == nullptr) {
ERR_ED << "Placeholder image not found" << std::endl;
return;
}
}
if(image->w != item_size_ || image->h != item_size_) {
image.assign(scale_surface(image, item_size_, item_size_));
}
tooltip_text << item.name;
}
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:25,代码来源:item_palette.cpp
示例5: get_cursor
static SDL_Cursor* get_cursor(cursor::CURSOR_TYPE type)
{
bool is_color = use_color_cursors();
if(cache[type] == NULL || indeterminate(cache_color[type]) || cache_color[type] != is_color) {
const std::string prefix = is_color ? "cursors/" : "cursors-bw/";
const surface surf(image::get_image(prefix + (is_color ? color_images : bw_images)[type]));
if (is_color) {
cache[type] = SDL_CreateColorCursor(surf.get(), shift_x[type], shift_y[type]);
} else {
cache[type] = create_cursor(surf);
}
cache_color[type] = is_color;
}
return cache[type];
}
开发者ID:quyetdx55,项目名称:wesnoth,代码行数:16,代码来源:cursor.cpp
示例6: dialog_image
dialog_image(label *const caption, CVideo &video, surface img) : widget(video, false),
surf_(img), caption_(caption)
{
if(!img.null()) {
set_measurements(img->w, img->h);
}
}
开发者ID:rasata,项目名称:wesnoth,代码行数:7,代码来源:construct_dialog.hpp
示例7: blit
void surface::blit(rectangle srcrect, surface& dst, rectangle dstrect) {
SDL_Surface* ptr = get_low();
SDL_Rect srcr = rectangle::exchange_rect<SDL_Rect>(srcrect);
SDL_Rect dstr = rectangle::exchange_rect<SDL_Rect>(dstrect);
SDL_Surface* ptrd = dst.get_low();
if(SDL_BlitSurface(ptr,&srcr,ptrd,&dstr)<0)
throw exception_sdl();
}
开发者ID:nicolas-van,项目名称:codeyong,代码行数:8,代码来源:sdlw_surface.cpp
示例8: run_formula
void run_formula(surface surf, const std::string& algo)
{
const hi_res_timer timer("run_formula");
const int ticks = SDL_GetTicks();
surface_formula_symbol_table table(surf);
game_logic::formula f(algo, &table);
bool locked = false;
if(SDL_MUSTLOCK(surf.get())) {
const int res = SDL_LockSurface(surf.get());
if(res == 0) {
locked = true;
}
}
std::map<Uint32, Uint32> pixel_map;
Uint32* pixels = reinterpret_cast<Uint32*>(surf->pixels);
Uint32* end_pixels = pixels + surf->w*surf->h;
Uint32 AlphaPixel = SDL_MapRGBA(surf->format, 0x6f, 0x6d, 0x51, 0x0);
int skip = 0;
while(pixels != end_pixels) {
if(((*pixels)&(~surf->format->Amask)) == AlphaPixel) {
++pixels;
continue;
}
std::map<Uint32, Uint32>::const_iterator itor = pixel_map.find(*pixels);
if(itor == pixel_map.end()) {
pixel_callable p(surf, *pixels);
Uint32 result = f.execute(p).as_int();
pixel_map[*pixels] = result;
*pixels = result;
} else {
*pixels = itor->second;
}
++pixels;
}
if(locked) {
SDL_UnlockSurface(surf.get());
}
}
开发者ID:davewx7,项目名称:Wizard-Tactics,代码行数:44,代码来源:surface_formula.cpp
示例9: compare_surfaces
static void compare_surfaces(const surface<float>& expected, const surface<float>& observed, float abs_error) {
ASSERT_EQ(expected.width(), observed.width());
ASSERT_EQ(expected.height(), observed.height());
for (uint32_t x = 0; x < expected.width(); x++) {
for (uint32_t y = 0; y < expected.height(); y++) {
SCOPED_TRACE("(" + to_string(x) + ", " + to_string(y) + ")");
EXPECT_NEAR(expected.at(x, y), observed.at(x, y), abs_error);
}
}
}
开发者ID:Catuna,项目名称:xyuv,代码行数:11,代码来源:regress_format_templates.cpp
示例10: map
void terrain_palette::draw_item(const t_translation::t_terrain& terrain,
surface& image, std::stringstream& tooltip_text) {
const t_translation::t_terrain base_terrain =
map().get_terrain_info(terrain).default_base();
//Draw default base for overlay terrains
if(base_terrain != t_translation::NONE_TERRAIN) {
const std::string base_filename = map().get_terrain_info(base_terrain).editor_image();
surface base_image(image::get_image(base_filename));
if(base_image == nullptr) {
tooltip_text << "BASE IMAGE NOT FOUND\n";
ERR_ED << "image for terrain : '" << base_filename << "' not found" << std::endl;
base_image = image::get_image(game_config::images::missing);
if (base_image == nullptr) {
ERR_ED << "Placeholder image not found" << std::endl;
return;
}
}
if(base_image->w != item_size_ || base_image->h != item_size_) {
base_image.assign(scale_surface(base_image,
item_size_, item_size_));
}
}
const std::string filename = map().get_terrain_info(terrain).editor_image();
image = image::get_image(filename);
if(image == nullptr) {
tooltip_text << "IMAGE NOT FOUND\n";
ERR_ED << "image for terrain: '" << filename << "' not found" << std::endl;
image = image::get_image(game_config::images::missing);
if (image == nullptr) {
ERR_ED << "Placeholder image not found" << std::endl;
return;
}
}
if(image->w != item_size_ || image->h != item_size_) {
image.assign(scale_surface(image,
item_size_, item_size_));
}
tooltip_text << map().get_terrain_editor_string(terrain);
if (gui_.get_draw_terrain_codes()) {
tooltip_text << " " + utils::unicode_em_dash + " " << terrain;
}
}
开发者ID:shikadilord,项目名称:wesnoth,代码行数:49,代码来源:terrain_palettes.cpp
示例11: get_surface_formula
surface get_surface_formula(surface input, const std::string& algo)
{
if(algo.empty()) {
return input;
}
cache_key key(input, algo);
surface surf = cache().get(key);
if(surf.get() == NULL) {
surf = input.clone();
run_formula(surf, algo);
cache().put(key, surf);
}
return surf;
}
开发者ID:gradonly,项目名称:frogatto,代码行数:16,代码来源:surface_formula.cpp
示例12: glGenBuffers
void VisSurface::build(){
sharedInfo->release();
glGenBuffers(1, &(sharedInfo->vtx_buf_id));
glGenBuffers(1, &(sharedInfo->idx_buf_id));
glBindBuffer(GL_ARRAY_BUFFER, sharedInfo->vtx_buf_id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sharedInfo->idx_buf_id);
//prepare for data generation
Vec2i dicing = sharedInfo->dicing;
Vec2d dicingf = Vec2d(dicing.x - 1, dicing.y - 1);
int num_floats = dicing.x * dicing.y * 3;
int num_idxs = dicing.x * (dicing.y-1) * 2;
float *vtxData = new float[num_floats];
unsigned int *idxData = new unsigned int[num_idxs];
//generate pt data
for (int y = 0; y < dicing.y; y++){
for (int x = 0; x < dicing.x; x++){
Vec2d st = sharedInfo->region.remap(Vec2d(x,y) / dicingf);
Vec3d pt = surface->eval(st);
unsigned int vtx_num = (unsigned int)(dicing.x) * y + x;
vtxData[3*vtx_num] = pt.x;
vtxData[3*vtx_num+1] = pt.y;
vtxData[3*vtx_num+2] = pt.z;
if (y < dicing.y - 1){
idxData[vtx_num * 2] = vtx_num;
idxData[vtx_num * 2 + 1] = vtx_num + dicing.x;
}
}
}
//TODO: normals (interleave; it's better)
//send the data
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * num_floats, vtxData, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * num_idxs, idxData, GL_STATIC_DRAW);
sharedInfo->valid = true;
delete [] vtxData;
delete [] idxData;
}
开发者ID:trbabb,项目名称:gltoy,代码行数:43,代码来源:VisSurface.cpp
示例13: draw_item
void unit_palette::draw_item(const unit_type& u, surface& image, std::stringstream& tooltip_text) {
std::stringstream filename;
filename << u.image() << "~RC(" << u.flag_rgb() << '>'
<< team::get_side_color_id(gui_.viewing_side()) << ')';
image = image::get_image(filename.str());
if(image == nullptr) {
tooltip_text << "IMAGE NOT FOUND\n";
ERR_ED << "image for unit type: '" << filename.str() << "' not found" << std::endl;
image = image::get_image(game_config::images::missing);
if(image == nullptr) {
ERR_ED << "Placeholder image not found" << std::endl;
return;
}
}
if(image->w != item_size_ || image->h != item_size_) {
image.assign(scale_surface(image, item_size_, item_size_));
}
tooltip_text << u.type_name();
}
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:23,代码来源:unit_palette.cpp
示例14: show_dialog
int show_dialog(display& screen, surface image,
const std::string& caption, const std::string& message,
DIALOG_TYPE type,
const std::vector<std::string>* menu_items,
const std::vector<preview_pane*>* preview_panes,
const std::string& text_widget_label,
std::string* text_widget_text,
const int text_widget_max_chars,
std::vector<check_item>* options,
int xloc,
int yloc,
const dialog_frame::style* dialog_style,
std::vector<dialog_button_info>* action_buttons,
const menu::sorter* sorter,
menu::style* menu_style)
{
std::string title;
if (image.null()) title = caption;
const dialog::style& style = (dialog_style)? *dialog_style : dialog::default_style;
CVideo &disp = screen.video();
gui::dialog d(screen, title, message, type, style);
//add the components
if(!image.null()) {
d.set_image(image, caption);
}
if(menu_items) {
d.set_menu( new gui::menu(disp,*menu_items,type == MESSAGE,-1,dialog::max_menu_width,sorter,menu_style,false));
}
if(preview_panes) {
for(unsigned int i=0; i < preview_panes->size(); ++i) {
d.add_pane((*preview_panes)[i]);
}
}
if(text_widget_text) {
d.set_textbox(text_widget_label,*text_widget_text, text_widget_max_chars);
}
if(options) {
for(unsigned int i=0; i < options->size(); ++i) {
check_item& item = (*options)[i];
d.add_option(item.label, item.checked);
}
}
if(action_buttons) {
for(unsigned int i=0; i < action_buttons->size(); ++i) {
d.add_button((*action_buttons)[i]);
}
}
//enter the dialog loop
d.show(xloc, yloc);
//send back results
if(options) {
for(unsigned int i=0; i < options->size(); ++i)
{
(*options)[i].checked = d.option_checked(i);
}
}
if(text_widget_text) {
*text_widget_text = d.textbox_text();
}
return d.result();
}
开发者ID:CliffsDover,项目名称:wesnoth_ios,代码行数:64,代码来源:show_dialog.cpp
示例15: draw_text_line
SDL_Rect draw_text_line(surface gui_surface, const SDL_Rect& area, int size,
const SDL_Color& colour, const std::string& text,
int x, int y, bool use_tooltips, int style)
{
if (gui_surface.null()) {
text_surface const &u = text_cache::find(text_surface(text, size, colour, style));
SDL_Rect res = {0, 0, u.width(), u.height()};
return res;
}
if(area.w == 0) { // no place to draw
SDL_Rect res = {0,0,0,0};
return res;
}
const std::string etext = make_text_ellipsis(text, size, area.w);
// for the main current use, we already parsed markup
surface surface(render_text(etext,size,colour,style,false));
if(surface == NULL) {
SDL_Rect res = {0,0,0,0};
return res;
}
SDL_Rect dest;
if(x!=-1) {
dest.x = x;
#ifdef HAVE_FRIBIDI
// Oron -- Conditional, until all draw_text_line calls have fixed area parameter
if(getenv("NO_RTL") == NULL) {
bool is_rtl = text_cache::find(text_surface(text, size, colour, style)).is_rtl();
if(is_rtl)
dest.x = area.x + area.w - surface->w - (x - area.x);
}
#endif
} else
dest.x = (area.w/2)-(surface->w/2);
if(y!=-1)
dest.y = y;
else
dest.y = (area.h/2)-(surface->h/2);
dest.w = surface->w;
dest.h = surface->h;
if(line_width(text, size) > area.w) {
tooltips::add_tooltip(dest,text);
}
if(dest.x + dest.w > area.x + area.w) {
dest.w = area.x + area.w - dest.x;
}
if(dest.y + dest.h > area.y + area.h) {
dest.h = area.y + area.h - dest.y;
}
if(gui_surface != NULL) {
SDL_Rect src = dest;
src.x = 0;
src.y = 0;
SDL_BlitSurface(surface,&src,gui_surface,&dest);
}
if(use_tooltips) {
tooltips::add_tooltip(dest,text);
}
return dest;
}
开发者ID:oys0317,项目名称:opensanguo,代码行数:69,代码来源:font.cpp
示例16: start_drag
void data_device::start_drag(data_source* source_, surface& origin_, surface* icon_, uint32_t serial_) {
marshal(0, source_ ? source_->wl_obj() : nullptr, origin_.wl_obj(), icon_ ? icon_->wl_obj() : nullptr, serial_);
}
开发者ID:ElementW,项目名称:wlcppgen,代码行数:3,代码来源:data_device.cpp
示例17: surface
surface(const surface& s) : surface_(s.get())
{
add_surface_ref(surface_);
}
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:4,代码来源:surface.hpp
示例18: image_name_
void timage::draw(surface& canvas
, const game_logic::map_formula_callable& variables)
{
DBG_GUI_D << "Image: draw.\n";
/**
* @todo formulas are now recalculated every draw cycle which is a bit
* silly unless there has been a resize. So to optimize we should use an
* extra flag or do the calculation in a separate routine.
*/
const std::string& name = image_name_(variables);
if(name.empty()) {
DBG_GUI_D << "Image: formula returned no value, will not be drawn.\n";
return;
}
/*
* The locator might return a different surface for every call so we can't
* cache the output, also not if no formula is used.
*/
surface tmp(image::get_image(image::locator(name)));
if(!tmp) {
ERR_GUI_D << "Image: '" << name << "' not found and won't be drawn.\n";
return;
}
image_.assign(make_neutral_surface(tmp));
assert(image_);
src_clip_ = ::create_rect(0, 0, image_->w, image_->h);
game_logic::map_formula_callable local_variables(variables);
local_variables.add("image_original_width", variant(image_->w));
local_variables.add("image_original_height", variant(image_->h));
unsigned w = w_(local_variables);
VALIDATE_WITH_DEV_MESSAGE(
static_cast<int>(w) >= 0
, _("Image doesn't fit on canvas.")
, (formatter() << "Image '" << name
<< "', w = " << static_cast<int>(w) << ".").str());
unsigned h = h_(local_variables);
VALIDATE_WITH_DEV_MESSAGE(
static_cast<int>(h) >= 0
, _("Image doesn't fit on canvas.")
, (formatter() << "Image '" << name
<< "', h = " << static_cast<int>(h) << ".").str());
local_variables.add("image_width", variant(w ? w : image_->w));
local_variables.add("image_height", variant(h ? h : image_->h));
const unsigned x = x_(local_variables);
VALIDATE_WITH_DEV_MESSAGE(
static_cast<int>(x) >= 0
, _("Image doesn't fit on canvas.")
, (formatter() << "Image '" << name
<< "', x = " << static_cast<int>(x) << ".").str());
const unsigned y = y_(local_variables);
VALIDATE_WITH_DEV_MESSAGE(
static_cast<int>(y) >= 0
, _("Image doesn't fit on canvas.")
, (formatter() << "Image '" << name
<< "', y = " << static_cast<int>(y) << ".").str());
// Copy the data to local variables to avoid overwriting the originals.
SDL_Rect src_clip = src_clip_;
SDL_Rect dst_clip = ::create_rect(x, y, 0, 0);
surface surf;
// Test whether we need to scale and do the scaling if needed.
if(w || h) {
bool done = false;
bool stretch_image = (resize_mode_ == stretch) && (!!w ^ !!h);
if(!w) {
if(stretch_image) {
DBG_GUI_D << "Image: vertical stretch from " << image_->w
<< ',' << image_->h << " to a height of " << h << ".\n";
surf = stretch_surface_vertical(image_, h, false);
done = true;
}
w = image_->w;
}
if(!h) {
if(stretch_image) {
DBG_GUI_D << "Image: horizontal stretch from " << image_->w
<< ',' << image_->h << " to a width of " << w << ".\n";
surf = stretch_surface_horizontal(image_, w, false);
done = true;
}
h = image_->h;
}
if(!done) {
//.........这里部分代码省略.........
开发者ID:RushilPatel,项目名称:BattleForWesnoth,代码行数:101,代码来源:canvas.cpp
示例19: assign
void assign(const surface& s)
{
assign_surface_internal(s.get());
}
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:4,代码来源:surface.hpp
示例20: show_dialog
int show_dialog(display& screen, surface image,
const std::string& caption, const std::string& message,
DIALOG_TYPE type,
const std::vector<shared_string>* menu_items,
const std::vector<preview_pane*>* preview_panes,
const std::string& text_widget_label,
std::string* text_widget_text,
const int text_widget_max_chars,
std::vector<check_item>* options,
int xloc,
int yloc,
const dialog_frame::style* dialog_style,
std::vector<dialog_button_info>* action_buttons,
const menu::sorter* sorter,
menu::style* menu_style)
{
std::string title;
if (image.null()) title = caption;
const dialog::style& style = (dialog_style)? *dialog_style : dialog::default_style;
CVideo &disp = screen.video();
gui::dialog d(screen, title, message, type, style);
//add the components
if(!image.null()) {
d.set_image(image, caption);
}
if(menu_items) {
d.set_menu( new gui::menu(disp,*menu_items,type == MESSAGE,-1,dialog::max_menu_width,sorter,menu_style,false));
}
if(preview_panes) {
for(unsigned int i=0; i < preview_panes->size(); ++i) {
d.add_pane((*preview_panes)[i]);
}
}
if(text_widget_text) {
d.set_textbox(text_widget_label,*text_widget_text, text_widget_max_chars);
}
if(options) {
for(unsigned int i=0; i < options->size(); ++i) {
check_item& item = (*options)[i];
d.add_option(item.label, item.checked);
}
}
if(action_buttons) {
for(unsigned int i=0; i < action_buttons->size(); ++i) {
d.add_button((*action_buttons)[i]);
}
}
//enter the dialog loop
d.show(xloc, yloc);
// KP: unfortunately, undrawing doesn't work now since we don't have easy access to the framebuffer pixels with openGL
// so we set a global variable that the parent should redraw everything
gRedraw = true;
//send back results
if(options) {
for(unsigned int i=0; i < options->size(); ++i)
{
(*options)[i].checked = d.option_checked(i);
}
}
if(text_widget_text) {
*text_widget_text = d.textbox_text();
}
return d.result();
}
开发者ID:dodikk,项目名称:iWesnoth,代码行数:68,代码来源:show_dialog.cpp
注:本文中的surface类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论