mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-11-30 03:08:12 +08:00
remove window.show/hide
This commit is contained in:
parent
4cbb80090a
commit
49a1f2912c
@ -24,6 +24,11 @@ public:
|
||||
{View*v=LayoutInflater::from(container->getContext())->inflate(res[position-2],nullptr,false);
|
||||
container->addView(v);
|
||||
v->requestLayout();
|
||||
View*btn=v->findViewById(uidemo::R::id::button1);
|
||||
if(btn)btn->setOnClickListener([](View&v){
|
||||
Window*w=new Window(0,0,400,400);
|
||||
w->setBackgroundColor(0x80FF0000);
|
||||
});
|
||||
return v;
|
||||
}break;
|
||||
case 0:
|
||||
@ -31,6 +36,7 @@ public:
|
||||
ListView*lv=new ListView(800,480);
|
||||
lv->setDivider(new ColorDrawable(0x80224422));
|
||||
lv->setDividerHeight(1);
|
||||
lv->setFastScrollEnabled(true);
|
||||
lv->setSelector(new ColorDrawable(0x8800FF00));
|
||||
lv->setVerticalScrollBarEnabled(true);
|
||||
lv->setOverScrollMode(View::OVER_SCROLL_ALWAYS);
|
||||
@ -66,7 +72,7 @@ public:
|
||||
}
|
||||
});
|
||||
gv->setVerticalScrollBarEnabled(true);
|
||||
gv->setNumColumns(3);
|
||||
gv->setNumColumns(2);
|
||||
gv->setAdapter(adapter);
|
||||
gv->setHorizontalSpacing(2);
|
||||
gv->setVerticalSpacing(2);
|
||||
@ -136,7 +142,6 @@ MediaWindow::MediaWindow(int x,int y,int w,int h):Window(x,y,w,h){
|
||||
Window*CreateMultiMedia(){
|
||||
MediaWindow*w=new MediaWindow(0,0,800,640);
|
||||
w->setText("Media");
|
||||
w->show();
|
||||
LOGD("CreateMultiMedia");
|
||||
return w;
|
||||
}
|
||||
|
@ -160,17 +160,15 @@ void GraphDevice::composeSurfaces(){
|
||||
long t2,t1=SystemClock::uptimeMillis();
|
||||
trackFPS();
|
||||
|
||||
std::vector<RefPtr<Canvas>>wSurfaces;
|
||||
std::vector<Rect>wBounds;
|
||||
std::vector<Window*>wins;
|
||||
std::vector<RefPtr<Canvas>>wSurfaces;
|
||||
std::vector<RefPtr<Region>>winVisibleRgns;
|
||||
WindowManager::getInstance().enumWindows([&wSurfaces,&wBounds,&wins](Window*w)->bool{
|
||||
if( w->getVisibility()==View::VISIBLE ){
|
||||
Rect rcw=w->getBound();
|
||||
if(w->mAttachInfo->mCanvas){
|
||||
wSurfaces.push_back(w->mAttachInfo->mCanvas);
|
||||
wBounds.push_back(rcw);
|
||||
wins.push_back(w);
|
||||
wBounds.push_back(w->getBound()); wins.push_back(w);
|
||||
return true;
|
||||
}
|
||||
}return false;
|
||||
@ -179,12 +177,11 @@ void GraphDevice::composeSurfaces(){
|
||||
primaryContext->set_operator(Cairo::Context::Operator::SOURCE);
|
||||
Rect rcBlited={0,0,0,0};
|
||||
for(int i=0;i<wSurfaces.size();i++){
|
||||
Rect rcw=wBounds[i];
|
||||
Rect rcw = wBounds[i];
|
||||
std::vector<Rectangle> clipRects;
|
||||
HANDLE hdlSurface = wSurfaces[i]->mHandle;
|
||||
RefPtr<Region>rgn;
|
||||
if(winVisibleRgns[i]->empty())continue;
|
||||
rgn = Region::create();
|
||||
RefPtr<Region> rgn = Region::create();
|
||||
wSurfaces[i]->copy_clip_rectangle_list(clipRects);
|
||||
for(auto r:clipRects){
|
||||
Rect rc;
|
||||
@ -196,6 +193,11 @@ void GraphDevice::composeSurfaces(){
|
||||
rects+=rgn->get_num_rectangles();
|
||||
for(int j=0;j<rgn->get_num_rectangles();j++){
|
||||
RectangleInt rc=rgn->get_rectangle(j);
|
||||
Rect rcc={rc.x,rc.y,rc.width,rc.height};
|
||||
rcc.offset(rcw.left,rcw.top);
|
||||
rcc.intersect(0,0,width,height);
|
||||
if(rcc.empty())continue;
|
||||
|
||||
if(hdlSurface)GFXBlit(primarySurface , rcw.left+rc.x , rcw.top+rc.y , hdlSurface,(const GFXRect*)&rc);
|
||||
else primaryContext->rectangle(rcw.left+rc.x , rcw.top+rc.y, rc.width , rc.height);
|
||||
rcBlited.Union(rcw.left+rc.x , rcw.top+rc.y, rc.width , rc.height);
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
bool onKeyUp(int keyCode,KeyEvent& evt)override{
|
||||
LOGV("...%d flags=%x",keyCode,evt.getFlags());
|
||||
switch(keyCode){
|
||||
case KEY_ESCAPE:hide();return true;
|
||||
case KEY_ESCAPE:setVisibility(View::INVISIBLE);return true;
|
||||
default: return Window::onKeyDown(keyCode,evt);
|
||||
}
|
||||
}
|
||||
@ -222,14 +222,14 @@ void InputMethodManager::focusIn(View*view){
|
||||
|
||||
void InputMethodManager::focusOut(View*view){
|
||||
if(imeWindow){
|
||||
imeWindow->hide();
|
||||
imeWindow->setVisibility(View::INVISIBLE);
|
||||
}
|
||||
LOGV("view=%p %d",view,view->getId());
|
||||
}
|
||||
|
||||
void InputMethodManager::showIme(){
|
||||
LOGV("imeWindow=%p",imeWindow);
|
||||
if(imeWindow)imeWindow->show();
|
||||
if(imeWindow)imeWindow->setVisibility(View::VISIBLE);
|
||||
}
|
||||
|
||||
void InputMethodManager::sendKeyEvent(KeyEvent&k){
|
||||
@ -248,7 +248,7 @@ void InputMethodManager::setInputType(int inputType){
|
||||
}
|
||||
switch(mInputType){
|
||||
case EditText::TYPE_NONE:
|
||||
if(imeWindow)imeWindow->hide();
|
||||
if(imeWindow)imeWindow->setVisibility(View::INVISIBLE);
|
||||
break;
|
||||
default:
|
||||
if(imemethods.size()){
|
||||
|
@ -68,7 +68,6 @@ void WindowManager::addWindow(Window*win){
|
||||
Looper::getDefault()->addEventHandler(win->source);
|
||||
win->post(std::bind(&Window::onActive,win));
|
||||
activeWindow=win;
|
||||
//resetVisibleRegion();
|
||||
LOGV("win=%p source=%p windows.size=%d",win,win->source,windows.size());
|
||||
}
|
||||
|
||||
@ -79,7 +78,6 @@ void WindowManager::removeWindow(Window*w){
|
||||
auto itw=std::find(windows.begin(),windows.end(),w);
|
||||
const Rect wrect=w->getBound();
|
||||
windows.erase(itw);
|
||||
//resetVisibleRegion();
|
||||
for(auto itr=windows.begin();itr!=windows.end();itr++){
|
||||
Window*w1=(*itr);
|
||||
RECT rc=w1->getBound();
|
||||
@ -102,25 +100,13 @@ void WindowManager::removeWindow(Window*w){
|
||||
}
|
||||
|
||||
void WindowManager::moveWindow(Window*w,int x,int y){
|
||||
auto itw=std::find(windows.begin(),windows.end(),w);
|
||||
if(w->isAttachedToWindow()==false)return;
|
||||
if( (w->isAttachedToWindow()==false)||(w->getVisibility()!=View::VISIBLE))
|
||||
return;
|
||||
Rect rcw=w->getBound();
|
||||
GraphDevice::getInstance().invalidate(rcw);
|
||||
rcw.left=x;rcw.top=y;
|
||||
GraphDevice::getInstance().invalidate(rcw);
|
||||
for(auto itr=windows.begin();itr!=itw;itr++){
|
||||
RECT rcw=w->getBound();
|
||||
Window*w1=(*itr);
|
||||
RefPtr<Canvas>c=w1->getCanvas();
|
||||
RECT r=w1->getBound();
|
||||
if(w1->getVisibility()!=View::VISIBLE)continue;
|
||||
r.intersect(rcw);
|
||||
r.offset(-w1->getX(),-w1->getY());
|
||||
r=w1->getBound();
|
||||
rcw.left=x;rcw.top=y;
|
||||
r.intersect(rcw);
|
||||
r.offset(-w1->getX(),-w1->getY());
|
||||
}
|
||||
GraphDevice::getInstance().flip();
|
||||
}
|
||||
|
||||
int WindowManager::enumWindows(WNDENUMPROC cbk){
|
||||
|
@ -420,23 +420,25 @@ static void endElement(void *userData, const XML_Char *name){
|
||||
((StateListDrawable*)parent)->addState(state,topchild);
|
||||
LOGV("add drawable %p to StateListDrawable %p",topchild,parent);
|
||||
}else if(dynamic_cast<LevelListDrawable*>(parent)){
|
||||
int minLevel= atts.getInt("minLevel");//get child level info
|
||||
int maxLevel= atts.getInt("maxLevel");
|
||||
int minLevel= atts.getInt("minLevel",INT_MIN);//get child level info
|
||||
int maxLevel= atts.getInt("maxLevel",INT_MIN);
|
||||
if( minLevel == INT_MIN ) minLevel = maxLevel;
|
||||
if( maxLevel == INT_MIN ) maxLevel = minLevel;
|
||||
((LevelListDrawable*)parent)->addLevel(minLevel,maxLevel,topchild);
|
||||
LOGV("add drawable %p to LevelListDrawable %p level=(%d,%d)",topchild,parent,minLevel,maxLevel);
|
||||
}else if(dynamic_cast<LayerDrawable*>(parent)){
|
||||
LayerDrawable*ld=dynamic_cast<LayerDrawable*>(parent);
|
||||
int idx=ld->addLayer(topchild);
|
||||
const int idx=ld->addLayer(topchild);
|
||||
ld->setLayerInset(idx,atts.getDimensionPixelOffset("left"),atts.getDimensionPixelOffset("top"),
|
||||
atts.getDimensionPixelOffset("right"),atts.getDimensionPixelOffset("bottom"));
|
||||
ld->setLayerGravity(idx,atts.getGravity("gravity",0));
|
||||
int id=atts.getInt("id",-1);
|
||||
const int id=atts.getInt("id",-1);
|
||||
const std::string src=atts.getString("drawable");
|
||||
if(id!=-1)ld->setId(idx,id);
|
||||
LOGV("add drawable %pi[%s] to LayerDrawable %p index=%d id=%d",topchild,src.c_str(),parent,idx,id);
|
||||
}else if(dynamic_cast<AnimationDrawable*>(parent)){
|
||||
AnimationDrawable*ad=(AnimationDrawable*)parent;
|
||||
int duration=atts.getInt("duration",0);
|
||||
const int duration=atts.getInt("duration",0);
|
||||
const std::string src=atts.getString("drawable");
|
||||
ad->addFrame(topchild,duration);
|
||||
LOGV("add drawable %p[%s] to AnimationDrawable %p duration=%d",topchild,src.c_str(),parent,duration);
|
||||
|
@ -93,28 +93,11 @@ void Window::draw(){
|
||||
GraphDevice::getInstance().flip();
|
||||
}
|
||||
|
||||
void Window::show(){
|
||||
if(isAttachedToWindow()&&getVisibility()!=VISIBLE){
|
||||
setVisibility(VISIBLE);
|
||||
if(mAttachInfo->mCanvas==nullptr)
|
||||
invalidate(true);
|
||||
//WindowManager::getInstance().resetVisibleRegion();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::hide(){
|
||||
if(getVisibility()==VISIBLE){
|
||||
setVisibility(INVISIBLE);
|
||||
//WindowManager::getInstance().resetVisibleRegion();
|
||||
}
|
||||
}
|
||||
|
||||
View& Window::setPos(int x,int y){
|
||||
const bool changed =(x!=mLeft)||(mTop!=y);
|
||||
if( changed && isAttachedToWindow()){
|
||||
WindowManager::getInstance().moveWindow(this,x,y);
|
||||
ViewGroup::setPos(x,y);
|
||||
//WindowManager::getInstance().resetVisibleRegion();
|
||||
}
|
||||
GraphDevice::getInstance().flip();
|
||||
return *this;
|
||||
@ -124,6 +107,11 @@ void Window::onSizeChanged(int w,int h,int oldw,int oldh){
|
||||
//WindowManager::getInstance().resetVisibleRegion();
|
||||
}
|
||||
|
||||
void Window::onVisibilityChanged(View& changedView,int visibility){
|
||||
GraphDevice::getInstance().invalidate(getBound());
|
||||
GraphDevice::getInstance().flip();
|
||||
}
|
||||
|
||||
ViewGroup*Window::invalidateChildInParent(int* location,Rect& dirty){
|
||||
ViewGroup::invalidateChildInParent(location,dirty);
|
||||
invalidate(dirty);
|
||||
@ -140,7 +128,6 @@ RefPtr<Canvas>Window::getCanvas(){
|
||||
if(mAttachInfo==nullptr)return nullptr;
|
||||
RefPtr<Canvas> canvas=mAttachInfo->mCanvas;
|
||||
if((canvas==nullptr)&&(getVisibility()==VISIBLE)){
|
||||
//GraphDevice::getInstance().createContext(getBound());
|
||||
canvas=make_refptr_for_instance<Canvas>(new Canvas(getWidth(),getHeight()));
|
||||
mAttachInfo->mCanvas=canvas;
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ protected:
|
||||
class UIEventSource*source;
|
||||
void onFinishInflate()override;
|
||||
void onSizeChanged(int w,int h,int oldw,int oldh)override;
|
||||
void onVisibilityChanged(View& changedView,int visibility)override;
|
||||
ViewGroup*invalidateChildInParent(int* location,Rect& dirty)override;
|
||||
int processInputEvent(InputEvent&event);
|
||||
int processKeyEvent(KeyEvent&event);
|
||||
@ -80,8 +81,6 @@ public:
|
||||
void setRegion(const RefPtr<Region>®ion);
|
||||
void draw();
|
||||
virtual ~Window();
|
||||
virtual void show();
|
||||
virtual void hide();
|
||||
virtual void setText(const std::string&);
|
||||
const std::string getText()const;
|
||||
virtual View& setPos(int x,int y)override;
|
||||
|
Loading…
Reference in New Issue
Block a user