-fixes to navigation, so edge-merging is more flexible on conflict

-add tab support to richtextlabel
-some click fixes to audio stream resampled
-ability to import largetextures (dialog)
This commit is contained in:
Juan Linietsky
2015-06-01 19:42:34 -03:00
parent 07a466f6e6
commit ab99671bb8
12 changed files with 611 additions and 55 deletions
+77
View File
@@ -1124,6 +1124,7 @@ void Image::create( const char ** p_xpm ) {
}
#define DETECT_ALPHA_MAX_TRESHOLD 254
#define DETECT_ALPHA_MIN_TRESHOLD 2
#define DETECT_ALPHA( m_value )\
{ \
uint8_t value=m_value;\
@@ -1136,6 +1137,82 @@ void Image::create( const char ** p_xpm ) {
}\
}
#define DETECT_NON_ALPHA( m_value )\
{ \
uint8_t value=m_value;\
if (value>0) {\
\
detected=true;\
break;\
}\
}
bool Image::is_invisible() const {
if (format==FORMAT_GRAYSCALE ||
format==FORMAT_RGB ||
format==FORMAT_INDEXED)
return false;
int len = data.size();
if (len==0)
return true;
if (format >= FORMAT_YUV_422 && format <= FORMAT_YUV_444)
return false;
int w,h;
_get_mipmap_offset_and_size(1,len,w,h);
DVector<uint8_t>::Read r = data.read();
const unsigned char *data_ptr=r.ptr();
bool detected=false;
switch(format) {
case FORMAT_INTENSITY: {
for(int i=0;i<len;i++) {
DETECT_NON_ALPHA(data_ptr[i]);
}
} break;
case FORMAT_GRAYSCALE_ALPHA: {
for(int i=0;i<(len>>1);i++) {
DETECT_NON_ALPHA(data_ptr[(i<<1)+1]);
}
} break;
case FORMAT_RGBA: {
for(int i=0;i<(len>>2);i++) {
DETECT_NON_ALPHA(data_ptr[(i<<2)+3])
}
} break;
case FORMAT_INDEXED: {
return false;
} break;
case FORMAT_INDEXED_ALPHA: {
return false;
} break;
case FORMAT_PVRTC2_ALPHA:
case FORMAT_PVRTC4_ALPHA:
case FORMAT_BC2:
case FORMAT_BC3: {
detected=true;
} break;
default: {}
}
return !detected;
}
Image::AlphaMode Image::detect_alpha() const {
if (format==FORMAT_GRAYSCALE ||
+1
View File
@@ -305,6 +305,7 @@ public:
};
AlphaMode detect_alpha() const;
bool is_invisible() const;
void put_indexed_pixel(int p_x, int p_y, uint8_t p_idx,int p_mipmap=0);
uint8_t get_indexed_pixel(int p_x, int p_y,int p_mipmap=0) const;
+26 -3
View File
@@ -91,9 +91,13 @@ void Navigation2D::_navpoly_link(int p_id) {
} else {
if (C->get().B!=NULL) {
print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
ConnectionPending pending;
pending.polygon=&p;
pending.edge=j;
p.edges[j].P=C->get().pending.push_back(pending);
continue;
//print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
}
ERR_CONTINUE(C->get().B!=NULL); //wut
C->get().B=&p;
C->get().B_edge=j;
@@ -133,7 +137,12 @@ void Navigation2D::_navpoly_unlink(int p_id) {
EdgeKey ek(edges[i].point,edges[next].point);
Map<EdgeKey,Connection>::Element *C=connections.find(ek);
ERR_CONTINUE(!C);
if (C->get().B) {
if (edges[i].P) {
C->get().pending.erase(edges[i].P);
edges[i].P=NULL;
} else if (C->get().B) {
//disconnect
C->get().B->edges[C->get().B_edge].C=NULL;
@@ -149,6 +158,20 @@ void Navigation2D::_navpoly_unlink(int p_id) {
C->get().B=NULL;
C->get().B_edge=-1;
if (C->get().pending.size()) {
//reconnect if something is pending
ConnectionPending cp = C->get().pending.front()->get();
C->get().pending.pop_front();
C->get().B=cp.polygon;
C->get().B_edge=cp.edge;
C->get().A->edges[C->get().A_edge].C=cp.polygon;
C->get().A->edges[C->get().A_edge].C_edge=cp.edge;
cp.polygon->edges[cp.edge].C=C->get().A;
cp.polygon->edges[cp.edge].C_edge=C->get().A_edge;
cp.polygon->edges[cp.edge].P=NULL;
}
} else {
connections.erase(C);
//erase
+11 -1
View File
@@ -41,7 +41,13 @@ class Navigation2D : public Node2D {
struct NavMesh;
struct Polygon;
struct ConnectionPending {
Polygon *polygon;
int edge;
};
struct Polygon {
@@ -49,7 +55,8 @@ class Navigation2D : public Node2D {
Point point;
Polygon *C; //connection
int C_edge;
Edge() { C=NULL; C_edge=-1; }
List<ConnectionPending>::Element *P;
Edge() { C=NULL; C_edge=-1; P=NULL; }
};
Vector<Edge> edges;
@@ -72,6 +79,9 @@ class Navigation2D : public Node2D {
int A_edge;
Polygon *B;
int B_edge;
List<ConnectionPending> pending;
Connection() { A=NULL; B=NULL; A_edge=-1; B_edge=-1;}
};
+27 -3
View File
@@ -85,9 +85,14 @@ void Navigation::_navmesh_link(int p_id) {
} else {
if (C->get().B!=NULL) {
print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
ConnectionPending pending;
pending.polygon=&p;
pending.edge=j;
p.edges[j].P=C->get().pending.push_back(pending);
continue;
//print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
}
ERR_CONTINUE(C->get().B!=NULL); //wut
//ERR_CONTINUE(C->get().B!=NULL); //wut
C->get().B=&p;
C->get().B_edge=j;
@@ -126,8 +131,13 @@ void Navigation::_navmesh_unlink(int p_id) {
EdgeKey ek(edges[i].point,edges[next].point);
Map<EdgeKey,Connection>::Element *C=connections.find(ek);
ERR_CONTINUE(!C);
if (C->get().B) {
if (edges[i].P) {
C->get().pending.erase(edges[i].P);
edges[i].P=NULL;
} else if (C->get().B) {
//disconnect
C->get().B->edges[C->get().B_edge].C=NULL;
@@ -143,6 +153,20 @@ void Navigation::_navmesh_unlink(int p_id) {
C->get().B=NULL;
C->get().B_edge=-1;
if (C->get().pending.size()) {
//reconnect if something is pending
ConnectionPending cp = C->get().pending.front()->get();
C->get().pending.pop_front();
C->get().B=cp.polygon;
C->get().B_edge=cp.edge;
C->get().A->edges[C->get().A_edge].C=cp.polygon;
C->get().A->edges[C->get().A_edge].C_edge=cp.edge;
cp.polygon->edges[cp.edge].C=C->get().A;
cp.polygon->edges[cp.edge].C_edge=C->get().A_edge;
cp.polygon->edges[cp.edge].P=NULL;
}
} else {
connections.erase(C);
//erase
+12 -1
View File
@@ -42,6 +42,13 @@ class Navigation : public Spatial {
struct NavMesh;
struct Polygon;
struct ConnectionPending {
Polygon *polygon;
int edge;
};
struct Polygon {
@@ -50,7 +57,8 @@ class Navigation : public Spatial {
Point point;
Polygon *C; //connection
int C_edge;
Edge() { C=NULL; C_edge=-1; }
List<ConnectionPending>::Element *P;
Edge() { C=NULL; C_edge=-1; P=NULL; }
};
Vector<Edge> edges;
@@ -72,6 +80,9 @@ class Navigation : public Spatial {
int A_edge;
Polygon *B;
int B_edge;
List<ConnectionPending> pending;
Connection() { A=NULL; B=NULL; A_edge=-1; B_edge=-1;}
};
+52 -6
View File
@@ -58,7 +58,7 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item* p_item) {
}
void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos,Item **r_click_item,int *r_click_char,bool *r_outside) {
void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos,Item **r_click_item,int *r_click_char,bool *r_outside,int p_char_count) {
RID ci;
if (r_outside)
@@ -80,6 +80,7 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p
int line=0;
int spaces=0;
if (p_mode!=PROCESS_CACHE) {
ERR_FAIL_INDEX(line,l.offset_caches.size());
@@ -89,6 +90,7 @@ void RichTextLabel::_process_line(int &y, int p_width, int p_line, ProcessMode p
if (p_mode==PROCESS_CACHE) {
l.offset_caches.clear();
l.height_caches.clear();
l.char_count=0;
}
int wofs=margin;
@@ -216,6 +218,8 @@ if (m_height > line_height) {\
underline=true;
}
} else if (p_mode==PROCESS_CACHE) {
l.char_count+=text->text.length();
}
rchar=0;
@@ -326,18 +330,23 @@ if (m_height > line_height) {\
}
}
int cw;
int cw=0;
bool visible = visible_characters<0 || p_char_count<visible_characters;
if (selected) {
cw = font->get_char_size(c[i],c[i+1]).x;
draw_rect(Rect2(pofs,y,cw,lh),selection_bg);
font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],selection_fg);
if (visible)
font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],selection_fg);
} else {
cw=font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],color);
if (visible)
cw=font->draw_char(ci,Point2(pofs,y+lh-(fh-ascent)),c[i],c[i+1],color);
}
p_char_count++;
if (c[i]=='\t') {
cw=tab_size*font->get_char_size(' ').width;
}
@@ -371,6 +380,8 @@ if (m_height > line_height) {\
lh=0;
if (p_mode!=PROCESS_CACHE)
lh = line<l.height_caches.size()?l.height_caches[line]:1;
else
l.char_count+=1; //images count as chars too
ItemImage *img = static_cast<ItemImage*>(it);
@@ -383,9 +394,12 @@ if (m_height > line_height) {\
ENSURE_WIDTH( img->image->get_width() );
if (p_mode==PROCESS_DRAW) {
bool visible = visible_characters<0 || p_char_count<visible_characters;
if (p_mode==PROCESS_DRAW && visible) {
img->image->draw(ci,Point2(wofs,y+lh-font->get_descent()-img->image->get_height()));
}
p_char_count++;
ADVANCE( img->image->get_width() );
CHECK_HEIGHT( (img->image->get_height()+font->get_descent()) );
@@ -556,11 +570,13 @@ void RichTextLabel::_notification(int p_what) {
//todo, change to binary search
int from_line = 0;
int total_chars = 0;
while (from_line<lines.size()) {
if (lines[from_line].height_accum_cache>=ofs)
break;
from_line++;
total_chars+=lines[from_line].char_count;
}
if (from_line>=lines.size())
@@ -572,7 +588,8 @@ void RichTextLabel::_notification(int p_what) {
while (y<size.height && from_line<lines.size()) {
_process_line(y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color);
_process_line(y,size.width-scroll_w,from_line,PROCESS_DRAW,base_font,base_color,Point2i(),NULL,NULL,NULL,total_chars);
total_chars+=lines[from_line].char_count;
from_line++;
}
}
@@ -1688,11 +1705,17 @@ void RichTextLabel::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_bbcode","text"),&RichTextLabel::set_bbcode);
ObjectTypeDB::bind_method(_MD("get_bbcode"),&RichTextLabel::get_bbcode);
ObjectTypeDB::bind_method(_MD("set_visible_characters","amount"),&RichTextLabel::set_visible_characters);
ObjectTypeDB::bind_method(_MD("get_visible_characters"),&RichTextLabel::get_visible_characters);
ObjectTypeDB::bind_method(_MD("get_total_character_count"),&RichTextLabel::get_total_character_count);
ObjectTypeDB::bind_method(_MD("set_use_bbcode","enable"),&RichTextLabel::set_use_bbcode);
ObjectTypeDB::bind_method(_MD("is_using_bbcode"),&RichTextLabel::is_using_bbcode);
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"bbcode/enabled"),_SCS("set_use_bbcode"),_SCS("is_using_bbcode"));
ADD_PROPERTY(PropertyInfo(Variant::STRING,"bbcode/bbcode",PROPERTY_HINT_MULTILINE_TEXT),_SCS("set_bbcode"),_SCS("get_bbcode"));
ADD_PROPERTY(PropertyInfo(Variant::INT,"visible_characters",PROPERTY_HINT_RANGE,"-1,128000,1"),_SCS("set_visible_characters"),_SCS("get_visible_characters"));
ADD_SIGNAL( MethodInfo("meta_clicked",PropertyInfo(Variant::NIL,"meta")));
@@ -1719,6 +1742,27 @@ void RichTextLabel::_bind_methods() {
}
void RichTextLabel::set_visible_characters(int p_visible) {
visible_characters=p_visible;
update();
}
int RichTextLabel::get_visible_characters() const {
return visible_characters;
}
int RichTextLabel::get_total_character_count() const {
int tc=0;
for(int i=0;i<lines.size();i++)
tc+=lines[i].char_count;
return tc;
}
RichTextLabel::RichTextLabel() {
@@ -1756,6 +1800,8 @@ RichTextLabel::RichTextLabel() {
selection.active=false;
selection.enabled=false;
visible_characters=-1;
}
RichTextLabel::~RichTextLabel() {
+10 -3
View File
@@ -171,8 +171,9 @@ private:
Vector<int> space_caches;
int height_cache;
int height_accum_cache;
int char_count;
Line() { from=NULL; }
Line() { from=NULL; char_count=0; }
};
@@ -223,10 +224,10 @@ private:
Selection selection;
int visible_characters;
void _process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos=Point2i(),Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL);
void _process_line(int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos=Point2i(),Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL,int p_char_count=0);
void _find_click(const Point2i& p_click,Item **r_click_item=NULL,int *r_click_char=NULL,bool *r_outside=NULL);
@@ -246,6 +247,8 @@ private:
bool use_bbcode;
String bbcode;
protected:
void _notification(int p_what);
@@ -304,6 +307,10 @@ public:
void set_bbcode(const String& p_bbcode);
String get_bbcode() const;
void set_visible_characters(int p_visible);
int get_visible_characters() const;
int get_total_character_count() const;
RichTextLabel();
~RichTextLabel();
};
@@ -230,6 +230,51 @@ bool AudioStreamResampled::mix(int32_t *p_dest, int p_frames) {
case 4: read=_resample<4>(p_dest,todo,increment); break;
case 6: read=_resample<6>(p_dest,todo,increment); break;
}
#if 1
//end of stream, fadeout
int remaining = p_frames-todo;
if (remaining && todo>0) {
//print_line("fadeout");
for(int c=0;c<channels;c++) {
for(int i=0;i<todo;i++) {
int32_t samp = p_dest[i*channels+c]>>8;
uint32_t mul = (todo-i) * 256 /todo;
//print_line("mul: "+itos(i)+" "+itos(mul));
p_dest[i*channels+c]=samp*mul;
}
}
}
#else
int remaining = p_frames-todo;
if (remaining && todo>0) {
for(int c=0;c<channels;c++) {
int32_t from = p_dest[(todo-1)*channels+c]>>8;
for(int i=0;i<remaining;i++) {
uint32_t mul = (remaining-i) * 256 /remaining;
p_dest[(todo+i)*channels+c]=from*mul;
}
}
}
#endif
//zero out what remains there to avoid glitches
for(int i=todo*channels;i<int(p_frames)*channels;i++) {
p_dest[i]=0;
}
if (read>rb_todo)
read=rb_todo;
@@ -316,6 +361,16 @@ AudioStreamResampled::AudioStreamResampled() {
rb=NULL;
offset=0;
read_buf=NULL;
rb_read_pos=0;
rb_write_pos=0;
rb_bits=0;
rb_len=0;
rb_mask=0;
read_buff_len=0;
channels=0;
mix_rate=0;
}
AudioStreamResampled::~AudioStreamResampled() {
+2 -1
View File
@@ -4229,8 +4229,9 @@ EditorNode::EditorNode() {
editor_import_export->add_import_plugin( Ref<EditorTextureImportPlugin>( memnew(EditorTextureImportPlugin(this,EditorTextureImportPlugin::MODE_TEXTURE_2D) )));
editor_import_export->add_import_plugin( Ref<EditorTextureImportPlugin>( memnew(EditorTextureImportPlugin(this,EditorTextureImportPlugin::MODE_TEXTURE_3D) )));
editor_import_export->add_import_plugin( Ref<EditorTextureImportPlugin>( memnew(EditorTextureImportPlugin(this,EditorTextureImportPlugin::MODE_ATLAS) )));
editor_import_export->add_import_plugin( Ref<EditorTextureImportPlugin>( memnew(EditorTextureImportPlugin(this,EditorTextureImportPlugin::MODE_LARGE) )));
editor_import_export->add_import_plugin( Ref<EditorTextureImportPlugin>( memnew(EditorTextureImportPlugin(this,EditorTextureImportPlugin::MODE_TEXTURE_3D) )));
Ref<EditorSceneImportPlugin> _scene_import = memnew(EditorSceneImportPlugin(this) );
Ref<EditorSceneImporterCollada> _collada_import = memnew( EditorSceneImporterCollada);
_scene_import->add_importer(_collada_import);
File diff suppressed because it is too large Load Diff
@@ -56,7 +56,9 @@ public:
enum Mode {
MODE_TEXTURE_2D,
MODE_TEXTURE_3D,
MODE_ATLAS
MODE_ATLAS,
MODE_LARGE,
MODE_MAX
};
@@ -65,10 +67,10 @@ private:
Mode mode;
EditorNode *editor;
EditorTextureImportDialog *dialog;
static EditorTextureImportPlugin *singleton[3];
static EditorTextureImportPlugin *singleton[MODE_MAX];
//used by other importers such as mesh
Error _process_texture_data(Ref<ImageTexture> &texture, int format, float quality, int flags,EditorExportPlatform::ImageCompression p_compr,int tex_flags,int shrink);
void compress_image(EditorExportPlatform::ImageCompression p_mode,Image& image,bool p_smaller);
public: