Пример #1
0
bool BasicEditboxView::mouseDrag(int x, int y)
{
  int textheight = text_height(textfont);
  if(model->getSelection().isSelecting())
  {
    pair<int, int> oldsel = model->getSelection().getSelection();
    CharPos cp = findCharacter(x,y);
    model->getCursor().updateCursor(cp.totalIndex);
    model->getSelection().adjustSelection(model->getCursor());
    if(y < area_ystart)
    {
      view_y = zc_max(0, view_y-1);
    }
    if(y > area_ystart+area_height)
    {
      int ymost = zc_max(area_height, (int)model->getLines().size()*textheight);
      view_y = zc_min(ymost-area_height, view_y+1);
    }
    if(x < area_xstart)
      view_x = zc_max(0, view_x-1);
    if(x > area_xstart+area_width)
    {
      int xmost = zc_max(area_width, view_width);
      view_x = zc_min(xmost-area_width, view_x+1);
    }
    if(oldsel != model->getSelection().getSelection())
	{
      return true;
	}
  }
  return false;
}
Пример #2
0
void master_volume(int dv,int mv)
{
    if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
    
    if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
    
    int i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
    set_volume(digi_volume,mixvol(tunes[i].volume,midi_volume));
}
Пример #3
0
void BasicEditboxView::enforceHardLimits()
{
    int textheight = text_height(textfont);
    int ymost = zc_max(area_height, (int)model->getLines().size()*textheight);
    view_y = zc_max(view_y, 0);
    view_y = zc_min(view_y, ymost-area_height);
    int xmost = zc_max(area_width, view_width);
    view_x = zc_max(view_x, 0);
    view_x = zc_min(view_x, xmost-area_width);
}
Пример #4
0
void EditboxVScrollView::drawExtraComponents()
{
    int textheight = text_height(textfont);
    //draw the scrollbar
    draw_arrow_button(dbuf, toparrow_x-host->x, toparrow_y-host->y, 16, 16, true, toparrow_state*3);
    draw_arrow_button(dbuf, bottomarrow_x-host->x, bottomarrow_y-host->y, 16, 16, false, bottomarrow_state*3);
    
    if(!sbarpattern)
    {
        sbarpattern = create_bitmap_ex(bitmap_color_depth(screen),2,2);
        putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]);
        putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]);
        putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]);
        putpixel(sbarpattern, 0, 1, scheme[jcLIGHT]);
    }
    
    drawing_mode(DRAW_MODE_COPY_PATTERN, sbarpattern, 0, 0);
    int barstart = toparrow_y + 16 - host->y;
    int barend = bottomarrow_y - host->y-1;
    
    if(barstart < barend)
        rectfill(dbuf, toparrow_x-host->x, barstart, toparrow_x-host->x+15, barend, 0);
        
    solid_mode();
    //compute the bar button, based on view_y
    int totallen = (int)model->getLines().size()*textheight;
    int available = bottomarrow_y-(toparrow_y+16);
    
    if(available < 0)
    {
        baroff=barlen=0;
    }
    
    else
    {
        //area_height:totallen = barlen:available
        barlen = (available*area_height)/zc_max(totallen,area_height)+1;
        //clip to reasonable values
        barlen = zc_max(barlen, 8);
        baroff = zc_min(baroff, available-barlen);
        
        //view_y:(totallen-area_height) = baroff:(available-barlen)
        if(totallen <= area_height)
            baroff=0;
        else
            baroff = ((available-barlen)*view_y)/(totallen-area_height);
            
    }
    
    if(barlen > 0)
    {
        jwin_draw_button(dbuf, toparrow_x-host->x, toparrow_y+16-host->y+baroff, 16, barlen, false, 1);
    }
}
Пример #5
0
void BasicEditboxView::ensureCursorOnScreen()
{
    CursorPos cp = model->findCursor();
    int textheight = text_height(textfont);
    int cystart = cp.lineno*textheight;
    int cyend	= cystart+textheight;
    view_y = zc_min(view_y, cystart);
    view_y = zc_max(view_y, cyend-area_height);
    view_x = zc_min(view_x, cp.x);
    view_x = zc_max(view_x, cp.x-area_width);
    //enforce hard limits
    enforceHardLimits();
}
Пример #6
0
void get_midi_info(MIDI *midi, midi_info *mi)
{
    dword max_dt = 0;
    mi->tempo_changes = 0;
    bool gottempo = false;
    
    if(midi==NULL)
        goto done;
        
    for(int i=0; midi->track[i].len>0; i++)
    {
        byte *data = midi->track[i].data;
        
        if(data==NULL)
            break;
            
        dword total_dt=0;
        mi->event=0;
        mi->running_status = 0;
        // tempo info should only be in first track, but sometimes it isn't
        bool gettempo = (i==0)||(!gottempo);
        
        while(!eot(mi) && data - midi->track[i].data < midi->track[i].len)
        {
            parse_mtrk(&data,mi);
            total_dt += mi->dt;
            
            if(gettempo && mi->event==0xFF && mi->type==0x51 && mi->tempo_changes<MAX_TEMPO_CHANGES)
            {
                mi->tempo[mi->tempo_changes] = tempo(mi->buf);
                int tempo_c = mi->tempo_c[mi->tempo_changes] = beats(total_dt,midi->divisions);
                
                if(mi->tempo_changes==0 && tempo_c!=0)              // make sure there is a tempo at beat 0
                {
                    mi->tempo_c[0] = 0;
                    mi->tempo_c[1] = tempo_c;
                    mi->tempo[1] = mi->tempo[0];
                    mi->tempo_changes++;
                }
                
                mi->tempo_changes++;
                gottempo=true;
            }
        }
        
        max_dt = zc_max(max_dt,total_dt);
    }
    
done:

    if(mi->tempo_changes==0)                                  // then guess
    {
        mi->tempo_changes=1;
        mi->tempo[0]=120.0;
        mi->tempo_c[0]=0;
    }
    
    mi->len_beats = (midi==NULL) ? 0 : beats(max_dt,midi->divisions);
    mi->len_sec = (midi==NULL) ? 0 : runtime(mi->len_beats,mi);
}
Пример #7
0
void EditboxNoWrapView::drawExtraComponents()
{
    EditboxVScrollView::drawExtraComponents();
    int textheight;
    textheight = text_height(textfont);
    //draw the scrollbar
    draw_arrow_button_horiz(dbuf, leftarrow_x-host->x, leftarrow_y-host->y, 16, 16, true, leftarrow_state*3);
    draw_arrow_button_horiz(dbuf, rightarrow_x-host->x, rightarrow_y-host->y, 16, 16, false, rightarrow_state*3);
    drawing_mode(DRAW_MODE_COPY_PATTERN, sbarpattern, 0, 0);
    int hbarstart = leftarrow_x + 16 - host->x;
    int hbarend = rightarrow_x - host->x-1;
    
    if(hbarstart < hbarend)
        rectfill(dbuf, hbarstart, leftarrow_y-host->y, hbarend, leftarrow_y-host->y+15, 0);
        
    solid_mode();
    //compute the bar button, based on view_y
    int totallen = view_width;
    int available = rightarrow_x-(leftarrow_x+16);
    
    if(available < 0)
    {
        hbaroff=hbarlen=0;
    }
    
    else
    {
        //area_width:totallen = barlen:available
        hbarlen = (available*area_width)/zc_max(totallen,area_width)+1;
        //clip to reasonable values
        hbarlen = zc_max(hbarlen, 8);
        hbaroff = zc_min(hbaroff, available-hbarlen);
        
        //view_x:(totallen-area_width) = baroff:(available-hbarlen)
        if(totallen <= area_width)
            hbaroff = 0;
        else
            hbaroff = ((available-hbarlen)*view_x)/(totallen-area_width);
    }
    
    if(hbarlen > 0)
    {
        jwin_draw_button(dbuf, leftarrow_x-host->x+hbaroff+16, leftarrow_y-host->y, hbarlen, 16, false, 1);
    }
}
Пример #8
0
void EditboxView::invertRectangle(int x1, int y1, int x2, int y2)
{
    //I don't feel like dicking around with colormaps right now
    //this method is SLOOOW, big efficiency opportunity here
    static std::map<int, int> invmap;
    RGB color;
    //don't wast time drawing in stupid places
    x1 = zc_max(x1, 0);
    x1 = zc_min(x1, host->w);
    x2 = zc_max(x2,0);
    x2 = zc_min(x2, host->w);
    y1 = zc_max(y1, 0);
    y1 = zc_min(y1, host->h);
    y2 = zc_max(y2, 0);
    y2 = zc_min(y2, host->h);
    
    for(int i=x1; i<x2; i++)
    {
        for(int j=y1; j<y2; j++)
        {
            int c = getpixel(dbuf, i,j);
            
            if(c != -1)
            {
                std::map<int, int>::iterator it = invmap.find(c);
                int invcolor;
                
                if(it == invmap.end())
                {
                    Backend::palette->getPaletteEntry(c, color);
                    unsigned char r = 4*(((~color.r)&0x3F)+1)-1;
                    unsigned char g = 4*(((~color.g)&0x3F)+1)-1;
                    unsigned char b = 4*(((~color.b)&0x3F)+1)-1;
                    invcolor = makecol(r,g,b);
                    invmap[c] = invcolor;
                }
                else
                    invcolor = it->second;
                    
                putpixel(dbuf, i,j,invcolor);
            }
        }
    }
}
Пример #9
0
void BasicEditboxView::init()
{
    area_xstart = host->x+2;
    area_ystart = host->y+2;
    area_width = zc_max(0, host->w-20); //scrollbar
    area_height = host->h-4;
    view_width = area_width;
    
    //make the initial lines
    model->makeLines(model->getLines(), model->getBuffer());
}
Пример #10
0
void gamedata::set_counter(word change, byte c)
{
#ifdef DEBUG_GD_COUNTERS
    al_trace("Changing counter %i from %i to %i\n", c, _counter[c], change);
#endif
    
    if(c>=32)  // Sanity check
        return;
        
    if(game!=NULL)
    {
        int ringID=current_item_id(itype_ring, true);
        _counter[c]=zc_max(change, 0);
        
        // ringcolor is very slow, so make sure the ring has actually changed
        if(ringID!=current_item_id(itype_ring, true))
            ringcolor(false);
    }
    else
        _counter[c]=zc_max(change, 0);
        
    return;
}
Пример #11
0
int set_argument(char *argbuf, ffscript **script, int com, int argument)
{
    long *arg;
    
    if(argument)
    {
        arg = &((*script)[com].arg2);
    }
    else
    {
        arg = &((*script)[com].arg1);
    }
    
    int i=0;
    char tempvar[20];
    
    while(variable_list[i].id>-1)
    {
        if(variable_list[i].maxcount>1)
        {
            for(int j=0; j<variable_list[i].maxcount; ++j)
            {
                if(strcmp(variable_list[i].name,"A")==0)
                    sprintf(tempvar, "%s%d", variable_list[i].name, j+1);
                else sprintf(tempvar, "%s%d", variable_list[i].name, j);
                
                if(stricmp(argbuf,tempvar)==0)
                {
                    long temp = variable_list[i].id+(j*zc_max(1,variable_list[i].multiple));
                    *arg = temp;
                    return 1;
                }
            }
        }
        else
        {
            if(stricmp(argbuf,variable_list[i].name)==0)
            {
                *arg = variable_list[i].id;
                return 1;
            }
        }
        
        ++i;
    }
    
    return 0;
}
Пример #12
0
void gamedata::change_maxcounter(short change, byte c)
{
#ifdef DEBUG_GD_COUNTERS
    al_trace("Changing max counter %i from %i by +%i\n", c, _maxcounter[c], change);
#endif
    
    if(c==2)
    {
        change_maxbombs(change);
        return;
    }
    
    if(c>=32)  // Sanity check
        return;
        
    _maxcounter[c]=zc_max(0, _maxcounter[c]+change);
    return;
}
Пример #13
0
static int zc_arraylist_expand_inner(zc_arraylist_t * a_list, int max)
{
	void *tmp;
	int new_size;

	new_size = zc_max(a_list->size * 2, max);
	tmp = realloc(a_list->array, new_size * sizeof(void *));
	if (!tmp) {
		zc_error("realloc fail, errno[%d]", errno);
		free(a_list->array);
		return -1;
	}
	a_list->array = (void **)tmp;
	memset(a_list->array + a_list->size, 0x00,
	       (new_size - a_list->size) * sizeof(void *));
	a_list->size = new_size;
	return 0;
}
Пример #14
0
CharPos BasicEditboxView::findCharacter(int x, int y)
{
  int absolutey = y-area_ystart+view_y;
  int textheight = text_height(textfont);
  int lineno = absolutey/textheight;
  lineno = zc_max(lineno, 0);
  lineno = zc_min(lineno, (int)(model->getLines().size())-1);
  int totalindex = 0;
  //NOTE: future optimization opportunity
  list<LineData>::iterator it = model->getLines().begin();
  for(int i=0; i<lineno; i++)
  {
    totalindex += it->numchars;
    it++;
  }
  CharPos rval;
  rval.it = it;
  rval.lineIndex = Unicode::getIndexOfWidth(it->line, -area_xstart+x+view_x, textfont);
  rval.totalIndex = totalindex + rval.lineIndex;
  return rval;
}