static int sheepdrawing_pictureselect_keypress(liqcell *self, liqcellkeyeventargs *args,liqcell *sheepdrawing_pictureselect) { liqcell *search = liqcell_child_lookup(sheepdrawing_pictureselect,"search"); if(liqcell_getvisible(search)==0) { // start it just off screen liqcell_setpos( search, liqcell_getx(search), liqcell_geth(sheepdrawing_pictureselect) ); liqcell_setvisible(search,1); } return liqcell_handlerrun(search,"keypress",args); }
static int sheepdrawing_pictureselect_paint(liqcell *self, liqcellpainteventargs *args,liqcell *sheepdrawing_pictureselect) { liqcell *search = liqcell_child_lookup(sheepdrawing_pictureselect,"search"); if(liqcell_getvisible(search)) { if( liqcell_gety(search) > ( liqcell_geth(sheepdrawing_pictureselect) - liqcell_geth(search) ) ) { // move it a bit more onscreen int dif = liqcell_gety(search) - ( liqcell_geth(sheepdrawing_pictureselect) - liqcell_geth(search) ); //if(dif>5)dif=5; liqcell_setpos( search, liqcell_getx(search), liqcell_gety(search) - dif ); liqcell_setdirty(sheepdrawing_pictureselect,1); } } return 0; }
static int textbox_mouse(liqcell *self, liqcellmouseeventargs *args,void *context) { // if i have a font on my cell, surely it will have been rendered correctly first.. // infact, thats right i think //liqcell *base = liqcell_getbasewidget(self); //liqcell *body = self; liqfont *font = liqcell_getfont( self); if(!font)return 0; char *cap = liqcell_getcaption(self); if(!cap)return 0; // 20090814_184437 lcuk : if password, replace cap with string("*",len(cap)) for selection purposes char passbuff[1024]; if(liqcell_propgeti(self,"textispassword",0)) { int clen = strlen(cap); if(clen>=sizeof(passbuff)-1)clen=sizeof(passbuff)-1; int x; for(x=0;x<clen;x++)passbuff[x]='*'; passbuff[x]=0; cap=passbuff; } //int caplen = strlen(cap); //########################## // this tells me where abouts I am on a single line int mx = args->mex - liqcell_getx(self) - 8; // available space per line int my = args->mey - liqcell_gety(self) - 4; int chpos = liqfont_textfitinside(font,cap,mx); // char pos of selection //########################## // count all the lines #define linemax 128 char *linestarts[linemax]; int lineheight = liqfont_textheight(font); int lineoffsets[linemax]; int linelengths[linemax]; int linecount=0; char *c = cap; while(c && *c) { int tl = strlen(c); // total length remaining int lc = liqfont_textfitinside(font, c, liqcell_getw(self)-4 ); if(lc<tl) { int le = lc; while(le>0) { switch(c[le-1]) { case ' ': case ',': case ';': case ':': case '.': le--; break; default: goto fin; } } fin: if(le>0)lc=le; while(c[lc]==' ')lc++; } linestarts[linecount] = c; lineoffsets[linecount] = c-cap; linelengths[linecount] = lc; linecount++; c=&c[lc]; } //########################## // work out which line the mouse has hit int lx=mx; int ly=0; ly = my / lineheight; //liqapp_log("mx=%3i, my=%3i, chpos=%3i lx=%3i, ly=%3i",mx,my,chpos, lx,ly); if(ly>=linecount)ly=linecount-1; if(ly>=0) { // adjust chpos to make sure now we are selecting from the correct line chpos = lineoffsets[ly] + liqfont_textfitinside(font, linestarts[ly] ,mx); } // neat :) i know where the mouse clicked (left aligned text only...) // todo: handle other alignments if(args->mcnt==1) { // start of selection.. liqcell_propseti( self, "selfirst", chpos ); liqcell_propseti( self, "selstart", chpos ); liqcell_propseti( self, "sellength", 0 ); liqcell_propseti( self, "cursorpos", chpos ); } else { // extending selection int selfirst = liqcell_propgeti( self,"selfirst",chpos); int selstart; int sellength; if(chpos<selfirst) { // got to invert selstart=chpos; sellength=selfirst-chpos; } else { selstart=selfirst; sellength=chpos-selfirst; } liqcell_propseti( self, "selstart", selstart ); liqcell_propseti( self, "sellength", sellength ); liqcell_propseti( self, "cursorpos", chpos ); } return 1; }
// damn, this should be taken care of by the OS itself // this is because the hitpoint will not always match with where I think it will be // this is bad and good in practice static int textbox_mouse(liqcell *self, liqcellmouseeventargs *args,void *context) { // if i have a font on my cell, surely it will have been rendered correctly first.. // infact, thats right i think //liqcell *base = liqcell_getbasewidget(self); liqcell *body = self; liqfont *font = liqcell_getfont( self); if(!font)return 0; char *cap = liqcell_getcaption(self); if(!cap)return 0; int caplen = strlen(cap); int mx = args->mex - liqcell_getx(self); int chpos = liqfont_textfitinside(font,cap,mx); // neat :) i know where the mouse clicked (left aligned text only...) // todo: handle other alignments if(args->mcnt==1) { // start of selection.. liqcell_propseti( self, "selfirst", chpos ); liqcell_propseti( self, "selstart", chpos ); liqcell_propseti( self, "sellength", 0 ); liqcell_propseti( self, "cursorpos", chpos ); } else { // extending selection int selfirst = liqcell_propgeti( self,"selfirst",chpos); int selstart; int sellength; if(chpos<selfirst) { // got to invert selstart=chpos; sellength=selfirst-chpos; } else { selstart=selfirst; sellength=chpos-selfirst; } liqcell_propseti( self, "selstart", selstart ); liqcell_propseti( self, "sellength", sellength ); liqcell_propseti( self, "cursorpos", chpos ); } liqcell_handlerrun(self,"selchange",NULL); return 1; }
/** * liqcell_easyrun_mouseeventargs_multitouchprepare prepare the multitouch fields for use :) */ int liqcell_easyrun_mouseeventargs_multitouchprepare(liqcell *self, liqcellmouseeventargs *args,liqcell *context) { // if((args->msy-args->oy) >= (par->h*0.8)) { // 20090724_034021 lcuk : i'd like to try something here.. // 20090724_034233 lcuk : lets assume that the user has pressed for a time in the lower quadrant of a list // 20090724_034253 lcuk : which is why we are here now if(!liqmultitouch_f1) liqmultitouch_f1 = liqcell_quickcreatevis("f1",NULL,0,0,0,0); if(!liqmultitouch_f2) liqmultitouch_f2 = liqcell_quickcreatevis("f2",NULL,0,0,0,0); if(!liqmultitouch_f3) liqmultitouch_f3 = liqcell_quickcreatevis("f3",NULL,0,0,0,0); //liqcell *userf1 = liqcell_child_lookup(self, "userf1"); //liqcell *userf2 = liqcell_child_lookup(self, "userf2"); //liqcell *userf3 = liqcell_child_lookup(self, "userf3"); liqcell *userf1 = liqmultitouch_f1; liqcell *userf2 = liqmultitouch_f2; liqcell *userf3 = liqmultitouch_f3; if(userf1 && userf2 && userf3) { if( (args->mcnt == 1) ) { // starting, so lets make sure these are not visible.. liqcell_setvisible(userf1,0); liqcell_setvisible(userf2,0); liqcell_setvisible(userf3,0); liqcell_settag(userf1, NULL ); liqcell_settag(userf2, NULL ); liqcell_settag(userf3, NULL ); liqmultitouch_initrectfromliqpointstream(userf1 ,args->stroke->pointlast, 1,NULL); liqmultitouch_initrectfromliqpointstream(userf2,NULL, 1,NULL); liqmultitouch_initrectfromliqpointstream(userf3,NULL, 1,NULL); } else { float ml = sqrt((float)(args->mdx*args->mdx+args->mdy*args->mdy)); if( (args->mez > 0) ) { // continuing if(liqcell_gettag(userf1)==NULL) { // we are in normal single finger mode // depending on how far this step takes us we might split into a multitouch if(ml>35) { // bsg.hybrid.jump(); // set the starting point, so we know where to jump from liqcell_settag(userf1, args->stroke->pointlast->linkprev ); liqmultitouch_initrectfromliqpointstream(userf1 ,args->stroke->pointlast->linkprev, 1,NULL); // now, setup for userf2 liqmultitouch_initrectfromliqpointstream(userf2 ,args->stroke->pointlast, samplecount, (liqpoint *)liqcell_gettag(userf1)); // make sure we double the offset //liqcell_adjustpos(userf2, (liqcell_getcx(userf2)-liqcell_getcx(userf1))/2, (liqcell_getcy(userf2)-liqcell_getcy(userf1))/2 ); liqcell_setrect( userf3, liqcell_getx(userf2)+((liqcell_getcx(userf2)-liqcell_getcx(userf1))), liqcell_gety(userf2)+((liqcell_getcy(userf2)-liqcell_getcy(userf1))), liqcell_getw(userf2), liqcell_geth(userf2) ); liqcell_setvisible(userf3,liqcell_getvisible(userf2)); // store this first time away // this is the first identification of a second finger we have args->multifx = liqcell_getcx(userf1); args->multify = liqcell_getcy(userf1); } else { // carry on being single touch.. liqmultitouch_initrectfromliqpointstream(userf1 ,args->stroke->pointlast, 1,NULL); liqmultitouch_initrectfromliqpointstream(userf2,NULL, 1,NULL); liqcell_setrect( userf3, liqcell_getx(userf2)+((liqcell_getcx(userf2)-liqcell_getcx(userf1))), liqcell_gety(userf2)+((liqcell_getcy(userf2)-liqcell_getcy(userf1))), liqcell_getw(userf2), liqcell_geth(userf2) ); liqcell_setvisible(userf3,liqcell_getvisible(userf2)); } } else { // we already have a multitouch in progress // do not alter userf1 now, it is fixed and locked liqmultitouch_initrectfromliqpointstream(userf2 ,args->stroke->pointlast, samplecount, (liqpoint *)liqcell_gettag(userf1)); // make sure we double the offset //liqcell_adjustpos(userf2, (liqcell_getcx(userf2)-liqcell_getcx(userf1))/2, (liqcell_getcy(userf2)-liqcell_getcy(userf1))/2 ); liqcell_setrect( userf3, liqcell_getx(userf2)+((liqcell_getcx(userf2)-liqcell_getcx(userf1))), liqcell_gety(userf2)+((liqcell_getcy(userf2)-liqcell_getcy(userf1))), liqcell_getw(userf2), liqcell_geth(userf2) ); liqcell_setvisible(userf3,liqcell_getvisible(userf2)); } } else { // finishing // lets make sure we tell our source that we completed liqcell_settag(userf1, NULL ); liqcell_settag(userf2, NULL ); liqcell_settag(userf3, NULL ); liqcell_setvisible(userf1,0); liqcell_setvisible(userf2,0); liqcell_setvisible(userf3,0); } } } args->multiok = liqcell_getvisible(userf3); args->multisx = liqcell_getcx(userf1); args->multisy = liqcell_getcy(userf1); args->multix = liqcell_getcx(userf3); args->multiy = liqcell_getcy(userf3); args->multiw = liqcell_getw(userf3); args->multih = liqcell_geth(userf3); } return 0; }