frame.cpp

来自「ncbi源码」· C++ 代码 · 共 242 行

CPP
242
字号
/* * =========================================================================== * PRODUCTION $Log: frame.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:09:06  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2 * PRODUCTION * =========================================================================== *//*  $Id: frame.cpp,v 1000.1 2004/06/01 21:09:06 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software / database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software / database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors:  Mike DiCuccio * * File Description: * */#include <ncbi_pch.hpp>#include <gui/widgets/fl/frame.hpp>#include <FL/Fl.H>#include <FL/fl_draw.H>BEGIN_NCBI_SCOPE////////////////////////////////////////////////////////////////////////////// CFlFrame//CFlFrame::CFlFrame(int x, int y, int w, int h, const char* label)    : Fl_Group(x, y, w, h, label){}int CFlFrame::align() const{    return Fl_Group::align();}void CFlFrame::align(int a){    Fl_Group::align(a | FL_ALIGN_INSIDE);}void CFlFrame::draw_label(){    // save and restore our font for rendering    int font_face = fl_font();    int font_size = fl_size();    int pos_x = x();    int pos_y = y();    fl_font(labelfont(), labelsize());    int text_wid = (int)fl_width(label());    int text_ht = labelsize();    _TRACE("text size: " << text_wid << ", " << text_ht);    // make sure we appear correctly    // the default is always the top    if (align() & FL_ALIGN_BOTTOM) {        pos_y += h() - (text_ht / 2) - 1;    } else {        pos_y -= (text_ht - 1) / 2;    }    int offs = 6;    if (align() & FL_ALIGN_LEFT) {        // left justified        pos_x += offs;    } else if (align() & FL_ALIGN_RIGHT) {        // right-justified        pos_x += (w() - text_wid - offs);    } else {        // centered        pos_x += (w() - text_wid) / 2;    }    draw_label(pos_x, pos_y, text_wid, text_ht);    fl_font(font_face, font_size);}void CFlFrame::draw_label(int x, int y, int w, int h){    fl_rectf(x - 2, y, w + 4, h, color());    fl_color(labelcolor());    fl_draw(label(), x, y, w, h, FL_ALIGN_CENTER);}void CFlFrame::draw(){    // call draw_children(), as we handle the rendering of the frame and label    if (damage() & ~FL_DAMAGE_CHILD) {        // label and frame get drawn        draw_box();        draw_label();    }    draw_children();}////////////////////////////////////////////////////////////////////////////// CFlEnabledFrame//static void s_toggle_frame(Fl_Widget* w, void* data){    CFlEnabledFrame* fw = static_cast<CFlEnabledFrame*>(data);    if (fw) {        fw->ToggleEnabled();    }}CFlEnabledFrame::CFlEnabledFrame(int x, int y, int w, int h, const char* label)    : CFlFrame(x, y, w, h, label)    , m_Button(x, y, w, h){    m_Button.label(label);    m_Button.box(FL_FLAT_BOX);    m_Button.callback(s_toggle_frame, this);}const char* CFlEnabledFrame::label() const{    return m_Button.label();}void CFlEnabledFrame::label(const char* l){    m_Button.label(l);}void CFlEnabledFrame::draw_label(int x, int y, int w, int h){    w += 20;    if (align() & FL_ALIGN_RIGHT) {        x -= 20;    }    m_Button.resize(x, y, w, h);    m_Button.redraw();}void CFlEnabledFrame::SetEnabled(bool b){    if (b) {        for (int i = 0;  i < children();  ++i) {            if (child(i) != &m_Button) {                child(i)->activate();            }        }    } else {        for (int i = 0;  i < children();  ++i) {            if (child(i) != &m_Button) {                child(i)->deactivate();            }        }    }    m_Button.value(b);    m_Button.redraw();}void CFlEnabledFrame::ToggleEnabled(){    SetEnabled( !m_Button.value() );    m_Button.value( !m_Button.value() );    /**    if (m_Button.value()) {        for (int i = 0;  i < children();  ++i) {            if (child(i) != &m_Button) {                child(i)->deactivate();            }        }    } else {        for (int i = 0;  i < children();  ++i) {            if (child(i) != &m_Button) {                child(i)->activate();            }        }    }    **/    Fl::focus(this);}END_NCBI_SCOPE/* * =========================================================================== * $Log: frame.cpp,v $ * Revision 1000.1  2004/06/01 21:09:06  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2 * * Revision 1.2  2004/05/21 22:27:53  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.1  2003/09/29 15:25:39  dicuccio * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?